Class Block<T>
Namespace: Libplanet.Blocks
Assembly: Libplanet.dll
Syntax
public class Block<T> : object where T : IAction, new()
Type Parameters
Name | Description |
---|---|
T |
Constructors
| Improve this Doc View SourceBlock(Bencodex.Types.Dictionary)
Creates a Block<T> instance from its serialization.
Declaration
public Block(Bencodex.Types.Dictionary dict)
Parameters
Type | Name | Description |
---|---|---|
Bencodex.Types.Dictionary | dict | The |
Block(Block<T>, Nullable<HashDigest<SHA256>>)
Declaration
public Block(Block<T> block, HashDigest<SHA256>? stateRootHash)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | block | |
Nullable<HashDigest<SHA256>> | stateRootHash |
Block(Int64, Int64, BigInteger, Nonce, Nullable<Address>, Nullable<HashDigest<SHA256>>, DateTimeOffset, IEnumerable<Transaction<T>>, Nullable<HashDigest<SHA256>>, Nullable<HashDigest<SHA256>>)
Creates a Block<T> instance by manually filling all field values. For a more automated way, see also Mine(Int64, Int64, BigInteger, Address, Nullable<HashDigest<SHA256>>, DateTimeOffset, IEnumerable<Transaction<T>>, CancellationToken) method.
Declaration
public Block(long index, long difficulty, BigInteger totalDifficulty, Nonce nonce, Address? miner, HashDigest<SHA256>? previousHash, DateTimeOffset timestamp, IEnumerable<Transaction<T>> transactions, HashDigest<SHA256>? preEvaluationHash = null, HashDigest<SHA256>? stateRootHash = null)
Parameters
Type | Name | Description |
---|---|---|
Int64 | index | The height of the block to create. Goes to the Index. |
Int64 | difficulty | The mining difficulty that |
BigInteger | totalDifficulty | The total mining difficulty until this block. See also Difficulty. |
Nonce | nonce | The nonce which satisfy the given |
Nullable<Address> | miner | An optional address refers to who mines this block. Goes to the Miner. |
Nullable<HashDigest<SHA256>> | previousHash | The previous block's Hash. If it's a genesis
block (i.e., |
DateTimeOffset | timestamp | The time this block is created. Goes to the Timestamp. |
IEnumerable<Transaction<T>> | transactions | The transactions to be mined together with this block. Transactions become sorted in an unpredicted-before-mined order and then go to the Transactions property. |
Nullable<HashDigest<SHA256>> | preEvaluationHash | The hash derived from the block except of
|
Nullable<HashDigest<SHA256>> | stateRootHash | The Hash of the states on the block. |
See Also
Properties
| Improve this Doc View SourceBytesLength
The bytes length in its serialized format.
Declaration
public int BytesLength { get; }
Property Value
Type | Description |
---|---|
Int32 |
Difficulty
Declaration
public long Difficulty { get; }
Property Value
Type | Description |
---|---|
Int64 |
Hash
Declaration
public HashDigest<SHA256> Hash { get; }
Property Value
Type | Description |
---|---|
HashDigest<SHA256> |
See Also
| Improve this Doc View SourceIndex
Declaration
public long Index { get; }
Property Value
Type | Description |
---|---|
Int64 |
Miner
Declaration
public Address? Miner { get; }
Property Value
Type | Description |
---|---|
Nullable<Address> |
Nonce
Declaration
public Nonce Nonce { get; }
Property Value
Type | Description |
---|---|
Nonce |
PreEvaluationHash
The hash derived from the block except of StateRootHash (i.e., without action evaluation). Used for Libplanet.Blocks.BlockHeader.Validate(DateTimeOffset) checking Nonce.
Declaration
public HashDigest<SHA256> PreEvaluationHash { get; }
Property Value
Type | Description |
---|---|
HashDigest<SHA256> |
See Also
PreviousHash
Declaration
public HashDigest<SHA256>? PreviousHash { get; }
Property Value
Type | Description |
---|---|
Nullable<HashDigest<SHA256>> |
StateRootHash
The Hash of the states on the block.
Declaration
public HashDigest<SHA256>? StateRootHash { get; }
Property Value
Type | Description |
---|---|
Nullable<HashDigest<SHA256>> |
See Also
| Improve this Doc View SourceTimestamp
Declaration
public DateTimeOffset Timestamp { get; }
Property Value
Type | Description |
---|---|
DateTimeOffset |
TotalDifficulty
Declaration
public BigInteger TotalDifficulty { get; }
Property Value
Type | Description |
---|---|
BigInteger |
Transactions
Declaration
public IEnumerable<Transaction<T>> Transactions { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Transaction<T>> |
TxHash
Declaration
public HashDigest<SHA256>? TxHash { get; }
Property Value
Type | Description |
---|---|
Nullable<HashDigest<SHA256>> |
Methods
| Improve this Doc View SourceDeserialize(Byte[])
Declaration
public static Block<T> Deserialize(byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | bytes |
Returns
Type | Description |
---|---|
Block<T> | A decoded Block<T> object. |
See Also
| Improve this Doc View SourceEvaluate(DateTimeOffset, AccountStateGetter, AccountBalanceGetter, ITrie)
Executes every IAction in the Transactions and gets result states of each step of every Transaction<T>.
It throws an InvalidBlockException or an InvalidTxException if there is any integrity error.
Otherwise it enumerates an ActionEvaluation for each IAction.
Declaration
public IEnumerable<ActionEvaluation> Evaluate(DateTimeOffset currentTime, AccountStateGetter accountStateGetter = null, AccountBalanceGetter accountBalanceGetter = null, ITrie previousBlockStatesTrie = null)
Parameters
Type | Name | Description |
---|---|---|
DateTimeOffset | currentTime | The current time to validate time-wise conditions. |
AccountStateGetter | accountStateGetter | An AccountStateGetter delegate to get
a previous state. A |
AccountBalanceGetter | accountBalanceGetter | An AccountBalanceGetter delegate to
get previous account balance.
A |
ITrie | previousBlockStatesTrie | The trie to contain states at previous block. |
Returns
Type | Description |
---|---|
IEnumerable<ActionEvaluation> | An ActionEvaluation for each IAction. |
Exceptions
Type | Condition |
---|---|
InvalidBlockTimestampException | Thrown when
the Timestamp is invalid, for example, it is the far
future than the given |
InvalidBlockIndexException | Thrown when the Indexis invalid, for example, it is a negative integer. |
InvalidBlockDifficultyException | Thrown when the Difficulty is not properly configured, for example, it is too easy. |
InvalidBlockPreviousHashException | Thrown when PreviousHash is invalid so that the Block<T>s are not continuous. |
InvalidBlockNonceException | Thrown when the Nonce does not satisfy its Difficulty level. |
InvalidTxSignatureException | Thrown when its Signature is invalid or not signed by the account who corresponds to its PublicKey. |
InvalidTxPublicKeyException | |
InvalidTxUpdatedAddressesException | Thrown when any IAction of Transactions tries to update the states of Addresses not included in UpdatedAddresses. |
EvaluateActionsPerTx(AccountStateGetter, AccountBalanceGetter, ITrie)
Executes every IAction in the Transactions step by step, and emits a pair of a transaction, and an ActionEvaluation for each step.
Declaration
public IEnumerable<Tuple<Transaction<T>, ActionEvaluation>> EvaluateActionsPerTx(AccountStateGetter accountStateGetter = null, AccountBalanceGetter accountBalanceGetter = null, ITrie previousBlockStatesTrie = null)
Parameters
Type | Name | Description |
---|---|---|
AccountStateGetter | accountStateGetter | An AccountStateGetter
delegate to get a previous state.
A |
AccountBalanceGetter | accountBalanceGetter | An AccountBalanceGetter delegate to
get previous account balance.
A |
ITrie | previousBlockStatesTrie | The trie to contain states at previous block. |
Returns
Type | Description |
---|---|
IEnumerable<Tuple<Transaction<T>, ActionEvaluation>> | Enumerates pair of a transaction, and ActionEvaluation for each action. The order of pairs are the same to the Transactions and their Actions (e.g., tx¹-act¹, tx¹-act², tx²-act¹, tx²-act², …). Note that each Random object has a unconsumed state. |
Mine(Int64, Int64, BigInteger, Address, Nullable<HashDigest<SHA256>>, DateTimeOffset, IEnumerable<Transaction<T>>, CancellationToken)
Generate a block with given transactions
.
Declaration
public static Block<T> Mine(long index, long difficulty, BigInteger previousTotalDifficulty, Address miner, HashDigest<SHA256>? previousHash, DateTimeOffset timestamp, IEnumerable<Transaction<T>> transactions, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
Int64 | index | Index of the block. |
Int64 | difficulty | |
BigInteger | previousTotalDifficulty | The total difficulty until the previous Block<T>. |
Address | miner | The Address of miner that mined the block. |
Nullable<HashDigest<SHA256>> | previousHash | The HashDigest<T> of previous block. |
DateTimeOffset | timestamp | The |
IEnumerable<Transaction<T>> | transactions | Transaction<T>s that are going to be included in the block. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Block<T> | A Block<T> that mined. |
Serialize()
Declaration
public byte[] Serialize()
Returns
Type | Description |
---|---|
Byte[] |
ToBencodex()
Declaration
public Bencodex.Types.Dictionary ToBencodex()
Returns
Type | Description |
---|---|
Bencodex.Types.Dictionary |
ToBlockDigest()
Gets BlockDigest representation of the Block<T>.
Declaration
public BlockDigest ToBlockDigest()
Returns
Type | Description |
---|---|
BlockDigest | BlockDigest representation of the Block<T>. |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Operators
| Improve this Doc View SourceEquality(Block<T>, Block<T>)
Declaration
public static bool operator ==(Block<T> left, Block<T> right)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | left | |
Block<T> | right |
Returns
Type | Description |
---|---|
Boolean |
Inequality(Block<T>, Block<T>)
Declaration
public static bool operator !=(Block<T> left, Block<T> right)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | left | |
Block<T> | right |
Returns
Type | Description |
---|---|
Boolean |