Show / Hide Table of Contents

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.

Inheritance
Object
BlockMetadata
Implements
IBlockMetadata
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Libplanet.Types.Blocks
Assembly: Libplanet.Types.dll
Syntax
public class BlockMetadata : IBlockMetadata

Constructors

| Improve this Doc View Source

BlockMetadata(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
BlockMetadata(Int32, Int64, DateTimeOffset, Address, PublicKey, Nullable<BlockHash>, Nullable<HashDigest<SHA256>>, BlockCommit)
| Improve this Doc View Source

BlockMetadata(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 protocolVersion is less than zero or greater than CurrentProtocolVersion, the latest known protocol version.

InvalidBlockIndexException

Thrown when index is less than zero.

InvalidBlockPublicKeyException

Thrown when any of the following conditions isn't satisfied:

  • If protocolVersion >= 2, miner should match the derived address of publicKey.
  • Otherwise, publicKey must be null.
InvalidBlockPreviousHashException

Thrown when previousHash is not null while index is zero or previousHash is null while index is nonzero.

See Also
BlockContent
| Improve this Doc View Source

BlockMetadata(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
BlockMetadata(Int32, Int64, DateTimeOffset, Address, PublicKey, Nullable<BlockHash>, Nullable<HashDigest<SHA256>>, BlockCommit)

Fields

| Improve this Doc View Source

CurrentProtocolVersion

The latest protocol version.

Declaration
public const int CurrentProtocolVersion = 4
Field Value
Type Description
Int32
See Also
BlockContent
| Improve this Doc View Source

PoWProtocolVersion

The last PoW protocol version.

Declaration
public const int PoWProtocolVersion = 3
Field Value
Type Description
Int32
See Also
BlockContent

Properties

| 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. Not allowed to be negative.

See Also
BlockContent
| Improve this Doc View Source

LastCommit

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
BlockContent
| Improve this Doc View Source

Miner

The address of the miner.

Declaration
public Address Miner { get; }
Property Value
Type Description
Address
See Also
BlockContent
| 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>
See Also
BlockContent
| Improve this Doc View Source

ProtocolVersion

The protocol version number.

Declaration
public int ProtocolVersion { get; }
Property Value
Type Description
Int32
See Also
BlockContent
| 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
See Also
BlockContent
| 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.

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

Methods

| Improve this Doc View Source

DerivePreEvaluationHash(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
BlockContent
| Improve this Doc View Source

MakeCandidateData(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.

See Also
BlockContent

Implements

IBlockMetadata

Extension Methods

IBlockMetadataExtensions.ValidateTimestamp(IBlockMetadata)
IBlockMetadataExtensions.ValidateTimestamp(IBlockMetadata, DateTimeOffset)

See Also

BlockContent
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium