Trait chain_core::property::Block
source · pub trait Block: Serialize {
type Id: BlockId;
type Date: BlockDate;
type Version;
type ChainLength: ChainLength;
// Required methods
fn id(&self) -> Self::Id;
fn parent_id(&self) -> Self::Id;
fn date(&self) -> Self::Date;
fn version(&self) -> Self::Version;
fn chain_length(&self) -> Self::ChainLength;
}
Expand description
Block property
a block is part of a chain of block called Blockchain. the chaining is done via one block pointing to another block, the parent block (the previous block).
This means that a blockchain is a link-list, ordered from the most recent block to the furthest/oldest block.
The Oldest block is called the Genesis Block. TODO: add a Readable trait bound
Required Associated Types§
sourcetype Id: BlockId
type Id: BlockId
the Block identifier. It must be unique. This mean that 2 different blocks have 2 different identifiers.
In bitcoin this block is a SHA2 256bits. For Cardano’s blockchain it is Blake2b 256bits.
sourcetype Date: BlockDate
type Date: BlockDate
the block date (also known as a block number) represents the absolute position of the block in the chain. This can be used for random access (if the storage algorithm allows it) or for identifying the position of a block in a given epoch or era.
sourcetype ChainLength: ChainLength
type ChainLength: ChainLength
the length of the blockchain (number of blocks)
Required Methods§
sourcefn parent_id(&self) -> Self::Id
fn parent_id(&self) -> Self::Id
get the parent block identifier (the previous block in the blockchain).
sourcefn chain_length(&self) -> Self::ChainLength
fn chain_length(&self) -> Self::ChainLength
get the block’s chain length. The number of block created following this thread of blocks on the blockchain (including Self).