Package org.bitcoinj.store
Interface BlockStore
- All Known Subinterfaces:
FullPrunedBlockStore
- All Known Implementing Classes:
MemoryBlockStore
,MemoryFullPrunedBlockStore
,SPVBlockStore
public interface BlockStore
An implementor of BlockStore saves StoredBlock objects to disk. Different implementations store them in
different ways. An in-memory implementation (MemoryBlockStore) exists for unit testing but real apps will want to
use implementations that save to disk.
A BlockStore is a map of hashes to StoredBlock. The hash is the double digest of the Bitcoin serialization of the block header, not the header with the extra data as well.
BlockStores are thread safe.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the store.get
(Sha256Hash hash) Returns the StoredBlock given a hash.Returns theStoredBlock
that represents the top of the chain of greatest total work.void
put
(StoredBlock block) Saves the given block header+extra data.void
setChainHead
(StoredBlock chainHead) Sets theStoredBlock
that represents the top of the chain of greatest total work.
-
Method Details
-
put
Saves the given block header+extra data. The key isn't specified explicitly as it can be calculated from the StoredBlock directly. Can throw if there is a problem with the underlying storage layer such as running out of disk space.- Throws:
BlockStoreException
-
get
Returns the StoredBlock given a hash. The returned values block.getHash() method will be equal to the parameter. If no such block is found, returns null.- Throws:
BlockStoreException
-
getChainHead
Returns theStoredBlock
that represents the top of the chain of greatest total work. Note that this can be arbitrarily expensive, you probably should useAbstractBlockChain.getChainHead()
or perhapsAbstractBlockChain.getBestChainHeight()
which will run in constant time and not take any heavyweight locks.- Throws:
BlockStoreException
-
setChainHead
Sets theStoredBlock
that represents the top of the chain of greatest total work.- Throws:
BlockStoreException
-
close
Closes the store.- Throws:
BlockStoreException
-