Class Blockchain
java.lang.Object
com.exonum.binding.core.blockchain.Blockchain
public final class Blockchain extends Object
Provides read-only access to the subset of
blockchain::Schema features in the Core API: blocks, transaction messages, execution
results.
All method arguments are non-null by default.
-
Method Summary
Modifier and Type Method Description booleancontainsBlock(Block block)Returns true if the blockchain contains exactly the same block as the passed value; false if it does not contain such block.Optional<Block>findBlock(HashCode blockHash)Returns a block object for given block hash.BlockgetBlock(long height)Returns the block at the given height.ListIndex<HashCode>getBlockHashes()Returns a list of all block hashes, indexed by the block height.MapIndex<HashCode,Block>getBlocks()Returns a map that stores a block object for every block hash.ProofListIndexProxy<HashCode>getBlockTransactions(long height)Returns a proof list of transaction hashes committed in the block at the given height.ProofListIndexProxy<HashCode>getBlockTransactions(HashCode blockId)Returns a proof list of transaction hashes committed in the block with the given id.ProofListIndexProxy<HashCode>getBlockTransactions(Block block)Returns a proof list of transaction hashes committed in the given block.Blockchain.ConfiggetConsensusConfiguration()Returns the current consensus configuration of the network.longgetHeight()Returns the blockchain height which is the height of the latest committed block in the blockchain.BlockgetLastBlock()Returns the latest committed block.KeySetIndexProxy<HashCode>getTransactionPool()Returns a set of uncommitted (in-pool) transaction hashes; empty in case of no transactions.Optional<TransactionLocation>getTxLocation(HashCode messageHash)Returns transaction position inside the blockchain for given message hash.MapIndex<HashCode,TransactionLocation>getTxLocations()Returns a map that keeps the transaction position inside the blockchain for every transaction hash.MapIndex<HashCode,TransactionMessage>getTxMessages()Returns a map of transaction messages identified by their SHA-256 hashes.Optional<Runtime.ExecutionStatus>getTxResult(HashCode messageHash)Returns a transaction execution result for given message hash.ProofMapIndexProxy<HashCode,Runtime.ExecutionStatus>getTxResults()Returns a map with a key-value pair of a transaction hash and execution result.static BlockchainnewInstance(View view)Constructs a new blockchain instance for the given database view.
-
Method Details
-
newInstance
Constructs a new blockchain instance for the given database view. -
containsBlock
Returns true if the blockchain contains exactly the same block as the passed value; false if it does not contain such block. Please note that all block fields are compared, not only its hash.- Parameters:
block- a value to check for presence in the blockchain
-
getHeight
public long getHeight()Returns the blockchain height which is the height of the latest committed block in the blockchain. The block height is a distance between the last block and the "genesis", or initial, block. Therefore, the blockchain height is equal to the number of blocks plus one.For example, the "genesis" block has height
h = 0. The latest committed block has heighth = getBlockHashes().size() - 1.- Throws:
RuntimeException- if the "genesis block" was not created
-
getBlockHashes
Returns a list of all block hashes, indexed by the block height. For example, the "genesis block" will be at index 0, the block at heighth = 10— at index 10. The last committed block will be at heighth = getBlockHashes().size() - 1. -
getBlockTransactions
Returns a proof list of transaction hashes committed in the block at the given height.- Parameters:
height- block height starting from 0- Throws:
IllegalArgumentException- if the height is invalid: negative or exceeding the blockchain height
-
getBlockTransactions
Returns a proof list of transaction hashes committed in the block with the given id.- Parameters:
blockId- id of the block- Throws:
IllegalArgumentException- if there is no block with given id
-
getBlockTransactions
Returns a proof list of transaction hashes committed in the given block. The given block must match exactly the block that is stored in the database.- Parameters:
block- block of which list of transaction hashes should be returned- Throws:
IllegalArgumentException- if there is no such block in the blockchain
-
getTxMessages
Returns a map of transaction messages identified by their SHA-256 hashes. Both committed and in-pool (not yet processed) transactions are returned. -
getTxResults
Returns a map with a key-value pair of a transaction hash and execution result. Note that this is a proof map that uses non-hashed keys. -
getTxResult
Returns a transaction execution result for given message hash.- Returns:
- a transaction execution result, or
Optional.empty()if this transaction is unknown or was not yet executed
-
getTxLocations
Returns a map that keeps the transaction position inside the blockchain for every transaction hash. -
getTxLocation
Returns transaction position inside the blockchain for given message hash.- Returns:
- a transaction execution result, or
Optional.empty()if this transaction is unknown or was not yet executed
-
getBlocks
Returns a map that stores a block object for every block hash. -
getBlock
Returns the block at the given height.- Parameters:
height- the height of the block; must be non-negative and less than or equal to the current blockchain height- Returns:
- a block at the height
- Throws:
IndexOutOfBoundsException- if the height is not valid
-
findBlock
Returns a block object for given block hash.- Returns:
- a corresponding block, or
Optional.empty()if there is no block with given block hash
-
getLastBlock
Returns the latest committed block.- Throws:
RuntimeException- if the "genesis block" was not created
-
getConsensusConfiguration
Returns the current consensus configuration of the network.- Throws:
IllegalStateException- if the "genesis block" was not created- See Also:
- Exonum configuration for consensus configuration information.
-
getTransactionPool
Returns a set of uncommitted (in-pool) transaction hashes; empty in case of no transactions. Note that this pool represents the state as of the current snapshot, and its state is volatile even between block commits.- See Also:
- Pool of Unconfirmed Transactions
-