Wallet_Adapter
in package
The wallet adapter is an object that abstracts communication with a wallet backend.
Wallet backends can represent connections to one (e.g. Bitcoin core, Litecoin core, etc) or more (e.g. CoinPayments) actual coin wallets. The adapter encapsulates any connection settings. It receives these settings from the wallets-wallet custom post type. The settings are passed as an array into the constructor. The adapter exposes methods that allow processing transactions and retrieving info from the wallet.
Tags
Table of Contents
- $settings : mixed
- $settings_schema : mixed
- $wallet : mixed
- __construct() : mixed
- __get() : mixed|null
- Get a setting automagically
- __set() : mixed
- do_cron() : void
- Do periodic tasks related to this adapter.
- do_description_text() : void
- Render a short description of what this adapter is about.
- do_move() : bool
- Perform additional tasks before an internal debit transaction.
- do_withdrawals() : void
- Perform a batch of withdrawals, possibly in one transaction.
- get_block_height() : int|null
- Block height
- get_extra_field_name() : null|string
- Return the extra field for addresses associated with this currency, if any.
- get_hot_available_balance() : int
- Retrieve the hot wallet balance that is available for immediate use.
- get_hot_balance() : int
- Retrieve the hot wallet balance.
- get_hot_locked_balance() : int
- get_new_address() : Address
- Create a new address for this wallet.
- get_settings_schema() : array<string|int, array<string|int, mixed>>
- Return the settings schema for this adapter.
- get_wallet_version() : string
- Wallet backend version
- is_locked() : bool
- Determines if withdrawals are locked.
- do_deposit() : int|null
- Process a potential deposit transaction.
- validate_tcp_ip_address() : bool
- Validate an IP address.
Properties
$settings
protected
mixed
$settings
= []
$settings_schema
protected
mixed
$settings_schema
= []
$wallet
protected
mixed
$wallet
Methods
__construct()
public
__construct(Wallet $wallet) : mixed
Parameters
- $wallet : Wallet
Return values
mixed —__get()
Get a setting automagically
public
__get(string $id) : mixed|null
Parameters
- $id : string
-
The ID of the setting.
Return values
mixed|null —The setting's value, or the setting's default value, or NULL if the setting was not found.
__set()
public
__set(mixed $id, mixed $value) : mixed
Parameters
- $id : mixed
- $value : mixed
Return values
mixed —do_cron()
Do periodic tasks related to this adapter.
public
do_cron([callable|null $log = null ]) : void
The plugin will call this periodically. Adapters can optionally perform arbitrary periodic tasks, as needed. Add here any housekeeping tasks specific to the type of wallet that this adapter connects to.
Parameters
- $log : callable|null = null
-
The log function.
Tags
Return values
void —do_description_text()
Render a short description of what this adapter is about.
public
abstract do_description_text() : void
A short description of this adapter, explaining what type of wallet it connects to.
Tags
Return values
void —do_move()
Perform additional tasks before an internal debit transaction.
public
do_move(Transaction $debit) : bool
Most adapters will NOT need to override this.
Every time an internal transfer is executed, the corresponding adapter is notified first. If the adapter returns false, then the transaction will be marked with "failed" status. The adapter can also set an error message in the transaction:
$debit->error = 'I do not like this tranasction!';
The adapter can get the corresponding credit transaction with:
$credit = $debit->get_other_tx();
Parameters
- $debit : Transaction
-
The debit transaction (the one that removes balance from the sender).
Return values
bool —Whether the internal transfer should proceed.
do_withdrawals()
Perform a batch of withdrawals, possibly in one transaction.
public
do_withdrawals(array<string|int, Transaction> $withdrawals) : void
The method takes an array of Transactions and executes them. The method sets the following data into the transactions before returning them:
- actual fees paid
- TXID
- block height
The Transactions passed must all be of the same currency. The adapter does not have to be able to cater to different currencies in one call. Subclasses can call this parent implementation to perform these checks, before proceeding to withdraw a batch of transactions.
Parameters
- $withdrawals : array<string|int, Transaction>
-
Array of transactions to process. The transactions may be modified.
Tags
Return values
void —get_block_height()
Block height
public
abstract get_block_height([Currency|null $currency = null ]) : int|null
Parameters
- $currency : Currency|null = null
-
If the wallet supports multiple currencies, pass the desired currency here.
Tags
Return values
int|null —The block height up to which the connected wallet is synced currently or null if block height cannot be determined.
get_extra_field_name()
Return the extra field for addresses associated with this currency, if any.
public
get_extra_field_name([Currency|null $currency = null ]) : null|string
For example: Destination Tag, Payment ID, Memo, etc.
Parameters
- $currency : Currency|null = null
-
The currency to query for. Useful only for adapters to multi-currency wallets.
Tags
Return values
null|string —The name of the field, or null if the field is not used.
get_hot_available_balance()
Retrieve the hot wallet balance that is available for immediate use.
public
get_hot_available_balance([Currency|null $currency = null ]) : int
Available balance excludes any funds that are not mature. Immature funds are those that originate from transaction that have a low confimation count, or any funds that are mined too recently, or locked in other pending withdrawals in the wallet.
Parameters
- $currency : Currency|null = null
-
If the wallet supports multiple currencies, pass the desired currency here.
Tags
Return values
int —The available balance as an integer.
get_hot_balance()
Retrieve the hot wallet balance.
public
abstract get_hot_balance([Currency|null $currency = null ]) : int
Parameters
- $currency : Currency|null = null
-
If the wallet supports multiple currencies, pass the desired currency here.
Tags
Return values
int —The balance as an integer.
get_hot_locked_balance()
public
abstract get_hot_locked_balance([Currency|null $currency = null ]) : int
Parameters
- $currency : Currency|null = null
Return values
int —get_new_address()
Create a new address for this wallet.
public
abstract get_new_address([Currency|null $currency = null ]) : Address
Will generate a new address
Parameters
- $currency : Currency|null = null
-
If the wallet supports multiple currencies, pass the desired currency here.
Tags
Return values
Address —The object encapsulating the new address.
get_settings_schema()
Return the settings schema for this adapter.
public
final get_settings_schema() : array<string|int, array<string|int, mixed>>
This schema can be used to render input form fields in the wallets-wallet metaboxes.
Tags
Return values
array<string|int, array<string|int, mixed>> —The schema is an array of arrays with the following fields each: id, name, type, description.
get_wallet_version()
Wallet backend version
public
abstract get_wallet_version() : string
Tags
Return values
string —The version of the currently connected wallet, if available.
is_locked()
Determines if withdrawals are locked.
public
abstract is_locked() : bool
A wallet can be locked for withdrawals if the necessary secrets are not available, or for any other reasaon.
Tags
Return values
bool —True if withdrawals cannot be performed at this time.
do_deposit()
Process a potential deposit transaction.
protected
final do_deposit( $potential_deposit) : int|null
This takes a Transaction object that is still in memory and looks up the deposit addresses to see if it corresponds to a user address. If the deposit concerns an existing user, the deposit is stored to the DB and the address's action slug is triggered with the transaction data as its first argument. Existing deposits are not re-created.
Concrete implementations of this abstact class must call this method to notify the plugin of any potential deposits. Since the adapter does not know which deposits correspond to users, it can notify the plugin about all potential deposits. The plugin will discard any invalid deposits.
Parameters
- $potential_deposit :
-
A Transaction that does not yet have a user assigned to it and is not saved to the DB.
Return values
int|null —The Transaction post_id or null if the Transaction is of no interest to us/was not saved.
validate_tcp_ip_address()
Validate an IP address.
protected
validate_tcp_ip_address(string $address) : bool
Parameters
- $address : string