[][src]Struct exonum::blockchain::Block

pub struct Block {
    pub height: Height,
    pub tx_count: u32,
    pub prev_hash: Hash,
    pub tx_hash: Hash,
    pub state_hash: Hash,
    pub error_hash: Hash,
    pub additional_headers: AdditionalHeaders,
}

Header of a block.

A block is essentially a list of transactions. Blocks are produced as a result of the consensus algorithm (thus authenticated by the supermajority of validators) and are applied atomically to the blockchain state. The header contains a block summary, such as the number of transactions and the transactions root hash, but not the transactions themselves.

Note that this structure is export-only, meaning that one can rely on the serialization format provided by corresponding Protobuf definitions, but cannot expect Exonum nodes or the exonum crate to accept and process Blocks created externally.

Fields

height: Height

Height of the block, which is also the number of this particular block in the blockchain.

tx_count: u32

Number of transactions in this block.

prev_hash: Hash

Hash link to the previous block in the blockchain.

tx_hash: Hash

Root hash of the Merkle tree of transactions in this block.

state_hash: Hash

Hash of the blockchain state after applying transactions in the block.

error_hash: Hash

Root hash of the Merkle Patricia tree of the erroneous calls performed within the block. These calls can include transactions, before_transactions and/or after_transactions hooks for services.

additional_headers: AdditionalHeaders

Additional information that can be added into the block.

Methods

impl Block[src]

pub fn epoch(&self) -> Option<Height>[src]

Retrieves the epoch associated with this block, or None if the epoch is not recorded.

pub fn is_skip(&self) -> bool[src]

Checks if this block is formed as a result of skipping ordinary block creation.

pub fn get_header<K: BlockHeaderKey>(&self) -> Result<Option<K::Value>>[src]

Gets the value of an additional header for the specified key type, which is specified via the type parameter.

Examples

// Suppose we store a list of active service IDs in a block.
// We can do this by defining a corresponding BlockHeaderKey implementation.
struct ActiveServices {
    service_ids: Vec<u32>,
}

// To implement `BlockHeaderKey` we need to provide the key name and a corresponding
// value type. In this case it's `Self`.
impl BlockHeaderKey for ActiveServices {
    const NAME: &'static str = "active_services";
    type Value = Self;
}

// Create an empty block.
let block = Block {
    // other fields skipped...
    additional_headers: AdditionalHeaders::new(),
};

let services = block.get_header::<ActiveServices>().unwrap();
assert!(services.is_none());

Trait Implementations

impl BinaryValue for Block[src]

impl Clone for Block[src]

impl Debug for Block[src]

impl<'de> Deserialize<'de> for Block[src]

impl Eq for Block[src]

impl ObjectHash for Block[src]

impl Ord for Block[src]

impl PartialEq<Block> for Block[src]

impl PartialOrd<Block> for Block[src]

impl ProtobufConvert for Block[src]

type ProtoStruct = Block

Type generated from the Protobuf definition.

impl Serialize for Block[src]

impl StructuralEq for Block[src]

impl StructuralPartialEq for Block[src]

Auto Trait Implementations

impl RefUnwindSafe for Block

impl Send for Block

impl Sync for Block

impl Unpin for Block

impl UnwindSafe for Block

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,