Interface BlockchainStorage
- All Known Implementing Classes:
BlockchainStorageInMemory,BlockchainStorageSingleFile
public interface BlockchainStorage
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classBlockchainStorage.TransactionOutputIdentifier -
Method Summary
Modifier and Type Method Description voidbuildUnspentTransactionOutputSet()Builds the local UTXO set from the entire blockchain.booleanclose()Called once to perform any cleanup or saving after all blockchain operations have been completed.BlockgetBlock(byte[] blockHash)Retrieves the block associated with the specified block hash.BlockgetBlockByHeight(int height)Retrieves the block associated with the specified block height.BlockgetBlockByTransaction(byte[] transactionHash)Retrieves the block associated with the specified transaction.java.util.List<Block>getBlockchain()Returns an ordered list of the entire local blockchain.java.util.List<Block>getBlockchainRange(int beginHeight, int endHeight)Returns an ordered list of a range of the local blockchain.BlockHeadergetBlockHeader(byte[] blockHash)Retrieves the block header associated with the specified block hash.BlockHeadergetBlockHeaderByHeight(int height)Retrieves the block header associated with the specified block height.intgetBlockHeight()Gets the current local block height, can be thought of as the index of the most recent block (zero-indexed).BlockgetHighestBlock()Returns the most recent block in the local blockchain.byte[]getHighestBlockHash()Returns the block hash of the most recent block in the local blockchain.TransactiongetMempoolTransaction(byte[] transactionHash)Returns the mempool transaction specified.java.util.Set<Transaction>getMempoolTransactions()Returns the current set of mempool (pending) transactions.TransactiongetTransaction(byte[] transactionHash)Retrieve a transaction by its hash.TransactionInputgetTransactionInput(byte[] transactionHash, int index)Returns the transaction input from the transaction hash and index.TransactionOutputgetTransactionOutput(byte[] transactionHash, int index)Returns the transaction output from the transaction hash and index.java.util.Set<BlockchainStorage.TransactionOutputIdentifier>getUnspentTransactionOutputs()Returns the local UTXO (unspent transaction output) set.booleanhasBlock(byte[] blockHash)Returns whether the local blockchain contains a block corresponding to the provided block hash.booleanhasBlockHeader(byte[] blockHash)Returns whether the local blockchain contains a block header corresponding to the provided block hash.booleanhasMempoolTransaction(byte[] transactionHash)Returns whether the mempool contains the specified transaction.booleanhasTransaction(byte[] transactionHash)Returns whether a transaction with the specified hash exist on the local blockchain.booleanisOperational()Called to determine whether it is safe to perform blockchain operations.booleanisTransactionOutputSpent(byte[] transactionHash, int index)Returns whether the specified transaction output has been spent.booleanopen()Called once to perform any initialization before accessing the blockchain.booleanputBlock(Block block)Store a block on the local blockchain.booleanputBlockHeader(BlockHeader blockHeader)Store a block header on the local blockchain.booleanputMempoolTransaction(Transaction transaction)Stores the specified transaction in the mempool.booleanremoveMempoolTransaction(byte[] transactionHash)Remove the specified transaction from the mempool.booleanverify()Verify the validity of the entire blockchain.booleanverifyRange(int beginHeight, int endHeight)Verify whether a range of the local blockchain is valid.
-
Method Details
-
open
boolean open()Called once to perform any initialization before accessing the blockchain.- Returns:
- Whether initialization was successful.
-
close
boolean close()Called once to perform any cleanup or saving after all blockchain operations have been completed.- Returns:
- Whether cleanup and saving was successful.
-
isOperational
boolean isOperational()Called to determine whether it is safe to perform blockchain operations.- Returns:
- Whether it is safe to perform blockchain operations.
-
verify
boolean verify()Verify the validity of the entire blockchain.- Returns:
- Whether the entire blockchain is valid.
-
verifyRange
Verify whether a range of the local blockchain is valid.- Parameters:
beginHeight- The first block to validate, inclusive.endHeight- The last block to validate, inclusive.- Returns:
- Whether the range of blocks is valid.
- Throws:
NoSuchBlockException- If the range provided is not within the bounds of the local blockchain.
-
getBlockHeight
int getBlockHeight()Gets the current local block height, can be thought of as the index of the most recent block (zero-indexed).- Returns:
- The current local block height.
-
getBlockchain
java.util.List<Block> getBlockchain()Returns an ordered list of the entire local blockchain.- Returns:
- An ordered list of the entire local blockchain.
-
getBlockchainRange
java.util.List<Block> getBlockchainRange(int beginHeight, int endHeight) throws NoSuchBlockExceptionReturns an ordered list of a range of the local blockchain.- Parameters:
beginHeight- The first block to include in the list, inclusive.endHeight- The last block to include in the list, inclusive.- Returns:
- Whether the range of blocks is valid.
- Throws:
NoSuchBlockException- If the range provided is not within the bounds of the local blockchain.
-
getHighestBlockHash
Returns the block hash of the most recent block in the local blockchain.- Returns:
- The block hash of the most recent block in the local blockchain.
- Throws:
NoSuchBlockException- If there are no blocks in the local blockchain.
-
getHighestBlock
Returns the most recent block in the local blockchain.- Returns:
- The most recent block in the local blockchain.
- Throws:
NoSuchBlockException- If there are no blocks in the local blockchain.
-
hasBlockHeader
boolean hasBlockHeader(byte[] blockHash)Returns whether the local blockchain contains a block header corresponding to the provided block hash.- Parameters:
blockHash- The block hash to search by.- Returns:
- Whether the local blockchain contains a block header corresponding to the provided block hash.
-
getBlockHeader
Retrieves the block header associated with the specified block hash.- Parameters:
blockHash- The block hash to search by.- Returns:
- The block header associated with the specified block hash.
- Throws:
NoSuchBlockException- If there was no block header associated with the provided block hash.
-
getBlockHeaderByHeight
Retrieves the block header associated with the specified block height.- Parameters:
height- The block height to search by.- Returns:
- The block header associated with the specified block height.
- Throws:
NoSuchBlockException- If there was no block header associated with the provided block height.
-
hasBlock
boolean hasBlock(byte[] blockHash)Returns whether the local blockchain contains a block corresponding to the provided block hash.- Parameters:
blockHash- The block hash to search by.- Returns:
- Whether the local blockchain contains a block corresponding to the provided block hash.
-
getBlock
Retrieves the block associated with the specified block hash.- Parameters:
blockHash- The block hash to search by.- Returns:
- The block associated with the specified block hash.
- Throws:
NoSuchBlockException- If there was no block associated with the provided block hash.
-
getBlockByHeight
Retrieves the block associated with the specified block height.- Parameters:
height- The block height to search by.- Returns:
- The block associated with the specified block height.
- Throws:
NoSuchBlockException- If there was no block associated with the provided block height.
-
getBlockByTransaction
Block getBlockByTransaction(byte[] transactionHash) throws NoSuchBlockException, NoSuchTransactionExceptionRetrieves the block associated with the specified transaction.- Parameters:
transactionHash- The hash of the transaction to search by.- Returns:
- The block containing the specified transaction.
- Throws:
NoSuchBlockException- If there is no block associated with the specified transaction in the local blockchain.NoSuchTransactionException- If there is no transaction with the specified hash in the local blockchain.
-
putBlock
Store a block on the local blockchain.- Parameters:
block- The block to store.- Returns:
- Whether the block was stored successfully.
-
putBlockHeader
Store a block header on the local blockchain. Optional, for header only clients.- Parameters:
blockHeader- The block header to store.- Returns:
- Whether the block header was stored successfully.
-
hasTransaction
boolean hasTransaction(byte[] transactionHash)Returns whether a transaction with the specified hash exist on the local blockchain.- Parameters:
transactionHash- The transaction hash to search by.- Returns:
- Whether a transaction with the specified hash exist on the local blockchain.
-
getTransaction
Transaction getTransaction(byte[] transactionHash) throws NoSuchTransactionException, NoSuchBlockExceptionRetrieve a transaction by its hash.- Parameters:
transactionHash- The transaction hash to search by.- Returns:
- The transaction with the specified hash.
- Throws:
NoSuchTransactionException- If there is no transaction with that hash in the local blockchain.NoSuchBlockException- If there is no block associated with the specified transaction in the local blockchain.
-
getTransactionInput
TransactionInput getTransactionInput(byte[] transactionHash, int index) throws NoSuchTransactionException, NoSuchBlockExceptionReturns the transaction input from the transaction hash and index.- Parameters:
transactionHash- The transaction hash to search by.index- The input index.- Returns:
- The transaction input specified.
- Throws:
NoSuchTransactionException- If there is no transaction with that hash in the local blockchain.NoSuchBlockException- If there is no block associated with the specified transaction in the local blockchain.
-
getTransactionOutput
TransactionOutput getTransactionOutput(byte[] transactionHash, int index) throws NoSuchTransactionException, NoSuchBlockExceptionReturns the transaction output from the transaction hash and index.- Parameters:
transactionHash- The transaction hash to search by.index- The output index.- Returns:
- The transaction output specified.
- Throws:
NoSuchTransactionException- If there is no transaction with that hash in the local blockchain.NoSuchBlockException- If there is no block associated with the specified transaction in the local blockchain.
-
isTransactionOutputSpent
boolean isTransactionOutputSpent(byte[] transactionHash, int index)Returns whether the specified transaction output has been spent. Typically, this will check whether it exists in the UTXO set.- Parameters:
transactionHash- The transaction hash to search by.index- The output index.- Returns:
- Whether the transaction output has been spent. (true for spent, false for unspent)
-
getUnspentTransactionOutputs
java.util.Set<BlockchainStorage.TransactionOutputIdentifier> getUnspentTransactionOutputs()Returns the local UTXO (unspent transaction output) set.- Returns:
- A set of TransactionOutputIdentifier representing the local UTXO set.
-
buildUnspentTransactionOutputSet
void buildUnspentTransactionOutputSet()Builds the local UTXO set from the entire blockchain. -
hasMempoolTransaction
boolean hasMempoolTransaction(byte[] transactionHash)Returns whether the mempool contains the specified transaction.- Parameters:
transactionHash- The transaction hash to search by.- Returns:
- Whether the mempool contains the specified transaction.
-
getMempoolTransactions
java.util.Set<Transaction> getMempoolTransactions()Returns the current set of mempool (pending) transactions.- Returns:
- The current set of mempool (pending) transactions.
-
getMempoolTransaction
Returns the mempool transaction specified.- Parameters:
transactionHash- The transaction hash to search by.- Returns:
- The specified mempool transaction.
- Throws:
NoSuchTransactionException- If the specified transaction does not exist in the mempool.
-
putMempoolTransaction
Stores the specified transaction in the mempool.- Parameters:
transaction- The transaction to store in the mempool.- Returns:
- Whether the transaction was successfully stored in the mempool.
-
removeMempoolTransaction
boolean removeMempoolTransaction(byte[] transactionHash)Remove the specified transaction from the mempool.- Parameters:
transactionHash- The hash of the transaction to remove from the mempool.- Returns:
- Whether the transaction was removed from the mempool.
-