pub struct Block<V = Unchecked>where
V: Validation,{ /* private fields */ }Expand description
Bitcoin block.
A collection of transactions with an attached proof of work.
See Bitcoin Wiki: Block for more information.
§Bitcoin Core References
Implementations§
Source§impl Block<Unchecked>
impl Block<Unchecked>
Sourcepub fn new_unchecked(header: Header, transactions: Vec<Transaction>) -> Self
pub fn new_unchecked(header: Header, transactions: Vec<Transaction>) -> Self
Constructs a new Block without doing any validation.
Sourcepub fn assume_checked(
self,
witness_root: Option<WitnessMerkleNode>,
) -> Block<Checked>
pub fn assume_checked( self, witness_root: Option<WitnessMerkleNode>, ) -> Block<Checked>
Ignores block validation logic and just assumes you know what you are doing.
You should only use this function if you trust the block i.e., it comes from a trusted node.
Sourcepub fn into_parts(self) -> (Header, Vec<Transaction>)
pub fn into_parts(self) -> (Header, Vec<Transaction>)
Decomposes block into its constituent parts.
Sourcepub fn as_parts(&self) -> (&Header, &[Transaction])
pub fn as_parts(&self) -> (&Header, &[Transaction])
Returns the constituent parts of the block by reference.
Sourcepub fn validate(self) -> Result<Block<Checked>, InvalidBlockError>
pub fn validate(self) -> Result<Block<Checked>, InvalidBlockError>
Validates (or checks) a block.
We define valid as:
- The Merkle root of the header matches Merkle root of the transaction list.
- The witness commitment in coinbase matches the transaction list.
§Errors
Returns an error if:
- The block has no transactions.
- The first transaction is not a coinbase transaction.
- The Merkle root of the header does not match the Merkle root of the transaction list.
- The witness commitment in the coinbase does not match the transaction list.
Sourcepub fn check_merkle_root(&self) -> bool
pub fn check_merkle_root(&self) -> bool
Checks if Merkle root of header matches Merkle root of the transaction list.
Sourcepub fn compute_witness_commitment(
&self,
witness_reserved_value: &[u8],
) -> Option<(WitnessMerkleNode, WitnessCommitment)>
pub fn compute_witness_commitment( &self, witness_reserved_value: &[u8], ) -> Option<(WitnessMerkleNode, WitnessCommitment)>
Computes the witness commitment for a list of transactions.
Sourcepub fn check_witness_commitment(&self) -> (bool, Option<WitnessMerkleNode>)
pub fn check_witness_commitment(&self) -> (bool, Option<WitnessMerkleNode>)
Checks if witness commitment in coinbase matches the transaction list.
Source§impl Block<Checked>
impl Block<Checked>
Sourcepub fn transactions(&self) -> &[Transaction]
pub fn transactions(&self) -> &[Transaction]
Gets a reference to the block’s list of transactions.
Sourcepub fn cached_witness_root(&self) -> Option<WitnessMerkleNode>
pub fn cached_witness_root(&self) -> Option<WitnessMerkleNode>
Returns the cached witness root if one is present.
It is assumed that a block will have the witness root calculated and cached as part of the validation process.
Source§impl<V: Validation> Block<V>
impl<V: Validation> Block<V>
Sourcepub fn block_hash(&self) -> BlockHash
pub fn block_hash(&self) -> BlockHash
Returns the block hash.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Block
Available on crate features arbitrary and alloc only.
impl<'a> Arbitrary<'a> for Block
arbitrary and alloc only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Encodable for Block
Available on crate feature alloc only.
impl Encodable for Block
alloc only.