Bitcoin and Altcoin Wallets 6.2.5

Address extends Post_Type
in package

Address class

Represents a blockchain address. An address contains at least a string, and possibly a second string. It is also associated with a currency.

Create a new deposit address for current user

Here we assign a hardcoded string. Normally we'd be getting this string from a wallet adapter.

$bitcoin = \DSWallets\get_first_currency_by_symbol( 'BTC' );
if ( $bitcoin ) {
	$my_address           = new Address;
	$my_address->type     = 'deposit';
	$my_address->currency = $bitcoin;
	$my_address->user     = new \WP_User( get_current_user_id() );
	$my_address->address  = '1ADDRESSSTRINGFOOBAR';
	$my_address->label    = 'This is my foobar deposit address';

	try {
		$my_address->save();
	} catch ( \Exception $e ) {
		error_log( 'Could not save address due to: ' . $e->getMessage() );
	}

	if ( $my_address->post_id ) {
		error_log( "Address was saved with post_id: $my_address->post_id" );
	}
}

Iterate over all addresses for a user, in this case the current user:

$user_id = get_current_user_id();
$addresses = DSWallets\get_all_addresses_for_user_id( $user_id );
foreach ( $addresses as $address ) {
	error_log( $address );
	// do stuff with each address here
}

Create a new deposit address, or retrieve the existing address from the DB, if the address string already exists. We then proceed to set a label to that address.

	$my_address          = new Address;
	$my_address->type    = 'deposit';
	$my_address->user    = new \WP_User( get_current_user_id() );
	$my_address->address = '1ADDRESSSTRINGFOOBAR';

	$address_that_definitely_exists        = \DSWallets\get_or_make_address( $my_address );
	$address_that_definitely_exists->label = 'This is my foo bar deposit address';

	try {
		$address_that_definitely_exists->save();
	} catch ( \Exception $e ) {
		error_log( 'Could not save new address label due to: ' . $e->getMessage() );
	}
Tags
since
6.0.0

Introduced.

author

Alexandros Georgiou info@dashed-slug.net

Table of Contents

$post_id  : int
The id of the post that this object represents.
$address  : string|null
Base address string. Excludes any extra optional field.
$currency  : Currency|null
Currency associated with this address.
$extra  : string|null
Extra optional field (payment_id, memo, etc).
$label  : string|null
Optional label.
$type  : string
Address type.
$user  : WP_User|null
User.
__get()  : mixed
Allows getting one of this object's fields.
__set()  : mixed
Sets a field of this Address object.
__toString()  : string
To String.
delete()  : mixed
Trashes this object in the DB.
load()  : Address
Load an Address from its custom post entry.
save()  : void
Saves this object to the DB.
render_bool_field()  : mixed
render_boolean_field()  : mixed
render_number_field()  : mixed
render_secret_field()  : mixed
render_select_field()  : mixed
render_string_field()  : mixed
render_strings_field()  : mixed

Properties

$address

Base address string. Excludes any extra optional field.

private string|null $address

$currency

Currency associated with this address.

private Currency|null $currency

Also points to the wallet.

$extra

Extra optional field (payment_id, memo, etc).

private string|null $extra

$label

Optional label.

private string|null $label

A user text associated with this address. This is only for display to the user. Free text string, stored on the post_title column in the DB.

$type

Address type.

private string $type

Can be deposit or withdrawal.

$user

User.

private WP_User|null $user

Deposits to the address count towards this user's balance.

Methods

__get()

Allows getting one of this object's fields.

public __get(string $name) : mixed
Parameters
$name : string

Can be: post_id, address, extra, type, currency, user, label.

Tags
see
Post_Type::__get()
Return values
mixed

__set()

Sets a field of this Address object.

public __set(string $name, mixed $value) : mixed
Parameters
$name : string

Can be: post_id, address, extra, type, currency, user, label.

$value : mixed

The value to set to the field.

Tags
see
Post_Type::__set()
throws
InvalidArgumentException

If value is not appropriate for field or if field does not exist.

Return values
mixed

delete()

Trashes this object in the DB.

public delete([mixed $force = false ]) : mixed
Parameters
$force : mixed = false
Tags
throws
Exception

If the object was not on the DB or if it could not be trashed.

Return values
mixed

load()

Load an Address from its custom post entry.

public static load(int $post_id) : Address
Parameters
$post_id : int

The post_id for the object to load.

Tags
inheritdoc
see
Post_Type::load()
Return values
Address

save()

Saves this object to the DB.

public save() : void

If the object already had a post_id, then the post is updated. Else, a new custom post is created and the new post_id is assigned to the object.

Return values
void

render_bool_field()

protected static render_bool_field(mixed $schema, mixed $value) : mixed
Parameters
$schema : mixed
$value : mixed
Return values
mixed

render_boolean_field()

protected static render_boolean_field(mixed $schema, mixed $value) : mixed
Parameters
$schema : mixed
$value : mixed
Return values
mixed

render_number_field()

protected static render_number_field(mixed $schema, mixed $value) : mixed
Parameters
$schema : mixed
$value : mixed
Return values
mixed

render_secret_field()

protected static render_secret_field(mixed $schema, mixed $value) : mixed
Parameters
$schema : mixed
$value : mixed
Return values
mixed

render_select_field()

protected static render_select_field(mixed $schema, mixed $value) : mixed
Parameters
$schema : mixed
$value : mixed
Return values
mixed

render_string_field()

protected static render_string_field(mixed $schema, mixed $value) : mixed
Parameters
$schema : mixed
$value : mixed
Return values
mixed

render_strings_field()

protected static render_strings_field(mixed $schema, mixed $value) : mixed
Parameters
$schema : mixed
$value : mixed
Return values
mixed

Search results