public final class Blockchain extends Object
All method arguments are non-null by default.
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsBlock(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(com.exonum.binding.common.hash.HashCode blockHash)
Returns a block object for given block hash.
|
com.exonum.binding.common.configuration.StoredConfiguration |
getActualConfiguration()
Returns the configuration for the latest height of the blockchain, including services and their
parameters.
|
Block |
getBlock(long height)
Returns the block at the given height.
|
ListIndex<com.exonum.binding.common.hash.HashCode> |
getBlockHashes()
Returns a list of all block hashes, indexed by the block height.
|
MapIndex<com.exonum.binding.common.hash.HashCode,Block> |
getBlocks()
Returns a map that stores a block object for every block hash.
|
ProofListIndexProxy<com.exonum.binding.common.hash.HashCode> |
getBlockTransactions(Block block)
Returns a proof list of transaction hashes committed in the given block.
|
ProofListIndexProxy<com.exonum.binding.common.hash.HashCode> |
getBlockTransactions(com.exonum.binding.common.hash.HashCode blockId)
Returns a proof list of transaction hashes committed in the block with the given id.
|
ProofListIndexProxy<com.exonum.binding.common.hash.HashCode> |
getBlockTransactions(long height)
Returns a proof list of transaction hashes committed in the block at the given height.
|
long |
getHeight()
Returns the blockchain height which is the height of the latest committed block
in the blockchain.
|
Block |
getLastBlock()
Returns the latest committed block.
|
KeySetIndexProxy<com.exonum.binding.common.hash.HashCode> |
getTransactionPool()
Returns a set of uncommitted (in-pool) transaction hashes; empty in case of no transactions.
|
Optional<com.exonum.binding.common.blockchain.TransactionLocation> |
getTxLocation(com.exonum.binding.common.hash.HashCode messageHash)
Returns transaction position inside the blockchain for given message hash.
|
MapIndex<com.exonum.binding.common.hash.HashCode,com.exonum.binding.common.blockchain.TransactionLocation> |
getTxLocations()
Returns a map that keeps the transaction position inside the blockchain for every transaction
hash.
|
MapIndex<com.exonum.binding.common.hash.HashCode,com.exonum.binding.common.message.TransactionMessage> |
getTxMessages()
Returns a map of transaction messages identified by their SHA-256 hashes.
|
Optional<com.exonum.binding.common.blockchain.TransactionResult> |
getTxResult(com.exonum.binding.common.hash.HashCode messageHash)
Returns a transaction execution result for given message hash.
|
ProofMapIndexProxy<com.exonum.binding.common.hash.HashCode,com.exonum.binding.common.blockchain.TransactionResult> |
getTxResults()
Returns a map with a key-value pair of a transaction hash and execution result.
|
static Blockchain |
newInstance(View view)
Constructs a new blockchain instance for the given database view.
|
public static Blockchain newInstance(View view)
public boolean containsBlock(Block block)
block - a value to check for presence in the blockchainpublic long getHeight()
For example, the "genesis" block has height h = 0. The latest committed block
has height h = getBlockHashes().size() - 1.
RuntimeException - if the "genesis block" was not createdpublic ListIndex<com.exonum.binding.common.hash.HashCode> getBlockHashes()
h = 10 — at index 10.
The last committed block will be at height h = getBlockHashes().size() - 1.public ProofListIndexProxy<com.exonum.binding.common.hash.HashCode> getBlockTransactions(long height)
height - block height starting from 0IllegalArgumentException - if the height is invalid: negative or exceeding
the blockchain heightpublic ProofListIndexProxy<com.exonum.binding.common.hash.HashCode> getBlockTransactions(com.exonum.binding.common.hash.HashCode blockId)
blockId - id of the blockIllegalArgumentException - if there is no block with given idpublic ProofListIndexProxy<com.exonum.binding.common.hash.HashCode> getBlockTransactions(Block block)
block - block of which list of transaction hashes should be returnedIllegalArgumentException - if there is no such block in the blockchainpublic MapIndex<com.exonum.binding.common.hash.HashCode,com.exonum.binding.common.message.TransactionMessage> getTxMessages()
public ProofMapIndexProxy<com.exonum.binding.common.hash.HashCode,com.exonum.binding.common.blockchain.TransactionResult> getTxResults()
public Optional<com.exonum.binding.common.blockchain.TransactionResult> getTxResult(com.exonum.binding.common.hash.HashCode messageHash)
Optional.empty() if this transaction
is unknown or was not yet executedpublic MapIndex<com.exonum.binding.common.hash.HashCode,com.exonum.binding.common.blockchain.TransactionLocation> getTxLocations()
public Optional<com.exonum.binding.common.blockchain.TransactionLocation> getTxLocation(com.exonum.binding.common.hash.HashCode messageHash)
Optional.empty() if this transaction
is unknown or was not yet executedpublic MapIndex<com.exonum.binding.common.hash.HashCode,Block> getBlocks()
public Block getBlock(long height)
height - the height of the block; must be non-negative and less than or equal to
the current blockchain heightIndexOutOfBoundsException - if the height is not validpublic Optional<Block> findBlock(com.exonum.binding.common.hash.HashCode blockHash)
Optional.empty() if there is no block with given
block hashpublic Block getLastBlock()
RuntimeException - if the "genesis block" was not createdpublic com.exonum.binding.common.configuration.StoredConfiguration getActualConfiguration()
RuntimeException - if the "genesis block" was not createdpublic KeySetIndexProxy<com.exonum.binding.common.hash.HashCode> getTransactionPool()
Copyright © 2019 Exonum. All rights reserved.