Class BlockChain
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, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable<IRenderer>) constructor.
Implements
Inherited Members
Namespace: Libplanet.Blockchain
Assembly: Libplanet.dll
Syntax
public class BlockChain : IBlockChainStates
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 SourceBlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable<IRenderer>)
Initializes a new instance of the BlockChain class by loading
the canonical chain from given store
.
Declaration
public BlockChain(IBlockPolicy policy, IStagePolicy stagePolicy, IStore store, IStateStore stateStore, Block genesisBlock, IBlockChainStates blockChainStates, IActionEvaluator actionEvaluator, IEnumerable<IRenderer> renderers = null)
Parameters
Type | Name | Description |
---|---|---|
IBlockPolicy | policy | IBlockPolicy to use in the BlockChain. |
IStagePolicy | stagePolicy | The staging policy to follow. |
IStore | store | IStore to store Blocks, Transactions, and BlockChain information. |
IStateStore | stateStore | IStateStore to store states. |
Block | genesisBlock | The genesis Block of
the BlockChain, which is a part of the consensus.
If the given |
IBlockChainStates | blockChainStates | The IBlockChainStates implementation for state lookup. |
IActionEvaluator | actionEvaluator | The Libplanet.Blockchain.BlockChain.ActionEvaluator implementation to calculate next states when append new blocks. |
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 |
ArgumentNullException | Thrown when either of |
InvalidGenesisBlockException | Thrown when the |
Properties
| Improve this Doc View SourceActionRenderers
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.
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.
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.
Count
Returns a Int64 that represents the number of Blocks in a BlockChain. This is guaranteed to be greater than or equal to 1, as BlockChain always contains at least its genesis Block.
Declaration
public long Count { get; }
Property Value
Type | Description |
---|---|
Int64 | The number of Blocks in the BlockChain. |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
Genesis
The first Block in the BlockChain.
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.
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, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, 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.
Item[in BlockHash]
Gets the block corresponding to the blockHash
.
Declaration
public Block this[in BlockHash blockHash] { get; }
Parameters
Type | Name | Description |
---|---|---|
BlockHash | blockHash |
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 |
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. |
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. |
Policy
The block and blockchain policy.
Declaration
public IBlockPolicy Policy { get; }
Property Value
Type | Description |
---|---|
IBlockPolicy |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
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 object is instantiated; use renderers
option of BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable<IRenderer>)
constructor instead.
StagePolicy
The staging policy.
Declaration
public IStagePolicy StagePolicy { get; set; }
Property Value
Type | Description |
---|---|
IStagePolicy |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
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 SourceAppend(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
|
InvalidBlockException | Thrown when the given |
InvalidActionException | Thrown when given |
InvalidTxNonceException | Thrown when the Nonce is different from GetNextTxNonce(Address) result of the Signer. |
InvalidBlockCommitException | Thrown when the given
|
ContainsBlock(BlockHash)
Determines whether the BlockChain 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. |
Returns
Type | Description |
---|---|
Boolean | true if the BlockChain contains
Block with the specified |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
Create(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IActionEvaluator, IEnumerable<IRenderer>, IBlockChainStates)
Creates a new instance of BlockChain from an empty IStore.
Declaration
public static BlockChain Create(IBlockPolicy policy, IStagePolicy stagePolicy, IStore store, IStateStore stateStore, Block genesisBlock, IActionEvaluator actionEvaluator, IEnumerable<IRenderer> renderers = null, IBlockChainStates blockChainStates = null)
Parameters
Type | Name | Description |
---|---|---|
IBlockPolicy | policy | |
IStagePolicy | stagePolicy | |
IStore | store | |
IStateStore | stateStore | |
Block | genesisBlock | |
IActionEvaluator | actionEvaluator | |
IEnumerable<IRenderer> | renderers | |
IBlockChainStates | blockChainStates |
Returns
Type | Description |
---|---|
BlockChain | A newly created BlockChain. |
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 |
ArgumentException | Thrown when |
InvalidBlockException | Thrown when |
InvalidTxException | Thrown when |
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
|
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 |
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.StateStore regardless of whether the state root hash
obdatined through commiting to Libplanet.Blockchain.BlockChain.StateStore
matches the block
's StateRootHash or not.
Exceptions
Type | Condition |
---|---|
InvalidActionException | Thrown when given |
See Also
DetermineGenesisStateRootHash(IActionEvaluator, IPreEvaluationBlock, out IReadOnlyList<IActionEvaluation>)
Determines the state root hash of preEvaluationBlock
by evaluating on top of empty states.
Declaration
[Pure]
public static HashDigest<SHA256> DetermineGenesisStateRootHash(IActionEvaluator actionEvaluator, IPreEvaluationBlock preEvaluationBlock, out IReadOnlyList<IActionEvaluation> evaluations)
Parameters
Type | Name | Description |
---|---|---|
IActionEvaluator | actionEvaluator | The IActionEvaluator to use to evaluate the proposed Block. |
IPreEvaluationBlock | preEvaluationBlock | The IPreEvaluationBlock for which to determine the state root hash. |
IReadOnlyList<IActionEvaluation> | evaluations | The evaluation result from EvaluateGenesis(IActionEvaluator, IPreEvaluationBlock)
for |
Returns
Type | Description |
---|---|
HashDigest<SHA256> | The state root hash calculated by committing |
Remarks
This method computes the state root hash by commiting evaluations
to an ephemeral empty IStateStore.
See Also
| Improve this Doc View SourceEvaluateBlock(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 |
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 |
See Also
EvaluateGenesis(IActionEvaluator, IPreEvaluationBlock)
Evaluates preEvaluationBlock
on top of empty states.
Declaration
[Pure]
public static IReadOnlyList<IActionEvaluation> EvaluateGenesis(IActionEvaluator actionEvaluator, IPreEvaluationBlock preEvaluationBlock)
Parameters
Type | Name | Description |
---|---|---|
IActionEvaluator | actionEvaluator | The IActionEvaluator to use to evaluate the proposed Block. |
IPreEvaluationBlock | preEvaluationBlock | The IPreEvaluationBlock to evaluate. |
Returns
Type | Description |
---|---|
IReadOnlyList<IActionEvaluation> | An IReadOnlyList<T> of IActionEvaluations
resulting from evaluating |
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 |
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, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, 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.
FindNextHashes(BlockLocator, Nullable<BlockHash>, Int32)
Finds the branch point BlockHash between this BlockChain
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.
Fork(BlockHash, Boolean)
Forks the chain at point
and returns the newly forked chain.
Declaration
public BlockChain 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 | 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 |
GetBalance(Address, Currency, BlockHash)
Queries address
's balance of the currency
in the
BlockChain 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 |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
GetBalance(Address, Currency, Nullable<BlockHash>)
Queries address
's balance of the currency
in the
BlockChain 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 if it is null. |
Returns
Type | Description |
---|---|
FungibleAssetValue | The |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
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. |
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:
|
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. |
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.
GetNextTxNonce(Address)
Gets next Nonce of the address.
Declaration
public long GetNextTxNonce(Address address)
Parameters
Type | Name | Description |
---|---|---|
Address | address |
Returns
Type | Description |
---|---|
Int64 | The next Nonce value of the
|
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
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.
GetState(Address, Nullable<BlockHash>)
Gets the state of the given address
in the
BlockChain 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 if it is null. |
Returns
Type | Description |
---|---|
Bencodex.Types.IValue | The current state of given |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
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, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, 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.
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 |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
GetTotalSupply(Currency, BlockHash)
Gets the total supply of a currency
in the
BlockChain 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 |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
GetTotalSupply(Currency, Nullable<BlockHash>)
Gets the total supply of a currency
in the
BlockChain 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 |
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
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 |
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 |
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.
GetValidatorSet(BlockHash)
Returns the validator set in the
BlockChain 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
|
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
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, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, 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.
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
|
Nullable<DateTimeOffset> | timestamp | The time this Transaction is created and signed. |
Returns
Type | Description |
---|---|
Transaction | A created new Transaction signed by the given
|
Remarks
This object is guaranteed that it has at least one block, since it takes a genesis block when it's instantiated.
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. |
ProposeGenesisBlock(IActionEvaluator, PrivateKey, ImmutableList<Transaction>, Nullable<DateTimeOffset>)
Propose a genesis block for creating a BlockChain.
Note that a genesis Block produced may not be suitable as
a genesis for Create(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IActionEvaluator, 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(IActionEvaluator actionEvaluator, PrivateKey privateKey = null, ImmutableList<Transaction> transactions = null, DateTimeOffset? timestamp = null)
Parameters
Type | Name | Description |
---|---|---|
IActionEvaluator | actionEvaluator | The IActionEvaluator to use to evaluate the proposed Block. |
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. |
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
| Improve this Doc View SourceStageTransaction(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
|
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.