Show / Hide Table of Contents

Class Block<T>

Inheritance
Object
Block<T>
Implements
IBlockExcerpt
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Namespace: Libplanet.Blocks
Assembly: Libplanet.dll
Syntax
public class Block<T> : IBlockExcerpt where T : IAction, new()
Type Parameters
Name Description
T

Constructors

| Improve this Doc View Source

Block(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 representation of Block<T> instance.

| Improve this Doc View Source

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

Block(Int64, Int64, BigInteger, Nonce, Nullable<Address>, Nullable<HashDigest<SHA256>>, DateTimeOffset, IEnumerable<Transaction<T>>, Nullable<HashDigest<SHA256>>, Nullable<HashDigest<SHA256>>, Int32)

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>>, Int32, 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 = default(HashDigest<SHA256>? ), HashDigest<SHA256>? stateRootHash = default(HashDigest<SHA256>? ), int protocolVersion = 1)
Parameters
Type Name Description
Int64 index

The height of the block to create. Goes to the Index.

Int64 difficulty

The mining difficulty that nonce has to satisfy. Goes to the Difficulty.

BigInteger totalDifficulty

The total mining difficulty until this block. See also Difficulty.

Nonce nonce

The nonce which satisfy the given difficulty with any other field values. Goes to the Nonce.

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., index is 0) this should be null. Goes to the PreviousHash.

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 stateRootHash (i.e., without action evaluation). Automatically determined if null is passed (which is default).

Nullable<HashDigest<SHA256>> stateRootHash

The Hash of the states on the block.

Int32 protocolVersion

The protocol version. CurrentProtocolVersion by default.

See Also
Mine(Int64, Int64, BigInteger, Address, Nullable<HashDigest<SHA256>>, DateTimeOffset, IEnumerable<Transaction<T>>, Int32, CancellationToken)

Fields

| Improve this Doc View Source

CurrentProtocolVersion

The most latest protocol version.

Declaration
public const int CurrentProtocolVersion = 1
Field Value
Type Description
Int32

Properties

| Improve this Doc View Source

BytesLength

The bytes length in its serialized format.

Declaration
public int BytesLength { get; }
Property Value
Type Description
Int32
| Improve this Doc View Source

Difficulty

Declaration
public long Difficulty { get; }
Property Value
Type Description
Int64
| Improve this Doc View Source

Hash

Hash is derived from a serialized Block<T> after Actions are evaluated.

Declaration
public HashDigest<SHA256> Hash { get; }
Property Value
Type Description
HashDigest<SHA256>
See Also
PreEvaluationHash
StateRootHash
| Improve this Doc View Source

Header

The BlockHeader of the block.

Declaration
public BlockHeader Header { get; }
Property Value
Type Description
BlockHeader
| Improve this Doc View Source

Index

Declaration
public long Index { get; }
Property Value
Type Description
Int64
| Improve this Doc View Source

Miner

Declaration
public Address? Miner { get; }
Property Value
Type Description
Nullable<Address>
| Improve this Doc View Source

Nonce

Declaration
public Nonce Nonce { get; }
Property Value
Type Description
Nonce
| Improve this Doc View Source

PreEvaluationHash

The hash derived from the block except of StateRootHash (i.e., without action evaluation). Used for Libplanet.Blocks.BlockHeader.Validate(System.DateTimeOffset) checking Nonce.

Declaration
public HashDigest<SHA256> PreEvaluationHash { get; }
Property Value
Type Description
HashDigest<SHA256>
See Also
Nonce
Libplanet.Blocks.BlockHeader.Validate(System.DateTimeOffset)
| Improve this Doc View Source

PreviousHash

Declaration
public HashDigest<SHA256>? PreviousHash { get; }
Property Value
Type Description
Nullable<HashDigest<SHA256>>
| Improve this Doc View Source

ProtocolVersion

The protocol version number.

Declaration
public int ProtocolVersion { get; }
Property Value
Type Description
Int32
| Improve this Doc View Source

StateRootHash

The Hash of the states on the block.

Declaration
public HashDigest<SHA256>? StateRootHash { get; }
Property Value
Type Description
Nullable<HashDigest<SHA256>>
See Also
Hash
| Improve this Doc View Source

Timestamp

Declaration
public DateTimeOffset Timestamp { get; }
Property Value
Type Description
DateTimeOffset
| Improve this Doc View Source

TotalDifficulty

Declaration
public BigInteger TotalDifficulty { get; }
Property Value
Type Description
BigInteger
| Improve this Doc View Source

Transactions

Declaration
public IEnumerable<Transaction<T>> Transactions { get; }
Property Value
Type Description
IEnumerable<Transaction<T>>
| Improve this Doc View Source

TxHash

Declaration
public HashDigest<SHA256>? TxHash { get; }
Property Value
Type Description
Nullable<HashDigest<SHA256>>

Methods

| Improve this Doc View Source

Deserialize(Byte[])

Decodes a Block<T>'s Bencodex representation.

Declaration
[Pure]
public static Block<T> Deserialize(byte[] bytes)
Parameters
Type Name Description
Byte[] bytes

A Bencodex representation of a Block<T>.

Returns
Type Description
Block<T>

A decoded Block<T> object.

See Also
Serialize()
| Improve this Doc View Source

Evaluate(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 null value, which is default, means a constant function that returns null. This affects the execution of Actions.

AccountBalanceGetter accountBalanceGetter

An AccountBalanceGetter delegate to get previous account balance. A null value, which is default, means a constant function that returns zero. This affects the execution of Actions.

ITrie previousBlockStatesTrie

The trie to contain states at previous block.

Returns
Type Description
IEnumerable<ActionEvaluation>

An ActionEvaluation for each IAction.

Exceptions
Type Condition
InvalidBlockHashException

Thrown when the Hash is invalid.

InvalidBlockTimestampException

Thrown when the Timestamp is invalid, for example, it is the far future than the given currentTime.

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.

InvalidBlockTxHashException

Thrown when the TxHash does not match with its Transactions.

InvalidTxUpdatedAddressesException

Thrown when any IAction of Transactions tries to update the states of Addresses not included in UpdatedAddresses.

InvalidTxSignatureException

Thrown when its Signature is invalid or not signed by the account who corresponds to its PublicKey.

InvalidTxPublicKeyException

Thrown when its Signer is not derived from its PublicKey.

| Improve this Doc View Source

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
[Pure]
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 null value, which is default, means a constant function that returns null.

AccountBalanceGetter accountBalanceGetter

An AccountBalanceGetter delegate to get previous account balance. A null value, which is default, means a constant function that returns zero.

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.

| Improve this Doc View Source

Mine(Int64, Int64, BigInteger, Address, Nullable<HashDigest<SHA256>>, DateTimeOffset, IEnumerable<Transaction<T>>, Int32, 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, int protocolVersion = 1, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
Int64 index

Index of the block.

Int64 difficulty

Difficulty to find the Block<T> Nonce.

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 DateTimeOffset when mining started.

IEnumerable<Transaction<T>> transactions

Transaction<T>s that are going to be included in the block.

Int32 protocolVersion

The protocol version.

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.

| Improve this Doc View Source

Serialize()

Declaration
public byte[] Serialize()
Returns
Type Description
Byte[]
| Improve this Doc View Source

ToBencodex()

Declaration
public Bencodex.Types.Dictionary ToBencodex()
Returns
Type Description
Bencodex.Types.Dictionary
| Improve this Doc View Source

ToBlockDigest()

Gets BlockDigest representation of the Block<T>.

Declaration
public BlockDigest ToBlockDigest()
Returns
Type Description
BlockDigest

BlockDigest representation of the Block<T>.

| Improve this Doc View Source

ToString()

Declaration
public override string ToString()
Returns
Type Description
String
Overrides
Object.ToString()

Operators

| Improve this Doc View Source

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

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

Implements

IBlockExcerpt

Extension Methods

BlockExcerpt.ToExcerptString(IBlockExcerpt)
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2021 Planetarium