com.google.bitcoin.store
Class MemoryBlockStore

java.lang.Object
  extended by com.google.bitcoin.store.MemoryBlockStore
All Implemented Interfaces:
BlockStore

public class MemoryBlockStore
extends Object
implements BlockStore

Keeps StoredBlocks in memory. Used primarily for unit testing.


Constructor Summary
MemoryBlockStore(NetworkParameters params)
           
 
Method Summary
 void close()
          Closes the store.
 StoredBlock get(Sha256Hash hash)
          Returns the StoredBlock given a hash.
 StoredBlock getChainHead()
          Returns the StoredBlock 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 the StoredBlock that represents the top of the chain of greatest total work.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryBlockStore

public MemoryBlockStore(NetworkParameters params)
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 interface BlockStore
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 interface BlockStore
Throws:
BlockStoreException

getChainHead

public StoredBlock getChainHead()
                         throws BlockStoreException
Description copied from interface: BlockStore
Returns the StoredBlock that represents the top of the chain of greatest total work. Note that this can be arbitrarily expensive, you probably should use AbstractBlockChain.getChainHead() or perhaps AbstractBlockChain.getBestChainHeight() which will run in constant time and not take any heavyweight locks.

Specified by:
getChainHead in interface BlockStore
Throws:
BlockStoreException

setChainHead

public void setChainHead(StoredBlock chainHead)
                  throws BlockStoreException
Description copied from interface: BlockStore
Sets the StoredBlock that represents the top of the chain of greatest total work.

Specified by:
setChainHead in interface BlockStore
Throws:
BlockStoreException

close

public void close()
Description copied from interface: BlockStore
Closes the store.

Specified by:
close in interface BlockStore


Copyright © 2014. All rights reserved.