• Overview
  • Design
  • API Reference
  • Changelog
  • Contribute
Show / Hide Table of Contents
  • Libplanet
    • Address
    • AddressExtension
    • ByteUtil
    • Hashcash
    • Hashcash.Stamp
    • HashDigest<T>
    • HashDigestExtension
    • Nonce
  • Libplanet.Action
    • AccountStateGetter
    • ActionEvaluation
    • ActionTypeAttribute
    • IAccountStateDelta
    • IAction
    • IActionContext
    • IRandom
    • MissingActionTypeException
    • PolymorphicAction<T>
    • RandomExtension
    • UnexpectedlyTerminatedActionException
  • Libplanet.Blockchain
    • BlockChain<T>
    • BlockChain<T>.TipChangedEventArgs
    • IncompleteBlockStatesException
    • MineBlockEventArgs<T>
  • Libplanet.Blockchain.Policies
    • BlockPolicy<T>
    • IBlockPolicy<T>
  • Libplanet.Blocks
    • Block<T>
    • InvalidBlockDifficultyException
    • InvalidBlockException
    • InvalidBlockHashException
    • InvalidBlockIndexException
    • InvalidBlockNonceException
    • InvalidBlockPreviousHashException
    • InvalidBlockTimestampException
    • InvalidGenesisBlockException
  • Libplanet.Crypto
    • CryptoConfig
    • DefaultCryptoBackend
    • ICryptoBackend
    • InvalidCiphertextException
    • PrivateKey
    • PublicKey
    • SymmetricKey
  • Libplanet.KeyStore
    • IncorrectPassphraseException
    • InvalidKeyJsonException
    • KeyJsonException
    • MismatchedAddressException
    • ProtectedPrivateKey
    • UnsupportedKeyJsonException
  • Libplanet.KeyStore.Ciphers
    • Aes128Ctr
    • ICipher
  • Libplanet.KeyStore.Kdfs
    • IKdf
    • Pbkdf2<T>
    • Scrypt
  • Libplanet.Net
    • ActionExecutionState
    • BlockDownloadState
    • BoundPeer
    • DifferentAppProtocolVersionException
    • DifferentProtocolVersionEventArgs
    • IceServer
    • IceServerException
    • InvalidMessageException
    • NoSwarmContextException
    • Peer
    • PeerNotFoundException
    • PeerState
    • PreloadBlockDownloadFailEventArgs
    • PreloadState
    • StateDownloadState
    • Swarm<T>
    • SwarmException
  • Libplanet.Net.Protocols
    • PeerDiscoveryException
  • Libplanet.Serialization
    • SerializationInfoExtension
  • Libplanet.Store
    • BaseIndex<TKey, TVal>
    • BaseStore
    • BlockSet<T>
    • ChainIdNotFoundException
    • DefaultStore
    • IStore
    • StoreExtension
    • TransactionSet<T>
  • Libplanet.Tx
    • InvalidTxException
    • InvalidTxIdException
    • InvalidTxNonceException
    • InvalidTxPublicKeyException
    • InvalidTxSignatureException
    • InvalidTxUpdatedAddressesException
    • Transaction<T>
    • TxId

Class Block<T>

Inheritance
Object
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 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(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 has to satisfy. Goes to the 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.

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

Properties

| Improve this Doc View Source

Difficulty

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

Hash

Declaration
public HashDigest<SHA256> Hash { get; }
Property Value
Type Description
HashDigest<SHA256>
| 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

PreviousHash

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

Timestamp

Declaration
public DateTimeOffset Timestamp { get; }
Property Value
Type Description
DateTimeOffset
| 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
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)

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 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.

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.

InvalidTxUpdatedAddressesException

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

| Improve this Doc View Source

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

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, 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

Difficulty to find the Block<T> Nonce.

Address miner

The Address of miner that mined the block.

Nullable<HashDigest<SHA256>> previousHash

The HashDigest<T> of previous block.

DateTimeOffset timestamp

The when mining started.

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.

| 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

ToString()

Declaration
public override string ToString()
Returns
Type Description
String
  • Improve this Doc
  • View Source
Back to top Copyright © 2019–2020 Planetarium