|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.bitcoin.store.PostgresFullPrunedBlockStore
public class PostgresFullPrunedBlockStore
A full pruned block store using the Postgres database engine. As an added bonus an address index is calculated,
so you can use calculateBalanceForAddress(com.google.bitcoin.core.Address) to quickly look up
the quantity of bitcoins controlled by that address.
| Constructor Summary | |
|---|---|
PostgresFullPrunedBlockStore(NetworkParameters params,
int fullStoreDepth,
String hostname,
String dbName,
String username,
String password)
Creates a new PostgresFullPrunedBlockStore. |
|
| Method Summary | |
|---|---|
void |
abortDatabaseBatchWrite()
|
void |
addUnspentTransactionOutput(StoredTransactionOutput out)
Adds a StoredTransactionOutput to the list of unspent TransactionOutputs |
void |
beginDatabaseBatchWrite()
Begins/Commits/Aborts a database transaction. |
BigInteger |
calculateBalanceForAddress(Address address)
Calculate the balance for a coinbase, to-address, or p2sh address. |
void |
close()
Closes the store. |
void |
commitDatabaseBatchWrite()
|
void |
dumpSizes()
Dumps information about the size of actual data in the database to standard output The only truly useless data counted is printed in the form "N in id indexes" This does not take database indexes into account |
StoredBlock |
get(Sha256Hash hash)
Returns the StoredBlock given a hash. |
StoredBlock |
get(Sha256Hash hash,
boolean wasUndoableOnly)
|
StoredBlock |
getChainHead()
Returns the StoredBlock that represents the top of the chain of greatest total work. |
StoredBlock |
getOnceUndoableStoredBlock(Sha256Hash hash)
Returns the StoredBlock that was added as a StoredUndoableBlock given a hash. |
StoredTransactionOutput |
getTransactionOutput(Sha256Hash hash,
long index)
Gets a StoredTransactionOutput with the given hash and index, or null if none is found |
StoredUndoableBlock |
getUndoBlock(Sha256Hash hash)
Returns a StoredUndoableBlock whose block.getHash() method will be equal to the parameter. |
StoredBlock |
getVerifiedChainHead()
Returns the StoredBlock that represents the top of the chain of greatest total work that has
been fully verified and the point in the chain at which the unspent transaction output set in this
store represents. |
boolean |
hasUnspentOutputs(Sha256Hash hash,
int numOutputs)
True if this store has any unspent outputs from a transaction with a hash equal to the first parameter |
void |
put(StoredBlock storedBlock)
Saves the given block header+extra data. |
void |
put(StoredBlock storedBlock,
StoredUndoableBlock undoableBlock)
Saves the given StoredUndoableBlock and StoredBlock. |
void |
removeUnspentTransactionOutput(StoredTransactionOutput out)
Removes a StoredTransactionOutput from the list of unspent TransactionOutputs
Note that the coinbase of the genesis block should NEVER be spendable and thus never in the list. |
void |
resetStore()
|
void |
setChainHead(StoredBlock chainHead)
Sets the StoredBlock that represents the top of the chain of greatest total work. |
void |
setVerifiedChainHead(StoredBlock chainHead)
Sets the StoredBlock that represents the top of the chain of greatest total work that has been
fully verified. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PostgresFullPrunedBlockStore(NetworkParameters params,
int fullStoreDepth,
String hostname,
String dbName,
String username,
String password)
throws BlockStoreException
params - A copy of the NetworkParameters usedfullStoreDepth - The number of blocks of history stored in full (something like 1000 is pretty safe)hostname - The hostname of the database to connect todbName - The database to connect tousername - The database usernamepassword - The password to the database
BlockStoreException - if the database fails to open for any reason| Method Detail |
|---|
public void close()
BlockStore
close in interface BlockStore
public void resetStore()
throws BlockStoreException
BlockStoreException
public void dumpSizes()
throws SQLException,
BlockStoreException
SQLException
BlockStoreException
public void put(StoredBlock storedBlock)
throws BlockStoreException
BlockStore
put in interface BlockStoreBlockStoreException
public void put(StoredBlock storedBlock,
StoredUndoableBlock undoableBlock)
throws BlockStoreException
FullPrunedBlockStoreSaves the given StoredUndoableBlock and StoredBlock. Calculates keys from the StoredBlock
Though not required for proper function of a FullPrunedBlockStore, any user of a FullPrunedBlockStore should ensure that a StoredUndoableBlock for each block up to the fully verified chain head has been added to this block store using this function (not put(StoredBlock)), so that the ability to perform reorgs is maintained.
put in interface FullPrunedBlockStoreBlockStoreException - if there is a problem with the underlying storage layer, such as running out of disk space.
public StoredBlock get(Sha256Hash hash,
boolean wasUndoableOnly)
throws BlockStoreException
BlockStoreException
public StoredBlock get(Sha256Hash hash)
throws BlockStoreException
BlockStore
get in interface BlockStoreBlockStoreException
public StoredBlock getOnceUndoableStoredBlock(Sha256Hash hash)
throws BlockStoreException
FullPrunedBlockStore
getOnceUndoableStoredBlock in interface FullPrunedBlockStoreBlockStoreException
public StoredUndoableBlock getUndoBlock(Sha256Hash hash)
throws BlockStoreException
FullPrunedBlockStoreStoredUndoableBlock whose block.getHash() method will be equal to the parameter. If no such
block is found, returns null. Note that this may return null more often than get(Sha256Hash hash) as not all
StoredBlocks have a StoredUndoableBlock copy stored as well.
getUndoBlock in interface FullPrunedBlockStoreBlockStoreException
public StoredBlock getChainHead()
throws BlockStoreException
BlockStoreStoredBlock 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 BlockStoreBlockStoreException
public void setChainHead(StoredBlock chainHead)
throws BlockStoreException
BlockStoreStoredBlock that represents the top of the chain of greatest total work.
setChainHead in interface BlockStoreBlockStoreException
public StoredBlock getVerifiedChainHead()
throws BlockStoreException
FullPrunedBlockStoreStoredBlock that represents the top of the chain of greatest total work that has
been fully verified and the point in the chain at which the unspent transaction output set in this
store represents.
getVerifiedChainHead in interface FullPrunedBlockStoreBlockStoreException
public void setVerifiedChainHead(StoredBlock chainHead)
throws BlockStoreException
FullPrunedBlockStoreStoredBlock that represents the top of the chain of greatest total work that has been
fully verified. It should generally be set after a batch of updates to the transaction unspent output set,
before a call to commitDatabaseBatchWrite.
If chainHead has a greater height than the non-verified chain head (ie that set with
BlockStore.setChainHead) the non-verified chain head should be set to the one set here.
In this way a class using a FullPrunedBlockStore only in full-verification mode can ignore the regular
BlockStore functions implemented as a part of a FullPrunedBlockStore.
setVerifiedChainHead in interface FullPrunedBlockStoreBlockStoreException
public StoredTransactionOutput getTransactionOutput(Sha256Hash hash,
long index)
throws BlockStoreException
FullPrunedBlockStoreStoredTransactionOutput with the given hash and index, or null if none is found
getTransactionOutput in interface FullPrunedBlockStoreBlockStoreException
public void addUnspentTransactionOutput(StoredTransactionOutput out)
throws BlockStoreException
FullPrunedBlockStoreStoredTransactionOutput to the list of unspent TransactionOutputs
addUnspentTransactionOutput in interface FullPrunedBlockStoreBlockStoreException
public void removeUnspentTransactionOutput(StoredTransactionOutput out)
throws BlockStoreException
FullPrunedBlockStoreStoredTransactionOutput from the list of unspent TransactionOutputs
Note that the coinbase of the genesis block should NEVER be spendable and thus never in the list.
removeUnspentTransactionOutput in interface FullPrunedBlockStoreBlockStoreException - if there is an underlying storage issue, or out was not in the list.
public void beginDatabaseBatchWrite()
throws BlockStoreException
FullPrunedBlockStoreBegins/Commits/Aborts a database transaction.
If abortDatabaseBatchWrite() is called by the same thread that called beginDatabaseBatchWrite(), any data writes between this call and abortDatabaseBatchWrite() made by the same thread should be discarded.
Furthermore, any data written after a call to beginDatabaseBatchWrite() should not be readable by any other threads until commitDatabaseBatchWrite() has been called by this thread. Multiple calls to beginDatabaseBatchWrite() in any given thread should be ignored and treated as one call.
beginDatabaseBatchWrite in interface FullPrunedBlockStoreBlockStoreException
public void commitDatabaseBatchWrite()
throws BlockStoreException
commitDatabaseBatchWrite in interface FullPrunedBlockStoreBlockStoreException
public void abortDatabaseBatchWrite()
throws BlockStoreException
abortDatabaseBatchWrite in interface FullPrunedBlockStoreBlockStoreException
public boolean hasUnspentOutputs(Sha256Hash hash,
int numOutputs)
throws BlockStoreException
FullPrunedBlockStore
hasUnspentOutputs in interface FullPrunedBlockStorenumOutputs - the number of outputs the given transaction has
BlockStoreException
public BigInteger calculateBalanceForAddress(Address address)
throws BlockStoreException
address - The address to calculate the balance of
BlockStoreException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||