zpywallet.address package

Submodules

zpywallet.address.blockcypher module

class BlockcypherClient(addresses, coin='BTC', chain='main', request_interval=(3, 1), transactions=None, **kwargs)[source]

Bases: AddressProvider

A class representing a list of crypto addresses.

This class allows you to retrieve the balance, UTXO set, and transaction history of a crypto address using Blockcypher.

DEFAULT_URL = 'https://api.blockcypher.com'
__init__(addresses, coin='BTC', chain='main', request_interval=(3, 1), transactions=None, **kwargs)[source]

Initializes an instance of the BlockcypherAddress class.

Parameters:
  • addresses (list) – A list of human-readable crypto addresses.

  • api_key (str) – The API key for accessing the Blockcypher API.

  • request_interval (tuple) – A pair of integers indicating the number of requests allowed during a particular amount of seconds. Set to (0,N) for no rate limiting, where N>0.

get_block_height()[source]

Retrieves the current block height.

Returns:

The current block height.

Return type:

int

Raises:

NetworkException – If the API request fails or the block height cannot be retrieved.

get_transaction_history()[source]

Retrieves the transaction history of the crypto address from cached data augmented with network data.

Returns:

A list of transaction objects.

Return type:

list

Raises:

NetworkException – If the API request fails or the transaction history cannot be retrieved.

convert_to_utc_timestamp(date_string, format_string='%Y-%m-%dT%H:%M:%SZ')[source]

zpywallet.address.blockstream module

class BlockstreamClient(addresses, coin='BTC', chain='main', request_interval=(3, 1), transactions=None, **kwargs)[source]

Bases: EsploraClient

A class representing a list of crypto testnet addresses.

This class allows you to retrieve the balance, UTXO set, and transaction history of a crypto testnet address using Blockstream.

zpywallet.address.cache module

class DatabaseConnection(dbmodule, connection_params)[source]

Bases: object

BLOB_TYPE = 'BLOB'
PLACEHOLDER = '?'
connect()[source]
disconnect()[source]
classmethod parse_connection_params(connection_params)[source]
static parse_uri(uri)[source]
placeholders(count)[source]
reconnect()[source]
upsert_sql(table, columns, conflict_column)[source]
exception DatabaseError[source]

Bases: Exception

class MySQLConnection(dbmodule, connection_params)[source]

Bases: DatabaseConnection

BLOB_TYPE = 'BLOB'
PLACEHOLDER = '%s'
upsert_sql(table, columns, _conflict_column)[source]
class PostgreSQLConnection(dbmodule, connection_params)[source]

Bases: DatabaseConnection

BLOB_TYPE = 'BYTEA'
PLACEHOLDER = '%s'
class SQLTransactionStorage(connection_params)[source]

Bases: object

clear_transactions()[source]
commit()[source]
connect()[source]
create_metadata_table()[source]
create_transactions_table()[source]
create_txos_table()[source]
delete_dropped_txids()[source]
delete_transaction(txid)[source]
disconnect()[source]
get_block_height()[source]
get_transaction_by_txid(txid)[source]
get_transactions_by_address(address)[source]
have_transaction(txid)[source]
reconnect()[source]
rollback()[source]
set_block_height(height)[source]
store_transaction(transaction)[source]
class SQLiteConnection(dbmodule, connection_params)[source]

Bases: DatabaseConnection

BLOB_TYPE = 'BLOB'
PLACEHOLDER = '?'
upsert_sql(table, columns, _conflict_column)[source]

zpywallet.address.esplora module

class EsploraClient(addresses, coin='BTC', chain='main', request_interval=(3, 1), transactions=None, **kwargs)[source]

Bases: AddressProvider

A class representing a list of crypto addresses.

This class allows you to retrieve the balance, UTXO set, and transaction history of a crypto address using an Esplora instance.

Esplora is a block explorer software used by a few websites, including mempool.space (rate limited) and blockstream.info.

Note: Esplora has a built-in limitation of returning up to 50 unconfirmed transactions per address.

Note 2: This API will not return the transaction inside the Genesis block. This will affect balance displayed for Satoshi’s first address 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa - but that output is unspendable for unrelated reasons.

__init__(addresses, coin='BTC', chain='main', request_interval=(3, 1), transactions=None, **kwargs)[source]

Initializes an instance of the EsploraClient class.

Parameters:
  • addresses (list) – A list of human-readable crypto addresses.

  • endpoint (str) – The Esplora endpoint to use.

  • request_interval (tuple) – A pair of integers indicating the number of requests allowed during a particular amount of seconds. Set to (0,N) for no rate limiting, where N>0.

get_block_height()[source]

Retrieves the current block height.

Returns:

The current block height.

Return type:

int

Raises:

NetworkException – If the API request fails or the block height cannot be retrieved.

get_transaction_history()[source]

Retrieves the transaction history of the crypto address from cached data augmented with network data.

Returns:

A list of dictionaries representing the transaction history.

Return type:

list

Raises:

NetworkException – If the API request fails or the transaction history cannot be retrieved.

zpywallet.address.fullnode module

class RPCClient(addresses, coin='BTC', chain='main', request_interval=(3, 1), transactions=None, **kwargs)[source]

Bases: AddressProvider

A class indexing all transactions in bitcoin-like blockchains and mempools into a database for quick fetching. It also lets you query transactions by address.

The performance of this class heavily depends on the network speed and CPU speed of the node as well as the number of threads available, the size of the RPC batch work queue specified in the constructor, and the amount of transactions in megabytes you are trying to fetch at once.

Additionally, the number of transactions returned depends on the number of transactions in the mempool itself and how well-connected the node is to other nodes. The longer you run your node and the more peers it has, the faster the mempool fills up with thransactions.

If you intend to use the mempool to track pending payments, it is recommended to update it once every 10 to 60 seconds for optimal user experience. However, if this mempool class is empty, it can take several minutes to fill it with the current mempool. As a result, you should do this while your app is initializing in order to avoid stuck processing workflows caused by slow mempool initialization.

The mempool class caches existing unconfirmed tranasctions so that they do not have to be fetched a second time, which should greatly improve performance and reduce waiting times during status updates.

This class does not work well with nodes running behind web servers that use rate limiting.

Requires a node running with -txindex.

get_block_height()[source]

Retrieves the current block height.

Returns:

The current block height.

Return type:

int

Raises:

NetworkException – If the API request fails or the block height cannot be retrieved.

get_transaction_history()[source]

Retrieves the transaction history of the addresses from cached data. Does not include Genesis blocks.

Returns:

A list of transaction objects.

Return type:

list

Raises:

NetworkException – If the RPC request fails or the transaction history cannot be retrieved.

read_mempool()[source]
read_transaction_history()[source]
transform_and_sort_transactions(data)[source]

zpywallet.address.loadbalancer module

class CryptoClient(addresses, coin='BTC', chain='main', use_database=False, transactions=None, **kwargs)[source]

Bases: AddressProvider

Represents a list of crypto addresses.

Developers should use this class, because it autoselects the most stable providers to fetch data from.

get_balance()[source]

Retrieves the balance of the crypto address.

Returns:

The total balance and the confirmed balance of the crypto address whole units e.g. BTC e.g. BTC.

Return type:

tuple

Raises:

NetworkException – If the API request fails or the address balance cannot be retrieved.

get_block_height()[source]

Retrieves the current block height.

Returns:

The current block height.

Return type:

int

Raises:

NetworkException – If the API request fails or the block height cannot be retrieved.

get_transaction_history()[source]

Retrieves the transaction history of the Litecoin address from cached data augmented with network data.

Returns:

A list of transaction objects.

Return type:

list

Raises:

NetworkException – If the API request fails or the transaction history cannot be retrieved.

initialize_database()[source]

zpywallet.address.mempoolspace module

class MempoolSpaceClient(addresses, coin='BTC', chain='main', request_interval=(3, 1), transactions=None, **kwargs)[source]

Bases: EsploraClient

A class representing a list of crypto testnet addresses.

This class allows you to retrieve the balance, UTXO set, and transaction history of a crypto testnet address using Mempool.space.

zpywallet.address.provider module

class AddressProvider(addresses, request_interval=(3, 1), transactions=None)[source]

Bases: object

A class representing a list of crypto addresses.

This class allows you to retrieve the balance, UTXO set, and transaction history of a crypto address. It is the base class of all other providers.

HTTPS_ADAPTER = 'https://'
__init__(addresses, request_interval=(3, 1), transactions=None)[source]

Initializes an instance of the BlockcypherAddress class.

Parameters:
  • addresses (list) – A list of human-readable crypto addresses.

  • api_key (str) – The API key for accessing the Blockcypher API.

  • request_interval (tuple) – A pair of integers indicating the number of requests allowed during a particular amount of seconds. Set to (0,N) for no rate limiting, where N>0.

deduplicate(elements)[source]
get_balance()[source]

Retrieves the balance of the crypto address.

Returns:

The total balance and the confirmed balance of the crypto address whole units e.g. BTC e.g. BTC.

Return type:

tuple

Raises:

NetworkException – If the API request fails or the address balance cannot be retrieved.

get_block_height()[source]

Retrieves the current block height.

Returns:

The current block height.

Return type:

int

get_transaction_history()[source]

Retrieves the transaction history of the crypto address from cached data augmented with network data.

Returns:

A list of transaction objects.

Return type:

list

get_utxos()[source]

Fetches the UTXO set for the addresses.

Returns:

A list of UTXOs

Return type:

list

zpywallet.address.web3node module

class Web3Client(addresses, coin='ETH', chain='main', transactions=None, **kwargs)[source]

Bases: object

A class indexing all transactions in ethereum-like blockchains into a database for quick fetching. It also lets you query transactions by address.

The performance of this class heavily depends on the network speed and CPU speed of the node as well as the number of threads available, the size of the RPC batch work queue specified in the constructor, and the amount of transactions in megabytes you are trying to fetch at once.

You can run a private node with many 3rd party providers such as Alchemy, Infura, QuickNode, and GetBlock.

WARNING: Ethereum nodes have a –txlookuplimit and keep only recent transactions, unless this option is turned off. 3rd party providers should have this disabled, but ensure it is turned off if you are running your own node.

get_balance()[source]

Retrieves the balance of the Ethereum address.

The ETH balance can be obtained without fetching the Ethereum transactions first.

Returns:

The balance of the Ethereum address in Gwei.

Return type:

int

Raises:

NetworkException – If the API request fails or the address balance cannot be retrieved.

get_block_height()[source]

Retrieves the current block height.

Returns:

The current block height.

Return type:

int

Raises:

NetworkException – If the API request fails or the block height cannot be retrieved.

get_transaction_history()[source]

Retrieves the transaction history of the addresses from cached data.

Returns:

A list of transaction objects.

Return type:

list

Raises:

NetworkException – If the RPC request fails or the transaction history cannot be retrieved.

read_mempool()[source]
add_web3_cache_middleware(middleware_onion)[source]
deduplicate(elements)[source]

Module contents