Trait BlockchainInterface

Source
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_ibd(&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 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, UtxoData>, del_hashes: Vec<Hash>, acc: Stump, ) -> Result<(), Self::Error>; fn get_fork_point(&self, block: BlockHash) -> Result<BlockHash, Self::Error>; fn get_params(&self) -> Params; fn acc(&self) -> Stump;
}
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§

Source

type Error: Error + Send + Sync + 'static

Required Methods§

Source

fn get_block_hash(&self, height: u32) -> Result<BlockHash, Self::Error>

Returns the block with a given height in our current tip.

Source

fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Self::Error>

Returns a bitcoin [Transaction] given it’s txid.

Source

fn get_height(&self) -> Result<u32, Self::Error>

Get the height of our best know chain.

Source

fn broadcast(&self, tx: &Transaction) -> Result<(), Self::Error>

Broadcasts a transaction to the network.

Source

fn estimate_fee(&self, target: usize) -> Result<f64, Self::Error>

Returns fee estimation for inclusion in target blocks.

Source

fn get_block(&self, hash: &BlockHash) -> Result<Block, Self::Error>

Returns a block with a given hash if any.

Source

fn get_best_block(&self) -> Result<(u32, BlockHash), Self::Error>

Returns the best known block

Source

fn get_block_header(&self, hash: &BlockHash) -> Result<BlockHeader, Self::Error>

Returns associated header for block with hash

Source

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 transferred to the atual worker, otherwise chainstate will be stuck for as long as you have work to do.

Source

fn is_in_ibd(&self) -> bool

Tells whether or not we are on IBD

Source

fn get_unbroadcasted(&self) -> Vec<Transaction>

Returns the list of unbroadcasted transactions.

Source

fn is_coinbase_mature( &self, height: u32, block: BlockHash, ) -> Result<bool, Self::Error>

Checks if a coinbase is mature

Source

fn get_block_locator(&self) -> Result<Vec<BlockHash>, Self::Error>

Returns a block locator

Source

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

Source

fn get_validation_index(&self) -> Result<u32, Self::Error>

Returns the last block we validated

Source

fn get_block_height(&self, hash: &BlockHash) -> Result<Option<u32>, Self::Error>

Returns the height of a block, given it’s hash

Source

fn update_acc( &self, acc: Stump, block: UtreexoBlock, height: u32, proof: Proof, del_hashes: Vec<Hash>, ) -> Result<Stump, Self::Error>

Source

fn get_chain_tips(&self) -> Result<Vec<BlockHash>, Self::Error>

Source

fn validate_block( &self, block: &Block, proof: Proof, inputs: HashMap<OutPoint, UtxoData>, del_hashes: Vec<Hash>, acc: Stump, ) -> Result<(), Self::Error>

Source

fn get_fork_point(&self, block: BlockHash) -> Result<BlockHash, Self::Error>

Source

fn get_params(&self) -> Params

Source

fn acc(&self) -> Stump

Implementations on Foreign Types§

Source§

impl<T: BlockchainInterface> BlockchainInterface for Arc<T>

Source§

type Error = <T as BlockchainInterface>::Error

Source§

fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Self::Error>

Source§

fn get_params(&self) -> Params

Source§

fn acc(&self) -> Stump

Source§

fn broadcast(&self, tx: &Transaction) -> Result<(), Self::Error>

Source§

fn get_block(&self, hash: &BlockHash) -> Result<Block, Self::Error>

Source§

fn subscribe(&self, tx: Arc<dyn BlockConsumer>)

Source§

fn is_in_ibd(&self) -> bool

Source§

fn get_height(&self) -> Result<u32, Self::Error>

Source§

fn estimate_fee(&self, target: usize) -> Result<f64, Self::Error>

Source§

fn get_block_hash(&self, height: u32) -> Result<BlockHash, Self::Error>

Source§

fn get_best_block(&self) -> Result<(u32, BlockHash), Self::Error>

Source§

fn get_block_header(&self, hash: &BlockHash) -> Result<BlockHeader, Self::Error>

Source§

fn get_block_height(&self, hash: &BlockHash) -> Result<Option<u32>, Self::Error>

Source§

fn get_unbroadcasted(&self) -> Vec<Transaction>

Source§

fn get_block_locator(&self) -> Result<Vec<BlockHash>, Self::Error>

Source§

fn is_coinbase_mature( &self, height: u32, block: BlockHash, ) -> Result<bool, Self::Error>

Source§

fn get_validation_index(&self) -> Result<u32, Self::Error>

Source§

fn get_block_locator_for_tip( &self, tip: BlockHash, ) -> Result<Vec<BlockHash>, BlockchainError>

Source§

fn update_acc( &self, acc: Stump, block: UtreexoBlock, height: u32, proof: Proof, del_hashes: Vec<Hash>, ) -> Result<Stump, Self::Error>

Source§

fn get_chain_tips(&self) -> Result<Vec<BlockHash>, Self::Error>

Source§

fn validate_block( &self, block: &Block, proof: Proof, inputs: HashMap<OutPoint, UtxoData>, del_hashes: Vec<Hash>, acc: Stump, ) -> Result<(), Self::Error>

Source§

fn get_fork_point(&self, block: BlockHash) -> Result<BlockHash, Self::Error>

Implementors§