duniterpy.helpers package

Submodules

duniterpy.helpers.blockchain module

duniterpy.helpers.blockchain.Blockchain(json_blockchain)

convert json to duniterpy block document

class duniterpy.helpers.blockchain.JsonBlockchain(folder)

Bases: object

current_block()

returns current block as a duniterpy block document

get_block_number(number)

get one precise block (do not use for iteration)

parsechunk()

parse a json chunk file

duniterpy.helpers.blockchain.load(path='.config/duniter/duniter_default/g1/')

returns an iterator allowing to browse all the blockchain in practice, it will load chunk by chunk and only keep one in memory at a time

duniterpy.helpers.blockchain.load_json(path='.config/duniter/duniter_default/g1/')

returns a JsonBlockchain object

duniterpy.helpers.money module

duniterpy.helpers.money.output_available(condition: Condition, comparison: Any, value: str | int) bool

Check if output source is available Currently only handle unique condition without composition

operator.lt(a, b) is equivalent to a < b operator.le(a, b) is equivalent to a <= b operator.gt(a, b) is equivalent to a > b operator.ge(a, b) is equivalent to a >= b

duniterpy.helpers.network module

duniterpy.helpers.network.get_available_nodes(client: Client) List[List[Dict[str, Any]]]

Get available nodes grouped and sorted by descending block_id

Each entry is a list of nodes (HeadV2 instance, inline endpoint list) sharing the same block_id:

[

[{“head”: HeadV2, “endpoints”: [str, …]}, …], [{“head”: HeadV2, “endpoints”: [str, …]}, …], …

]

You can just select the first endpoint of the first node of the first group to quickly get an available node.

groups = get_available_nodes(client) first_node_first_endpoint = groups[0][0][“endpoints”][0]

If node is down, you can select another node.

Warning: only nodes with BMAS, BASIC_MERKLED_API, and GVA endpoint are selected

and only those endpoints are available in the endpoint list

Parameters:

client – Client instance

Returns:

duniterpy.helpers.ws2p module

duniterpy.helpers.ws2p.generate_ws2p_endpoint(bma_endpoint: str | BMAEndpoint | SecuredBMAEndpoint) WS2PEndpoint

Retrieve WS2P endpoints from BMA peering Take the first one found

duniterpy.helpers.ws2p.handshake(ws: WSConnection, signing_key: SigningKey, currency: str = 'g1')

Perform ws2p handshake on the web socket connection using the signing_key instance

Parameters:
  • ws – Web socket connection instance

  • signing_key – SigningKey instance

  • currency – Currency codename (default=constants.CURRENCY_CODENAME_G1)

Returns:

Module contents