public class SPVBlockStore extends Object implements BlockStore
Modifier and Type | Field and Description |
---|---|
protected LinkedHashMap<Sha256Hash,StoredBlock> |
blockCache |
protected MappedByteBuffer |
buffer |
static int |
DEFAULT_NUM_HEADERS
The default number of headers that will be stored in the ring buffer.
|
protected static int |
FILE_PROLOGUE_BYTES |
protected FileLock |
fileLock |
static String |
HEADER_MAGIC |
protected StoredBlock |
lastChainHead |
protected ReentrantLock |
lock |
protected LinkedHashMap<Sha256Hash,Object> |
notFoundCache |
protected static Object |
notFoundMarker |
protected int |
numHeaders |
protected NetworkParameters |
params |
protected RandomAccessFile |
randomAccessFile |
protected static int |
RECORD_SIZE |
Constructor and Description |
---|
SPVBlockStore(NetworkParameters params,
File file)
Creates and initializes an SPV block store.
|
Modifier and Type | Method and Description |
---|---|
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. |
int |
getFileSize()
Returns the size in bytes of the file that is used to store the chain with the current parameters.
|
NetworkParameters |
getParams()
Get the
NetworkParameters of this store. |
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. |
public static final int DEFAULT_NUM_HEADERS
public static final String HEADER_MAGIC
protected volatile MappedByteBuffer buffer
protected int numHeaders
protected NetworkParameters params
protected ReentrantLock lock
protected LinkedHashMap<Sha256Hash,StoredBlock> blockCache
protected static final Object notFoundMarker
protected LinkedHashMap<Sha256Hash,Object> notFoundCache
protected FileLock fileLock
protected RandomAccessFile randomAccessFile
protected StoredBlock lastChainHead
protected static final int RECORD_SIZE
protected static final int FILE_PROLOGUE_BYTES
public SPVBlockStore(NetworkParameters params, File file) throws BlockStoreException
BlockStoreException
public final int getFileSize()
public void put(StoredBlock block) throws BlockStoreException
BlockStore
put
in interface BlockStore
BlockStoreException
@Nullable public StoredBlock get(Sha256Hash hash) throws BlockStoreException
BlockStore
get
in interface BlockStore
BlockStoreException
public StoredBlock getChainHead() throws BlockStoreException
BlockStore
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.getChainHead
in interface BlockStore
BlockStoreException
public void setChainHead(StoredBlock chainHead) throws BlockStoreException
BlockStore
StoredBlock
that represents the top of the chain of greatest total work.setChainHead
in interface BlockStore
BlockStoreException
public void close() throws BlockStoreException
BlockStore
close
in interface BlockStore
BlockStoreException
public NetworkParameters getParams()
BlockStore
NetworkParameters
of this store.getParams
in interface BlockStore
Copyright © 2016. All rights reserved.