• Design
  • API Reference
  • Changelog
  • Contribute
Show / Hide Table of Contents
  • Libplanet
    • Address
    • AddressExtension
    • BencodexExtension
    • ByteUtil
    • Hashcash
    • Hashcash.Stamp
    • HashDigest<T>
    • HashDigestExtension
    • Nonce
  • Libplanet.Action
    • AccountStateGetter
    • ActionEvaluation
    • ActionTypeAttribute
    • AddressStateMap
    • 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
  • Libplanet.Crypto
    • 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
    • BlockStateDownloadState
    • BoundPeer
    • DifferentAppProtocolVersionException
    • DifferentProtocolVersionEventArgs
    • IceServer
    • IceServerException
    • InvalidMessageException
    • NoSwarmContextException
    • Peer
    • PeerNotFoundException
    • PreloadState
    • StateReferenceDownloadState
    • Swarm<T>
    • SwarmException
  • Libplanet.Serialization
    • BencodexFormatter<T>
    • SerializationInfoExtension
  • Libplanet.Store
    • BaseIndex<TKey, TVal>
    • BaseStore
    • BlockSet<T>
    • ChainIdNotFoundException
    • IStore
    • LiteDBStore
    • StoreExtension
    • TransactionSet<T>
  • Libplanet.Tx
    • InvalidTxException
    • InvalidTxIdException
    • InvalidTxNonceException
    • InvalidTxPublicKeyException
    • InvalidTxSignatureException
    • InvalidTxUpdatedAddressesException
    • Transaction<T>
    • TxId

Class BlockChain<T>

A class have Block<T>s, Transaction<T>s, and the chain information.

Inheritance
Object
BlockChain<T>
Namespace: Libplanet.Blockchain
Assembly: Libplanet.dll
Syntax
public class BlockChain<T> : object where T : IAction, new()
Type Parameters
Name Description
T

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

Constructors

| Improve this Doc View Source

BlockChain(IBlockPolicy<T>, IStore)

Initializes a new instance of the BlockChain<T> class.

Declaration
public BlockChain(IBlockPolicy<T> policy, IStore store)
Parameters
Type Name Description
IBlockPolicy<T> policy

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

IStore store

IStore to store Block<T>s, Transaction<T>s, and BlockChain<T> information.

Properties

| 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 integer that represents the number of elements in the BlockChain<T>.

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

Count

Returns a integer that represents the number of elements in the BlockChain<T>.

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

A number that represents how many elements in the BlockChain<T>.

| Improve this Doc View Source

Id

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

Item[HashDigest<SHA256>]

Gets the block corresponding to the hash.

Declaration
public Block<T> this[HashDigest<SHA256> hash] { get; }
Parameters
Type Name Description
HashDigest<SHA256> hash

A Hash of the Block<T> to get.

Property Value
Type Description
Block<T>
| Improve this Doc View Source

Item[Int32]

Gets the block corresponding to the index.

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

A number of index of Block<T>.

Property Value
Type Description
Block<T>
| Improve this Doc View Source

Item[Int64]

Gets the block corresponding to the index.

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

A number of index of Block<T>.

Property Value
Type Description
Block<T>
| Improve this Doc View Source

Policy

Declaration
public IBlockPolicy<T> Policy { get; }
Property Value
Type Description
IBlockPolicy<T>
| Improve this Doc View Source

Tip

The topmost Block<T> of the current blockchain. Can be null if the blockchain is empty.

Declaration
public Block<T> Tip { get; }
Property Value
Type Description
Block<T>

Methods

| Improve this Doc View Source

Append(Block<T>)

Adds a block to the end of this chain.

Note that Render(IActionContext, IAccountStateDelta) methods of all IAction objects that belong to the block are called right after the block is confirmed (and thus all states reflect changes in the block).

Declaration
public void Append(Block<T> block)
Parameters
Type Name Description
Block<T> block

A next Block<T>, which is mined, to add.

Exceptions
Type Condition
InvalidBlockException

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

InvalidTxNonceException

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

| Improve this Doc View Source

Append(Block<T>, DateTimeOffset)

Adds a block to the end of this chain.

Note that Render(IActionContext, IAccountStateDelta) methods of all IAction objects that belong to the block are called right after the block is confirmed (and thus all states reflect changes in the block).

Declaration
public void Append(Block<T> block, DateTimeOffset currentTime)
Parameters
Type Name Description
Block<T> block

A next Block<T>, which is mined, to add.

DateTimeOffset currentTime

The current time.

Exceptions
Type Condition
InvalidBlockException

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

InvalidTxNonceException

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

| Improve this Doc View Source

Contains(Block<T>)

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

Declaration
public bool Contains(Block<T> block)
Parameters
Type Name Description
Block<T> block

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

Returns
Type Description
Boolean

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

| Improve this Doc View Source

Contains(HashDigest<SHA256>)

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

Declaration
public bool Contains(HashDigest<SHA256> hash)
Parameters
Type Name Description
HashDigest<SHA256> hash

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

Returns
Type Description
Boolean

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

| Improve this Doc View Source

Contains(TxId)

Determines whether the BlockChain<T> contains Transaction<T> the specified txId.

Declaration
public bool Contains(TxId txId)
Parameters
Type Name Description
TxId txId

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

Returns
Type Description
Boolean

true if the BlockChain<T> contains Transaction<T> with the specified txId; otherwise, false.

| Improve this Doc View Source

Finalize()

Declaration
protected void Finalize()
| 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.

| Improve this Doc View Source

GetState(Address, Nullable<HashDigest<SHA256>>, Boolean)

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

Declaration
public AddressStateMap GetState(Address address, HashDigest<SHA256>? offset = null, bool completeStates = false)
Parameters
Type Name Description
Address address

An Address to get the states of.

Nullable<HashDigest<SHA256>> 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.

Boolean completeStates

When the BlockChain<T> instance does not contain states dirty of the block which lastly updated states of a requested address, this option makes the incomplete states calculated and filled on the fly. If this option is turned off (which is default) this method throws IncompleteBlockStatesException instead for the same situation. Just-in-time calculation of states could take a long time so that the overall latency of an application may rise.

Returns
Type Description
AddressStateMap

The AddressStateMap of given address.

Exceptions
Type Condition
IncompleteBlockStatesException

Thrown when the BlockChain<T> instance does not contain states dirty of the block which lastly updated states of a requested address, because actions in the block have never been executed. If completeStates option is turned on this exception is not thrown and incomplete states are calculated and filled on the fly instead.

| Improve this Doc View Source

GetTransaction(TxId)

Gets the transaction corresponding to the txId.

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

A TxId of the Transaction<T> to get.

Returns
Type Description
Transaction<T>

Transaction<T> with txId.

| Improve this Doc View Source

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

Creates a new Transaction<T> and stage the transaction.

Declaration
public Transaction<T> MakeTransaction(PrivateKey privateKey, IEnumerable<T> 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<T> actions

A list of IActions to include to a new transaction.

IImmutableSet<Address> updatedAddresses

Addresses whose states affected by actions.

Nullable<DateTimeOffset> timestamp

The time this Transaction<T> is created and signed.

Returns
Type Description
Transaction<T>

A created new Transaction<T> signed by the given privateKey.

See Also
Create(Int64, PrivateKey, IEnumerable<T>, IImmutableSet<Address>, Nullable<DateTimeOffset>)
| Improve this Doc View Source

MineBlock(Address)

Declaration
public Task<Block<T>> MineBlock(Address miner)
Parameters
Type Name Description
Address miner
Returns
Type Description
Task<Block<T>>
| Improve this Doc View Source

MineBlock(Address, DateTimeOffset, CancellationToken)

Mine a Block<T> using staged Transaction<T>s.

Declaration
public Task<Block<T>> MineBlock(Address miner, DateTimeOffset currentTime, CancellationToken cancellationToken = null)
Parameters
Type Name Description
Address miner

The Address of miner that mined the block.

DateTimeOffset currentTime

The when mining started.

CancellationToken cancellationToken

A cancellation token used to propagate notification that this operation should be canceled.

Returns
Type Description
Task<Block<T>>

An awaitable task with a Block<T> that is mined.

| Improve this Doc View Source

StageTransactions(IImmutableSet<Transaction<T>>)

Adds transactions to the pending list so that a next Block<T> to be mined contains these transactions.

Declaration
public void StageTransactions(IImmutableSet<Transaction<T>> transactions)
Parameters
Type Name Description
IImmutableSet<Transaction<T>> transactions

Transaction<T>s to add to the pending list.

| Improve this Doc View Source

UnstageTransactions(ISet<Transaction<T>>)

Removes transactions from the pending list.

Declaration
public void UnstageTransactions(ISet<Transaction<T>> transactions)
Parameters
Type Name Description
ISet<Transaction<T>> transactions

Transaction<T>s to remove from the pending list.

See Also
StageTransactions(IImmutableSet<Transaction<T>>)

Events

| Improve this Doc View Source

TipChanged

An event which is invoked when Tip is changed.

Declaration
public event EventHandler<BlockChain<T>.TipChangedEventArgs> TipChanged
Event Type
Type Description
EventHandler<BlockChain.TipChangedEventArgs<>>

See Also

IAction
Block<T>
Transaction<T>
  • Improve this Doc
  • View Source
Back to top Copyright © 2019 Planetarium
Generated by DocFX