Class BlockHeader
Block header containing information about Block<T>s except transactions.
Namespace: Libplanet.Blocks
Assembly: Libplanet.dll
Syntax
public sealed class BlockHeader : object, IBlockHeader, IPreEvaluationBlockHeader, IBlockMetadata, IBlockExcerpt
Constructors
| Improve this Doc View SourceBlockHeader(PreEvaluationBlockHeader, HashDigest<SHA256>, Nullable<ImmutableArray<Byte>>)
Creates a BlockHeader instance from the given
preEvaluationBlockHeader
and stateRootHash
.
This automatically derives its hash from the given inputs.
Declaration
public BlockHeader(PreEvaluationBlockHeader preEvaluationBlockHeader, HashDigest<SHA256> stateRootHash, ImmutableArray<byte>? signature)
Parameters
Type | Name | Description |
---|---|---|
PreEvaluationBlockHeader | preEvaluationBlockHeader | The pre-evaluation block header. |
HashDigest<SHA256> | stateRootHash | The state root hash. |
Nullable<ImmutableArray<Byte>> | signature | The block signature. |
Exceptions
Type | Condition |
---|---|
InvalidBlockSignatureException | Thrown when
the |
BlockHeader(PreEvaluationBlockHeader, HashDigest<SHA256>, Nullable<ImmutableArray<Byte>>, BlockHash)
Creates a BlockHeader instance from the given
preEvaluationBlockHeader
and stateRootHash
.
It also checks the sanity of the given hash
.
Declaration
public BlockHeader(PreEvaluationBlockHeader preEvaluationBlockHeader, HashDigest<SHA256> stateRootHash, ImmutableArray<byte>? signature, BlockHash hash)
Parameters
Type | Name | Description |
---|---|---|
PreEvaluationBlockHeader | preEvaluationBlockHeader | The pre-evaluation block header. |
HashDigest<SHA256> | stateRootHash | The state root hash. |
Nullable<ImmutableArray<Byte>> | signature | The block signature. |
BlockHash | hash | The block hash to check. |
Exceptions
Type | Condition |
---|---|
InvalidBlockSignatureException | Thrown when
the |
InvalidBlockHashException | Thrown when the given block
|
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 SourceIndex
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 must 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 SourceTxHash
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 SourceToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |