pub trait BlockchainInterface {
type Error: Error + Send + Sync + 'static;
Show 22 methods
// Required methods
fn get_block_hash(&self, height: u32) -> Result<BlockHash, Self::Error>;
fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Self::Error>;
fn get_height(&self) -> Result<u32, Self::Error>;
fn broadcast(&self, tx: &Transaction) -> Result<(), Self::Error>;
fn estimate_fee(&self, target: usize) -> Result<f64, Self::Error>;
fn get_block(&self, hash: &BlockHash) -> Result<Block, Self::Error>;
fn get_best_block(&self) -> Result<(u32, BlockHash), Self::Error>;
fn get_block_header(
&self,
hash: &BlockHash
) -> Result<BlockHeader, Self::Error>;
fn subscribe(&self, tx: Arc<dyn BlockConsumer>);
fn is_in_idb(&self) -> bool;
fn get_unbroadcasted(&self) -> Vec<Transaction>;
fn is_coinbase_mature(
&self,
height: u32,
block: BlockHash
) -> Result<bool, Self::Error>;
fn get_block_locator(&self) -> Result<Vec<BlockHash>, Self::Error>;
fn get_block_locator_for_tip(
&self,
tip: BlockHash
) -> Result<Vec<BlockHash>, BlockchainError>;
fn get_validation_index(&self) -> Result<u32, Self::Error>;
fn rescan(&self, start_height: u32) -> Result<(), Self::Error>;
fn get_rescan_index(&self) -> Option<u32>;
fn get_block_height(
&self,
hash: &BlockHash
) -> Result<Option<u32>, Self::Error>;
fn update_acc(
&self,
acc: Stump,
block: UtreexoBlock,
height: u32,
proof: Proof,
del_hashes: Vec<Hash>
) -> Result<Stump, Self::Error>;
fn get_chain_tips(&self) -> Result<Vec<BlockHash>, Self::Error>;
fn validate_block(
&self,
block: &Block,
proof: Proof,
inputs: HashMap<OutPoint, TxOut>,
del_hashes: Vec<Hash>,
acc: Stump
) -> Result<(), Self::Error>;
fn get_fork_point(&self, block: BlockHash) -> Result<BlockHash, Self::Error>;
}
Expand description
This trait is the main interface between our blockchain backend and other services. It’ll be useful for transitioning from rpc to a p2p based node
Required Associated Types§
Required Methods§
sourcefn get_block_hash(&self, height: u32) -> Result<BlockHash, Self::Error>
fn get_block_hash(&self, height: u32) -> Result<BlockHash, Self::Error>
Returns the block with a given height in our current tip.
sourcefn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Self::Error>
fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Self::Error>
Returns a bitcoin Transaction given it’s txid.
sourcefn get_height(&self) -> Result<u32, Self::Error>
fn get_height(&self) -> Result<u32, Self::Error>
Get the height of our best know chain.
sourcefn broadcast(&self, tx: &Transaction) -> Result<(), Self::Error>
fn broadcast(&self, tx: &Transaction) -> Result<(), Self::Error>
Broadcasts a transaction to the network.
sourcefn estimate_fee(&self, target: usize) -> Result<f64, Self::Error>
fn estimate_fee(&self, target: usize) -> Result<f64, Self::Error>
Returns fee estimation for inclusion in target
blocks.
sourcefn get_block(&self, hash: &BlockHash) -> Result<Block, Self::Error>
fn get_block(&self, hash: &BlockHash) -> Result<Block, Self::Error>
Returns a block with a given hash
if any.
sourcefn get_block_header(&self, hash: &BlockHash) -> Result<BlockHeader, Self::Error>
fn get_block_header(&self, hash: &BlockHash) -> Result<BlockHeader, Self::Error>
Returns associated header for block with hash
sourcefn subscribe(&self, tx: Arc<dyn BlockConsumer>)
fn subscribe(&self, tx: Arc<dyn BlockConsumer>)
Register for receiving notifications for some event. Right now it only works for new blocks, but may work with transactions in the future too. if a module performs some heavy-lifting on the block’s data, it should pass in a vector or a channel where data can be transfered to the atual worker, otherwise chainstate will be stuck for as long as you have work to do.
sourcefn get_unbroadcasted(&self) -> Vec<Transaction>
fn get_unbroadcasted(&self) -> Vec<Transaction>
Returns the list of unbroadcasted transactions.
sourcefn is_coinbase_mature(
&self,
height: u32,
block: BlockHash
) -> Result<bool, Self::Error>
fn is_coinbase_mature( &self, height: u32, block: BlockHash ) -> Result<bool, Self::Error>
Checks if a coinbase is mature
sourcefn get_block_locator_for_tip(
&self,
tip: BlockHash
) -> Result<Vec<BlockHash>, BlockchainError>
fn get_block_locator_for_tip( &self, tip: BlockHash ) -> Result<Vec<BlockHash>, BlockchainError>
Returns a block locator from a given tip
This method may be used to get the locator from a tip that’s not the best one
sourcefn get_validation_index(&self) -> Result<u32, Self::Error>
fn get_validation_index(&self) -> Result<u32, Self::Error>
Returns the last block we validated
sourcefn rescan(&self, start_height: u32) -> Result<(), Self::Error>
fn rescan(&self, start_height: u32) -> Result<(), Self::Error>
Triggers a rescan, downloading (but not validating) all blocks in [start_height:tip]
sourcefn get_rescan_index(&self) -> Option<u32>
fn get_rescan_index(&self) -> Option<u32>
Returns where we are in the rescan
sourcefn get_block_height(&self, hash: &BlockHash) -> Result<Option<u32>, Self::Error>
fn get_block_height(&self, hash: &BlockHash) -> Result<Option<u32>, Self::Error>
Returns the height of a block, given it’s hash