DaemonRPC

class nerva.daemon.DaemonRPC(*, host='localhost', port=17566, ssl=False, timeout=10.0, username=None, password=None)

Bases: object

A class to interact with the Nerva daemon’s JSON-RPC interface.

Parameters:
  • host (str, optional) – The host of the daemon.

  • port (int, optional) – The port of the daemon.

  • ssl (bool, optional) – Whether to use SSL.

  • timeout (float, optional) – The timeout for the request.

  • username (Optional[str])

  • password (Optional[str])

url

The URL of the daemon.

Type:

str

timeout

The timeout for the request.

Type:

float

headers

The headers for the request.

Type:

dict[str, str]

async get_block_count()

Get the current block count.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async on_get_block_hash(*, height)

Get the block hash at a certain height.

Parameters:

height (int) – The height of the block.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_block_template(*, wallet_address, reserve_size)

Get a block template for mining.

Parameters:
  • wallet_address (str) – The wallet address to mine to.

  • reserve_size (int) – The reserve size.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async submit_block(*, block_blob)

Submit a block to the network.

Parameters:

block_blob (list[str]) – The block blob to submit.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_last_block_header()

Get the last block header.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_block_header_by_hash(*, block_hash)

Get the block header by hash.

Parameters:

block_hash (str) – The hash of the block.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_block_header_by_height(*, height)

Get the block header by height.

Parameters:

height (int) – The height of the block.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_block_headers_range(*, start_height, end_height)

Get a range of block headers.

Parameters:
  • start_height (int) – The start height.

  • end_height (int) – The end height.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_block(*, block_hash=None, height=None)

Get a block by hash or height.

Parameters:
  • block_hash (str, optional) – The hash of the block.

  • height (int, optional) – The height of the block.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_connections()

Get the connections to the daemon.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_info()

Get the information about the daemon.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async hard_fork_info()

Get the hard fork information.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async set_bans(*, bans)

Set bans for the daemon.

Parameters:

bans (list[dict[str, Any]]) –

The bans to set. Each ban should be a dictionary with the following keys:
  • hoststr

    Host to ban (IP in A.B.C.D format).

  • ipint, optional

    IP to ban (int format).

  • banbool

    Set true to ban, false to unban.

  • secondsint

    Time to ban in seconds.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_bans()

Get the bans of the daemon.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async flush_txpool(*, txids=None)

Flush the transaction pool.

Parameters:

txids (list, optional) – The transaction IDs to flush. If not provided, all transactions will be flushed.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_output_histogram(*, amounts, min_count, max_count, unlocked, recent_cutoff)

Get the output histogram.

Parameters:
  • amounts (list) – The amounts to get the histogram for.

  • min_count (int) – The minimum count.

  • max_count (int) – The maximum count.

  • unlocked (bool) – Whether to get the unlocked outputs.

  • recent_cutoff (int) – The recent cutoff.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_version()

Get the version of the daemon.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_coinbase_tx_sum(*, height, count)

Get the coinbase transaction sum.

Parameters:
  • height (int) – The height of the block.

  • count (int) – The count of blocks.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_fee_estimate(*, grace_blocks=None)

Get the fee estimate.

Parameters:

grace_blocks (int, optional) – The number of grace blocks.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_alternate_chains()

Get the alternate chains.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async relay_tx(*, txids)

Relay transactions to the network.

Parameters:

txids (list) – The transaction IDs to relay.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async sync_info()

Get the sync information of the daemon.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_txpool_backlog()

Get the transaction pool backlog.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_output_distribution(*, amounts, from_height=0, to_height=0, cumulative=False, binary=True, compress=False)

Get the output distribution.

Parameters:
  • amounts (list[int]) – The amounts to get the distribution for.

  • from_height (int, optional) – The height to start from.

  • to_height (int, optional) – The height to end at.

  • cumulative (bool, optional) – Whether to get the cumulative distribution.

  • binary (bool, optional) – Whether to get the binary distribution.

  • compress (bool, optional) – Whether to compress the distribution.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async prune_blockchain()

Prune the blockchain.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async flush_cache(*, bad_txs=False)

Flush the cache.

Parameters:

bad_txs (bool, optional) – Whether to flush the bad transactions.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_generated_coins(*, height=None)

Get the generated coins.

Parameters:

height (int, optional) – The height.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_min_version()

Get the minimum version of the daemon.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async get_tx_pubkey(*, extra)

Get the transaction public key.

Parameters:

extra (str) – The extra data.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async decode_outputs(*, tx_hashes, sec_view_key, address)

Decode the outputs of transactions.

Parameters:
  • tx_hashes (list) – The transaction hashes.

  • sec_view_key (str) – The secret view key.

  • address (str) – The address to decode.

Returns:

The response from the daemon.

Return type:

dict[str, Any]

async add_peer(*, host)

Add a peer to the daemon.

Parameters:

host (str) – The host of the peer.

Returns:

The response from the daemon.

Return type:

dict[str, Any]