Class PostgresFullPrunedBlockStore
- java.lang.Object
-
- org.bitcoinj.store.DatabaseFullPrunedBlockStore
-
- org.bitcoinj.store.PostgresFullPrunedBlockStore
-
- All Implemented Interfaces:
UTXOProvider
,BlockStore
,FullPrunedBlockStore
public class PostgresFullPrunedBlockStore extends DatabaseFullPrunedBlockStore
A full pruned block store using the Postgres database engine. As an added bonus an address index is calculated, so you can use
DatabaseFullPrunedBlockStore.calculateBalanceForAddress(Address)
to quickly look up the quantity of bitcoins controlled by that address.
-
-
Field Summary
-
Fields inherited from class org.bitcoinj.store.DatabaseFullPrunedBlockStore
allConnections, chainHeadBlock, chainHeadHash, conn, connectionURL, fullStoreDepth, params, password, schemaName, username, verifiedChainHeadBlock, verifiedChainHeadHash
-
-
Constructor Summary
Constructors Constructor Description PostgresFullPrunedBlockStore(NetworkParameters params, int fullStoreDepth, java.lang.String hostname, java.lang.String dbName, java.lang.String username, java.lang.String password)
Creates a new PostgresFullPrunedBlockStore.PostgresFullPrunedBlockStore(NetworkParameters params, int fullStoreDepth, java.lang.String hostname, java.lang.String dbName, java.lang.String username, java.lang.String password, java.lang.String schemaName)
Create a new PostgresFullPrunedBlockStore, storing the tables in the schema specified.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<java.lang.String>
getCreateIndexesSQL()
Get the SQL statements that create the indexes (DDL).protected java.util.List<java.lang.String>
getCreateSchemeSQL()
Get the SQL statements that create the schema (DDL).protected java.util.List<java.lang.String>
getCreateTablesSQL()
Get the SQL statements that create the tables (DDL).protected java.lang.String
getDatabaseDriverClass()
Get the database driver class,protected java.lang.String
getDuplicateKeyErrorCode()
Get the database specific error code that indicated a duplicate key error when inserting a record.void
put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock)
Saves the givenStoredUndoableBlock
andStoredBlock
.-
Methods inherited from class org.bitcoinj.store.DatabaseFullPrunedBlockStore
abortDatabaseBatchWrite, addUnspentTransactionOutput, beginDatabaseBatchWrite, calculateBalanceForAddress, close, commitDatabaseBatchWrite, deleteStore, dumpSizes, get, get, getBalanceSelectSQL, getChainHead, getChainHeadHeight, getCompatibilitySQL, getDeleteOpenoutputsSQL, getDeleteUndoableBlocksSQL, getDropTablesSQL, getInsertHeadersSQL, getInsertOpenoutputsSQL, getInsertSettingsSQL, getInsertUndoableBlocksSQL, getOnceUndoableStoredBlock, getOpenTransactionOutputs, getParams, getSelectHeadersDumpSQL, getSelectHeadersSQL, getSelectOpenoutputsCountSQL, getSelectopenoutputsDumpSQL, getSelectOpenoutputsSQL, getSelectSettingsDumpSQL, getSelectSettingsSQL, getSelectUndoableblocksDumpSQL, getSelectUndoableBlocksSQL, getTablesExistSQL, getTransactionOutput, getTransactionOutputSelectSQL, getUndoBlock, getUpdateHeadersSQL, getUpdateSettingsSLQ, getUpdateUndoableBlocksSQL, getVerifiedChainHead, hasUnspentOutputs, maybeConnect, put, putUpdateStoredBlock, removeUnspentTransactionOutput, resetStore, setChainHead, setVerifiedChainHead
-
-
-
-
Constructor Detail
-
PostgresFullPrunedBlockStore
public PostgresFullPrunedBlockStore(NetworkParameters params, int fullStoreDepth, java.lang.String hostname, java.lang.String dbName, java.lang.String username, java.lang.String password) throws BlockStoreException
Creates a new PostgresFullPrunedBlockStore.- Parameters:
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- Throws:
BlockStoreException
- if the database fails to open for any reason
-
PostgresFullPrunedBlockStore
public PostgresFullPrunedBlockStore(NetworkParameters params, int fullStoreDepth, java.lang.String hostname, java.lang.String dbName, java.lang.String username, java.lang.String password, @Nullable java.lang.String schemaName) throws BlockStoreException
Create a new PostgresFullPrunedBlockStore, storing the tables in the schema specified. You may want to specify a schema to avoid name collisions, or just to keep the database better organized. The schema is not required, and if one is not provided than the default schema for the username will be used. See the postgres schema docs for more on schemas.
- Parameters:
params
- A copy of the NetworkParameters used.fullStoreDepth
- The number of blocks of history stored in full (something like 1000 is pretty safe).hostname
- The hostname of the database to connect to.dbName
- The database to connect to.username
- The database username.password
- The password to the database.schemaName
- The name of the schema to put the tables in. May be null if no schema is being used.- Throws:
BlockStoreException
- If the database fails to open for any reason.
-
-
Method Detail
-
getDuplicateKeyErrorCode
protected java.lang.String getDuplicateKeyErrorCode()
Description copied from class:DatabaseFullPrunedBlockStore
Get the database specific error code that indicated a duplicate key error when inserting a record.This is the code returned by
SQLException.getSQLState()
- Specified by:
getDuplicateKeyErrorCode
in classDatabaseFullPrunedBlockStore
- Returns:
- The database duplicate error code.
-
getCreateTablesSQL
protected java.util.List<java.lang.String> getCreateTablesSQL()
Description copied from class:DatabaseFullPrunedBlockStore
Get the SQL statements that create the tables (DDL).- Specified by:
getCreateTablesSQL
in classDatabaseFullPrunedBlockStore
- Returns:
- The list of SQL statements.
-
getCreateIndexesSQL
protected java.util.List<java.lang.String> getCreateIndexesSQL()
Description copied from class:DatabaseFullPrunedBlockStore
Get the SQL statements that create the indexes (DDL).- Specified by:
getCreateIndexesSQL
in classDatabaseFullPrunedBlockStore
- Returns:
- The list of SQL statements.
-
getCreateSchemeSQL
protected java.util.List<java.lang.String> getCreateSchemeSQL()
Description copied from class:DatabaseFullPrunedBlockStore
Get the SQL statements that create the schema (DDL).- Specified by:
getCreateSchemeSQL
in classDatabaseFullPrunedBlockStore
- Returns:
- The list of SQL statements.
-
getDatabaseDriverClass
protected java.lang.String getDatabaseDriverClass()
Description copied from class:DatabaseFullPrunedBlockStore
Get the database driver class,i.e org.postgresql.Driver.
- Specified by:
getDatabaseDriverClass
in classDatabaseFullPrunedBlockStore
- Returns:
- The fully qualified database driver class.
-
put
public void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException
Description copied from interface:FullPrunedBlockStore
Saves the given
StoredUndoableBlock
andStoredBlock
. Calculates keys from theStoredBlock
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.
- Specified by:
put
in interfaceFullPrunedBlockStore
- Overrides:
put
in classDatabaseFullPrunedBlockStore
- Throws:
BlockStoreException
- if there is a problem with the underlying storage layer, such as running out of disk space.
-
-