Struct Blockchain

Source
pub struct Blockchain { /* private fields */ }
Expand description

The blockchain

Implementations§

Source§

impl Blockchain

Source

pub fn new(network: Network) -> Blockchain

Constructs a new blockchain

Source

pub fn get_block(&self, hash: Sha256dHash) -> Option<&BlockchainNode>

Looks up a block in the chain and returns the BlockchainNode containing it

Source

pub fn add_txdata(&mut self, block: Block) -> Result<(), BlockchainError>

Locates a block in the chain and overwrites its txdata

Source

pub fn remove_txdata( &mut self, hash: Sha256dHash, ) -> Result<(), BlockchainError>

Locates a block in the chain and removes its txdata

Source

pub fn add_header(&mut self, header: BlockHeader) -> Result<(), BlockchainError>

Adds a block header to the chain

Source

pub fn add_block(&mut self, block: Block) -> Result<(), BlockchainError>

Adds a block to the chain

Source

pub fn genesis_hash(&self) -> Sha256dHash

Returns the genesis block’s blockhash

Source

pub fn best_tip(&self) -> &Block

Returns the best tip

Source

pub fn best_tip_height(&self) -> u32

Returns the best tip height

Source

pub fn best_tip_hash(&self) -> Sha256dHash

Returns the best tip’s blockhash

Source

pub fn locator_hashes(&self) -> Vec<Sha256dHash>

Returns an array of locator hashes used in getheaders messages

Source

pub fn iter(&self, start_hash: Sha256dHash) -> BlockIter<'_>

An iterator over all blocks in the chain starting from start_hash

Source

pub fn rev_iter(&self, start_hash: Sha256dHash) -> RevBlockIter<'_>

An iterator over all blocks in reverse order to the genesis, starting with start_hash

Source

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: Decoder> Decodable<D> for Blockchain

Source§

fn consensus_decode(d: &mut D) -> Result<Blockchain, Error>

Decode an object with a well-defined format
Source§

impl<S: Encoder> Encodable<S> for Blockchain

Source§

fn consensus_encode(&self, s: &mut S) -> Result<(), Error>

Encode an object with a well-defined format, should only ever error if the underlying Encoder errors.
Source§

impl Send for Blockchain

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.