Show / Hide Table of Contents

Class Block<T>

The complete block including all block contents and done proof-of-work and action evaluation.

Inheritance
Object
Block<T>
Implements
IPreEvaluationBlock<T>
IBlockContent<T>
IBlockHeader
IPreEvaluationBlockHeader
IBlockMetadata
IBlockExcerpt
IEquatable<Block<T>>
Namespace: Libplanet.Blocks
Assembly: Libplanet.dll
Syntax
public sealed class Block<T> : object, IPreEvaluationBlock<T>, IBlockContent<T>, IBlockHeader, IPreEvaluationBlockHeader, IBlockMetadata, IBlockExcerpt, IEquatable<Block<T>> where T : IAction, new()
Type Parameters
Name Description
T

A class implementing IAction to include. This type parameter is aligned with Transaction<T>'s type parameter.

Constructors

| Improve this Doc View Source

Block(IBlockHeader, IEnumerable<Transaction<T>>)

Creates a Block<T> instance by combining a block header and transactions.

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

The block header.

IEnumerable<Transaction<T>> 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.

InvalidBlockDifficultyException

Thrown when the header's Difficulty is negative.

InvalidBlockTotalDifficultyException

Thrown when the header's TotalDifficulty is less than its Difficulty.

InvalidTxSignatureException

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

InvalidTxPublicKeyException

Thrown when any tx signer is not derived from its its public key.

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 BlockChain<T>.

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.

InvalidBlockNonceException

Thrown when the given header's Nonce does not satisfy the required Difficulty.

| Improve this Doc View Source

Block(PreEvaluationBlock<T>, HashDigest<SHA256>, Nullable<ImmutableArray<Byte>>)

Creates a Block<T> instance by combining a preEvaluationBlock and its corresponding stateRootHash.

Declaration
public Block(PreEvaluationBlock<T> preEvaluationBlock, HashDigest<SHA256> stateRootHash, ImmutableArray<byte>? signature)
Parameters
Type Name Description
PreEvaluationBlock<T> preEvaluationBlock

A pre-evaluation block.

HashDigest<SHA256> stateRootHash

A state root hash determined from the given preEvaluationBlock and its previous state root.

Nullable<ImmutableArray<Byte>> signature

The block signature made using the miner's private key.

Exceptions
Type Condition
InvalidBlockSignatureException

Thrown when the signature signature is invalid.

Fields

| Improve this Doc View Source

CurrentProtocolVersion

The latest protocol version.

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

Properties

| Improve this Doc View Source

BytesLength

The bytes length in its serialized format.

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

Difficulty

The mining difficulty that the block's Nonce has to satisfy.

Declaration
public long Difficulty { get; }
Property Value
Type Description
Int64
| 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

HashAlgorithm

The hash algorithm used for calculating PreEvaluationHash.

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

Header

The BlockHeader of the block.

Declaration
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
Int64
Remarks

Zero means it is a genesis block. Disallowed to be negative.

See Also
Index
| 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

Nonce

The proof-of-work nonce which satisfies the required Difficulty.

Declaration
public Nonce Nonce { get; }
Property Value
Type Description
Nonce
| 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 ImmutableArray<byte> PreEvaluationHash { get; }
Property Value
Type Description
ImmutableArray<Byte>
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 should be null.

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

ProtocolVersion

The protocol version number.

Declaration
public int ProtocolVersion { get; }
Property Value
Type Description
Int32
See Also
ProtocolVersion
| 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
public ImmutableArray<byte>? Signature { get; }
Property Value
Type Description
Nullable<ImmutableArray<Byte>>
| Improve this Doc View Source

StateRootHash

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

Declaration
public HashDigest<SHA256> StateRootHash { get; }
Property Value
Type Description
HashDigest<SHA256>
See Also
Hash
| 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

TotalDifficulty

The total mining difficulty since the genesis including the block's Difficulty.

Declaration
public BigInteger TotalDifficulty { get; }
Property Value
Type Description
BigInteger
Remarks

This must be greater than or equal to Difficulty at least, and must not be negative.

See Also
TotalDifficulty
| Improve this Doc View Source

Transactions

Transactions belonging to the block.

Declaration
public IReadOnlyList<Transaction<T>> Transactions { get; }
Property Value
Type Description
IReadOnlyList<Transaction<T>>
Remarks

This is always ordered by Id.

| 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<T>)

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

Equals(Nullable<Object>)

Declaration
public override bool Equals(object? obj)
Parameters
Type Name Description
Nullable<Object> obj
Returns
Type Description
Boolean
| Improve this Doc View Source

GetHashCode()

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

ToString()

Declaration
public override string ToString()
Returns
Type Description
String

Operators

| Improve this Doc View Source

Equality(Block<T>, Block<T>)

Equivalent to .

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

A block.

Block<T> right

Another block.

Returns
Type Description
Boolean

true if two blocks are equal. Otherwise false.

| Improve this Doc View Source

Inequality(Block<T>, Block<T>)

Negation of .

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

A block.

Block<T> right

Another block.

Returns
Type Description
Boolean

true if two blocks are different. Otherwise false.

Implements

IPreEvaluationBlock<T>
IBlockContent<T>
IBlockHeader
IPreEvaluationBlockHeader
IBlockMetadata
IBlockExcerpt
IEquatable<>
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2021 Planetarium