Class BlockContent<T>
A block content without any proofs like nonce or hash. This represents contents of a block that is not yet mined.
Inherited Members
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 SourceBlockContent()
Creates a new empty BlockContent<T> instance.
Declaration
public BlockContent()
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 |
InvalidBlockIndexException | Thrown when the value to set is negative. |
InvalidBlockDifficultyException | Thrown when the value to set is is negative. |
InvalidBlockTotalDifficultyException | Thrown when
the |
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
|
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 |
InvalidBlockIndexException | Thrown when the value to set is negative. |
InvalidBlockDifficultyException | Thrown when the value to set is is negative. |
InvalidBlockTotalDifficultyException | Thrown when
the |
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
|
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 |
InvalidBlockIndexException | Thrown when the |
InvalidBlockDifficultyException | Thrown when
the |
InvalidBlockTotalDifficultyException | Thrown when
the |
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
|
Properties
| Improve this Doc View SourceTransactions
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. |
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
Exceptions
Type | Condition |
---|---|
InvalidBlockTxHashException | Thrown when the TxHash is inconsistent with Transactions. |
Methods
| Improve this Doc View SourceMine(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. |