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(Int64, Int64, Nonce, Nullable<Address>, Nullable<HashDigest<SHA256>>, DateTimeOffset, IEnumerable<Transaction<T>>)
Creates a Block<T> instance by manually filling all field values. For a more automated way, see also Mine(Int64, Int64, Address, Nullable<HashDigest<SHA256>>, DateTimeOffset, IEnumerable<Transaction<T>>, CancellationToken) method.
Declaration
public Block(long index, long difficulty, Nonce nonce, Address? miner, HashDigest<SHA256>? previousHash, DateTimeOffset timestamp, IEnumerable<Transaction<T>> transactions)
Parameters
Type | Name | Description |
---|---|---|
Int64 | index | The height of the block to create. Goes to the Index. |
Int64 | difficulty | The mining difficulty that |
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. |
See Also
Properties
| Improve this Doc View SourceDifficulty
Declaration
public long Difficulty { get; }
Property Value
Type | Description |
---|---|
Int64 |
Hash
Declaration
public HashDigest<SHA256> Hash { get; }
Property Value
Type | Description |
---|---|
HashDigest<SHA256> |
Index
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 |
PreviousHash
Declaration
public HashDigest<SHA256>? PreviousHash { get; }
Property Value
Type | Description |
---|---|
Nullable<HashDigest<SHA256>> |
Timestamp
Declaration
public DateTimeOffset Timestamp { get; }
Property Value
Type | Description |
---|---|
DateTimeOffset |
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)
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)
Parameters
Type | Name | Description |
---|---|---|
DateTimeOffset | currentTime | The current time to validate time-wise conditions. |
AccountStateGetter | accountStateGetter | The getter of previous states. This affects the execution of Actions. |
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)
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)
Parameters
Type | Name | Description |
---|---|---|
AccountStateGetter | accountStateGetter | An AccountStateGetter
delegate to get a previous state.
A |
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, 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, 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 | |
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 |