Class BlockMetadata
A block metadata without transactions or any proof hash. This represents metadata of a block that is not yet mined nor proven.
To represent a block content including its metadata and transactions, use BlockContent.
Implements
Inherited Members
Namespace: Libplanet.Types.Blocks
Assembly: Libplanet.Types.dll
Syntax
public class BlockMetadata : IBlockMetadata
Constructors
| Improve this Doc View SourceBlockMetadata(IBlockMetadata)
Creates a BlockMetadata by copying the fields of another block
metadata
.
Declaration
public BlockMetadata(IBlockMetadata metadata)
Parameters
Type | Name | Description |
---|---|---|
IBlockMetadata | metadata | The source block metadata to copy. This needn't be an actual BlockMetadata instance, but can be any object which implements IBlockMetadata. |
Remarks
As metadata
needn't be an actual BlockMetadata
instance, but simply any object implementing IBlockMetadata interface,
it can't be trusted to satisfy all the constraints for a valid
BlockMetadata instance. As such, conditions are checked again whilst
creating a copy. This is a relatively heavy operation, so must be used sparingly.
This gets redirected to BlockMetadata(Int32, Int64, DateTimeOffset, Address, PublicKey, Nullable<BlockHash>, Nullable<HashDigest<SHA256>>, BlockCommit). Refer to the aforementioned constructor to see the full list of Exceptions that may be thrown.
See Also
| Improve this Doc View SourceBlockMetadata(Int32, Int64, DateTimeOffset, Address, PublicKey, Nullable<BlockHash>, Nullable<HashDigest<SHA256>>, BlockCommit)
Creates a BlockMetadata by manually filling in the fields for BlockMetadata. All other public constructors are redirected to this one.
Declaration
public BlockMetadata(int protocolVersion, long index, DateTimeOffset timestamp, Address miner, PublicKey publicKey, BlockHash? previousHash, HashDigest<SHA256>? txHash, BlockCommit lastCommit)
Parameters
Type | Name | Description |
---|---|---|
Int32 | protocolVersion | Goes to ProtocolVersion. |
Int64 | index | Goes to Index. |
DateTimeOffset | timestamp | Goes to Timestamp. |
Address | miner | Goes to Miner. |
PublicKey | publicKey | Goes to PublicKey. |
Nullable<BlockHash> | previousHash | Goes to PreviousHash. |
Nullable<HashDigest<SHA256>> | txHash | Goes to TxHash. |
BlockCommit | lastCommit | Goes to LastCommit. |
Remarks
Except for debugging and/or testing purposes, this shouldn't be called directly.
Exceptions
Type | Condition |
---|---|
InvalidBlockProtocolVersionException | Thrown when
|
InvalidBlockIndexException | Thrown when |
InvalidBlockPublicKeyException | Thrown when any of the following conditions isn't satisfied:
|
InvalidBlockPreviousHashException | Thrown when
|
See Also
| Improve this Doc View SourceBlockMetadata(Int64, DateTimeOffset, PublicKey, Nullable<BlockHash>, Nullable<HashDigest<SHA256>>, BlockCommit)
Creates a BlockMetadata with CurrentProtocolVersion as its ProtocolVersion.
Declaration
public BlockMetadata(long index, DateTimeOffset timestamp, PublicKey publicKey, BlockHash? previousHash, HashDigest<SHA256>? txHash, BlockCommit lastCommit)
Parameters
Type | Name | Description |
---|---|---|
Int64 | index | Goes to Index. |
DateTimeOffset | timestamp | Goes to Timestamp. |
PublicKey | publicKey | Goes to PublicKey. |
Nullable<BlockHash> | previousHash | Goes to PreviousHash. |
Nullable<HashDigest<SHA256>> | txHash | Goes to TxHash. |
BlockCommit | lastCommit | Goes to LastCommit. |
See Also
Fields
| Improve this Doc View SourceCurrentProtocolVersion
The latest protocol version.
Declaration
public const int CurrentProtocolVersion = 4
Field Value
Type | Description |
---|---|
Int32 |
See Also
| Improve this Doc View SourcePoWProtocolVersion
The last PoW protocol version.
Declaration
public const int PoWProtocolVersion = 3
Field Value
Type | Description |
---|---|
Int32 |
See Also
Properties
| 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. Not allowed to be negative.
See Also
| Improve this Doc View SourceLastCommit
A block metadata without transactions or any proof hash. This represents metadata of a block that is not yet mined nor proven.
To represent a block content including its metadata and transactions, use BlockContent.
Declaration
public BlockCommit LastCommit { get; set; }
Property Value
Type | Description |
---|---|
BlockCommit |
See Also
| Improve this Doc View SourceMiner
The address of the miner.
Declaration
public Address Miner { get; }
Property Value
Type | Description |
---|---|
Address |
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> |
See Also
| Improve this Doc View SourceProtocolVersion
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 |
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.
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>> |
See Also
Methods
| Improve this Doc View SourceDerivePreEvaluationHash(Nonce)
Derives a hash digest from the block metadata and nonce
.
Declaration
public HashDigest<SHA256> DerivePreEvaluationHash(Nonce nonce)
Parameters
Type | Name | Description |
---|---|---|
Nonce | nonce | The proof-of-work nonce. |
Returns
Type | Description |
---|---|
HashDigest<SHA256> | A pre-evaluation block hash. |
See Also
| Improve this Doc View SourceMakeCandidateData(Nonce)
Serializes data of a possible candidate shifted from it into a Bencodex dictionary.
This data is used for PoW (proof-of-work) to find the satisfying
nonce
, rather than transmitting the block over the network.
Declaration
public Dictionary MakeCandidateData(Nonce nonce)
Parameters
Type | Name | Description |
---|---|---|
Nonce | nonce | The nonce of the block. |
Returns
Type | Description |
---|---|
Bencodex.Types.Dictionary | The serialized block content in a Bencodex dictionary. |