RPC Events

async def test_notifier(self):
    rpc = pyrin.RPC()
    success = await rpc.connect()

    await rpc.on_block_added(lambda block: print(f"block-added: {block.header.hash}"))
    await rpc.on_finality_conflict(lambda violating_block_hash: print(f"finality-conflict: {violating_block_hash}"))
    await rpc.on_finality_conflict_resolved(lambda finality_block_hash: print(f"finality-conflict-resolved: {finality_block_hash}"))
    await rpc.on_new_block_template(lambda: print(f"new-block-template"))
    await rpc.on_pruning_point_utxo_set_override(lambda _: print(f"pruning-point-utxo-set-override"))
    await rpc.on_sink_blue_score_changed(lambda sink_blue_score: print(f"sink_blue_score: {sink_blue_score}"))
    await rpc.on_virtual_daa_score_changed(lambda score: print(f"virtual-daa-score: {score}"))

    def on_utxos_changed(added, removed):
        print(f"utxos-changed: {added[0].address}, {removed}")

    await rpc.on_utxos_changed(on_utxos_changed, ["pyrin:qqd9p8w75xqe80fx05qs0v3g0fmplztxays0f8x9l0asnn0apanlu9dd79gev"])

    def on_virtual_chain(added_chain_block_hashes, removed_chain_block_hashes, accepted_transaction_ids):
        print(f"virtual-chain: {added_chain_block_hashes}, {removed_chain_block_hashes}, {accepted_transaction_ids}")

    await rpc.on_virtual_chain_changed(on_virtual_chain, True)

    while True:
        await asyncio.sleep(1)

Block Added

Block added notification event is produced when a new block is added to the Pyrin BlockDAG

rpc = pyrin.RPC()
success = await rpc.connect()

await rpc.on_block_added(lambda block: print(f"block-added: {block.header.hash}"))

Virtual Chain Changed

Virtual chain changed notification event is produced when the virtual chain changes in the Pyrin BlockDAG

def on_virtual_chain(added_chain_block_hashes, removed_chain_block_hashes, accepted_transaction_ids):
     print(f"virtual-chain: {added_chain_block_hashes}, {removed_chain_block_hashes}, {accepted_transaction_ids}")

 await rpc.on_virtual_chain_changed(on_virtual_chain, True)

Finality Conflict

Finality conflict notification event is produced when a finality conflict occurs in the Pyrin BlockDAG

await rpc.on_finality_conflict(lambda violating_block_hash: print(f"finality-conflict: {violating_block_hash}"))

Finality Conflict Resolved

Finality conflict resolved notification event is produced when a finality conflict in the Pyrin BlockDAG is resolved

await rpc.on_finality_conflict_resolved(lambda finality_block_hash: print(f"finality-conflict-resolved: {finality_block_hash}"))

Utxos Changed

UTXOs changed notification event is produced when the set of unspent transaction outputs (UTXOs) changes in the Pyrin BlockDAG. The event notification is scoped to the monitored list of addresses specified during the subscription

def on_utxos_changed(added, removed):
      print(f"utxos-changed: {added[0].address}, {removed}")

  await rpc.on_utxos_changed(on_utxos_changed, ["pyrin:qqd9p8w75xqe80fx05qs0v3g0fmplztxays0f8x9l0asnn0apanlu9dd79gev"])

Sink Blue Score Changed

Sink blue score changed notification event is produced when the blue score of the sink block changes in the Pyrin BlockDAG

await rpc.on_sink_blue_score_changed(lambda sink_blue_score: print(f"sink_blue_score: {sink_blue_score}"))

Virtual DAA Score Changed

Virtual DAA score changed notification event is produced when the virtual Difficulty Adjustment Algorithm (DAA) score changes in the Pyrin BlockDAG

await rpc.on_virtual_daa_score_changed(lambda score: print(f"virtual-daa-score: {score}"))

Pruning Point Utxo Set Override

Pruning point UTXO set override notification event is produced when the UTXO set override for the pruning point changes in the Pyrin BlockDAG

await rpc.on_pruning_point_utxo_set_override(lambda _: print(f"pruning-point-utxo-set-override"))

New Block Template

New block template notification event is produced when a new block template is generated for mining in the Pyrin BlockDAG

await rpc.on_new_block_template(lambda: print(f"new-block-template"))

Last updated