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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes the store.StoredBlock
get(Sha256Hash hash)
Returns the StoredBlock given a hash.StoredBlock
getChainHead()
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 Detail
-
put
void put(StoredBlock block) throws BlockStoreException
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
StoredBlock get(Sha256Hash hash) throws BlockStoreException
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
StoredBlock getChainHead() throws BlockStoreException
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
void setChainHead(StoredBlock chainHead) throws BlockStoreException
Sets theStoredBlock
that represents the top of the chain of greatest total work.- Throws:
BlockStoreException
-
close
void close() throws BlockStoreException
Closes the store.- Throws:
BlockStoreException
-
-