Skip to main content

Block

Struct Block 

Source
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>

Source

pub fn new_unchecked(header: Header, transactions: Vec<Transaction>) -> Self

Constructs a new Block without doing any validation.

Source

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.

Source

pub fn into_parts(self) -> (Header, Vec<Transaction>)

Decomposes block into its constituent parts.

Source

pub fn as_parts(&self) -> (&Header, &[Transaction])

Returns the constituent parts of the block by reference.

Source

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.
Source

pub fn check_merkle_root(&self) -> bool

Checks if Merkle root of header matches Merkle root of the transaction list.

Source

pub fn compute_witness_commitment( &self, witness_reserved_value: &[u8], ) -> Option<(WitnessMerkleNode, WitnessCommitment)>

Computes the witness commitment for a list of transactions.

Source

pub fn check_witness_commitment(&self) -> (bool, Option<WitnessMerkleNode>)

Checks if witness commitment in coinbase matches the transaction list.

Source§

impl Block<Checked>

Source

pub fn header(&self) -> &Header

Gets a reference to the block header.

Source

pub fn transactions(&self) -> &[Transaction]

Gets a reference to the block’s list of transactions.

Source

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>

Source

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.
Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl<V> Clone for Block<V>
where V: Validation + Clone,

Source§

fn clone(&self) -> Block<V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V> Debug for Block<V>
where V: Validation + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Decodable for Block

Available on crate feature alloc only.
Source§

type Decoder = BlockDecoder

Associated decoder for the type.
Source§

fn decoder() -> Self::Decoder

Constructs a “default decoder” for the type.
Source§

impl Encodable for Block

Available on crate feature alloc only.
Source§

type Encoder<'e> = Encoder2<HeaderEncoder<'e>, Encoder2<CompactSizeEncoder, SliceEncoder<'e, Transaction>>> where Self: 'e

The encoder associated with this type. Conceptually, the encoder is like an iterator which yields byte slices.
Source§

fn encoder(&self) -> Self::Encoder<'_>

Constructs a “default encoder” for the type.
Source§

impl From<&Block> for BlockHash

Available on crate feature alloc only.
Source§

fn from(block: &Block) -> Self

Converts to this type from the input type.
Source§

impl From<Block> for BlockHash

Available on crate feature alloc only.
Source§

fn from(block: Block) -> Self

Converts to this type from the input type.
Source§

impl<V> PartialEq for Block<V>
where V: Validation + PartialEq,

Source§

fn eq(&self, other: &Block<V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V> Eq for Block<V>
where V: Validation + Eq,

Source§

impl<V> StructuralPartialEq for Block<V>
where V: Validation,

Auto Trait Implementations§

§

impl<V> Freeze for Block<V>

§

impl<V> RefUnwindSafe for Block<V>
where V: RefUnwindSafe,

§

impl<V> Send for Block<V>

§

impl<V> Sync for Block<V>

§

impl<V> Unpin for Block<V>

§

impl<V> UnsafeUnpin for Block<V>

§

impl<V> UnwindSafe for Block<V>
where V: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.