Show / Hide Table of Contents

Class Block

The complete block including all block contents and action evaluation.

Inheritance
Object
Block
Implements
IPreEvaluationBlock
IBlockContent
IBlockHeader
IPreEvaluationBlockHeader
IBlockMetadata
IBlockExcerpt
IEquatable<Block>
Inherited Members
Object.Equals(Object, Object)
System.Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Namespace: Libplanet.Types.Blocks
Assembly: Libplanet.Types.dll
Syntax
public sealed class Block : IPreEvaluationBlock, IBlockContent, IBlockHeader, IPreEvaluationBlockHeader, IBlockMetadata, IBlockExcerpt, IEquatable<Block>

Constructors

| Improve this Doc View Source

Block(IBlockHeader, IEnumerable<Transaction>)

Creates a Block instance by combining a block header and transactions.

Declaration
public Block(IBlockHeader header, IEnumerable<Transaction> transactions)
Parameters
Type Name Description
IBlockHeader header

The block header.

IEnumerable<Transaction> transactions

The transactions to include.

Exceptions
Type Condition
InvalidBlockProtocolVersionException

Thrown when the header's ProtocolVersion is less than 0, or greater than CurrentProtocolVersion, the latest known protocol version.

InvalidBlockIndexException

Thrown when the header has a negative Index.

InvalidTxSignatureException

Thrown when any tx signature is invalid or not signed by its signer.

InvalidTxNonceException

Thrown when the same tx nonce is used by a signer twice or more, or a tx nonce is used without its previous nonce by a signer. Note that this validates only a block's intrinsic integrity between its transactions, but does not guarantee integrity between blocks. Such validation needs to be conducted by .

InvalidTxGenesisHashException

Thrown when transactions to set have inconsistent genesis hashes.

InvalidBlockTxHashException

Thrown when the given block header's TxHash is not consistent with its transactions.

InvalidBlockPreEvaluationHashException

Thrown when the given header has an invalid PreEvaluationHash.

| Improve this Doc View Source

Block(PreEvaluationBlock, (HashDigest<SHA256> StateRootHash, Nullable<ImmutableArray<Byte>> Signature, BlockHash Hash))

Creates a Block instance by combining a preEvaluationBlock, its corresponding proof.StateRootHash.StateRootHash, valid proof.Signature.Signature, and correctly derived proof.Hash.Hash.

Declaration
public Block(PreEvaluationBlock preEvaluationBlock, (HashDigest<SHA256> StateRootHash, ImmutableArray<byte>? Signature, BlockHash Hash) proof)
Parameters
Type Name Description
PreEvaluationBlock preEvaluationBlock

A pre-evaluation block.

(T1 Item1, T2 Item2, T3 Item3)<HashDigest<SHA256>, Nullable<System.Collections.Immutable.ImmutableArray<System.Byte>>, BlockHash> proof

A triple of the state root hash, the block signature, and the block hash.

Fields

| Improve this Doc View Source

CurrentProtocolVersion

The latest protocol version.

Declaration
public const int CurrentProtocolVersion = 5
Field Value
Type Description
Int32

Properties

| Improve this Doc View Source

Hash

A block's hash.

Declaration
public BlockHash Hash { get; }
Property Value
Type Description
BlockHash
See Also
PreEvaluationHash
StateRootHash
Hash
| Improve this Doc View Source

Header

The BlockHeader of the block.

Declaration
[JsonIgnore]
public BlockHeader Header { get; }
Property Value
Type Description
BlockHeader
| Improve this Doc View Source

Index

The height of the block.

Declaration
public long Index { get; }
Property Value
Type Description
System.Int64
Remarks

Zero means it is a genesis block. Not allowed to be negative.

See Also
Index
| Improve this Doc View Source

LastCommit

The BlockCommit about previous block's vote information.

Declaration
public BlockCommit LastCommit { get; }
Property Value
Type Description
BlockCommit
| Improve this Doc View Source

Miner

The address of the miner.

Declaration
public Address Miner { get; }
Property Value
Type Description
Address
| Improve this Doc View Source

PreEvaluationHash

The hash derived from the block except of its state root hash (i.e., without action evaluation). Used for validating Nonce.

Declaration
public HashDigest<SHA256> PreEvaluationHash { get; }
Property Value
Type Description
HashDigest<SHA256>
See Also
Nonce
| Improve this Doc View Source

PreviousHash

The previous block's hash. If it's a genesis block (i.e., its Index is 0) this must be null.

Declaration
public BlockHash? PreviousHash { get; }
Property Value
Type Description
Nullable<BlockHash>
| Improve this Doc View Source

ProtocolVersion

The protocol version number. For the latest protocol version, see CurrentProtocolVersion. We have the following version info:

  • 0: The initial block protocol version number. This is not actually recorded in storage. That is, the lack of block protocol version in a stored block means it is of version 0.
  • 1: Introduced to be stored with the block data. Validation for PreEvaluationHash was added.
  • 2: Updated to include Signature to blocks. As a result, the miner's identity is provided as a PublicKey instead of a Address. Additionally, total difficulty was added.
  • 3: Updated to fix an issue with the internal execution ordering of Transactions in blocks.
  • 4: Updated to introduce a PBFT scheme. LastCommit was added and total difficulty was removed.
  • 5: Updated to introduce a world model. No structural changes were made to blocks. This is used as a marker indicating when the data model should be migrated.
Declaration
public int ProtocolVersion { get; }
Property Value
Type Description
Int32
See Also
CurrentProtocolVersion
| Improve this Doc View Source

PublicKey

The public key of the Miner. This is used for verifying the signature.

Although this is nullable type-wise, it is mandatory where ProtocolVersion is 2 or later. As blocks had not been signed in the previous protocol versions, the type of this is nullable.

Declaration
public PublicKey PublicKey { get; }
Property Value
Type Description
PublicKey
| Improve this Doc View Source

Signature

The digital signature of the whole block content (except for Hash, which is derived from the signature and other contents). This is made by the Miner's PrivateKey.

As the block signature is introduced since the protocol version 2, it is null for blocks with earlier protocol versions than 2. Although the property is type-wise, the block signature is mandatory since the protocol version 2.

Declaration
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(ByteArrayJsonConverter))]
public ImmutableArray<byte>? Signature { get; }
Property Value
Type Description
Nullable<System.Collections.Immutable.ImmutableArray<System.Byte>>
| Improve this Doc View Source

StateRootHash

The of the resulting states after evaluating transactions and a (if exists).

Declaration
public HashDigest<SHA256> StateRootHash { get; }
Property Value
Type Description
HashDigest<SHA256>
| Improve this Doc View Source

Timestamp

The time the block is created.

Declaration
public DateTimeOffset Timestamp { get; }
Property Value
Type Description
DateTimeOffset
Remarks

This is always UTC.

| Improve this Doc View Source

Transactions

Transactions belonging to the block.

Declaration
public IReadOnlyList<Transaction> Transactions { get; }
Property Value
Type Description
IReadOnlyList<Transaction>
| Improve this Doc View Source

TxHash

The hash of all transactions in the block. This is null if the block has no transactions.

Declaration
public HashDigest<SHA256>? TxHash { get; }
Property Value
Type Description
Nullable<HashDigest<SHA256>>

Methods

| Improve this Doc View Source

Equals(Block)

The complete block including all block contents and action evaluation.

Declaration
public bool Equals(Block other)
Parameters
Type Name Description
Block other
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Equals(Object)

The complete block including all block contents and action evaluation.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj
Returns
Type Description
System.Boolean
Overrides
Object.Equals(Object)
| Improve this Doc View Source

GetHashCode()

The complete block including all block contents and action evaluation.

Declaration
public override int GetHashCode()
Returns
Type Description
Int32
Overrides
Object.GetHashCode()
| Improve this Doc View Source

ToString()

The complete block including all block contents and action evaluation.

Declaration
public override string ToString()
Returns
Type Description
String
Overrides
System.Object.ToString()

Operators

| Improve this Doc View Source

Equality(Block, Block)

Equivalent to Equals(T).

Declaration
public static bool operator ==(Block left, Block right)
Parameters
Type Name Description
Block left

A block.

Block right

Another block.

Returns
Type Description
System.Boolean

true if two blocks are equal. Otherwise false.

| Improve this Doc View Source

Inequality(Block, Block)

Negation of Equals(T).

Declaration
public static bool operator !=(Block left, Block right)
Parameters
Type Name Description
Block left

A block.

Block right

Another block.

Returns
Type Description
System.Boolean

true if two blocks are different. Otherwise false.

Explicit Interface Implementations

| Improve this Doc View Source

IBlockContent.Transactions

Transactions belonging to the block.

Declaration
IReadOnlyList<ITransaction> IBlockContent.Transactions { get; }
Returns
Type Description
IReadOnlyList<ITransaction>

Implements

IPreEvaluationBlock
IBlockContent
IBlockHeader
IPreEvaluationBlockHeader
IBlockMetadata
IBlockExcerpt
System.IEquatable<T>

Extension Methods

BlockMarshaler.MarshalBlock(Block)
BlockExcerptExtensions.ExcerptEquals(IBlockExcerpt, IBlockExcerpt)
BlockExcerptExtensions.ToExcerptString(IBlockExcerpt)
BlockMarshaler.MarshalBlockHeader(IBlockHeader)
IBlockMetadataExtensions.ValidateTimestamp(IBlockMetadata)
IBlockMetadataExtensions.ValidateTimestamp(IBlockMetadata, DateTimeOffset)
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium