Monero Utilities¶
MoneroUtils ¶
Collection of Monero utilities.
atomic_units_to_xmr(amount_atomic_units) staticmethod ¶
Convert atomic units to XMR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount_atomic_units | int | amount in atomic units to convert to XMR. | required |
Returns:
| Type | Description |
|---|---|
float | amount in XMR. |
binary_blocks_fast_to_json(bin) staticmethod ¶
Deserialize blocks JSON string from the daemon's fast (get_blocks.bin) binary format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin | bytes | blocks JSON string in the fast binary format. | required |
Returns:
| Type | Description |
|---|---|
str | The deserialized blocks in JSON string format. |
binary_blocks_to_json(bin) staticmethod ¶
Deserialize blocks JSON string from binary format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin | bytes | blocks JSON string in binary format. | required |
Returns:
| Type | Description |
|---|---|
str | The deserialized blocks in JSON string format. |
binary_to_dict(bin) staticmethod ¶
Deserialize a dictionary from binary format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin | bytes | Dictionary in binary format. | required |
Returns:
| Type | Description |
|---|---|
dict[Any, Any] | Deserialized dictionary. |
binary_to_json(bin) staticmethod ¶
Deserialize a JSON string from binary format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin | bytes | JSON string in binary format. | required |
Returns:
| Type | Description |
|---|---|
str | The deserialized JSON string. |
configure_logging(path, console) staticmethod ¶
Initialize logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | the path to write logs to. | required |
console | bool | specifies whether or not to write to the console. | required |
dict_to_binary(dictionary) staticmethod ¶
Converts a dictionary into binary format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dictionary | dict | The dictionary to convert in binary format. | required |
Returns:
| Type | Description |
|---|---|
bytes | Binary format. |
get_blocks_from_outputs(outputs) staticmethod ¶
Get distinct blocks from outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs | list[MoneroOutputWallet] | Outputs to get blocks from. | required |
Returns:
| Type | Description |
|---|---|
list[MoneroBlock] | Distinct blocks obtained from outputs. |
get_blocks_from_transfers(transfers) staticmethod ¶
Get distinct blocks from transfers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transfers | list[MoneroTransfer] | Transfers to get blocks from. | required |
Returns:
| Type | Description |
|---|---|
list[MoneroBlock] | Distinct blocks obtained from transfers. |
get_blocks_from_txs(txs) staticmethod ¶
Get distinct blocks from transactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
txs | list[MoneroTxWallet] | Transactions to get blocks from. | required |
Returns:
| Type | Description |
|---|---|
list[MoneroBlock] | Distinct blocks obtained from transactions. |
get_integrated_address(network_type, standard_address, payment_id='') staticmethod ¶
Get an integrated address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_type | MoneroNetworkType | is the network type of the integrated address. | required |
standard_address | str | is the address to derive the integrated address from. | required |
payment_id | str | optionally specifies the integrated address's payment id (defaults to random payment id). | '' |
Returns:
| Type | Description |
|---|---|
MoneroIntegratedAddress | the integrated address. |
get_payment_uri(config, network_type=MoneroNetworkType.MAINNET) staticmethod ¶
Creates a payment URI from a tx configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | MoneroTxConfig | specifies configuration for a payment URI. | required |
network_type | MoneroNetworkType | address network type (optional). | MAINNET |
Returns:
| Type | Description |
|---|---|
str | the payment URI. |
get_ring_size() staticmethod ¶
Get network-enforced ring size.
Returns:
| Type | Description |
|---|---|
int | network-enforced ring size. |
get_version() staticmethod ¶
Get the version of the monero-python library.
Returns:
| Type | Description |
|---|---|
str | the version of this monero-python library |
is_valid_address(address, network_type) staticmethod ¶
Determine if the given address is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address | str | is the address to validate. | required |
network_type | MoneroNetworkType | is the address's network type. | required |
Returns:
| Type | Description |
|---|---|
bool |
|
is_valid_language(language) staticmethod ¶
Indicates if the given language is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language | str | is the language to validate | required |
Returns:
| Type | Description |
|---|---|
bool |
|
is_valid_mnemonic(mnemonic, language='') staticmethod ¶
Indicates if a mnemonic is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mnemonic | str | is the mnemonic to validate. | required |
language | str | is the mnemonic expected language. | '' |
Returns:
| Type | Description |
|---|---|
bool |
|
is_valid_payment_id(payment_id) staticmethod ¶
Indicates if a payment id is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payment_id | str | is the payment id to validate. | required |
Returns:
| Type | Description |
|---|---|
bool |
|
is_valid_private_spend_key(private_spend_key) staticmethod ¶
Indicates if a private spend key is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
private_spend_key | str | is the private spend key to validate. | required |
Returns:
| Type | Description |
|---|---|
bool |
|
is_valid_private_view_key(private_view_key) staticmethod ¶
Indicates if a private view key is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
private_view_key | str | is the private view key to validate. | required |
Returns:
| Type | Description |
|---|---|
bool |
|
is_valid_public_spend_key(public_spend_key) staticmethod ¶
Indicates if a public spend key is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
public_spend_key | str | is the public spend key to validate. | required |
Returns:
| Type | Description |
|---|---|
bool |
|
is_valid_public_view_key(public_view_key) staticmethod ¶
Indicates if a public view key is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
public_view_key | str | is the public view key to validate. | required |
Returns:
| Type | Description |
|---|---|
bool |
|
json_to_binary(json) staticmethod ¶
Convert a JSON string into binary format.
Returns:
| Type | Description |
|---|---|
bytes | Binary format. |
log_debug(message) staticmethod ¶
Log debug message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | the message to log. | required |
log_error(message) staticmethod ¶
Log error message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | the message to log. | required |
log_info(message) staticmethod ¶
Log info message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | the message to log. | required |
log_trace(message) staticmethod ¶
Log trace message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | the message to log. | required |
log_warning(message) staticmethod ¶
Log warning message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | the message to log. | required |
set_log_categories(categories) staticmethod ¶
Set the library's log categories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
categories | str | the library's log categories to set. | required |
set_log_level(loglevel) staticmethod ¶
Set the library's log level with 0 being least verbose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loglevel | int | the library's log level. | required |
validate_address(address, network_type) staticmethod ¶
Validates the given address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address | str | is the address to validate. | required |
network_type | MoneroNetworkType | is the address's network type. | required |
validate_mnemonic(mnemonic, language='') staticmethod ¶
Validates the given mnemonic phrase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mnemonic | str | is the mnemonic to validate. | required |
language | str | is the mnemonic expected language. | '' |
Raises:
| Type | Description |
|---|---|
MoneroError | if the given mnemonic is invalid. |
validate_payment_id(payment_id) staticmethod ¶
Validate a payment id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payment_id | str | is the payment id to validate. | required |
Raises:
| Type | Description |
|---|---|
MoneroError | if the given payment id is invalid. |
validate_private_spend_key(private_spend_key) staticmethod ¶
Validate a private spend key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
private_spend_key | str | is the private spend key to validate. | required |
Raises:
| Type | Description |
|---|---|
MoneroError | if the given private spend key is invalid. |
validate_private_view_key(private_view_key) staticmethod ¶
Validate a private view key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
private_view_key | str | is the private view key to validate. | required |
Raises:
| Type | Description |
|---|---|
MoneroError | if the given private view key is invalid. |
validate_public_spend_key(public_spend_key) staticmethod ¶
Validate a public spend key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
public_spend_key | str | is the public spend key to validate. | required |
Raises:
| Type | Description |
|---|---|
MoneroError | if the given public spend key is invalid. |
validate_public_view_key(public_view_key) staticmethod ¶
Validate a public view key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
public_view_key | str | is the public view key to validate. | required |
Raises:
| Type | Description |
|---|---|
MoneroError | if the given public view key is invalid. |
xmr_to_atomic_units(amount_xmr) staticmethod ¶
Convert XMR to atomic units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount_xmr | float | amount in XMR to convert to atomic units. | required |
Returns:
| Type | Description |
|---|---|
int | amount in atomic units. |
GenUtils ¶
Bases: ABC
Collection of generic utilities.
bool_equals(val, opt_val) staticmethod ¶
Compare a bool to an optional bool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val | bool | value to compare. | required |
opt_val | bool|None | optional value to compare against; | required |
Returns:
| Type | Description |
|---|---|
bool |
|
get_uuid() staticmethod ¶
Return a random unique identifier.
Returns:
| Type | Description |
|---|---|
str | a unique id. |
reconcile_bool(val1, val2, resolve_defined=None, resolve_true=None, resolve_max=None, err_msg='') staticmethod ¶
Reconcile two optional bools to a single value, the same logic used internally to merge model fields (e.g. MoneroTx.merge()).
- If both are equal (including both
None), returns that value. - If exactly one is
None, returns the other, unlessresolve_definedisFalse, in which caseNoneis returned. - Otherwise, if both are set and differ:
resolve_truepicks whichever operand equalsresolve_true; elseresolve_maxpicks the greater (True) or lesser (False) of the two, treatingTrueas 1 andFalseas 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val1 | bool|None | first value. | required |
val2 | bool|None | second value. | required |
resolve_defined | bool|None | when only one side is set and this is | None |
resolve_true | bool|None | when both sides are set and differ, prefer whichever operand equals this value. | None |
resolve_max | bool|None | when both sides are set and differ (and | None |
err_msg | str | extra context appended to the error message on conflict. | '' |
Returns:
| Type | Description |
|---|---|
bool | None | the reconciled value. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If none of the above resolves. |
reconcile_string(val1, val2, resolve_defined=None, resolve_true=None, resolve_max=None, err_msg='') staticmethod ¶
Reconcile two optional strings. Unlike the bool/int overloads, resolve_true/resolve_max are accepted for signature symmetry but are not used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val1 | str|None | first value. | required |
val2 | str|None | second value. | required |
resolve_defined | bool|None | see | None |
resolve_true | bool|None | accepted but ignored. | None |
resolve_max | bool|None | accepted but ignored. | None |
err_msg | str | extra context appended to the error message on conflict. | '' |
Returns:
| Type | Description |
|---|---|
str | None | the reconciled value. |
Raises:
| Type | Description |
|---|---|
RuntimeError | on different strings always regardless of |
reconcile_string_list(v1, v2, err_msg='') staticmethod ¶
Reconcile two string lists: equal lists are returned as-is, an empty list yields the other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v1 | list[str] | first list. | required |
v2 | list[str] | second list. | required |
err_msg | str | extra context appended to the error message on conflict. | '' |
Returns:
| Type | Description |
|---|---|
list[str] | the reconciled list. |
Raises:
| Type | Description |
|---|---|
RuntimeError | on two different non-empty lists. |
reconcile_uint64(val1, val2, resolve_defined=None, resolve_true=None, resolve_max=None, err_msg='') staticmethod ¶
Reconcile two optional unsigned 64-bit integers. See reconcile_bool for the resolution rules (resolve_max here picks the numeric max/min).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val1 | int|None | first value. | required |
val2 | int|None | second value. | required |
resolve_defined | bool|None | see | None |
resolve_true | bool|None | see | None |
resolve_max | bool|None | prefer the larger ( | None |
err_msg | str | extra context appended to the error message on conflict. | '' |
Returns:
| Type | Description |
|---|---|
int | None | the reconciled value. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If none of the above resolves. |
wait_for(duration_ms) staticmethod ¶
Block the calling thread for the given duration. Releases the GIL while sleeping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration_ms | int | duration to wait, in milliseconds. | required |
Raises:
| Type | Description |
|---|---|
TypeError | Must be a non-negative number that fits in a valid |
Comparators¶
TxHeightComparator ¶
Compares two transactions by their height.
compare(tx1, tx2) staticmethod ¶
Compare two transactions by height.
Unconfirmed transactions (no block) sort after confirmed ones; when both are unconfirmed or share the same height and block, their original order within the block's tx list is preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tx1 | MoneroTx | first transaction to compare. | required |
tx2 | MoneroTx | second transaction to compare. | required |
Returns:
| Type | Description |
|---|---|
bool |
|
IncomingTransferComparator ¶
Compares two incoming transfers by ascending account and subaddress indices.
compare(transfer1, transfer2) staticmethod ¶
Compare two incoming transfers.
Compares by transaction height first (see TxHeightComparator), then by account index, then by subaddress index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transfer1 | MoneroIncomingTransfer | first transfer to compare. | required |
transfer2 | MoneroIncomingTransfer | second transfer to compare. | required |
Returns:
| Type | Description |
|---|---|
bool |
|
OutputComparator ¶
Compares two wallet outputs by ascending account, subaddress and output index.
compare(output1, output2) staticmethod ¶
Compare two wallet outputs.
Compares by transaction height first (see TxHeightComparator), then by account index, subaddress index, output index and finally key image hex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output1 | MoneroOutputWallet | first output to compare. | required |
output2 | MoneroOutputWallet | second output to compare. | required |
Returns:
| Type | Description |
|---|---|
bool |
|