Class Block<T>
The complete block including all block contents and done proof-of-work and action evaluation.
Implements
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 SourceBlock(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 |
InvalidBlockIndexException | Thrown when the |
InvalidBlockDifficultyException | Thrown when
the |
InvalidBlockTotalDifficultyException | Thrown when
the |
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 BlockChain<T>. |
InvalidTxGenesisHashException | Thrown when transactions to set have inconsistent genesis hashes. |
InvalidBlockTxHashException | Thrown when the given block
|
InvalidBlockPreEvaluationHashException | Thrown when the given
|
InvalidBlockNonceException | Thrown when the given
|
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
|
Nullable<ImmutableArray<Byte>> | signature | The block signature made using the miner's private key. |
Exceptions
Type | Condition |
---|---|
InvalidBlockSignatureException | Thrown when
the |
Fields
| Improve this Doc View SourceCurrentProtocolVersion
The latest protocol version.
Declaration
public const int CurrentProtocolVersion = null
Field Value
Type | Description |
---|---|
Int32 |
Properties
| Improve this Doc View SourceDifficulty
The mining difficulty that the block's Nonce has to satisfy.
Declaration
public long Difficulty { get; }
Property Value
Type | Description |
---|---|
Int64 |
Hash
A block's hash.
Declaration
public BlockHash Hash { get; }
Property Value
Type | Description |
---|---|
BlockHash |
See Also
| Improve this Doc View SourceHashAlgorithm
The hash algorithm used for calculating PreEvaluationHash.
Declaration
public HashAlgorithmType HashAlgorithm { get; }
Property Value
Type | Description |
---|---|
HashAlgorithmType |
Header
The BlockHeader of the block.
Declaration
public BlockHeader Header { get; }
Property Value
Type | Description |
---|---|
BlockHeader |
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
| Improve this Doc View SourceMiner
The address of the miner.
Declaration
public Address Miner { get; }
Property Value
Type | Description |
---|---|
Address |
Nonce
The proof-of-work nonce which satisfies the required Difficulty.
Declaration
public Nonce Nonce { get; }
Property Value
Type | Description |
---|---|
Nonce |
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
| Improve this Doc View SourcePreviousHash
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> |
ProtocolVersion
The protocol version number.
Declaration
public int ProtocolVersion { get; }
Property Value
Type | Description |
---|---|
Int32 |
See Also
| Improve this Doc View SourcePublicKey
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 |
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>> |
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
| Improve this Doc View SourceTimestamp
The time the block is created.
Declaration
public DateTimeOffset Timestamp { get; }
Property Value
Type | Description |
---|---|
DateTimeOffset |
Remarks
This is always UTC.
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
| Improve this Doc View SourceTransactions
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.
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 SourceEquals(Block<T>)
Declaration
public bool Equals(Block<T> other)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | other |
Returns
Type | Description |
---|---|
Boolean |
Equals(Nullable<Object>)
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
Nullable<Object> | obj |
Returns
Type | Description |
---|---|
Boolean |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Operators
| Improve this Doc View SourceEquality(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 |
|
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 |
|