Struct bitcoin_chain::blockchain::Blockchain
source · pub struct Blockchain { /* private fields */ }
Expand description
The blockchain
Implementations§
source§impl Blockchain
impl Blockchain
sourcepub fn new(network: Network) -> Blockchain
pub fn new(network: Network) -> Blockchain
Constructs a new blockchain
sourcepub fn get_block(&self, hash: Sha256dHash) -> Option<&BlockchainNode>
pub fn get_block(&self, hash: Sha256dHash) -> Option<&BlockchainNode>
Looks up a block in the chain and returns the BlockchainNode containing it
sourcepub fn add_txdata(&mut self, block: Block) -> Result<(), BlockchainError>
pub fn add_txdata(&mut self, block: Block) -> Result<(), BlockchainError>
Locates a block in the chain and overwrites its txdata
sourcepub fn remove_txdata(&mut self, hash: Sha256dHash) -> Result<(), BlockchainError>
pub fn remove_txdata(&mut self, hash: Sha256dHash) -> Result<(), BlockchainError>
Locates a block in the chain and removes its txdata
sourcepub fn add_header(&mut self, header: BlockHeader) -> Result<(), BlockchainError>
pub fn add_header(&mut self, header: BlockHeader) -> Result<(), BlockchainError>
Adds a block header to the chain
sourcepub fn add_block(&mut self, block: Block) -> Result<(), BlockchainError>
pub fn add_block(&mut self, block: Block) -> Result<(), BlockchainError>
Adds a block to the chain
sourcepub fn genesis_hash(&self) -> Sha256dHash
pub fn genesis_hash(&self) -> Sha256dHash
Returns the genesis block’s blockhash
sourcepub fn best_tip_height(&self) -> u32
pub fn best_tip_height(&self) -> u32
Returns the best tip height
sourcepub fn best_tip_hash(&self) -> Sha256dHash
pub fn best_tip_hash(&self) -> Sha256dHash
Returns the best tip’s blockhash
sourcepub fn locator_hashes(&self) -> Vec<Sha256dHash>
pub fn locator_hashes(&self) -> Vec<Sha256dHash>
Returns an array of locator hashes used in getheaders
messages
sourcepub fn iter(&self, start_hash: Sha256dHash) -> BlockIter<'_> ⓘ
pub fn iter(&self, start_hash: Sha256dHash) -> BlockIter<'_> ⓘ
An iterator over all blocks in the chain starting from start_hash
sourcepub fn rev_iter(&self, start_hash: Sha256dHash) -> RevBlockIter<'_> ⓘ
pub fn rev_iter(&self, start_hash: Sha256dHash) -> RevBlockIter<'_> ⓘ
An iterator over all blocks in reverse order to the genesis, starting with start_hash
sourcepub fn rev_stale_iter(&self, start_hash: Sha256dHash) -> RevStaleBlockIter<'_> ⓘ
pub fn rev_stale_iter(&self, start_hash: Sha256dHash) -> RevStaleBlockIter<'_> ⓘ
An iterator over all blocks -not- in the best chain, in reverse order, starting from start_hash
Trait Implementations§
source§impl<D: SimpleDecoder> ConsensusDecodable<D> for Blockchain
impl<D: SimpleDecoder> ConsensusDecodable<D> for Blockchain
source§fn consensus_decode(d: &mut D) -> Result<Blockchain, Error>
fn consensus_decode(d: &mut D) -> Result<Blockchain, Error>
Decode an object with a well-defined format