Package org.bitcoinj.store
Class LevelDBBlockStore
java.lang.Object
org.bitcoinj.store.LevelDBBlockStore
- All Implemented Interfaces:
BlockStore
An SPV block store that writes every header it sees to a LevelDB.
This allows for fast lookup of block headers by block hash at the expense of more costly inserts and higher disk
usage than the
SPVBlockStore. If all you want is a regular wallet you don't need this class: it exists for
specialised applications where you need to quickly verify a standalone SPV proof.-
Constructor Summary
ConstructorsConstructorDescriptionLevelDBBlockStore(Context context, File directory) Creates a LevelDB SPV block store using the JNI/C++ version of LevelDB.LevelDBBlockStore(Context context, File directory, org.iq80.leveldb.DBFactory dbFactory) Creates a LevelDB SPV block store using the given factory, which is useful if you want a pure Java version. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the store.voiddestroy()get(Sha256Hash hash) Returns the StoredBlock given a hash.Returns theStoredBlockthat represents the top of the chain of greatest total work.Get theNetworkParametersof this store.voidput(StoredBlock block) Saves the given block header+extra data.voidreset()Erases the contents of the database (but NOT the underlying files themselves) and then reinitialises with the genesis block.voidsetChainHead(StoredBlock chainHead) Sets theStoredBlockthat represents the top of the chain of greatest total work.
-
Constructor Details
-
LevelDBBlockStore
Creates a LevelDB SPV block store using the JNI/C++ version of LevelDB.- Throws:
BlockStoreException
-
LevelDBBlockStore
public LevelDBBlockStore(Context context, File directory, org.iq80.leveldb.DBFactory dbFactory) throws BlockStoreException Creates a LevelDB SPV block store using the given factory, which is useful if you want a pure Java version.- Throws:
BlockStoreException
-
-
Method Details
-
put
Description copied from interface:BlockStoreSaves 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.- Specified by:
putin interfaceBlockStore- Throws:
BlockStoreException
-
get
Description copied from interface:BlockStoreReturns 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.- Specified by:
getin interfaceBlockStore- Throws:
BlockStoreException
-
getChainHead
Description copied from interface:BlockStoreReturns 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.- Specified by:
getChainHeadin interfaceBlockStore- Throws:
BlockStoreException
-
setChainHead
Description copied from interface:BlockStoreSets theStoredBlockthat represents the top of the chain of greatest total work.- Specified by:
setChainHeadin interfaceBlockStore- Throws:
BlockStoreException
-
close
Description copied from interface:BlockStoreCloses the store.- Specified by:
closein interfaceBlockStore- Throws:
BlockStoreException
-
reset
Erases the contents of the database (but NOT the underlying files themselves) and then reinitialises with the genesis block.- Throws:
BlockStoreException
-
destroy
- Throws:
IOException
-
getParams
Description copied from interface:BlockStoreGet theNetworkParametersof this store.- Specified by:
getParamsin interfaceBlockStore- Returns:
- The network params.
-