Show / Hide Table of Contents

Class BlockContent<T>

A block content without any proofs like nonce or hash. This represents contents of a block that is not yet mined.

Inheritance
Object
BlockMetadata
BlockContent<T>
Implements
IBlockContent<T>
IBlockMetadata
Inherited Members
BlockMetadata.CurrentProtocolVersion
BlockMetadata.ProtocolVersion
BlockMetadata.Index
BlockMetadata.Timestamp
BlockMetadata.Miner
BlockMetadata.PublicKey
BlockMetadata.Difficulty
BlockMetadata.TotalDifficulty
BlockMetadata.PreviousHash
BlockMetadata.MakeCandidateData(Nonce)
BlockMetadata.DerivePreEvaluationHash(HashAlgorithmType, Nonce)
BlockMetadata.MineNonce(HashAlgorithmType, CancellationToken)
BlockMetadata.MineNonce(HashAlgorithmType, Int32, CancellationToken)
Namespace: Libplanet.Blocks
Assembly: Libplanet.dll
Syntax
public sealed class BlockContent<T> : BlockMetadata, IBlockContent<T>, IBlockMetadata 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.

Remarks

Unlike other model types like Block<T> or Transaction<T>, this type is mutable. To get a distinct instance with partly changed fields, use BlockContent(IBlockContent<T>) constructor and property setters on a copy instead.

Constructors

| Improve this Doc View Source

BlockContent()

Creates a new empty BlockContent<T> instance.

Declaration
public BlockContent()
| Improve this Doc View Source

BlockContent(IBlockContent<T>)

Creates a BlockContent<T> by copying the fields of another block content.

Declaration
public BlockContent(IBlockContent<T> content)
Parameters
Type Name Description
IBlockContent<T> content

This source of the block content to copy. This hasn't be a actual BlockContent<T> instance, but can be any object which implements IBlockContent<T> instance.

Exceptions
Type Condition
InvalidBlockProtocolVersionException

Thrown when the content's ProtocolVersion is less than 0, or greater than CurrentProtocolVersion, the latest known protocol version.

InvalidBlockIndexException

Thrown when the value to set is negative.

InvalidBlockDifficultyException

Thrown when the value to set is is negative.

InvalidBlockTotalDifficultyException

Thrown when the content's TotalDifficulty is less than its Difficulty.

InvalidTxSignatureException

Thrown when any tx signature is invalid or not signed by its signer.

InvalidTxPublicKeyException

Thrown when any tx signer is not derived from its its public key.

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 content's TxHash is not consistent with its Transactions.

| Improve this Doc View Source

BlockContent(IBlockMetadata)

Creates a new BlockContent<T> instance filled with the given metadata's contents and zero transactions.

Declaration
public BlockContent(IBlockMetadata metadata)
Parameters
Type Name Description
IBlockMetadata metadata

The IBlockMetadata to copy.

Exceptions
Type Condition
InvalidBlockProtocolVersionException

Thrown when the metadata's to set is ProtocolVersion is less than 0, or greater than CurrentProtocolVersion, the latest known protocol version.

InvalidBlockIndexException

Thrown when the value to set is negative.

InvalidBlockDifficultyException

Thrown when the value to set is is negative.

InvalidBlockTotalDifficultyException

Thrown when the metadata's TotalDifficulty is less than its Difficulty.

InvalidTxSignatureException

Thrown when any tx signature is invalid or not signed by its signer.

InvalidTxPublicKeyException

Thrown when any tx signer is not derived from its its public key.

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 metadata's TxHash is not null.

| Improve this Doc View Source

BlockContent(IBlockMetadata, IEnumerable<Transaction<T>>)

Creates a new BlockContent<T> instance filled with the given metadata's contents and transactions.

Declaration
public BlockContent(IBlockMetadata metadata, IEnumerable<Transaction<T>> transactions)
Parameters
Type Name Description
IBlockMetadata metadata

The IBlockMetadata to copy.

IEnumerable<Transaction<T>> transactions

The transactions to include in the block.

Exceptions
Type Condition
InvalidBlockProtocolVersionException

Thrown when the metadata's ProtocolVersion is less than 0, or greater than CurrentProtocolVersion, the latest known protocol version.

InvalidBlockIndexException

Thrown when the metadata has a negative Index.

InvalidBlockDifficultyException

Thrown when the metadata's Difficulty is negative.

InvalidBlockTotalDifficultyException

Thrown when the metadata's TotalDifficulty is less than its Difficulty.

InvalidTxSignatureException

Thrown when any tx signature is invalid or not signed by its signer.

InvalidTxPublicKeyException

Thrown when any tx signer is not derived from its its public key.

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 metadata's TxHash is inconsistent with transactions.

Properties

| Improve this Doc View Source

Transactions

Transactions belonging to the block.

Declaration
public IReadOnlyList<Transaction<T>> Transactions { get; set; }
Property Value
Type Description
IReadOnlyList<Transaction<T>>
Remarks

This is always ordered by Id.

When Transactions is updated, TxHash is also updated together.

Exceptions
Type Condition
InvalidTxSignatureException

Thrown when any tx signature is invalid or not signed by its signer.

InvalidTxPublicKeyException

Thrown when any tx signer is not derived from its its public key.

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.

| 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 override HashDigest<SHA256>? TxHash { get; set; }
Property Value
Type Description
Nullable<HashDigest<SHA256>>
Overrides
BlockMetadata.TxHash
Exceptions
Type Condition
InvalidBlockTxHashException

Thrown when the TxHash is inconsistent with Transactions.

Methods

| Improve this Doc View Source

Mine(HashAlgorithmType, CancellationToken)

Mines the PoW (proof-of-work) nonce satisfying the block Difficulty, and returns a valid PreEvaluationBlock<T> instance.

Declaration
public PreEvaluationBlock<T> Mine(HashAlgorithmType hashAlgorithm, CancellationToken cancellationToken = null)
Parameters
Type Name Description
HashAlgorithmType hashAlgorithm

The hash algorithm to use for calculating pre-evaluation hash.

CancellationToken cancellationToken

An optional cancellation token used to propagate signal that this operation should be cancelled.

Returns
Type Description
PreEvaluationBlock<T>

A PreEvaluationBlock<T> instance with a valid proof-of-work.

Implements

IBlockContent<T>
IBlockMetadata
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2021 Planetarium