Struct floresta_chain::pruned_utreexo::chain_state::ChainState
source · pub struct ChainState<PersistedState: ChainStore> { /* private fields */ }
Implementations§
source§impl<PersistedState: ChainStore> ChainState<PersistedState>
impl<PersistedState: ChainStore> ChainState<PersistedState>
sourcepub fn push_headers(
&self,
headers: Vec<BlockHeader>,
height: u32
) -> Result<(), BlockchainError>
pub fn push_headers( &self, headers: Vec<BlockHeader>, height: u32 ) -> Result<(), BlockchainError>
Just adds headers to the chainstate, without validating them.
pub fn new( chainstore: PersistedState, network: Network, assume_valid: Option<BlockHash> ) -> ChainState<PersistedState>
pub fn load_chain_state( chainstore: KvChainStore, network: Network, assume_valid_hash: Option<BlockHash> ) -> Result<ChainState<KvChainStore>, BlockchainError>
pub fn acc(&self) -> Stump
Trait Implementations§
source§impl<PersistedState: ChainStore> BlockchainInterface for ChainState<PersistedState>
impl<PersistedState: ChainStore> BlockchainInterface for ChainState<PersistedState>
type Error = BlockchainError
source§fn 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
source§fn 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.
source§fn 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.
source§fn broadcast(&self, tx: &Transaction) -> Result<(), Self::Error>
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>
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>
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>
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>
fn get_block_header(&self, hash: &BlockHash) -> Result<BlockHeader, Self::Error>
Returns associated header for block with
hash
source§fn get_rescan_index(&self) -> Option<u32>
fn get_rescan_index(&self) -> Option<u32>
Returns where we are in the rescan
source§fn 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]
source§fn 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.
source§fn get_block_locator(&self) -> Result<Vec<BlockHash>, BlockchainError>
fn get_block_locator(&self) -> Result<Vec<BlockHash>, BlockchainError>
Returns a block locator
source§fn get_validation_index(&self) -> Result<u32, Self::Error>
fn get_validation_index(&self) -> Result<u32, Self::Error>
Returns the last block we validated
source§fn 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
source§fn get_unbroadcasted(&self) -> Vec<Transaction>
fn get_unbroadcasted(&self) -> Vec<Transaction>
Returns the list of unbroadcasted transactions.
source§impl<T: ChainStore> From<ChainStateBuilder<T>> for ChainState<T>
impl<T: ChainStore> From<ChainStateBuilder<T>> for ChainState<T>
source§fn from(builder: ChainStateBuilder<T>) -> Self
fn from(builder: ChainStateBuilder<T>) -> Self
Converts to this type from the input type.
source§impl<PersistedState: ChainStore> UpdatableChainstate for ChainState<PersistedState>
impl<PersistedState: ChainStore> UpdatableChainstate for ChainState<PersistedState>
source§fn invalidate_block(&self, block: BlockHash) -> Result<(), BlockchainError>
fn invalidate_block(&self, block: BlockHash) -> Result<(), BlockchainError>
Tells this blockchain to consider this block invalid, and not build on top of it
source§fn toggle_ibd(&self, is_ibd: bool)
fn toggle_ibd(&self, is_ibd: bool)
Toggle ibd on/off
source§fn process_rescan_block(&self, block: &Block) -> Result<(), BlockchainError>
fn process_rescan_block(&self, block: &Block) -> Result<(), BlockchainError>
Gives a requested block for rescan
source§fn connect_block(
&self,
block: &Block,
proof: Proof,
inputs: HashMap<OutPoint, TxOut>,
del_hashes: Vec<Hash>
) -> Result<u32, BlockchainError>
fn connect_block( &self, block: &Block, proof: Proof, inputs: HashMap<OutPoint, TxOut>, del_hashes: Vec<Hash> ) -> Result<u32, BlockchainError>
This is one of the most important methods for a ChainState, it gets a block and some utreexo data,
validates this block and connects to our chain of blocks. This function is meant to
be atomic and prone of running in parallel.
source§fn handle_transaction(&self) -> Result<(), BlockchainError>
fn handle_transaction(&self) -> Result<(), BlockchainError>
Not used for now, but in a future blockchain with mempool, we can process transactions
that are not in a block yet.
source§fn flush(&self) -> Result<(), BlockchainError>
fn flush(&self) -> Result<(), BlockchainError>
Persists our data. Should be invoked periodically.
source§fn accept_header(&self, header: BlockHeader) -> Result<(), BlockchainError>
fn accept_header(&self, header: BlockHeader) -> Result<(), BlockchainError>
Accepts a new header to our chain. This method is called before connect_block, and
makes some basic checks on a header and saves it on disk. We only accept a block as
valid after calling connect_block.
source§fn get_root_hashes(&self) -> Vec<NodeHash>
fn get_root_hashes(&self) -> Vec<NodeHash>
Returns the root hashes of our utreexo forest
Auto Trait Implementations§
impl<PersistedState> !RefUnwindSafe for ChainState<PersistedState>
impl<PersistedState> Send for ChainState<PersistedState>where PersistedState: Send,
impl<PersistedState> Sync for ChainState<PersistedState>where PersistedState: Send + Sync,
impl<PersistedState> Unpin for ChainState<PersistedState>where PersistedState: Unpin,
impl<PersistedState> !UnwindSafe for ChainState<PersistedState>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more