siliqua.network package

Submodules

siliqua.network.exceptions module

exception siliqua.network.exceptions.UnsupportedProtocolVersion(required_version, current_version)

Bases: ValueError

The protocol version supported by the NANO node is too old.

Module contents

class siliqua.network.AccountSyncStatus(account_id, head_hash=None)

Bases: object

Account sync status.

Sync status is tracked to determine when account has finished syncing and is therefore ready to pocket pending NANO.

Variables
  • account_id (str) – Account ID being tracked

  • wallet_head (str) – Block hash of latest block in the local wallet

  • network_head (str) – Block hash of last block retrieved from the network

  • sync_complete (bool) – Whether sync is complete. This means that no new blocks were found during the last round of updates.

  • timestamp – Timestamp for the last check

property ready_to_pocket

Whether this account is ready to pocket pending blocks.

Network and wallet head must match and sync must be complete.

property seconds_since_timestamp
update_timestamp()
class siliqua.network.ConnectionStatus

Bases: object

Connection status to the NANO network

Variables
  • connected (bool) – Whether connection has been established to the network (this may mean a NANO node)

  • aborted (bool) – If the connection was aborted due to a fatal error.

  • timestamp – Timestamp of the last successful request to the network

  • error – Exception that caused the connection to be aborted. This is available if aborted is True

  • completed_rounds (int) – How many rounds of updates have been completed

  • sync_complete (bool) – Whether the network plugin has finished syncing all accounts

  • meta (dict) – Dictionary that can be used to hold arbitrary connection-related information

abort(error=None)

Mark the connection as aborted.

Parameters

error – Exception that caused the connection to be aborted

update(connected)

Update the connection status.

This is called when any response has been completed, regardless of whether it succeeded or failed

Parameters

connected (bool) – Whether the connection has been established

class siliqua.network.BlockSyncResult(block, confirmed=False, rejected=False, error=None)

Bases: siliqua.util.BlockProxy

Result of a block that has been received from or broadcast on the network.

Block can be confirmed or rejected; in latter case, BlockProcessError is provided.

Variables
  • confirmed (bool) – Is the block confirmed

  • rejected (bool) – Is the block rejected

  • block – Block instance

  • errorBlockProcessError instance, if the block was rejected

block
confirmed
error
rejected
class siliqua.network.BlockSetQueue(maxsize=0)

Bases: queue.Queue

FIFO queue that accepts Block instances

remove(block)

Remove specific block from the queue

Returns

Returned block or None if no block was removed

class siliqua.network.BaseNetworkPlugin(**kwargs)

Bases: siliqua.plugins.BasePlugin

Base class used for network plugins.

Each network plugin has three queues to transmit blocks between the siliqua.server.WalletServer instance and the network:

  • processed_block_queue

    • confirmed blocks that have been retrieved from the network

  • siliqua.network.BaseNetworkPlugin.pocketable_block_queue

    • blocks that can be pocketed by accounts currently in the wallet

  • siliqua.network.BaseNetworkPlugin.broadcast_block_queue

    • blocks that currently only exist in the wallet and can be confirmed by broadcasting them into the network

siliqua.network.BaseNetworkPlugin.account_sync_statuses is a mapping of account IDs to siliqua.network.AccountSyncStatus instances to keep track of accounts that belong to the wallet and which may need syncing.

PLUGIN_TYPE = 'network'
add_blocks_to_broadcast(blocks)

Add blocks into the broadcast queue to be eventually broadcast into the network

Parameters

blocks (List[siliqua.wallet.accounts.Block]) – List of blocks to broadcast

property connected
Returns

Is the network plugin connected to the NANO network

Return type

bool

get_pocketable_blocks()

Get all the pocketable blocks from the queue

Returns

List of pocketable blocks

get_processed_blocks()

Get all the processed blocks from the queue

Returns

List of processed blocks

reload()

Reload the network plugin

start()

Start the network plugin

property started
Returns

Is the network plugin started

Return type

bool

stop()

Stop the network server.

update_accounts_to_sync(wallet)

Update the list of account IDs to sync from the wallet

Parameters

wallet (siliqua.wallet.Wallet) – Wallet containing accounts to sync

wait_for_connection(timeout=5)

Wait until the running node has made a successful request

Raises
  • ValueError – If the network plugin is stopped

  • TimeoutError – If connection can’t be established in given time

work_difficulty = 'ffffffc000000000'