Package org.bitcoinj.store
Class MemoryBlockStore
- java.lang.Object
-
- org.bitcoinj.store.MemoryBlockStore
-
- All Implemented Interfaces:
BlockStore
public class MemoryBlockStore extends java.lang.Object implements BlockStore
KeepsStoredBlock
s in memory. Used primarily for unit testing.
-
-
Constructor Summary
Constructors Constructor Description MemoryBlockStore(Block genesisBlock)
-
Method Summary
All Methods Instance Methods Concrete 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.
-
-
-
Constructor Detail
-
MemoryBlockStore
public MemoryBlockStore(Block genesisBlock)
-
-
Method Detail
-
put
public final 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
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 final 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()
Description copied from interface:BlockStore
Closes the store.- Specified by:
close
in interfaceBlockStore
-
-