Show / Hide Table of Contents

Class BlockChain<T>

A class have Blocks, Transactions, and the chain information.

In order to watch its state changes, implement IRenderer interface and pass it to the BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>) constructor.

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

An IAction type. It should match to Block's type parameter.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Constructors

| Improve this Doc View Source

BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>, IBlockChainStates, IActionEvaluator)

A class have Blocks, Transactions, and the chain information.

In order to watch its state changes, implement IRenderer interface and pass it to the BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>) constructor.

Declaration
public BlockChain(IBlockPolicy<T> policy, IStagePolicy<T> stagePolicy, IStore store, IStateStore stateStore, Block genesisBlock, IEnumerable<IRenderer> renderers, IBlockChainStates blockChainStates, IActionEvaluator actionEvaluator)
Parameters
Type Name Description
IBlockPolicy<T> policy
IStagePolicy<T> stagePolicy
IStore store
IStateStore stateStore
Block genesisBlock
IEnumerable<IRenderer> renderers
IBlockChainStates blockChainStates
IActionEvaluator actionEvaluator

The Libplanet.Blockchain.BlockChain`1.ActionEvaluator implementation to calculate next states when append new blocks.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>, IBlockChainStates)

A class have Blocks, Transactions, and the chain information.

In order to watch its state changes, implement IRenderer interface and pass it to the BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>) constructor.

Declaration
public BlockChain(IBlockPolicy<T> policy, IStagePolicy<T> stagePolicy, IStore store, IStateStore stateStore, Block genesisBlock, IEnumerable<IRenderer> renderers, IBlockChainStates blockChainStates)
Parameters
Type Name Description
IBlockPolicy<T> policy
IStagePolicy<T> stagePolicy
IStore store
IStateStore stateStore
Block genesisBlock
IEnumerable<IRenderer> renderers
IBlockChainStates blockChainStates

The IBlockChainStates implementation to state lookup.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>)

Initializes a new instance of the BlockChain<T> class by loading the canonical chain from given store.

Declaration
public BlockChain(IBlockPolicy<T> policy, IStagePolicy<T> stagePolicy, IStore store, IStateStore stateStore, Block genesisBlock, IEnumerable<IRenderer> renderers = null)
Parameters
Type Name Description
IBlockPolicy<T> policy

IBlockPolicy<T> to use in the BlockChain<T>.

IStagePolicy<T> stagePolicy

The staging policy to follow.

IStore store

IStore to store Blocks, Transactions, and BlockChain<T> information.

IStateStore stateStore

IStateStore to store states.

Block genesisBlock

The genesis Block of the BlockChain<T>, which is a part of the consensus. If the given store already contains the genesis block it checks if the existing genesis block and this argument is the same. If the store has no genesis block yet this argument will be used for that.

IEnumerable<IRenderer> renderers

Listens state changes on the created chain. Listens nothing by default or if it is null. Note that action renderers receive events made by unsuccessful transactions too; see also AtomicActionRenderer for workaround.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
ArgumentException

Thrown when store does not have canonical chain id set, i.e. GetCanonicalChainId() is null.

ArgumentNullException

Thrown when either of store or stateStore is null.

InvalidGenesisBlockException

Thrown when the store has a genesis block and it does not match to what the network expects (i.e., genesisBlock).

Properties

| Improve this Doc View Source

ActionRenderers

A filtered list, from Renderers, which contains only IActionRenderer instances.

Declaration
public IImmutableList<IActionRenderer> ActionRenderers { get; }
Property Value
Type Description
IImmutableList<IActionRenderer>
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

BlockHashes

All Hashes in the current index. The genesis block's hash goes first, and the tip goes last. Returns a Int64 integer that represents the number of elements in the BlockChain<T>.

Declaration
public IEnumerable<BlockHash> BlockHashes { get; }
Property Value
Type Description
IEnumerable<BlockHash>
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

Count

Returns a Int64 that represents the number of Blocks in a BlockChain<T>. This is guaranteed to be greater than or equal to 1, as BlockChain<T> always contains at least its genesis Block.

Declaration
public long Count { get; }
Property Value
Type Description
Int64

The number of Blocks in the BlockChain<T>.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

Genesis

The first Block in the BlockChain<T>.

Declaration
public Block Genesis { get; }
Property Value
Type Description
Block
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

Id

A class have Blocks, Transactions, and the chain information.

In order to watch its state changes, implement IRenderer interface and pass it to the BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>) constructor.

Declaration
public Guid Id { get; }
Property Value
Type Description
Guid
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

Item[in BlockHash]

Gets the block corresponding to the blockHash.

Declaration
public Block this[in BlockHash blockHash] { get; }
Parameters
Type Name Description
BlockHash blockHash

A Hash of the Block to get.

Property Value
Type Description
Block
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
KeyNotFoundException

Thrown when there is no Block with a given blockHash.

| Improve this Doc View Source

Item[Int32]

Gets the block corresponding to the index.

Declaration
public Block this[int index] { get; }
Parameters
Type Name Description
Int32 index

A number of index of Block.

Property Value
Type Description
Block
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the given index of Block does not exist.

| Improve this Doc View Source

Item[Int64]

Gets the block corresponding to the index.

Declaration
public Block this[long index] { get; }
Parameters
Type Name Description
Int64 index

A number of index of Block.

Property Value
Type Description
Block
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the given index of Block does not exist.

| Improve this Doc View Source

Policy

The block and blockchain policy.

Declaration
public IBlockPolicy<T> Policy { get; }
Property Value
Type Description
IBlockPolicy<T>
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

Renderers

The list of registered renderers listening the state changes.

Declaration
public IImmutableList<IRenderer> Renderers { get; }
Property Value
Type Description
IImmutableList<IRenderer>
Remarks

Since this value is immutable, renderers cannot be registered after once a BlockChain<T> object is instantiated; use renderers option of BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>) constructor instead.

| Improve this Doc View Source

StagePolicy

The staging policy.

Declaration
public IStagePolicy<T> StagePolicy { get; set; }
Property Value
Type Description
IStagePolicy<T>
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

Tip

The topmost Block of the current blockchain.

Declaration
public Block Tip { get; }
Property Value
Type Description
Block
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Methods

| Improve this Doc View Source

Append(Block, BlockCommit)

Adds a block to the end of this chain.

Transactions in the block updates states and balances in the blockchain, and TxExecutions for transactions are recorded.

Note that Renderers receive events right after the block is confirmed (and thus all states reflect changes in the block).

Declaration
public void Append(Block block, BlockCommit blockCommit)
Parameters
Type Name Description
Block block

A next Block, which is mined, to add.

BlockCommit blockCommit

A BlockCommit that has +2/3 commits for the given block.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
BlockPolicyViolationException

Thrown when given block does not satisfy any of the constraints validated by ValidateNextBlock(BlockChain<T>, Block) of Policy.

InvalidBlockException

Thrown when the given block is invalid, in itself or according to the Policy.

InvalidActionException

Thrown when given block contains an action that cannot be loaded with IActionLoader.

InvalidTxNonceException

Thrown when the Nonce is different from GetNextTxNonce(Address) result of the Signer.

InvalidBlockCommitException

Thrown when the given block and blockCommit is invalid.

| Improve this Doc View Source

ContainsBlock(BlockHash)

Determines whether the BlockChain<T> contains Block the specified blockHash.

Declaration
public bool ContainsBlock(BlockHash blockHash)
Parameters
Type Name Description
BlockHash blockHash

The HashDigest<T> of the Block to check if it is in the BlockChain<T>.

Returns
Type Description
Boolean

true if the BlockChain<T> contains Block with the specified blockHash; otherwise, false.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

Create(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, ActionEvaluator, IEnumerable<IRenderer>, IBlockChainStates)

Creates a new instance of BlockChain<T> from an empty IStore.

Declaration
public static BlockChain<T> Create(IBlockPolicy<T> policy, IStagePolicy<T> stagePolicy, IStore store, IStateStore stateStore, Block genesisBlock, ActionEvaluator actionEvaluator, IEnumerable<IRenderer> renderers = null, IBlockChainStates blockChainStates = null)
Parameters
Type Name Description
IBlockPolicy<T> policy
IStagePolicy<T> stagePolicy
IStore store
IStateStore stateStore
Block genesisBlock
ActionEvaluator actionEvaluator
IEnumerable<IRenderer> renderers
IBlockChainStates blockChainStates
Returns
Type Description
BlockChain<T>

A newly created BlockChain<T>.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
ArgumentNullException

Thrown when either store or stateStore is null.

ArgumentException

Thrown when store already has a canonical chain id.

InvalidBlockException

Thrown when genesisBlock is invalid.

InvalidTxException

Thrown when genesisBlock contains an invalid Transaction.

| Improve this Doc View Source

DetermineBlockStateRootHash(IPreEvaluationBlock, out IReadOnlyList<IActionEvaluation>)

Determines the state root hash given block and evaluations.

Declaration
public HashDigest<SHA256> DetermineBlockStateRootHash(IPreEvaluationBlock block, out IReadOnlyList<IActionEvaluation> evaluations)
Parameters
Type Name Description
IPreEvaluationBlock block

The IPreEvaluationBlock to execute for evaluations.

IReadOnlyList<IActionEvaluation> evaluations

The list of IActionEvaluations from which to extract the states to commit.

Returns
Type Description
HashDigest<SHA256>

The state root hash given block and its evaluations.

Remarks

Since the state root hash can only be calculated by making a commit to an IStateStore, this always has a side-effect to Libplanet.Blockchain.BlockChain`1.StateStore regardless of whether the state root hash obdatined through commiting to Libplanet.Blockchain.BlockChain`1.StateStore matches the block's StateRootHash or not.

Exceptions
Type Condition
InvalidActionException

Thrown when given block contains an action that cannot be loaded with IActionLoader.

See Also
EvaluateBlock(IPreEvaluationBlock)
Libplanet.Blockchain.BlockChain`1.ValidateBlockStateRootHash(Libplanet.Blocks.Block,System.Collections.Generic.IReadOnlyList{Libplanet.Action.IActionEvaluation}@)
| Improve this Doc View Source

DetermineGenesisStateRootHash(IPreEvaluationBlock, IAction, out IReadOnlyList<IActionEvaluation>)

Determines the state root hash of preEvaluationBlock by evaluating on top of empty states.

Declaration
[Pure]
public static HashDigest<SHA256> DetermineGenesisStateRootHash(IPreEvaluationBlock preEvaluationBlock, IAction blockAction, out IReadOnlyList<IActionEvaluation> evaluations)
Parameters
Type Name Description
IPreEvaluationBlock preEvaluationBlock

The IPreEvaluationBlock for which to determine the state root hash.

IAction blockAction

The BlockAction to use.

IReadOnlyList<IActionEvaluation> evaluations

The evaluation result from EvaluateGenesis(IPreEvaluationBlock, IAction) for preEvaluationBlock.

Returns
Type Description
HashDigest<SHA256>

The state root hash calculated by committing evaluations to an empty IStateStore.

Remarks

This method computes the state root hash by commiting evaluations to an ephemeral empty IStateStore.

See Also
EvaluateGenesis(IPreEvaluationBlock, IAction)
| Improve this Doc View Source

EvaluateBlock(IPreEvaluationBlock)

Evaluates the IActions in given block.

Declaration
[Pure]
public IReadOnlyList<IActionEvaluation> EvaluateBlock(IPreEvaluationBlock block)
Parameters
Type Name Description
IPreEvaluationBlock block

The IPreEvaluationBlock to execute.

Returns
Type Description
IReadOnlyList<IActionEvaluation>

An IReadOnlyList<T> of s for given block.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
InvalidActionException

Thrown when given block contains an action that cannot be loaded with IActionLoader.

See Also
Libplanet.Blockchain.BlockChain`1.ValidateBlockStateRootHash(Libplanet.Blocks.Block,System.Collections.Generic.IReadOnlyList{Libplanet.Action.IActionEvaluation}@)
| Improve this Doc View Source

EvaluateGenesis(IPreEvaluationBlock, IAction)

Evaluates preEvaluationBlock on top of empty states.

Declaration
[Pure]
public static IReadOnlyList<IActionEvaluation> EvaluateGenesis(IPreEvaluationBlock preEvaluationBlock, IAction blockAction)
Parameters
Type Name Description
IPreEvaluationBlock preEvaluationBlock

The IPreEvaluationBlock to evaluate.

IAction blockAction

The BlockAction to use.

Returns
Type Description
IReadOnlyList<IActionEvaluation>

An IReadOnlyList<T> of IActionEvaluations resulting from evaluating preEvaluationBlock using blockAction.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
ArgumentException

Thrown if preEvaluationBlocks Index is not zero.

| Improve this Doc View Source

Finalize()

A class have Blocks, Transactions, and the chain information.

In order to watch its state changes, implement IRenderer interface and pass it to the BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>) constructor.

Declaration
protected void Finalize()
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

FindNextHashes(BlockLocator, Nullable<BlockHash>, Int32)

Finds the branch point BlockHash between this BlockChain<T> and locator and returns the list of BlockHashes of successive Blocks starting from the branch point BlockHash.

Declaration
public Tuple<long?, IReadOnlyList<BlockHash>> FindNextHashes(BlockLocator locator, BlockHash? stop = null, int count = 500)
Parameters
Type Name Description
BlockLocator locator

The BlockLocator to find the branching point from.

Nullable<BlockHash> stop

The BlockHash to stop looking for subsequent blocks once encountered.

Int32 count

The Maximum number of BlockHashes to return.

Returns
Type Description
Tuple<Nullable<Int64>, IReadOnlyList<BlockHash>>

A tuple of the index of the branch point and BlockHashes including the branch point BlockHash. If no branch point is found, returns a tuple of null and an empty array of BlockHashes.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

Fork(BlockHash, Boolean)

Forks the chain at point and returns the newly forked chain.

Declaration
public BlockChain<T> Fork(BlockHash point, bool inheritRenderers = true)
Parameters
Type Name Description
BlockHash point

The hash in which to fork from.

Boolean inheritRenderers

Whether to inherit the renderers from the existing chain.

Returns
Type Description
BlockChain<T>

An instance of the newly forked chain.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
ArgumentException

Throws when the provided point does not exist in the current chain.

| Improve this Doc View Source

GetBalance(Address, Currency, BlockHash)

Queries address's balance of the currency in the BlockChain<T> from offset.

Declaration
public FungibleAssetValue GetBalance(Address address, Currency currency, BlockHash offset)
Parameters
Type Name Description
Address address

The owner Address to query.

Currency currency

The currency type to query.

BlockHash offset

The HashDigest<T> of the block to start finding the state.

Returns
Type Description
FungibleAssetValue

The address's current balance (or balance as of the given offset) of the currency.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetBalance(Address, Currency, Nullable<BlockHash>)

Queries address's balance of the currency in the BlockChain<T> from offset.

Declaration
public FungibleAssetValue GetBalance(Address address, Currency currency, BlockHash? offset = null)
Parameters
Type Name Description
Address address

The owner Address to query.

Currency currency

The currency type to query.

Nullable<BlockHash> offset

The HashDigest<T> of the block to start finding the state. It will be the tip of the BlockChain<T> if it is null.

Returns
Type Description
FungibleAssetValue

The address's current balance (or balance as of the given offset) of the currency.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetBlockCommit(BlockHash)

Returns a BlockCommit of given Block index.

Declaration
public BlockCommit GetBlockCommit(BlockHash blockHash)
Parameters
Type Name Description
BlockHash blockHash

A hash value of Block to retrieve.

Returns
Type Description
BlockCommit

Returns a BlockCommit of given Block hash, if the BlockCommit of Genesis block is requested, then returns null.

Remarks

The Genesis block does not have BlockCommit because the genesis block is not committed by a consensus.

Exceptions
Type Condition
KeyNotFoundException

Thrown if given hash does not exist in the blockchain.

| Improve this Doc View Source

GetBlockCommit(Int64)

Returns a BlockCommit of given Block index.

Declaration
public BlockCommit GetBlockCommit(long index)
Parameters
Type Name Description
Int64 index

A index value (height) of Block to retrieve.

Returns
Type Description
BlockCommit

Returns a BlockCommit of given Block index. Following conditions will return null:

  • Given Block ProtocolVersion is Proof-of-Work.
  • Given Block is Genesis block.
Remarks

The Genesis block does not have BlockCommit because the genesis block is not committed by a consensus.

Exceptions
Type Condition
KeyNotFoundException

Thrown if given index does not exist in the blockchain.

| Improve this Doc View Source

GetBlockLocator(Int32)

Returns a new BlockLocator from the tip of current chain.

Declaration
public BlockLocator GetBlockLocator(int threshold = 10)
Parameters
Type Name Description
Int32 threshold

The amount of consequent blocks to include before sampling.

Returns
Type Description
BlockLocator

A instance of block locator.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetNextTxNonce(Address)

Gets next Nonce of the address.

Declaration
public long GetNextTxNonce(Address address)
Parameters
Type Name Description
Address address

The Address from which to obtain the Nonce value.

Returns
Type Description
Int64

The next Nonce value of the address.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetStagedTransactionIds()

Lists all staged TxIds.

Declaration
public IImmutableSet<TxId> GetStagedTransactionIds()
Returns
Type Description
IImmutableSet<TxId>

IImmutableSet<T> of staged transactions.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetState(Address, Nullable<BlockHash>)

Gets the state of the given address in the BlockChain<T> from offset.

Declaration
public IValue GetState(Address address, BlockHash? offset = null)
Parameters
Type Name Description
Address address

An Address to get the states of.

Nullable<BlockHash> offset

The HashDigest<T> of the block to start finding the state. It will be The tip of the BlockChain<T> if it is null.

Returns
Type Description
Bencodex.Types.IValue

The current state of given address. This can be null if address has no value.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetStates(IReadOnlyList<Address>, BlockHash)

A class have Blocks, Transactions, and the chain information.

In order to watch its state changes, implement IRenderer interface and pass it to the BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>) constructor.

Declaration
public IReadOnlyList<IValue> GetStates(IReadOnlyList<Address> addresses, BlockHash offset)
Parameters
Type Name Description
IReadOnlyList<Address> addresses
BlockHash offset
Returns
Type Description
IReadOnlyList<Bencodex.Types.IValue>
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetStates(IReadOnlyList<Address>, Nullable<BlockHash>)

Gets multiple states associated to the specified addresses.

Declaration
public IReadOnlyList<IValue> GetStates(IReadOnlyList<Address> addresses, BlockHash? offset = null)
Parameters
Type Name Description
IReadOnlyList<Address> addresses

Addresses of states to query.

Nullable<BlockHash> offset

The HashDigest<T> of the block to start finding the states. Tip by default.

Returns
Type Description
IReadOnlyList<Bencodex.Types.IValue>

The states associated to the specified addresses. Associated values are ordered in the same way to the corresponding addresses. Absent states are represented as null.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetTotalSupply(Currency, BlockHash)

Gets the total supply of a currency in the BlockChain<T> from offset, and if not found, return 0.

Declaration
public FungibleAssetValue GetTotalSupply(Currency currency, BlockHash offset)
Parameters
Type Name Description
Currency currency

The currency type to query.

BlockHash offset

The HashDigest<T> of the block to start finding the state.

Returns
Type Description
FungibleAssetValue

The total supply value of currency at offset in FungibleAssetValue.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetTotalSupply(Currency, Nullable<BlockHash>)

Gets the total supply of a currency in the BlockChain<T> from offset, and if not found, derive from the sum of all balances.

Declaration
public FungibleAssetValue GetTotalSupply(Currency currency, BlockHash? offset = null)
Parameters
Type Name Description
Currency currency

The currency type to query.

Nullable<BlockHash> offset

The HashDigest<T> of the block to start finding the state.

Returns
Type Description
FungibleAssetValue

The total supply value of currency at offset in FungibleAssetValue.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetTransaction(TxId)

Gets the transaction corresponding to the txId.

Declaration
public Transaction GetTransaction(TxId txId)
Parameters
Type Name Description
TxId txId

A TxId of the Transaction to get.

Returns
Type Description
Transaction

Transaction with txId.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
KeyNotFoundException

Thrown when there is no Transaction with a given txId.

| Improve this Doc View Source

GetTrie(BlockHash)

Returns the state trie for offset.

Declaration
public ITrie GetTrie(BlockHash offset)
Parameters
Type Name Description
BlockHash offset

The HashDigest<T> of the block to start finding the state.

Returns
Type Description
ITrie

The merkle trie instance for given offset.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetTxExecution(BlockHash, TxId)

Queries the recorded TxExecution for a successful or failed Transaction within a Block.

Declaration
public TxExecution GetTxExecution(BlockHash blockHash, TxId txid)
Parameters
Type Name Description
BlockHash blockHash

The Hash of the Block that the Transaction is executed within.

TxId txid

The executed Transaction's Id.

Returns
Type Description
TxExecution

The recorded TxExecution. If the transaction has never been executed within the block, it returns null instead.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetValidatorSet(BlockHash)

Returns the validator set in the BlockChain<T> from offset.

Declaration
public ValidatorSet GetValidatorSet(BlockHash offset)
Parameters
Type Name Description
BlockHash offset

The HashDigest<T> of the block to start finding the state.

Returns
Type Description
ValidatorSet

The validator set of type ValidatorSet at the offset.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

GetValidatorSet(Nullable<BlockHash>)

A class have Blocks, Transactions, and the chain information.

In order to watch its state changes, implement IRenderer interface and pass it to the BlockChain(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, IEnumerable<IRenderer>) constructor.

Declaration
public ValidatorSet GetValidatorSet(BlockHash? offset = null)
Parameters
Type Name Description
Nullable<BlockHash> offset
Returns
Type Description
ValidatorSet
Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

MakeTransaction(PrivateKey, IEnumerable<IAction>, IImmutableSet<Address>, Nullable<DateTimeOffset>)

Creates a new Transaction with custom actions and stage it. It's available only if the genesis block exists.

Declaration
public Transaction MakeTransaction(PrivateKey privateKey, IEnumerable<IAction> actions, IImmutableSet<Address> updatedAddresses = null, DateTimeOffset? timestamp = null)
Parameters
Type Name Description
PrivateKey privateKey

A PrivateKey of the account who creates and signs a new transaction.

IEnumerable<IAction> actions

A list of custom actions to include to a new transaction.

IImmutableSet<Address> updatedAddresses

Addresses whose states affected by actions.

Nullable<DateTimeOffset> timestamp

The time this Transaction is created and signed.

Returns
Type Description
Transaction

A created new Transaction signed by the given privateKey.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

| Improve this Doc View Source

ProposeBlock(PrivateKey, BlockCommit, IComparer<Transaction>)

Proposes a next Block using staged Transactions.

By default, if successful, a policy adhering Block is produced with current timestamp that can be appeneded to the current chain.

Declaration
public Block ProposeBlock(PrivateKey proposer, BlockCommit lastCommit = null, IComparer<Transaction> txPriority = null)
Parameters
Type Name Description
PrivateKey proposer

The proposer's PublicKey that proposes the block.

BlockCommit lastCommit

The BlockCommit evidence of the previous Block.

IComparer<Transaction> txPriority

An optional comparer for give certain transactions to priority to belong to the block. No certain priority by default.

Returns
Type Description
Block

A Block that is proposed.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
OperationCanceledException

Thrown when Tip is changed while proposing.

| Improve this Doc View Source

ProposeGenesisBlock(PrivateKey, ImmutableList<Transaction>, Nullable<DateTimeOffset>, IAction)

Propose a genesis block for creating a BlockChain<T>.

Note that a genesis Block produced may not be suitable as a genesis for Create(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, ActionEvaluator, IEnumerable<IRenderer>, IBlockChainStates) if given transactions is invalid.

Make sure that the nonces for transactions are correct and each GenesisHash is set to null.

Declaration
public static Block ProposeGenesisBlock(PrivateKey privateKey = null, ImmutableList<Transaction> transactions = null, DateTimeOffset? timestamp = null, IAction blockAction = null)
Parameters
Type Name Description
PrivateKey privateKey

A private key to sign the transaction and the genesis block. If it's null, it will use new private key as default.

ImmutableList<Transaction> transactions

A list of Transactions to include in the genesis Block.

Nullable<DateTimeOffset> timestamp

The timestamp of the genesis block. If it's null, it will use UtcNow as default.

IAction blockAction

A block action to execute and be rendered for every block. It must match to BlockAction of Policy.

Returns
Type Description
Block

A genesis Block proposed with given parameters.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

See Also
Create(IBlockPolicy<T>, IStagePolicy<T>, IStore, IStateStore, Block, ActionEvaluator, IEnumerable<IRenderer>, IBlockChainStates)
| Improve this Doc View Source

StageTransaction(Transaction)

Adds transaction to the pending list so that a next Block to be mined may contain given transaction.

Declaration
public bool StageTransaction(Transaction transaction)
Parameters
Type Name Description
Transaction transaction

Transaction to add to the pending list.

Returns
Type Description
Boolean

true if staging was successful, false otherwise.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

Exceptions
Type Condition
InvalidTxGenesisHashException

Thrown when given transaction has invalid GenesisHash.

| Improve this Doc View Source

UnstageTransaction(Transaction)

Removes a transaction from the pending list.

Declaration
public bool UnstageTransaction(Transaction transaction)
Parameters
Type Name Description
Transaction transaction

A Transaction to remove from the pending list.

Returns
Type Description
Boolean

true if unstaging was successful, false otherwise.

Remarks

This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.

See Also
StageTransaction(Transaction)

Implements

IBlockChainStates
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium