Package org.bitcoinj.store
Class LevelDBBlockStore
- java.lang.Object
-
- org.bitcoinj.store.LevelDBBlockStore
-
- All Implemented Interfaces:
BlockStore
public class LevelDBBlockStore extends java.lang.Object implements 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 theSPVBlockStore
. 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
Constructors Constructor Description LevelDBBlockStore(Context context, java.io.File directory)
Creates a LevelDB SPV block store using the JNI/C++ version of LevelDB.LevelDBBlockStore(Context context, java.io.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the store.void
destroy()
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.NetworkParameters
getParams()
Get theNetworkParameters
of this store.void
put(StoredBlock block)
Saves the given block header+extra data.void
reset()
Erases the contents of the database (but NOT the underlying files themselves) and then reinitialises with the genesis block.void
setChainHead(StoredBlock chainHead)
Sets theStoredBlock
that represents the top of the chain of greatest total work.
-
-
-
Constructor Detail
-
LevelDBBlockStore
public LevelDBBlockStore(Context context, java.io.File directory) throws BlockStoreException
Creates a LevelDB SPV block store using the JNI/C++ version of LevelDB.- Throws:
BlockStoreException
-
LevelDBBlockStore
public LevelDBBlockStore(Context context, java.io.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 Detail
-
put
public void put(StoredBlock block) throws BlockStoreException
Description copied from interface:BlockStore
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.- Specified by:
put
in interfaceBlockStore
- Throws:
BlockStoreException
-
get
@Nullable public StoredBlock get(Sha256Hash hash) throws BlockStoreException
Description copied from interface:BlockStore
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.- Specified by:
get
in interfaceBlockStore
- Throws:
BlockStoreException
-
getChainHead
public StoredBlock getChainHead() throws BlockStoreException
Description copied from interface:BlockStore
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.- Specified by:
getChainHead
in interfaceBlockStore
- Throws:
BlockStoreException
-
setChainHead
public void setChainHead(StoredBlock chainHead) throws BlockStoreException
Description copied from interface:BlockStore
Sets theStoredBlock
that represents the top of the chain of greatest total work.- Specified by:
setChainHead
in interfaceBlockStore
- Throws:
BlockStoreException
-
close
public void close() throws BlockStoreException
Description copied from interface:BlockStore
Closes the store.- Specified by:
close
in interfaceBlockStore
- Throws:
BlockStoreException
-
reset
public void reset() throws BlockStoreException
Erases the contents of the database (but NOT the underlying files themselves) and then reinitialises with the genesis block.- Throws:
BlockStoreException
-
destroy
public void destroy() throws java.io.IOException
- Throws:
java.io.IOException
-
getParams
public NetworkParameters getParams()
Description copied from interface:BlockStore
Get theNetworkParameters
of this store.- Specified by:
getParams
in interfaceBlockStore
- Returns:
- The network params.
-
-