BlockStore

BlockStore

class BlockStore(**kwargs)

Implements the blockstore api endpoints.

addressindexer_tip(**kwargs) AddressIndexerTipModel

Retrieves the address indexer tip.

Parameters

**kwargs – Extra keyword arguments.

Returns

The address indexer tip hash and height.

Return type

AddressIndexerTipModel

Raises

APIError – Error thrown by node API. See message for details.

block(block_hash: Union[uint256, str], show_transaction_details: bool = True, output_json: bool = True, **kwargs) Union[BlockModel, BlockTransactionDetailsModel, hexstr, str]

Retrieves the block which matches the supplied block hash.

Parameters
  • block_hash (uint256, str) – The hash of the required block.

  • show_transaction_details (bool, optional) – A flag that indicates whether to return each block transaction complete with details or simply return transaction hashes. Default=True.

  • output_json (bool) – Output json or hex block. Default=True.

  • **kwargs – Extra keyword arguments.

Returns

The representation of the block.

Return type

(BlockModel, BlockTransactionDetailsModel, hexstr, str)

Raises

APIError – Error thrown by node API. See message for details.

get_block_count(**kwargs) int

Gets the current block count.

Parameters

**kwargs – Extra keyword arguments.

Returns

The current block count.

Return type

int

Raises

APIError – Error thrown by node API. See message for details.

get_addresses_balances(addresses: Union[List[Union[Address, str]], Address, str], min_confirmations: int = 0, **kwargs) GetAddressesBalancesModel

Provides balance of the given addresses confirmed with at least min_confirmations confirmations.

Requires addressindex=1 in node configuration.

Parameters
  • addresses (List(Address, str), Address, str) – A list of addresses or single address to query.

  • min_confirmations (int, optional) – Only blocks below consensus tip less this parameter will be considered. Default=0.

  • **kwargs – Extra keyword arguments.

Returns

The balances of the given address(es).

Return type

GetAddressesBalancesModel

Raises

APIError – Error thrown by node API. See message for details.

get_verbose_addresses_balances(addresses: Union[List[Union[Address, str]], Address, str], **kwargs) GetVerboseAddressesBalancesModel

Provides verbose balance data of the given addresses.

Parameters
  • addresses (List(Address, str), Address, str) – A list of addresses or single address to query.

  • **kwargs – Extra keyword arguments.

Returns

A verbose accounting of the balances of the specified address(es).

Return type

GetVerboseAddressesBalancesModel

Raises

APIError – Error thrown by node API. See message for details.

get_utxo_set(at_block_height: int, **kwargs) List[UTXOModel]

Gets the UTXO set at the specified block height.

Parameters
  • at_block_height (int) – The specified block height.

  • **kwargs – Extra keyword arguments.

Returns

A list of UTXO at the given height.

Return type

List[UTXOModel]

Raises

APIError – Error thrown by node API. See message for details.

get_last_balance_update_transaction(address: Union[Address, str], **kwargs) Optional[GetLastBalanceUpdateTransactionModel]

Gets the transaction information for a transaction last updating the given address.

Parameters
  • address (Address) – An address to query.

  • **kwargs – Extra keyword arguments.

Returns

Returns the information on the last transaction if the transaction exists, otherwise None.

Return type

(GetLastBalanceUpdateTransactionModel, None)

Raises

APIError – Error thrown by node API. See message for details.

get_utxoset_for_address(address: Union[Address, str], **kwargs) Optional[GetUTXOsForAddressModel]

Gets the utxoset and balance information for the given address.

Parameters
  • address (Address) – An address to query.

  • **kwargs – Extra keyword arguments.

Returns

Returns the current balance and utxo set for the given address.

Return type

(GetUTXOsForAddressModel, None)

Raises

APIError – Error thrown by node API. See message for details.

AddressBalanceModel

class AddressBalanceModel(*, address: Address, balance: Money)

A pydantic model representing an address and balance.

address: Address

Am address validated on the current network.

balance: Money

The balance in coin units.

AddressIndexerTipModel

class AddressIndexerTipModel(*, tipHash: uint256, tipHeight: int)

A pydantic model for the address indexer tip.

tip_hash: uint256

The block hash of the block at the address indexer tip.

tip_height: int

The block height of the address indexer tip.

BalanceChangesModel

class BalanceChangesModel(*, deposited: bool, satoshi: int, balanceChangedHeight: int)

A pydantic model representing changes in balance at a given address.

deposited: bool

If true, amount was received. False if value was withdrawn.

satoshi: int

The value of the amount changed, in satoshi.

balance_changed_height: int

The height of the block containing the transaction.

BlockModel

class BlockModel(*, hash: uint256, confirmations: int, size: int, weight: int, height: int, version: int, versionHex: str, merkleroot: hexstr, tx: List[uint256] = None, time: datetime.datetime, mediantime: datetime.datetime, nonce: int, bits: str, difficulty: float, chainwork: str, nTx: int, previousblockhash: uint256 = None, nextblockhash: uint256 = None, signature: str = None, modifierv2: str = None, flags: str = None, hashproof: str = None, blocktrust: str = None, chaintrust: str = None)

A pydantic model of a block.

hash: uint256

The block hash.

confirmations: int

The number of confirmations.

size: int

The size of the block.

weight: int

The weight of the block.

height: int

The height of the block.

version: int

The block version.

version_hex: str

The block version in hex.

merkleroot: hexstr

The block merkleroot.

tx: Optional[List[uint256]]

A list of transactions in the block.

time: datetime.datetime

The time the block was produced.

median_time: datetime.datetime

The median time.

nonce: int

The block’s nonce.

bits: str

The block bits.

difficulty: float

The block difficulty.

chainwork: str

The chain work.

n_tx: int

The number of transactions in the block.

previous_blockhash: Optional[uint256]

The previous block hash.

next_blockhash: Optional[uint256]

The next block hash.

signature: Optional[str]

The signature.

modifier_v2: Optional[str]

The block modifier.

flags: Optional[str]

Block flags.

hashproof: Optional[str]

Block hashproof.

blocktrust: Optional[str]

Blocktrust.

chaintrust: Optional[str]

Chaintrust.

BlockTransactionDetailsModel

class BlockTransactionDetailsModel(*, hash: uint256, confirmations: int, size: int, weight: int, height: int, version: int, versionHex: str, merkleroot: hexstr, tx: List[uint256] = None, time: datetime.datetime, mediantime: datetime.datetime, nonce: int, bits: str, difficulty: float, chainwork: str, nTx: int, previousblockhash: uint256 = None, nextblockhash: uint256 = None, signature: str = None, modifierv2: str = None, flags: str = None, hashproof: str = None, blocktrust: str = None, chaintrust: str = None, Transactions: List[TransactionModel])

A pydantic model for block transaction details.

transactions: List[TransactionModel]

A list of transactions.

hash: uint256

The block hash.

confirmations: int

The number of confirmations.

size: int

The size of the block.

weight: int

The weight of the block.

height: int

The height of the block.

version: int

The block version.

version_hex: str

The block version in hex.

merkleroot: hexstr

The block merkleroot.

tx: Optional[List[uint256]]

A list of transactions in the block.

time: datetime

The time the block was produced.

median_time: datetime

The median time.

nonce: int

The block’s nonce.

bits: str

The block bits.

difficulty: float

The block difficulty.

chainwork: str

The chain work.

n_tx: int

The number of transactions in the block.

previous_blockhash: Optional[uint256]

The previous block hash.

next_blockhash: Optional[uint256]

The next block hash.

signature: Optional[str]

The signature.

modifier_v2: Optional[str]

The block modifier.

flags: Optional[str]

Block flags.

hashproof: Optional[str]

Block hashproof.

blocktrust: Optional[str]

Blocktrust.

chaintrust: Optional[str]

Chaintrust.

GetAddressesBalancesModel

class GetAddressesBalancesModel(*, balances: List[AddressBalanceModel], reason: str = None)

A pydantic model for retrieving multiple address balances.

balances: List[AddressBalanceModel]

A list of addresses with current balances.

reason: Optional[str]

If query failed, a reason is given.

GetLastBalanceUpdateTransactionModel

class GetLastBalanceUpdateTransactionModel(*, transaction: TransactionModel, blockHeight: int)

A pydantic model containing information about there last transaction where a balance changed for an address.

transaction: TransactionModel

The transaction model containing the last balance update of the given address.

block_height: int

The block height for the last transaction for the given address.

GetUTXOsForAddressModel

class GetUTXOsForAddressModel(*, balance: Money, utxos: List[UTXOModel])

A pydantic model representing unspent transaction outputs (utxos) and balance for a given address.

balance: Money

The address balance.

utxos: List[UTXOModel]

A list of utxos for the given address.

GetVerboseAddressesBalancesModel

class GetVerboseAddressesBalancesModel(*, balancesData: List[VerboseAddressBalanceModel], consensusTipHeight: int, reason: str = None)

A pydantic model representing verbose address balance information.

balances_data: List[VerboseAddressBalanceModel]

A list of verbose address balance data for the given addresses.

consensus_tip_height: int

The current consensus tip height.

reason: Optional[str]

If query failed, a reason is given.

UtxoModel

class UTXOModel(*, txId: uint256, index: int, scriptPubKey: str, value: Money)

A pydantic model representing a unspent transaction output (utxo).

transaction_id: uint256

The transaction hash of the transaction containing the utxo.

index: int

The output index of the utxo.

script_pubkey: str

The scriptpubkey of the utxo.

value: Money

The value of the utxo in coin units.

VerboseAddressBalanceModel

class VerboseAddressBalanceModel(*, address: Address, balanceChanges: List[BalanceChangesModel])

A pydantic model that verbosely lists balance changes for a given address.

address: Address

The given address.

balance_changes: List[BalanceChangesModel]

A list of balance changes for the given address.