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§
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_best_block(&self) -> Result<(u32, BlockHash), Self::Error>
fn get_best_block(&self) -> Result<(u32, BlockHash), Self::Error>
Returns the best known block
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 transferred 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(&self) -> Result<Vec<BlockHash>, Self::Error>
fn get_block_locator(&self) -> Result<Vec<BlockHash>, Self::Error>
Returns a block locator
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 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