Module bitcoin_syncer

Source
Expand description

Β§Bitcoin Syncer

This module provides common utilities to fetch Bitcoin state. Other modules can use this module to operate over Bitcoin. Every block starting from paramset.start_height is fetched and stored in the database.

StructsΒ§

BitcoinSyncer
BitcoinSyncerTask
A task that syncs Bitcoin blocks from the Bitcoin node to the local database.
BlockInfo πŸ”’
Represents basic information of a Bitcoin block.
FinalizedBlockFetcherTask

EnumsΒ§

BitcoinSyncerEvent
Events emitted by the Bitcoin syncer. It emits the block_id of the block in the db that was saved.

ConstantsΒ§

BTC_SYNCER_POLL_DELAY

TraitsΒ§

BlockHandler
Trait for handling new blocks as they are finalized

FunctionsΒ§

_get_block_info_from_hash πŸ”’
_get_transaction_spent_utxos πŸ”’
fetch_block_info_from_height πŸ”’
Fetches the BlockInfo for a given height from Bitcoin.
fetch_new_blocks πŸ”’
Fetches the next block from Bitcoin, if it exists. Will also fetch previous blocks if the parent is missing, and give an error if the number of reorged blocks is greater than the finality depth.
handle_reorg_events πŸ”’
Marks blocks above the common ancestor as non-canonical and emits reorg events.
process_new_blocks πŸ”’
Processes and inserts new blocks into the database, emitting a new block event for each.
save_block πŸ”’
Saves a Bitcoin block’s metadata and it’s transactions into the database.
save_transaction_spent_utxos πŸ”’
Saves a Bitcoin transaction and its spent UTXOs to the database.
set_initial_block_info_if_not_exists
If no block info exists in the DB, fetches the current block from the RPC and initializes the DB.