Show / Hide Table of Contents

Class BlockHeader

Block header containing information about Block<T>s except transactions.

Inheritance
Object
BlockHeader
Implements
IBlockHeader
IPreEvaluationBlockHeader
IBlockMetadata
IBlockExcerpt
Namespace: Libplanet.Blocks
Assembly: Libplanet.dll
Syntax
public sealed class BlockHeader : object, IBlockHeader, IPreEvaluationBlockHeader, IBlockMetadata, IBlockExcerpt

Constructors

| Improve this Doc View Source

BlockHeader(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 signature signature is invalid.

| Improve this Doc View Source

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 signature signature is invalid.

InvalidBlockHashException

Thrown when the given block hash is consistent with other arguments.

Properties

| 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

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 must 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

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

ToString()

Declaration
public override string ToString()
Returns
Type Description
String

Implements

IBlockHeader
IPreEvaluationBlockHeader
IBlockMetadata
IBlockExcerpt
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2022 Planetarium