Package org.bitcoinj.store
Interface BlockStore
-
- All Known Subinterfaces:
FullPrunedBlockStore
- All Known Implementing Classes:
MemoryBlockStore,MemoryFullPrunedBlockStore,SPVBlockStore
public interface BlockStoreAn 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 voidclose()Closes the store.StoredBlockget(Sha256Hash hash)Returns the StoredBlock given a hash.StoredBlockgetChainHead()Returns theStoredBlockthat represents the top of the chain of greatest total work.NetworkParametersgetParams()Get theNetworkParametersof this store.voidput(StoredBlock block)Saves the given block header+extra data.voidsetChainHead(StoredBlock chainHead)Sets theStoredBlockthat 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 theStoredBlockthat 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 theStoredBlockthat represents the top of the chain of greatest total work.- Throws:
BlockStoreException
-
close
void close() throws BlockStoreExceptionCloses the store.- Throws:
BlockStoreException
-
getParams
NetworkParameters getParams()
Get theNetworkParametersof this store.- Returns:
- The network params.
-
-