# \Dashed_Slug_Wallets

The core of this plugin.

Provides an API for other plugins and themes to perform wallet actions, bound to the current logged in user.

## Summary

Methods
Properties
Constants
get_instance()
get_coin_adapters()
add_option()
update_option()
get_option()
delete_option()
get_balance()
get_transactions()
do_withdraw()
do_move()
get_deposit_address()
get_new_address()
get_exchange_rate()
is_fiat()
is_crypto()
No public properties found
ERR_GET_USERS_INFO
ERR_GET_COINS_INFO
ERR_GET_TRANSACTIONS
ERR_DO_WITHDRAW
ERR_DO_MOVE
ERR_NOT_LOGGED_IN
ERR_NOT_ALLOWED
No protected methods found
No protected properties found
N/A
get_exchange_rate_fixer()
get_exchange_rate_bittrex()
file_get_cached_contents()
No private properties found
N/A
final

File
  wallets-core.php
Package
  Default
Class hierarchy
  \Dashed_Slug_Wallets

## Tags

None found

## Constants

### ERR_GET_USERS_INFO

    ERR_GET_USERS_INFO

error code for exception thrown while getting user info

#

## Tags

None found

### ERR_GET_COINS_INFO

    ERR_GET_COINS_INFO

error code for exception thrown while getting coins info

#

## Tags

None found

### ERR_GET_TRANSACTIONS

    ERR_GET_TRANSACTIONS

error code for exception thrown while getting transactions

#

## Tags

None found

### ERR_DO_WITHDRAW

    ERR_DO_WITHDRAW

error code for exception thrown while performing withdrawals

#

## Tags

None found

### ERR_DO_MOVE

    ERR_DO_MOVE

error code for exception thrown while transferring funds between users

#

## Tags

None found

### ERR_NOT_LOGGED_IN

    ERR_NOT_LOGGED_IN

error code for exception thrown due to user not being logged in

#

## Tags

None found

### ERR_NOT_ALLOWED

    ERR_NOT_ALLOWED

error code for exception thrown due to insufficient capabilities

#

## Tags

None found

## Methods

### get_instance()

    get_instance()

Returns the singleton core of this plugin that provides the application-facing API.

@api

#

static

## Tags

since | 1.0.0 Introduced @return object The singleton instance of this class.

### get_coin_adapters()

    get_coin_adapters(string  $symbol = null, boolean  $check_capabilities = false) : \Dashed_Slug_Wallets_Coin_Adapter|array

Returns the coin adapter for the symbol specified, or an associative array of all the adapters if the symbol is omitted.

The adapters provide the low-level API for talking to the various wallets.

#### Parameters

string | $symbol | (Usually) three-letter symbol of the wallet's coin.
boolean | $check_capabilities | Capabilities are checked if set to true. Default: false.

#### Throws

\Exception

  If the operation fails. Exception code will be one of Dashed_SlugWallets::ERR*.

#### Returns

\Dashed_Slug_Wallets_Coin_Adapter|array —

The instance of the adapter or array of adapters requested.

#

## Tags

since | 2.2.0 Only returns enabled adapters 2.1.0 Added $check_capabilities argument 1.0.0 Introduced

### add_option()

    add_option(string  $option, mixed  $value) : boolean

This helper delegates to add_site_option if the plugin is network activated on a multisite install, or to add_option otherwise.

#### Parameters

string | $option | The option name.
mixed | $value | The option value.

#### Returns

boolean —

The result of the wrapped function.

#

static

See also
  https://developer.wordpress.org/reference/functions/add_site_option/
  https://developer.wordpress.org/reference/functions/add_option/

## Tags

since | 2.4.0 Added

### update_option()

    update_option(string  $option, mixed  $value) : boolean

This helper delegates to update_site_option if the plugin is network activated on a multisite install, or to update_option otherwise.

#### Parameters

string | $option | The option name.
mixed | $value | The option value.

#### Returns

boolean —

The result of the wrapped function.

#

static

See also
  https://developer.wordpress.org/reference/functions/update_site_option/
  https://developer.wordpress.org/reference/functions/update_option/

## Tags

since | 2.4.0 Added

### get_option()

    get_option(string  $option,   $default = false) : boolean

This helper delegates to get_site_option if the plugin is network activated on a multisite install, or to get_option otherwise.

#### Parameters

string | $option | The option name.
| $default |

#### Returns

boolean —

The result of the wrapped function.

#

static

See also
  https://developer.wordpress.org/reference/functions/get_site_option/
  https://developer.wordpress.org/reference/functions/get_option/

## Tags

since | 2.4.0 Added

### delete_option()

    delete_option(string  $option) : boolean

This helper delegates to delete_site_option if the plugin is network activated on a multisite install, or to delete_option otherwise.

#### Parameters

string | $option | The option name.

#### Returns

boolean —

The result of the wrapped function.

#

static

See also
  https://developer.wordpress.org/reference/functions/delete_site_option/
  https://developer.wordpress.org/reference/functions/delete_option/

## Tags

since | 2.4.0 Added

### get_balance()

    get_balance(string  $symbol, null  $minconf = null, boolean  $check_capabilities = false, integer  $account = null) : float

Get user's wallet balance.

Get the current logged in user's total wallet balance for a specific coin. Only transactions with status = 'done' are counted. This replaces the previous filtering based on the $minconf argument.

#### Parameters

string | $symbol | (Usually) three-letter symbol of the wallet's coin.
null | $minconf | Ignored.
boolean | $check_capabilities | Capabilities are checked if set to true. Default: false.
integer | $account | The user_id of the account to check, or null to retrieve logged in account's balance. Default: null.

#### Throws

\Exception

  If the operation fails. Exception code will be one of Dashed_SlugWallets::ERR*.

#### Returns

float —

The balance.

#

## Tags

api |
since | 2.3.0 The $minconf parameter is deprecated. 2.1.0 Added $check_capabilities argument. 1.0.0 Introduced

### get_transactions()

    get_transactions(string  $symbol, integer  $count = 10, integer  $from, integer  $minconf = null, boolean  $check_capabilities = false) : array

Get transactions of current logged in user.

Returns the deposits, withdrawals and intra-user transfers initiated by the current logged in user for the specified coin.

#### Parameters

string | $symbol | Character symbol of the wallet's coin.
integer | $count | Maximal number of transactions to return.
integer | $from | Start retrieving transactions from this offset.
integer | $minconf | (optional) Minimum number of confirmations for deposits and withdrawals. If left out, the default adapter setting is used.
boolean | $check_capabilities | Capabilities are checked if set to true. Default: false.

#### Throws

\Exception

  If the operation fails. Exception code will be one of Dashed_SlugWallets::ERR*.

#### Returns

array —

The transactions.

#

## Tags

api |
since | 2.1.0 Added $check_capabilities argument 1.0.0 Introduced

### do_withdraw()

    do_withdraw(string  $symbol, string  $address, float  $amount, string  $comment = '', string  $comment_to = '', boolean  $check_capabilities = false, boolean  $skip_confirm = false) : void

Withdraw from current logged in user's account.

#### Parameters

string | $symbol | Character symbol of the wallet's coin.
string | $address | Address to withdraw to.
float | $amount | Amount to withdraw to.
string | $comment | Optional comment to attach to the transaction.
string | $comment_to | Optional comment to attach to the destination address.
boolean | $check_capabilities | Capabilities are checked if set to true. Default: false.
boolean | $skip_confirm | Set to true if the transaction should not require confirmations. Useful for feature extensions.

#### Throws

\Exception

  If the operation fails. Exception code will be one of Dashed_SlugWallets::ERR*.

#

## Tags

api |
since | 2.4.0 Added $skip_confirm argument. 2.3.0 Only inserts a pending transaction. The transaction is to be executed after being accepted by the user and/or admin. 2.1.0 Added $check_capabilities argument 1.0.0 Introduced

### do_move()

    do_move(string  $symbol, integer  $toaccount, float  $amount, string  $comment, boolean  $check_capabilities = false, string  $tags = '', boolean  $skip_confirm = false, integer|null  $fromaccount = null) : void

Move funds from the current logged in user's balance to the specified user.

#### Parameters

string | $symbol | Character symbol of the wallet's coin.
integer | $toaccount | The WordPress user_ID of the recipient.
float | $amount | Amount to withdraw to.
string | $comment | Optional comment to attach to the transaction.
boolean | $check_capabilities | Capabilities are checked if set to true. Default: false.
string | $tags | A space separated list of tags, slugs, etc that further describe the type of transaction.
boolean | $skip_confirm | Set to true if the transaction should not require confirmations. Useful for feature extensions.
integer|null | $fromaccount | The WordPress user_ID of the sender, or null for current user ID.

#### Throws

\Exception

  If move fails. Exception code will be one of Dashed_SlugWallets::ERR*.

#

## Tags

api |
since | 2.4.2 Added $fromaccount. 2.4.0 Added $skip_confirm argument. 2.3.0 Only inserts a pending transaction. The transaction is to be executed after being accepted by the user and/or admin. 2.1.0 Added $check_capabilities argument 1.0.0 Introduced

### get_deposit_address()

    get_deposit_address(string  $symbol,   $account = null, boolean  $check_capabilities = false) : string

Get a deposit address for the current logged in user's account.

#### Parameters

string | $symbol | Character symbol of the wallet's coin.
| $account |
boolean | $check_capabilities | Capabilities are checked if set to true. Default: false.

#### Throws

\Exception

  If the operation fails.

#### Returns

string —

A deposit address associated with the current logged in user.

#

## Tags

api |
since | 2.4.2 Introduced to replace get_new_address

### get_new_address()

    get_new_address(string  $symbol, boolean  $check_capabilities = false) : string

Get a deposit address for the current logged in user's account.

#### Parameters

string | $symbol | Character symbol of the wallet's coin.
boolean | $check_capabilities | Capabilities are checked if set to true. Default: false.

#### Throws

\Exception

  If the operation fails. Exception code will be one of Dashed_SlugWallets::ERR*.

#### Returns

string —

A deposit address associated with the current logged in user.

#

#### Deprecated

Use get_deposit_address instead.

See also
  \Dashed_Slug_Wallets::get_deposit_address()

## Tags

api |
since | 2.4.2 Superseeded by get_deposit_address 2.1.0 Added $check_capabilities argument 1.0.0 Introduced

### get_exchange_rate()

    get_exchange_rate(string  $from, string  $to) : boolean|\number

Returns the exchange rate between two fiat currencies or cryptocurrencies, using fixer.io and bittrex.

example: get_exchange_rate( 'USD', 'BTC' ) would return

#### Parameters

string | $from | The currency to convert from.
string | $to | The currency to convert to.

#### Returns

boolean|\number —

Exchange rate or false.

#

static

## Tags

None found

### is_fiat()

    is_fiat(  $symbol)

#### Parameters

| $symbol |

#

static

## Tags

None found

### is_crypto()

    is_crypto(  $symbol)

#### Parameters

| $symbol |

#

static

## Tags

None found

### get_exchange_rate_fixer()

    get_exchange_rate_fixer(  $from,   $to)

#### Parameters

| $from |
| $to |

#

static

## Tags

None found

### get_exchange_rate_bittrex()

    get_exchange_rate_bittrex(  $from,   $to)

#### Parameters

| $from |
| $to |

#

static

## Tags

None found

### file_get_cached_contents()

    file_get_cached_contents(  $url)

#### Parameters

| $url |

#

static

## Tags

None found

### wallets-core.php