com.google.bitcoin.core
Interface BlockStore

All Known Implementing Classes:
BoundedOverheadBlockStore, DiskBlockStore, MemoryBlockStore

public interface BlockStore

An 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
 StoredBlock get(byte[] 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.
 

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(byte[] 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 the StoredBlock that represents the top of the chain of greatest total work.

Throws:
BlockStoreException

setChainHead

void setChainHead(StoredBlock chainHead)
                  throws BlockStoreException
Sets the StoredBlock that represents the top of the chain of greatest total work.

Throws:
BlockStoreException


Copyright © 2011. All Rights Reserved.