dcrpg

package module
v4.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2019 License: ISC Imports: 38 Imported by: 3

README

package dcrpg

The dcrpg package provides types and functions for manipulating PostgreSQL tables, and storing blocks, transactions, inputs, and outputs.

Supported Database Software

PostgreSQL versions 10.5 to 11.x are fully supported. The bulk of the testing and performance optimization is done with PostgreSQL in mind.

Experimental support for CockroachDB was added for dcrdata 5.0. However, compared to a well-configure PostgreSQL backend, CoackroachDB performance is suboptimal. See the CockroachDB support issue for more information.

Performance and Bulk Loading

When performing a bulk data import, it is wise to first drop any existing indexes and create them again after insertion is completed. Functions are provided to create and drop the indexes.

PostgreSQL performance will be poor, particularly during bulk import, unless synchronous transaction commits are disabled via the synchronous_commit = off configuration setting in your postgresql.conf. There are numerous PostreSQL tuning settings, but a quick suggestion for your system can be provided byPgTune. During initial table population, it is also OK to turn off full page writes, and possibly fsync, but change these two options back after initial sync.

Especially during normal operation, it is important to set autovacuum = on. For fast queries, it is critical to have regular table statistics collected by the autovacuum process.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeAllTables

func AnalyzeAllTables(db *sql.DB, statisticsTarget int) error

AnalyzeAllTables performs an ANALYZE on all tables after setting default_statistics_target for the transaction.

func AnalyzeTable

func AnalyzeTable(db *sql.DB, table string, statisticsTarget int) error

AnalyzeTable performs an ANALYZE on the specified table after setting default_statistics_target for the transaction.

func CheckColumnDataType

func CheckColumnDataType(db *sql.DB, table, column string) (dataType string, err error)

CheckColumnDataType gets the data type of specified table column .

func CheckCurrentTimeZone

func CheckCurrentTimeZone(db *sql.DB) (currentTZ string, err error)

CheckCurrentTimeZone queries for the currently set postgres time zone.

func CheckDefaultTimeZone

func CheckDefaultTimeZone(db *sql.DB) (defaultTZ, currentTZ string, err error)

CheckDefaultTimeZone queries for the default postgres time zone. This is the value that would be observed if postgres were restarted using its current configuration. The currently set time zone is also returned.

func ClearTestingTable

func ClearTestingTable(db *sql.DB) error

func Connect

func Connect(host, port, user, pass, dbname string) (*sql.DB, error)

Connect opens a connection to a PostgreSQL database. The caller is responsible for calling Close() on the returned db when finished using it. The input host may be an IP address for TCP connection, or an absolute path to a UNIX domain socket. An empty string should be provided for UNIX sockets.

func CountMergedFundingTxns

func CountMergedFundingTxns(ctx context.Context, db *sql.DB, address string) (count int64, err error)

func CountMergedSpendingTxns

func CountMergedSpendingTxns(ctx context.Context, db *sql.DB, address string) (count int64, err error)

func CountMergedTxns

func CountMergedTxns(ctx context.Context, db *sql.DB, address string) (count int64, err error)

func CreateTable

func CreateTable(db *sql.DB, tableName string) error

CreateTable creates one of the known tables by name.

func CreateTableLegacy

func CreateTableLegacy(db *sql.DB, tableName string) error

CreateTableLegacy creates one of the known tables by name.

func CreateTables

func CreateTables(db *sql.DB) error

CreateTables creates all tables required by dcrdata if they do not already exist.

func CreateTablesLegacy

func CreateTablesLegacy(db *sql.DB) error

CreateTablesLegacy creates all tables required by dcrdata if they do not already exist.

func DBBestBlock

func DBBestBlock(ctx context.Context, db *sql.DB) (hash string, height int64, err error)

DBBestBlock retrieves the best block hash and height from the meta table. The error value will never be sql.ErrNoRows; instead with height == -1 indicating no data in the meta table.

func DeindexAddressTableOnAddress

func DeindexAddressTableOnAddress(db *sql.DB) (err error)

func DeindexAddressTableOnTxHash

func DeindexAddressTableOnTxHash(db *sql.DB) (err error)

func DeindexAddressTableOnVoutID

func DeindexAddressTableOnVoutID(db *sql.DB) (err error)

func DeindexAgendaVotesTableOnAgendaID

func DeindexAgendaVotesTableOnAgendaID(db *sql.DB) (err error)

func DeindexAgendasTableOnAgendaID

func DeindexAgendasTableOnAgendaID(db *sql.DB) (err error)

func DeindexBlockTableOnHash

func DeindexBlockTableOnHash(db *sql.DB) (err error)

func DeindexBlockTableOnHeight

func DeindexBlockTableOnHeight(db *sql.DB) (err error)

func DeindexBlockTimeOnTableAddress

func DeindexBlockTimeOnTableAddress(db *sql.DB) (err error)

func DeindexMatchingTxHashOnTableAddress

func DeindexMatchingTxHashOnTableAddress(db *sql.DB) (err error)

func DeindexMissesTableOnHash

func DeindexMissesTableOnHash(db *sql.DB) (err error)

func DeindexProposalVotesTableOnProposalsID

func DeindexProposalVotesTableOnProposalsID(db *sql.DB) (err error)

func DeindexProposalsTableOnToken

func DeindexProposalsTableOnToken(db *sql.DB) (err error)

func DeindexTicketsTableOnHashes

func DeindexTicketsTableOnHashes(db *sql.DB) (err error)

func DeindexTicketsTableOnPoolStatus

func DeindexTicketsTableOnPoolStatus(db *sql.DB) (err error)

func DeindexTicketsTableOnTxDbID

func DeindexTicketsTableOnTxDbID(db *sql.DB) (err error)

func DeindexTransactionTableOnBlockIn

func DeindexTransactionTableOnBlockIn(db *sql.DB) (err error)

func DeindexTransactionTableOnHashes

func DeindexTransactionTableOnHashes(db *sql.DB) (err error)

func DeindexVinTableOnPrevOuts

func DeindexVinTableOnPrevOuts(db *sql.DB) (err error)

func DeindexVinTableOnVins

func DeindexVinTableOnVins(db *sql.DB) (err error)

func DeindexVotesTableOnBlockHash

func DeindexVotesTableOnBlockHash(db *sql.DB) (err error)

func DeindexVotesTableOnBlockTime

func DeindexVotesTableOnBlockTime(db *sql.DB) (err error)

func DeindexVotesTableOnCandidate

func DeindexVotesTableOnCandidate(db *sql.DB) (err error)

func DeindexVotesTableOnHash

func DeindexVotesTableOnHash(db *sql.DB) (err error)

func DeindexVotesTableOnHeight

func DeindexVotesTableOnHeight(db *sql.DB) (err error)

func DeindexVotesTableOnVoteVersion

func DeindexVotesTableOnVoteVersion(db *sql.DB) (err error)

func DeindexVoutTableOnTxHashIdx

func DeindexVoutTableOnTxHashIdx(db *sql.DB) (err error)

func DeleteBestBlock

func DeleteBestBlock(ctx context.Context, db *sql.DB) (res dbtypes.DeletionSummary, height int64, hash string, err error)

DeleteBestBlock removes all data for the best block in the DB from every table via DeleteBlockData. The returned height and hash are for the best block after successful data removal, or the initial best block if removal fails as indicated by a non-nil error value.

func DeleteBlockData

func DeleteBlockData(ctx context.Context, db *sql.DB, hash string) (res dbtypes.DeletionSummary, err error)

DeleteBlockData removes all data for the specified block from every table. Data are removed from tables in the following order: vins, vouts, addresses, transactions, tickets, votes, misses, blocks, block_chain. WARNING: When no indexes are present, these queries are VERY SLOW.

func DeleteBlocks

func DeleteBlocks(ctx context.Context, N int64, db *sql.DB) (res []dbtypes.DeletionSummary, height int64, hash string, err error)

DeleteBlocks removes all data for the N best blocks in the DB from every table via repeated calls to DeleteBestBlock.

func DeleteDuplicateAgendaVotes

func DeleteDuplicateAgendaVotes(db *sql.DB) (int64, error)

DeleteDuplicateAgendaVotes deletes rows in agenda_votes with duplicate votes-row-id and agendas-row-id leaving the one row with the lowest id.

func DeleteDuplicateAgendas

func DeleteDuplicateAgendas(db *sql.DB) (int64, error)

DeleteDuplicateAgendas deletes rows in agendas with duplicate names leaving the one row with the lowest id.

func DeleteDuplicateMisses

func DeleteDuplicateMisses(db *sql.DB) (int64, error)

DeleteDuplicateMisses deletes rows in misses with duplicate tx-block hashes, leaving the one row with the lowest id.

func DeleteDuplicateTickets

func DeleteDuplicateTickets(db *sql.DB) (int64, error)

DeleteDuplicateTickets deletes rows in tickets with duplicate tx-block hashes, leaving the one row with the lowest id.

func DeleteDuplicateTxns

func DeleteDuplicateTxns(db *sql.DB) (int64, error)

DeleteDuplicateTxns deletes rows in transactions with duplicate tx-block hashes, leaving the one row with the lowest id.

func DeleteDuplicateVins

func DeleteDuplicateVins(db *sql.DB) (int64, error)

DeleteDuplicateVins deletes rows in vin with duplicate tx information, leaving the one row with the lowest id.

func DeleteDuplicateVinsCockroach

func DeleteDuplicateVinsCockroach(db *sql.DB) (int64, error)

DeleteDuplicateVinsCockroach deletes rows in vin with duplicate tx information, leaving the one row with the lowest id.

func DeleteDuplicateVotes

func DeleteDuplicateVotes(db *sql.DB) (int64, error)

DeleteDuplicateVotes deletes rows in votes with duplicate tx-block hashes, leaving the one row with the lowest id.

func DeleteDuplicateVouts

func DeleteDuplicateVouts(db *sql.DB) (int64, error)

DeleteDuplicateVouts deletes rows in vouts with duplicate tx information, leaving the one row with the lowest id.

func DeleteDuplicateVoutsCockroach

func DeleteDuplicateVoutsCockroach(db *sql.DB) (int64, error)

DeleteDuplicateVoutsCockroach deletes rows in vouts with duplicate tx information, leaving the one row with the highest id.

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func DropTables

func DropTables(db *sql.DB)

DropTables drops all of the tables internally recognized tables.

func DropTestingTable

func DropTestingTable(db SqlExecutor) error

DropTestingTable drops only the "testing" table.

func ExistsIndex

func ExistsIndex(db *sql.DB, indexName string) (exists bool, err error)

ExistsIndex checks if the specified index name exists.

func IBDComplete

func IBDComplete(db *sql.DB) (ibdComplete bool, err error)

IBDComplete indicates whether initial block download was completed according to the meta.ibd_complete flag.

func IndexAddressTableOnAddress

func IndexAddressTableOnAddress(db *sql.DB) (err error)

IndexAddressTableOnAddress creates the index for the addresses table over address.

func IndexAddressTableOnTxHash

func IndexAddressTableOnTxHash(db *sql.DB) (err error)

IndexAddressTableOnTxHash creates the index for the addresses table over transaction hash.

func IndexAddressTableOnVoutID

func IndexAddressTableOnVoutID(db *sql.DB) (err error)

IndexAddressTableOnVoutID creates the index for the addresses table over vout row ID.

func IndexAgendaVotesTableOnAgendaID

func IndexAgendaVotesTableOnAgendaID(db *sql.DB) (err error)

func IndexAgendasTableOnAgendaID

func IndexAgendasTableOnAgendaID(db *sql.DB) (err error)

func IndexBlockTableOnHash

func IndexBlockTableOnHash(db *sql.DB) (err error)

func IndexBlockTableOnHeight

func IndexBlockTableOnHeight(db *sql.DB) (err error)

func IndexBlockTimeOnTableAddress

func IndexBlockTimeOnTableAddress(db *sql.DB) (err error)

IndexBlockTimeOnTableAddress creates the index for the addresses table over block time.

func IndexMatchingTxHashOnTableAddress

func IndexMatchingTxHashOnTableAddress(db *sql.DB) (err error)

IndexMatchingTxHashOnTableAddress creates the index for the addresses table over matching transaction hash.

func IndexMissesTableOnHashes

func IndexMissesTableOnHashes(db *sql.DB) (err error)

func IndexProposalVotesTableOnProposalsID

func IndexProposalVotesTableOnProposalsID(db *sql.DB) (err error)

func IndexProposalsTableOnToken

func IndexProposalsTableOnToken(db *sql.DB) (err error)

func IndexTicketsTableOnHashes

func IndexTicketsTableOnHashes(db *sql.DB) (err error)

func IndexTicketsTableOnPoolStatus

func IndexTicketsTableOnPoolStatus(db *sql.DB) (err error)

func IndexTicketsTableOnTxDbID

func IndexTicketsTableOnTxDbID(db *sql.DB) (err error)

func IndexTransactionTableOnBlockIn

func IndexTransactionTableOnBlockIn(db *sql.DB) (err error)

func IndexTransactionTableOnHashes

func IndexTransactionTableOnHashes(db *sql.DB) (err error)

func IndexVinTableOnPrevOuts

func IndexVinTableOnPrevOuts(db *sql.DB) (err error)

func IndexVinTableOnVins

func IndexVinTableOnVins(db *sql.DB) (err error)

func IndexVotesTableOnBlockHash

func IndexVotesTableOnBlockHash(db *sql.DB) (err error)

func IndexVotesTableOnBlockTime

func IndexVotesTableOnBlockTime(db *sql.DB) (err error)

IndexVotesTableOnBlockTime improves the speed of "Vote Choices By Block" agendas chart query.

func IndexVotesTableOnCandidate

func IndexVotesTableOnCandidate(db *sql.DB) (err error)

func IndexVotesTableOnHashes

func IndexVotesTableOnHashes(db *sql.DB) (err error)

func IndexVotesTableOnHeight

func IndexVotesTableOnHeight(db *sql.DB) (err error)

IndexVotesTableOnHeight improves the speed of "Cumulative Vote Choices" agendas chart query.

func IndexVotesTableOnVoteVersion

func IndexVotesTableOnVoteVersion(db *sql.DB) (err error)

func IndexVoutTableOnTxHashIdx

func IndexVoutTableOnTxHashIdx(db *sql.DB) (err error)

IndexVoutTableOnTxHashIdx creates the index for the addresses table over transaction hash and index.

func InsertAddressRow

func InsertAddressRow(db *sql.DB, dbA *dbtypes.AddressRow, dupCheck, updateExistingRecords bool) (uint64, error)

InsertAddressRow inserts an AddressRow (input or output), returning the row ID in the addresses table of the inserted data.

func InsertAddressRows

func InsertAddressRows(db *sql.DB, dbAs []*dbtypes.AddressRow, dupCheck, updateExistingRecords bool) ([]uint64, error)

InsertAddressRows inserts multiple transaction inputs or outputs for certain addresses ([]AddressRow). The row IDs of the inserted data are returned.

func InsertAddressRowsDbTx

func InsertAddressRowsDbTx(dbTx *sql.Tx, dbAs []*dbtypes.AddressRow, dupCheck, updateExistingRecords bool) ([]uint64, error)

InsertAddressRowsDbTx is like InsertAddressRows, except that it takes a sql.Tx. The caller is required to Commit or Rollback the transaction depending on the returned error value.

func InsertBlock

func InsertBlock(db *sql.DB, dbBlock *dbtypes.Block, isValid, isMainchain, checked bool) (uint64, error)

InsertBlock inserts the specified dbtypes.Block as with the given valid/mainchain status. If checked is true, an upsert statement is used so that a unique constraint violation will result in an update instead of attempting to insert a duplicate row. If checked is false and there is a duplicate row, an error will be returned.

func InsertBlockPrevNext

func InsertBlockPrevNext(db *sql.DB, blockDbID uint64,
	hash, prev, next string) error

InsertBlockPrevNext inserts a new row of the block_chain table.

func InsertProposal

func InsertProposal(db *sql.DB, tokenHash, author, commit string,
	timestamp time.Time, checked bool) (uint64, error)

InsertProposal adds the proposal details per commit to the proposal table.

func InsertProposalVote

func InsertProposalVote(db *sql.DB, proposalRowID uint64, ticket, choice string,
	checked bool) (uint64, error)

InsertProposalVote add the proposal votes entries to the proposal_votes table.

func InsertSpendingAddressRow

func InsertSpendingAddressRow(db *sql.DB, fundingTxHash string,
	fundingTxVoutIndex uint32, fundingTxTree int8, spendingTxHash string,
	spendingTxVinIndex uint32, vinDbID uint64, utxoData *dbtypes.UTXOData,
	checked, updateExisting, isValidMainchain bool,
	txType int16, updateFundingRow bool, spendingTXBlockTime dbtypes.TimeDef) (int64, error)

InsertSpendingAddressRow inserts a new spending tx row, and updates any corresponding funding tx row.

func InsertTickets

func InsertTickets(db *sql.DB, dbTxns []*dbtypes.Tx, txDbIDs []uint64, checked, updateExistingRecords bool) ([]uint64, []*dbtypes.Tx, error)

InsertTickets takes a slice of *dbtypes.Tx and corresponding DB row IDs for transactions, extracts the tickets, and inserts the tickets into the database. Outputs are a slice of DB row IDs of the inserted tickets, and an error.

func InsertTx

func InsertTx(db *sql.DB, dbTx *dbtypes.Tx, checked, updateExistingRecords bool) (uint64, error)

func InsertTxns

func InsertTxns(db *sql.DB, dbTxns []*dbtypes.Tx, checked, updateExistingRecords bool) ([]uint64, error)

func InsertTxnsDbTxn

func InsertTxnsDbTxn(dbTx *sql.Tx, dbTxns []*dbtypes.Tx, checked, updateExistingRecords bool) ([]uint64, error)

func InsertTxnsStmt

func InsertTxnsStmt(stmt *sql.Stmt, dbTxns []*dbtypes.Tx, checked, updateExistingRecords bool) ([]uint64, error)

func InsertVin

func InsertVin(db *sql.DB, dbVin dbtypes.VinTxProperty, checked bool, updateOnConflict ...bool) (id uint64, err error)

InsertVin either inserts, attempts to insert, or upserts the given vin data into the vins table. If checked=false, an unconditional insert as attempted, which may result in a violation of a unique index constraint (error). If checked=true, a constraint violation may be handled in one of two ways: update the conflicting row (upsert), or do nothing. In all cases, the id of the new/updated/conflicting row is returned. The updateOnConflict argument may be omitted, in which case an upsert will be favored over no nothing, but only if checked=true.

func InsertVins

func InsertVins(db *sql.DB, dbVins dbtypes.VinTxPropertyARRAY, checked bool, updateOnConflict ...bool) ([]uint64, error)

InsertVins is like InsertVin, except that it operates on a slice of vin data.

func InsertVinsDbTxn

func InsertVinsDbTxn(dbTx *sql.Tx, dbVins dbtypes.VinTxPropertyARRAY, checked bool, doUpsert bool) ([]uint64, error)

InsertVinsDbTxn is like InsertVins, except that it takes a sql.Tx. The caller is required to Commit or Rollback the transaction depending on the returned error value.

func InsertVinsStmt

func InsertVinsStmt(stmt *sql.Stmt, dbVins dbtypes.VinTxPropertyARRAY, checked bool, doUpsert bool) ([]uint64, error)

InsertVinsStmt is like InsertVins, except that it takes a sql.Stmt. The caller is required to Close the transaction.

func InsertVotes

func InsertVotes(db *sql.DB, dbTxns []*dbtypes.Tx, _ []uint64, fTx *TicketTxnIDGetter,
	msgBlock *MsgBlockPG, checked, updateExistingRecords bool, params *chaincfg.Params,
	votesMilestones *dbtypes.BlockChainData) ([]uint64, []*dbtypes.Tx, []string,
	[]uint64, map[string]uint64, error)

InsertVotes takes a slice of *dbtypes.Tx, which must contain all the stake transactions in a block, extracts the votes, and inserts the votes into the database. The input MsgBlockPG contains each stake transaction's MsgTx in STransactions, and they must be in the same order as the dbtypes.Tx slice.

This function also identifies and stores missed votes using msgBlock.Validators, which lists the ticket hashes called to vote on the previous block (msgBlock.WinningTickets are the lottery winners to be mined in the next block).

The TicketTxnIDGetter is used to get the spent tickets' row IDs. The get function, TxnDbID, is called with the expire argument set to false, so that subsequent cache lookups by other consumers will succeed.

votesMilestones holds up-to-date blockchain info deployment data.

It also updates the agendas and the agenda_votes tables. Agendas table holds the high level information about all agendas that is contained in the votingMilestones.MileStone (i.e. Agenda Name, Status and LockedIn, Activated & HardForked heights). Agenda_votes table hold the agendas vote choices information and references to the agendas and votes tables.

Outputs are slices of DB row IDs for the votes and misses, and an error.

func InsertVout

func InsertVout(db *sql.DB, dbVout *dbtypes.Vout, checked bool, updateOnConflict ...bool) (uint64, error)

InsertVout either inserts, attempts to insert, or upserts the given vout data into the vouts table. If checked=false, an unconditional insert as attempted, which may result in a violation of a unique index constraint (error). If checked=true, a constraint violation may be handled in one of two ways: update the conflicting row (upsert), or do nothing. In all cases, the id of the new/updated/conflicting row is returned. The updateOnConflict argument may be omitted, in which case an upsert will be favored over no nothing, but only if checked=true.

func InsertVouts

func InsertVouts(db *sql.DB, dbVouts []*dbtypes.Vout, checked bool, updateOnConflict ...bool) ([]uint64, []dbtypes.AddressRow, error)

InsertVouts is like InsertVout, except that it operates on a slice of vout data.

func InsertVoutsDbTxn

func InsertVoutsDbTxn(dbTx *sql.Tx, dbVouts []*dbtypes.Vout, checked bool, doUpsert bool) ([]uint64, []dbtypes.AddressRow, error)

InsertVoutsDbTxn is like InsertVouts, except that it takes a sql.Tx. The caller is required to Commit or Rollback the transaction depending on the returned error value.

func InsertVoutsStmt

func InsertVoutsStmt(stmt *sql.Stmt, dbVouts []*dbtypes.Vout, checked bool, doUpsert bool) ([]uint64, []dbtypes.AddressRow, error)

InsertVoutsStmt is like InsertVouts, except that it takes a sql.Stmt. The caller is required to Close the statement.

func IsRetryError

func IsRetryError(err error) bool

IsRetryError checks if an error is a retryError type.

func IsUniqueIndex

func IsUniqueIndex(db *sql.DB, indexName string) (isUnique bool, err error)

IsUniqueIndex checks if the given index name is defined as UNIQUE.

func MakeCsvAddressRows

func MakeCsvAddressRows(rows []*dbtypes.AddressRow) [][]string

MakeCsvAddressRows converts an AddressRow slice into a [][]string, including column headers, suitable for saving to CSV.

func MakeCsvAddressRowsCompact

func MakeCsvAddressRowsCompact(rows []*dbtypes.AddressRowCompact) [][]string

func RetrieveAddressBalance

func RetrieveAddressBalance(ctx context.Context, db *sql.DB, address string) (balance *dbtypes.AddressBalance, err error)

RetrieveAddressBalance gets the numbers of spent and unspent outpoints for the given address, the total amounts spent and unspent, the number of distinct spending transactions, and the fraction spent to and received from stake-related transactions.

func RetrieveAddressCreditTxns

func RetrieveAddressCreditTxns(ctx context.Context, db *sql.DB, address string, N, offset int64) ([]*dbtypes.AddressRow, error)

func RetrieveAddressDbUTXOs

func RetrieveAddressDbUTXOs(ctx context.Context, db *sql.DB, address string) ([]*dbtypes.AddressTxnOutput, error)

RetrieveAddressDbUTXOs gets the unspent transaction outputs (UTXOs) paying to the specified address as a []*dbtypes.AddressTxnOutput. The input current block height is used to compute confirmations of the located transactions.

func RetrieveAddressDebitTxns

func RetrieveAddressDebitTxns(ctx context.Context, db *sql.DB, address string, N, offset int64) ([]*dbtypes.AddressRow, error)

func RetrieveAddressIDsByOutpoint

func RetrieveAddressIDsByOutpoint(ctx context.Context, db *sql.DB, txHash string, voutIndex uint32) ([]uint64, []string, int64, error)

RetrieveAddressIDsByOutpoint gets all address row IDs, addresses, and values for a given outpoint.

func RetrieveAddressMergedCreditTxns

func RetrieveAddressMergedCreditTxns(ctx context.Context, db *sql.DB, address string, N, offset int64) ([]*dbtypes.AddressRow, error)

func RetrieveAddressMergedDebitTxns

func RetrieveAddressMergedDebitTxns(ctx context.Context, db *sql.DB, address string, N, offset int64) ([]*dbtypes.AddressRow, error)

func RetrieveAddressMergedTxns

func RetrieveAddressMergedTxns(ctx context.Context, db *sql.DB, address string, N, offset int64) ([]*dbtypes.AddressRow, error)

func RetrieveAddressSpent

func RetrieveAddressSpent(ctx context.Context, db *sql.DB, address string) (count, totalAmount int64, err error)

func RetrieveAddressTxns

func RetrieveAddressTxns(ctx context.Context, db *sql.DB, address string, N, offset int64) ([]*dbtypes.AddressRow, error)

func RetrieveAddressTxnsOrdered

func RetrieveAddressTxnsOrdered(ctx context.Context, db *sql.DB, addresses []string,
	recentBlockTime int64) (txs, recenttxs []chainhash.Hash, err error)

RetrieveAddressTxnsOrdered will get all transactions for addresses provided and return them sorted by time in descending order. It will also return a short list of recently (defined as greater than recentBlockHeight) confirmed transactions that can be used to validate mempool status.

func RetrieveAddressUTXOs

func RetrieveAddressUTXOs(ctx context.Context, db *sql.DB, address string, currentBlockHeight int64) ([]*apitypes.AddressTxnOutput, error)

RetrieveAddressUTXOs gets the unspent transaction outputs (UTXOs) paying to the specified address as a []*apitypes.AddressTxnOutput. The input current block height is used to compute confirmations of the located transactions.

func RetrieveAddressUnspent

func RetrieveAddressUnspent(ctx context.Context, db *sql.DB, address string) (count, totalAmount int64, err error)

func RetrieveAllAddressMergedTxns

func RetrieveAllAddressMergedTxns(ctx context.Context, db *sql.DB, address string, onlyValidMainchain bool) ([]uint64, []*dbtypes.AddressRow, error)

RetrieveAllAddressMergedTxns retrieves all merged rows of the address table pertaining to the given address. Specify only valid_mainchain=true rows via the onlyValidMainchain argument.

func RetrieveAllAddressTxns

func RetrieveAllAddressTxns(ctx context.Context, db *sql.DB, address string) ([]*dbtypes.AddressRow, error)

RetrieveAllAddressTxns retrieves all rows of the address table pertaining to the given address.

func RetrieveAllMainchainAddressTxns

func RetrieveAllMainchainAddressTxns(ctx context.Context, db *sql.DB, address string) ([]*dbtypes.AddressRow, error)

RetrieveAllMainchainAddressTxns retrieves all non-merged and valid_mainchain rows of the address table pertaining to the given address.

func RetrieveAllRevokes

func RetrieveAllRevokes(ctx context.Context, db *sql.DB) (ids []uint64, hashes []string, heights []int64, vinDbIDs []uint64, err error)

RetrieveAllRevokes gets for all ticket revocations the row IDs (primary keys), transaction hashes, block heights. It also gets the row ID in the vins table for the first input of the revocation transaction, which should correspond to the stakesubmission previous outpoint of the ticket purchase. This function is used in UpdateSpendingInfoInAllTickets, so it should not be subject to timeouts.

func RetrieveAllVinDbIDs

func RetrieveAllVinDbIDs(db *sql.DB) (vinDbIDs []uint64, err error)

RetrieveAllVinDbIDs gets every row ID (the primary keys) for the vins table. This function is used in UpdateSpendingInfoInAllAddresses, so it should not be subject to timeouts.

func RetrieveAllVotesDbIDsHeightsTicketDbIDs

func RetrieveAllVotesDbIDsHeightsTicketDbIDs(ctx context.Context, db *sql.DB) (ids []uint64, heights []int64,
	ticketDbIDs []uint64, err error)

RetrieveAllVotesDbIDsHeightsTicketDbIDs gets for all votes the row IDs (primary keys) in the votes table, the block heights, and the row IDs in the tickets table of the spent tickets. This function is used in UpdateSpendingInfoInAllTickets, so it should not be subject to timeouts.

func RetrieveBestBlock

func RetrieveBestBlock(ctx context.Context, db *sql.DB) (height int64, hash string, err error)

RetrieveBestBlock gets the best block height and hash (main chain only). If there are no results from the query, the height is -1 and err is nil.

func RetrieveBestBlockHeight

func RetrieveBestBlockHeight(ctx context.Context, db *sql.DB) (height uint64, hash string, id uint64, err error)

RetrieveBestBlockHeight gets the best block height and hash (main chain only). Be sure to check for sql.ErrNoRows.

func RetrieveBestBlockHeightAny

func RetrieveBestBlockHeightAny(ctx context.Context, db *sql.DB) (height uint64, hash string, id uint64, err error)

RetrieveBestBlockHeightAny gets the best block height, including side chains.

func RetrieveBlockChainDbID

func RetrieveBlockChainDbID(ctx context.Context, db *sql.DB, hash string) (dbID uint64, err error)

RetrieveBlockChainDbID retrieves the row id in the block_chain table of the block with the given hash, if it exists (be sure to check error against sql.ErrNoRows!).

func RetrieveBlockFlags

func RetrieveBlockFlags(ctx context.Context, db *sql.DB, hash string) (isValid bool, isMainchain bool, err error)

RetrieveBlockFlags retrieves the block's is_valid and is_mainchain flags.

func RetrieveBlockHash

func RetrieveBlockHash(ctx context.Context, db *sql.DB, idx int64) (hash string, err error)

RetrieveBlockHash retrieves the hash of the block at the given height, if it exists (be sure to check error against sql.ErrNoRows!). WARNING: this returns the most recently added block at this height, but there may be others.

func RetrieveBlockHeight

func RetrieveBlockHeight(ctx context.Context, db *sql.DB, hash string) (height int64, err error)

RetrieveBlockHeight retrieves the height of the block with the given hash, if it exists (be sure to check error against sql.ErrNoRows!).

func RetrieveBlockStatus

func RetrieveBlockStatus(ctx context.Context, db *sql.DB, hash string) (bs dbtypes.BlockStatus, err error)

RetrieveBlockStatus retrieves the block chain status for the block with the specified hash.

func RetrieveBlockSummaryByTimeRange

func RetrieveBlockSummaryByTimeRange(ctx context.Context, db *sql.DB, minTime, maxTime int64, limit int) ([]dbtypes.BlockDataBasic, error)

RetrieveBlockSummaryByTimeRange retrieves the slice of block summaries for the given time range. The limit specifies the number of most recent block summaries to return. A limit of 0 indicates all blocks in the time range should be included.

func RetrieveBlockTimeByHeight

func RetrieveBlockTimeByHeight(ctx context.Context, db *sql.DB, idx int64) (time dbtypes.TimeDef, err error)

RetrieveBlockTimeByHeight retrieves time hash of the main chain block at the given height, if it exists (be sure to check error against sql.ErrNoRows!).

func RetrieveBlockVoteCount

func RetrieveBlockVoteCount(ctx context.Context, db *sql.DB, hash string) (numVotes int16, err error)

RetrieveBlockVoteCount gets the number of votes mined in a block.

func RetrieveBlocksHashesAll

func RetrieveBlocksHashesAll(ctx context.Context, db *sql.DB) ([]string, error)

RetrieveBlocksHashesAll retrieve the hash of every block in the blocks table, ordered by their row ID.

func RetrieveDbTxByHash

func RetrieveDbTxByHash(ctx context.Context, db *sql.DB, txHash string) (id uint64, dbTx *dbtypes.Tx, err error)

RetrieveDbTxByHash retrieves a row of the transactions table corresponding to the given transaction hash. Transactions in valid and mainchain blocks are chosen first. This function is used by FillAddressTransactions, an important component of the addresses page.

func RetrieveDbTxsByHash

func RetrieveDbTxsByHash(ctx context.Context, db *sql.DB, txHash string) (ids []uint64, dbTxs []*dbtypes.Tx, err error)

RetrieveDbTxsByHash retrieves all the rows of the transactions table, including the primary keys/ids, for the given transaction hash. This function is used by the transaction page via ChainDB.Transaction.

func RetrieveDisapprovedBlocks

func RetrieveDisapprovedBlocks(ctx context.Context, db *sql.DB) (blocks []*dbtypes.BlockStatus, err error)

RetrieveDisapprovedBlocks retrieves the block chain status for all blocks that had their regular transactions invalidated by stakeholder disapproval.

func RetrieveFullTxByHash

func RetrieveFullTxByHash(ctx context.Context, db *sql.DB, txHash string) (id uint64,
	blockHash string, blockHeight int64, blockTime, timeVal dbtypes.TimeDef,
	txType int16, version int32, tree int8, blockInd uint32,
	lockTime, expiry int32, size uint32, spent, sent, fees int64,
	numVin int32, vinDbIDs []int64, numVout int32, voutDbIDs []int64,
	isValidBlock, isMainchainBlock bool, err error)

RetrieveFullTxByHash gets all data from the transactions table for the transaction specified by its hash. Transactions in valid and mainchain blocks are chosen first. See also RetrieveDbTxByHash.

func RetrieveFundingOutpointByTxIn

func RetrieveFundingOutpointByTxIn(ctx context.Context, db *sql.DB, txHash string,
	vinIndex uint32) (id uint64, tx string, index uint32, tree int8, err error)

RetrieveFundingOutpointByTxIn gets the previous outpoint for a transaction input specified by transaction hash and input index.

func RetrieveFundingOutpointByVinID

func RetrieveFundingOutpointByVinID(ctx context.Context, db *sql.DB, vinDbID uint64) (tx string, index uint32, tree int8, err error)

RetrieveFundingOutpointByVinID gets the previous outpoint for a transaction input specified by row ID in the vins table.

func RetrieveFundingOutpointIndxByVinID

func RetrieveFundingOutpointIndxByVinID(ctx context.Context, db *sql.DB, vinDbID uint64) (idx uint32, err error)

RetrieveFundingOutpointIndxByVinID gets the transaction output index of the previous outpoint for a transaction input specified by row ID in the vins table.

func RetrieveFundingTxByTxIn

func RetrieveFundingTxByTxIn(ctx context.Context, db *sql.DB, txHash string, vinIndex uint32) (id uint64, tx string, err error)

RetrieveFundingTxByTxIn gets the transaction hash of the previous outpoint for a transaction input specified by hash and input index.

func RetrieveFundingTxByVinDbID

func RetrieveFundingTxByVinDbID(ctx context.Context, db *sql.DB, vinDbID uint64) (tx string, err error)

RetrieveFundingTxByVinDbID gets the transaction hash of the previous outpoint for a transaction input specified by row ID in the vins table. This function is used only in UpdateSpendingInfoInAllTickets, so it should not be subject to timeouts.

func RetrieveFundingTxsByTx

func RetrieveFundingTxsByTx(db *sql.DB, txHash string) ([]uint64, []*dbtypes.Tx, error)

TODO: this does not appear correct.

func RetrieveMissForTicket

func RetrieveMissForTicket(ctx context.Context, db *sql.DB, ticketHash string) (blockHash string, blockHeight int64, err error)

RetrieveMissForTicket gets the mainchain block in which the ticket was called to place a vote on the previous block. The previous block that would have been validated by the vote is not the block data that is returned.

func RetrieveMissedVotesInBlock

func RetrieveMissedVotesInBlock(ctx context.Context, db *sql.DB, blockHash string) (ticketHashes []string, err error)

RetrieveMissedVotesInBlock gets a list of ticket hashes that were called to vote in the given block, but missed their vote.

func RetrieveMissesForTicket

func RetrieveMissesForTicket(ctx context.Context, db *sql.DB, ticketHash string) (blockHashes []string, blockHeights []int64, err error)

RetrieveMissesForTicket gets all of the blocks in which the ticket was called to place a vote on the previous block. The previous block that would have been validated by the vote is not the block data that is returned.

func RetrievePGVersion

func RetrievePGVersion(db *sql.DB) (ver string, err error)

RetrievePGVersion retrieves the version of the connected PostgreSQL server.

func RetrievePkScriptByOutpoint

func RetrievePkScriptByOutpoint(ctx context.Context, db *sql.DB, txHash string, voutIndex uint32) (pkScript []byte, ver uint16, err error)

func RetrievePkScriptByVinID

func RetrievePkScriptByVinID(ctx context.Context, db *sql.DB, vinID uint64) (pkScript []byte, ver uint16, err error)

func RetrievePkScriptByVoutID

func RetrievePkScriptByVoutID(ctx context.Context, db *sql.DB, voutID uint64) (pkScript []byte, ver uint16, err error)

func RetrievePreviousHashByBlockHash

func RetrievePreviousHashByBlockHash(ctx context.Context, db *sql.DB, hash string) (previousHash string, err error)

RetrievePreviousHashByBlockHash retrieves the previous block hash for the given block from the blocks table.

func RetrieveSideChainBlocks

func RetrieveSideChainBlocks(ctx context.Context, db *sql.DB) (blocks []*dbtypes.BlockStatus, err error)

RetrieveSideChainBlocks retrieves the block chain status for all known side chain blocks.

func RetrieveSideChainTips

func RetrieveSideChainTips(ctx context.Context, db *sql.DB) (blocks []*dbtypes.BlockStatus, err error)

RetrieveSideChainTips retrieves the block chain status for all known side chain tip blocks.

func RetrieveSpendingTxByTxOut

func RetrieveSpendingTxByTxOut(ctx context.Context, db *sql.DB, txHash string,
	voutIndex uint32) (id uint64, tx string, vin uint32, tree int8, err error)

RetrieveSpendingTxByTxOut gets any spending transaction input info for a previous outpoint specified by funding transaction hash and vout number. This function is called by SpendingTransaction, an important part of the address page loading.

func RetrieveSpendingTxByVinID

func RetrieveSpendingTxByVinID(ctx context.Context, db *sql.DB, vinDbID uint64) (tx string,
	vinIndex uint32, tree int8, err error)

RetrieveSpendingTxByVinID gets the spending transaction input (hash, vin number, and tx tree) for the transaction input specified by row ID in the vins table.

func RetrieveSpendingTxsByFundingTx

func RetrieveSpendingTxsByFundingTx(ctx context.Context, db *sql.DB, fundingTxID string) (dbIDs []uint64,
	txns []string, vinInds []uint32, voutInds []uint32, err error)

RetrieveSpendingTxsByFundingTx gets info on all spending transaction inputs for the given funding transaction specified by DB row ID. This function is called by SpendingTransactions, an important part of the transaction page loading, among other functions..

func RetrieveSpendingTxsByFundingTxWithBlockHeight

func RetrieveSpendingTxsByFundingTxWithBlockHeight(ctx context.Context, db *sql.DB, fundingTxID string) (aSpendByFunHash []*apitypes.SpendByFundingHash, err error)

RetrieveSpendingTxsByFundingTxWithBlockHeight will retrieve all transactions, indexes and block heights funded by a specific transaction. This function is used by the DCR to Insight transaction converter.

func RetrieveSysSettingSyncCommit

func RetrieveSysSettingSyncCommit(db *sql.DB) (syncCommit string, err error)

RetrieveSysSettingSyncCommit retrieves the synchronous_commit setting.

func RetrieveTicketIDByHashNoCancel

func RetrieveTicketIDByHashNoCancel(db *sql.DB, ticketHash string) (id uint64, err error)

RetrieveTicketIDByHashNoCancel gets the db row ID (primary key) in the tickets table for the given ticket hash. As the name implies, this query should not accept a cancelable context.

func RetrieveTicketIDsByHashes

func RetrieveTicketIDsByHashes(ctx context.Context, db *sql.DB, ticketHashes []string) (ids []uint64, err error)

RetrieveTicketIDsByHashes gets the db row IDs (primary keys) in the tickets table for the given ticket purchase transaction hashes.

func RetrieveTicketInfoByHash

func RetrieveTicketInfoByHash(ctx context.Context, db *sql.DB, ticketHash string) (spendStatus dbtypes.TicketSpendType,
	poolStatus dbtypes.TicketPoolStatus, purchaseBlock, lotteryBlock *apitypes.TinyBlock, spendTxid string, err error)

RetrieveTicketInfoByHash retrieves the ticket spend and pool statuses as well as the purchase and spending block info and spending txid.

func RetrieveTicketStatusByHash

func RetrieveTicketStatusByHash(ctx context.Context, db *sql.DB, ticketHash string) (id uint64,
	spendStatus dbtypes.TicketSpendType, poolStatus dbtypes.TicketPoolStatus, err error)

RetrieveTicketStatusByHash gets the spend status and ticket pool status for the given ticket hash.

func RetrieveTxBlockTimeByHash

func RetrieveTxBlockTimeByHash(ctx context.Context, db *sql.DB, txHash string) (blockTime dbtypes.TimeDef, err error)

func RetrieveTxByHash

func RetrieveTxByHash(ctx context.Context, db *sql.DB, txHash string) (id uint64, blockHash string,
	blockInd uint32, tree int8, err error)

func RetrieveTxnsBlocks

func RetrieveTxnsBlocks(ctx context.Context, db *sql.DB, txHash string) (blockHashes []string,
	blockHeights, blockIndexes []uint32, areValid, areMainchain []bool, err error)

RetrieveTxnsBlocks retrieves for the specified transaction hash the following data for each block containing the transactions: block_hash, block_index, is_valid, is_mainchain.

func RetrieveTxnsVinsByBlock

func RetrieveTxnsVinsByBlock(ctx context.Context, db *sql.DB, blockHash string) (vinDbIDs []dbtypes.UInt64Array,
	areValid []bool, areMainchain []bool, err error)

RetrieveTxnsVinsByBlock retrieves for all the transactions in the specified block the vin_db_ids arrays, is_valid, and is_mainchain. This function is used by handleVinsTableMainchainupgrade, so it should not be subject to timeouts.

func RetrieveTxnsVinsVoutsByBlock

func RetrieveTxnsVinsVoutsByBlock(ctx context.Context, db *sql.DB, blockHash string, onlyRegular bool) (vinDbIDs, voutDbIDs []dbtypes.UInt64Array,
	areMainchain []bool, err error)

RetrieveTxnsVinsVoutsByBlock retrieves for all the transactions in the specified block the vin_db_ids and vout_db_ids arrays. This function is used only by UpdateLastAddressesValid and other setting functions, where it should not be subject to a timeout.

func RetrieveTxsBestBlockMainchain

func RetrieveTxsBestBlockMainchain(ctx context.Context, db *sql.DB) (height int64, hash string, err error)

RetrieveTxsBestBlockMainchain returns the best mainchain block's height from the transactions table. If the table is empty, a height of -1, an empty hash string, and a nil error are returned

func RetrieveTxsBlocksAboveHeight

func RetrieveTxsBlocksAboveHeight(ctx context.Context, db *sql.DB, height int64) (heights []int64, hashes []string, err error)

RetrieveTxsBlocksAboveHeight returns all distinct mainchain block heights and hashes referenced in the transactions table above the given height.

func RetrieveTxsByBlockHash

func RetrieveTxsByBlockHash(ctx context.Context, db *sql.DB, blockHash string) (ids []uint64, txs []string,
	blockInds []uint32, trees []int8, blockTimes []dbtypes.TimeDef, err error)

RetrieveTxsByBlockHash retrieves all transactions in a given block. This is used by update functions, so care should be taken to not timeout in these cases.

func RetrieveUTXOs

func RetrieveUTXOs(ctx context.Context, db *sql.DB) ([]dbtypes.UTXO, error)

RetrieveUTXOs gets the entire UTXO set from the vouts and vins tables.

func RetrieveUnspentTickets

func RetrieveUnspentTickets(ctx context.Context, db *sql.DB) (ids []uint64, hashes []string, err error)

RetrieveUnspentTickets gets all unspent tickets.

func RetrieveVinByID

func RetrieveVinByID(ctx context.Context, db *sql.DB, vinDbID uint64) (prevOutHash string, prevOutVoutInd uint32,
	prevOutTree int8, txHash string, txVinInd uint32, txTree int8, valueIn int64, err error)

RetrieveVinByID gets from the vins table for the provided row ID.

func RetrieveVinsByIDs

func RetrieveVinsByIDs(ctx context.Context, db *sql.DB, vinDbIDs []uint64) ([]dbtypes.VinTxProperty, error)

RetrieveVinsByIDs retrieves vin details for the rows of the vins table specified by the provided row IDs. This function is an important part of the transaction page.

func RetrieveVoutIDByOutpoint

func RetrieveVoutIDByOutpoint(ctx context.Context, db *sql.DB, txHash string, voutIndex uint32) (id uint64, err error)

func RetrieveVoutValue

func RetrieveVoutValue(ctx context.Context, db *sql.DB, txHash string, voutIndex uint32) (value uint64, err error)

func RetrieveVoutValues

func RetrieveVoutValues(ctx context.Context, db *sql.DB, txHash string) (values []uint64, txInds []uint32, txTrees []int8, err error)

func RetrieveVoutsByIDs

func RetrieveVoutsByIDs(ctx context.Context, db *sql.DB, voutDbIDs []uint64) ([]dbtypes.Vout, error)

RetrieveVoutsByIDs retrieves vout details for the rows of the vouts table specified by the provided row IDs. This function is an important part of the transaction page.

func SetDBBestBlock

func SetDBBestBlock(db *sql.DB, hash string, height int64) error

SetDBBestBlock sets the best block hash and height in the meta table.

func SetIBDComplete

func SetIBDComplete(db SqlExecutor, ibdComplete bool) error

SetIBDComplete set the ibd_complete (Initial Block Download complete) flag in the meta table.

func SetMainchainByBlockHash

func SetMainchainByBlockHash(db *sql.DB, hash string, isMainchain bool) (previousHash string, err error)

SetMainchainByBlockHash is used to set the is_mainchain flag for the given block. This is required to handle a reorganization.

func SetPoolStatusForTickets

func SetPoolStatusForTickets(db *sql.DB, ticketDbIDs []uint64, poolStatuses []dbtypes.TicketPoolStatus) (int64, error)

SetPoolStatusForTickets sets the ticket pool status for the tickets specified by db row ID.

func SetPoolStatusForTicketsByHash

func SetPoolStatusForTicketsByHash(db *sql.DB, tickets []string,
	poolStatuses []dbtypes.TicketPoolStatus) (int64, error)

SetPoolStatusForTicketsByHash sets the ticket pool status for the tickets specified by ticket purchase transaction hash.

func SetSpendingForFundingOP

func SetSpendingForFundingOP(db SqlExecutor, fundingTxHash string, fundingTxVoutIndex uint32,
	spendingTxHash string, _ uint32) (int64, error)

SetSpendingForFundingOP updates funding rows of the addresses table with the provided spending transaction output info.

func SetSpendingForTickets

func SetSpendingForTickets(db *sql.DB, ticketDbIDs, spendDbIDs []uint64,
	blockHeights []int64, spendTypes []dbtypes.TicketSpendType,
	poolStatuses []dbtypes.TicketPoolStatus) (int64, error)

SetSpendingForTickets sets the spend type, spend height, spending transaction row IDs (in the table relevant to the spend type), and ticket pool status for the given tickets specified by their db row IDs.

func SetSpendingForVinDbID

func SetSpendingForVinDbID(db *sql.DB, vinDbID uint64) (int64, error)

SetSpendingForVinDbID updates rows of the addresses table with spending information from the row of the vins table specified by vinDbID. This does not insert the spending transaction into the addresses table.

func SetSpendingForVinDbIDs

func SetSpendingForVinDbIDs(db *sql.DB, vinDbIDs []uint64) ([]int64, int64, error)

SetSpendingForVinDbIDs updates rows of the addresses table with spending information from the rows of the vins table specified by vinDbIDs. This does not insert the spending transaction into the addresses table.

func SetSynchronousCommit

func SetSynchronousCommit(db SqlExecutor, syncCommit string) error

SetSynchronousCommit sets the synchronous_commit setting.

func TableExists

func TableExists(db *sql.DB, tableName string) (bool, error)

TableExists checks if the specified table exists.

func TableVersions

func TableVersions(db *sql.DB) map[string]TableVersion

TableVersions retrieve and maps the tables names in the auxiliary db to their current table versions.

func TicketPoolData

func TicketPoolData(interval dbtypes.TimeBasedGrouping, height int64) (timeGraph *dbtypes.PoolTicketsData,
	priceGraph *dbtypes.PoolTicketsData, donutChart *dbtypes.PoolTicketsData, actualHeight int64, intervalFound, isStale bool)

TicketPoolData is a thread-safe way to access the ticketpool graphs data stored in the cache.

func UpdateAddressesMainchainByIDs

func UpdateAddressesMainchainByIDs(db SqlExecutor, vinsBlk, voutsBlk []dbtypes.UInt64Array, isValidMainchain bool) (numSpendingRows, numFundingRows int64, err error)

UpdateAddressesMainchainByIDs sets the valid_mainchain column for the addresses specified by their vin (spending) or vout (funding) row IDs.

func UpdateBlockNext

func UpdateBlockNext(db SqlExecutor, blockDbID uint64, next string) error

UpdateBlockNext sets the next block's hash for the specified row of the block_chain table specified by DB row ID.

func UpdateBlockNextByHash

func UpdateBlockNextByHash(db SqlExecutor, this, next string) error

UpdateBlockNextByHash sets the next block's hash for the block in the block_chain table specified by hash.

func UpdateBlockNextByNextHash

func UpdateBlockNextByNextHash(db SqlExecutor, currentNext, newNext string) error

UpdateBlockNextByNextHash sets the next block's hash for the block in the block_chain table with a current next_hash specified by hash.

func UpdateLastAddressesValid

func UpdateLastAddressesValid(db *sql.DB, blockHash string, isValid bool) error

UpdateLastAddressesValid sets valid_mainchain as specified by isValid for addresses table rows pertaining to regular (non-stake) transactions found in the given block.

func UpdateLastBlockValid

func UpdateLastBlockValid(db SqlExecutor, blockDbID uint64, isValid bool) error

UpdateLastBlockValid updates the is_valid column of the block specified by the row id for the blocks table.

func UpdateLastVins

func UpdateLastVins(db *sql.DB, blockHash string, isValid, isMainchain bool) error

UpdateLastVins updates the is_valid and is_mainchain columns in the vins table for all of the transactions in the block specified by the given block hash.

func UpdateTicketPoolData

func UpdateTicketPoolData(interval dbtypes.TimeBasedGrouping, timeGraph *dbtypes.PoolTicketsData,
	priceGraph *dbtypes.PoolTicketsData, donutcharts *dbtypes.PoolTicketsData, height int64)

UpdateTicketPoolData updates the ticket pool cache with the latest data fetched. This is a thread-safe way to update ticket pool cache data. TryLock helps avoid stacking calls to update the cache.

func UpdateTicketsMainchain

func UpdateTicketsMainchain(db SqlExecutor, blockHash string, isMainchain bool) (int64, error)

UpdateTicketsMainchain sets the is_mainchain column for the tickets in the specified block.

func UpdateTransactionsMainchain

func UpdateTransactionsMainchain(db *sql.DB, blockHash string, isMainchain bool) (int64, []uint64, error)

UpdateTransactionsMainchain sets the is_mainchain column for the transactions in the specified block.

func UpdateTransactionsValid

func UpdateTransactionsValid(db *sql.DB, blockHash string, isValid bool) (int64, []uint64, error)

UpdateTransactionsValid sets the is_valid column of the transactions table for the regular (non-stake) transactions in the specified block.

func UpdateVotesMainchain

func UpdateVotesMainchain(db SqlExecutor, blockHash string, isMainchain bool) (int64, error)

UpdateVotesMainchain sets the is_mainchain column for the votes in the specified block.

func UpgradeDatabase

func UpgradeDatabase(db *sql.DB, bg BlockGetter) (bool, error)

UpgradeDatabase attempts to upgrade the given sql.DB with help from the BlockGetter. The DB version will be compared against the target version to decide what upgrade type to initiate.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BestBlock

type BestBlock struct {
	// contains filtered or unexported fields
}

BestBlock is mutex-protected block hash and height.

func (*BestBlock) Hash

func (block *BestBlock) Hash() *chainhash.Hash

Hash uses the last stored block hash.

func (*BestBlock) HashStr

func (block *BestBlock) HashStr() string

HashStr uses the last stored block hash.

func (*BestBlock) Height

func (block *BestBlock) Height() int64

Height uses the last stored height.

type BlockGetter

type BlockGetter interface {
	// rpcutils.BlockFetcher implements GetBestBlock, GetBlock, GetBlockHash,
	// and GetBlockHeaderVerbose.
	rpcutils.BlockFetcher

	// GetBlockChainInfo is required for a legacy upgrade involving agendas.
	GetBlockChainInfo() (*chainjson.GetBlockChainInfoResult, error)
}

BlockGetter implements a few basic blockchain data retrieval functions. It is like rpcutils.BlockFetcher except that it must also implement GetBlockChainInfo.

type ChainDB

type ChainDB struct {
	AddressCache *cache.AddressCache
	CacheLocks   cacheLocks

	InBatchSync bool
	InReorg     bool
	// contains filtered or unexported fields
}

ChainDB provides an interface for storing and manipulating extracted blockchain data in a PostgreSQL database.

func NewChainDB

func NewChainDB(dbi *DBInfo, params *chaincfg.Params, stakeDB *stakedb.StakeDatabase,
	devPrefetch, hidePGConfig bool, addrCacheCap int, mp rpcutils.MempoolAddressChecker,
	parser ProposalsFetcher, bg BlockGetter) (*ChainDB, error)

NewChainDB constructs a ChainDB for the given connection and Decred network parameters. By default, duplicate row checks on insertion are enabled. See NewChainDBWithCancel to enable context cancellation of running queries. proposalsUpdateChan is used to manage politeia update notifications trigger between the notifier and the handler method. A non-nil BlockGetter is only needed if database upgrades are required.

func NewChainDBWithCancel

func NewChainDBWithCancel(ctx context.Context, dbi *DBInfo, params *chaincfg.Params,
	stakeDB *stakedb.StakeDatabase, devPrefetch, hidePGConfig bool, addrCacheCap int,
	mp rpcutils.MempoolAddressChecker, parser ProposalsFetcher, bg BlockGetter) (*ChainDB, error)

NewChainDBWithCancel constructs a cancellation-capable ChainDB for the given connection and Decred network parameters. By default, duplicate row checks on insertion are enabled. See EnableDuplicateCheckOnInsert to change this behavior. NewChainDB creates context that cannot be cancelled (context.Background()) except by the pg timeouts. If it is necessary to cancel queries with CTRL+C, for example, use NewChainDBWithCancel. A non-nil BlockGetter is only needed if database upgrades are required.

func (*ChainDB) AddressBalance

func (pgb *ChainDB) AddressBalance(address string) (bal *dbtypes.AddressBalance, cacheUpdated bool, err error)

AddressBalance attempts to retrieve balance information for a specific address from cache, and if cache is stale or missing data for the address, a DB query is used. A successful DB query will freshen the cache.

func (*ChainDB) AddressHistory

func (pgb *ChainDB) AddressHistory(address string, N, offset int64,
	txnView dbtypes.AddrTxnViewType) ([]*dbtypes.AddressRow, *dbtypes.AddressBalance, error)

AddressHistory queries the database for rows of the addresses table containing values for a certain type of transaction (all, credits, or debits) for the given address.

func (*ChainDB) AddressHistoryAll

func (pgb *ChainDB) AddressHistoryAll(address string, N, offset int64) ([]*dbtypes.AddressRow, *dbtypes.AddressBalance, error)

AddressHistoryAll retrieves N address rows of type AddrTxnAll, skipping over offset rows first, in order of block time.

func (*ChainDB) AddressIDsByOutpoint

func (pgb *ChainDB) AddressIDsByOutpoint(txHash string, voutIndex uint32) ([]uint64, []string, int64, error)

AddressIDsByOutpoint fetches all address row IDs for a given outpoint (txHash:voutIndex).

func (*ChainDB) AddressMetrics

func (pgb *ChainDB) AddressMetrics(addr string) (*dbtypes.AddressMetrics, error)

AddressMetrics returns the block time of the oldest transaction and the total count for all the transactions linked to the provided address grouped by years, months, weeks and days time grouping in seconds. This helps plot more meaningful address history graphs to the user.

func (*ChainDB) AddressRowsCompact

func (pgb *ChainDB) AddressRowsCompact(address string) ([]*dbtypes.AddressRowCompact, error)

AddressRowsCompact gets non-merged address rows either from cache or via DB query.

func (*ChainDB) AddressRowsMerged

func (pgb *ChainDB) AddressRowsMerged(address string) ([]*dbtypes.AddressRowMerged, error)

AddressRowsMerged gets the merged address rows either from cache or via DB query.

func (*ChainDB) AddressTotals

func (pgb *ChainDB) AddressTotals(address string) (*apitypes.AddressTotals, error)

AddressTotals queries for the following totals: amount spent, amount unspent, number of unspent transaction outputs and number spent.

func (*ChainDB) AddressTransactionDetails

func (pgb *ChainDB) AddressTransactionDetails(addr string, count, skip int64,
	txnType dbtypes.AddrTxnViewType) (*apitypes.Address, error)

AddressTransactionDetails returns an apitypes.Address with at most the last count transactions of type txnType in which the address was involved, starting after skip transactions. This does NOT include unconfirmed transactions.

func (*ChainDB) AddressTransactionRawDetails

func (pgb *ChainDB) AddressTransactionRawDetails(addr string, count, skip int64,
	txnType dbtypes.AddrTxnViewType) ([]*apitypes.AddressTxRaw, error)

TODO: finish

func (*ChainDB) AddressTransactions

func (pgb *ChainDB) AddressTransactions(address string, N, offset int64,
	txnType dbtypes.AddrTxnViewType) (addressRows []*dbtypes.AddressRow, err error)

AddressTransactions retrieves a slice of *dbtypes.AddressRow for a given address and transaction type (i.e. all, credit, or debit) from the DB. Only the first N transactions starting from the offset element in the set of all txnType transactions.

func (*ChainDB) AddressTransactionsAll

func (pgb *ChainDB) AddressTransactionsAll(address string) (addressRows []*dbtypes.AddressRow, err error)

AddressTransactionsAll retrieves all non-merged main chain addresses table rows for the given address.

func (*ChainDB) AddressTransactionsAllMerged

func (pgb *ChainDB) AddressTransactionsAllMerged(address string) (addressRows []*dbtypes.AddressRow, err error)

AddressTransactionsAllMerged retrieves all merged (stakeholder-approved and mainchain only) addresses table rows for the given address.

func (*ChainDB) AddressTxIoCsv

func (pgb *ChainDB) AddressTxIoCsv(address string) ([][]string, error)

AddressTxIoCsv grabs rows of an address' transaction input/output data as a 2-D array of strings to be CSV-formatted.

func (*ChainDB) AddressUTXO

func (pgb *ChainDB) AddressUTXO(address string) ([]*dbtypes.AddressTxnOutput, bool, error)

AddressUTXO returns the unspent transaction outputs (UTXOs) paying to the specified address in a []*dbtypes.AddressTxnOutput.

func (*ChainDB) AgendaVoteCounts

func (pgb *ChainDB) AgendaVoteCounts(agendaID string) (yes, abstain, no uint32, err error)

AgendaVoteCounts returns the vote counts for the agenda as builtin types.

func (*ChainDB) AgendaVotes

func (pgb *ChainDB) AgendaVotes(agendaID string, chartType int) (*dbtypes.AgendaVoteChoices, error)

AgendaVotes fetches the data used to plot a graph of votes cast per day per choice for the provided agenda.

func (*ChainDB) AgendasVotesSummary

func (pgb *ChainDB) AgendasVotesSummary(agendaID string) (summary *dbtypes.AgendaSummary, err error)

AgendasVotesSummary fetches the total vote choices count for the provided agenda.

func (*ChainDB) AllAgendas

func (pgb *ChainDB) AllAgendas() (map[string]dbtypes.MileStone, error)

AllAgendas returns all the agendas stored currently.

func (*ChainDB) BestBlock

func (pgb *ChainDB) BestBlock() (*chainhash.Hash, int64)

func (*ChainDB) BestBlockHash

func (pgb *ChainDB) BestBlockHash() *chainhash.Hash

BestBlockHash is a getter for ChainDB.bestBlock.hash.

func (*ChainDB) BestBlockHashStr

func (pgb *ChainDB) BestBlockHashStr() string

BestBlockHashStr is a getter for ChainDB.bestBlock.hash.

func (*ChainDB) BestBlockStr

func (pgb *ChainDB) BestBlockStr() (string, int64)

func (*ChainDB) BlockChainDbID

func (pgb *ChainDB) BlockChainDbID(hash string) (dbID uint64, err error)

BlockChainDbID gets the row ID of the given block hash in the block_chain table. The cancellation context is used without timeout.

func (*ChainDB) BlockChainDbIDNoCancel

func (pgb *ChainDB) BlockChainDbIDNoCancel(hash string) (dbID uint64, err error)

BlockChainDbIDNoCancel gets the row ID of the given block hash in the block_chain table. The cancellation context is used without timeout.

func (*ChainDB) BlockFlags

func (pgb *ChainDB) BlockFlags(hash string) (bool, bool, error)

BlockFlags retrieves the block's isValid and isMainchain flags.

func (*ChainDB) BlockFlagsNoCancel

func (pgb *ChainDB) BlockFlagsNoCancel(hash string) (bool, bool, error)

BlockFlagsNoCancel retrieves the block's isValid and isMainchain flags.

func (*ChainDB) BlockHash

func (pgb *ChainDB) BlockHash(height int64) (string, error)

BlockHash queries the DB for the hash of the mainchain block at the given height.

func (*ChainDB) BlockHeight

func (pgb *ChainDB) BlockHeight(hash string) (int64, error)

BlockHeight queries the DB for the height of the specified hash.

func (*ChainDB) BlockMissedVotes

func (pgb *ChainDB) BlockMissedVotes(blockHash string) ([]string, error)

BlockMissedVotes retrieves the ticket IDs for all missed votes in the specified block, and an error value.

func (*ChainDB) BlockStatus

func (pgb *ChainDB) BlockStatus(hash string) (dbtypes.BlockStatus, error)

BlockStatus retrieves the block chain status of the specified block.

func (*ChainDB) BlockSummaryTimeRange

func (pgb *ChainDB) BlockSummaryTimeRange(min, max int64, limit int) ([]dbtypes.BlockDataBasic, error)

BlockSummaryTimeRange returns the blocks created within a specified time range (min, max time), up to limit transactions.

func (*ChainDB) BlockTimeByHeight

func (pgb *ChainDB) BlockTimeByHeight(height int64) (int64, error)

BlockTimeByHeight queries the DB for the time of the mainchain block at the given height.

func (*ChainDB) BlockTransactions

func (pgb *ChainDB) BlockTransactions(blockHash string) ([]string, []uint32, []int8, error)

BlockTransactions retrieves all transactions in the specified block, their indexes in the block, their tree, and an error value.

func (*ChainDB) ChainInfo

func (pgb *ChainDB) ChainInfo() *dbtypes.BlockChainData

ChainInfo guarantees thread-safe access of the deployment data.

func (*ChainDB) Close

func (pgb *ChainDB) Close() error

Close closes the underlying sql.DB connection to the database.

func (*ChainDB) CollectTicketSpendDBInfo

func (pgb *ChainDB) CollectTicketSpendDBInfo(dbTxns []*dbtypes.Tx, txDbIDs []uint64,
	msgBlock *wire.MsgBlock, isMainchain bool) (spendingTxDbIDs []uint64, spendTypes []dbtypes.TicketSpendType,
	ticketHashes []string, ticketDbIDs []uint64, err error)

CollectTicketSpendDBInfo processes the stake transactions in msgBlock, which correspond to the transaction data in dbTxns, and extracts data for votes and revokes, including the spent ticket hash and DB row ID.

func (*ChainDB) CountTransactions

func (pgb *ChainDB) CountTransactions(addr string, txnView dbtypes.AddrTxnViewType) (int, error)

CountTransactions gets the total row count for the given address and address transaction view.

func (*ChainDB) DbTxByHash

func (pgb *ChainDB) DbTxByHash(txid string) (*dbtypes.Tx, error)

DbTxByHash retrieves a row of the transactions table corresponding to the given transaction hash. Transactions in valid and mainchain blocks are chosen first.

func (*ChainDB) DeindexAddressTable

func (pgb *ChainDB) DeindexAddressTable() error

DeindexAddressTable drops the vin ID, block_time, matching_tx_hash and address column indexes for the address table.

func (*ChainDB) DeindexAll

func (pgb *ChainDB) DeindexAll() error

DeindexAll drops indexes in most tables.

func (*ChainDB) DeindexTicketsTable

func (pgb *ChainDB) DeindexTicketsTable() error

DeindexTicketsTable drops indexes in the tickets table on ticket hash, ticket pool status and tx DB ID columns.

func (*ChainDB) DeleteDuplicateAgendaVotes

func (pgb *ChainDB) DeleteDuplicateAgendaVotes() (int64, error)

func (*ChainDB) DeleteDuplicateAgendas

func (pgb *ChainDB) DeleteDuplicateAgendas() (int64, error)

func (*ChainDB) DeleteDuplicateMisses

func (pgb *ChainDB) DeleteDuplicateMisses() (int64, error)

func (*ChainDB) DeleteDuplicateTickets

func (pgb *ChainDB) DeleteDuplicateTickets() (int64, error)

func (*ChainDB) DeleteDuplicateTxns

func (pgb *ChainDB) DeleteDuplicateTxns() (int64, error)

func (*ChainDB) DeleteDuplicateVins

func (pgb *ChainDB) DeleteDuplicateVins() (int64, error)

func (*ChainDB) DeleteDuplicateVinsCockroach

func (pgb *ChainDB) DeleteDuplicateVinsCockroach() (int64, error)

func (*ChainDB) DeleteDuplicateVotes

func (pgb *ChainDB) DeleteDuplicateVotes() (int64, error)

func (*ChainDB) DeleteDuplicateVouts

func (pgb *ChainDB) DeleteDuplicateVouts() (int64, error)

func (*ChainDB) DeleteDuplicateVoutsCockroach

func (pgb *ChainDB) DeleteDuplicateVoutsCockroach() (int64, error)

func (*ChainDB) DeleteDuplicates

func (pgb *ChainDB) DeleteDuplicates(barLoad chan *dbtypes.ProgressBarLoad) error

DeleteDuplicates attempts to delete "duplicate" rows in tables where unique indexes are to be created.

func (*ChainDB) DeleteDuplicatesRecovery

func (pgb *ChainDB) DeleteDuplicatesRecovery(barLoad chan *dbtypes.ProgressBarLoad) error

func (*ChainDB) DevBalance

func (pgb *ChainDB) DevBalance() (*dbtypes.AddressBalance, error)

DevBalance returns the current development/project fund balance, updating the cached balance if it is stale. DevBalance differs slightly from addressBalance(devAddress) in that it will not initiate a DB query if a chain reorganization is in progress.

func (*ChainDB) DisapprovedBlocks

func (pgb *ChainDB) DisapprovedBlocks() ([]*dbtypes.BlockStatus, error)

DisapprovedBlocks retrieves all blocks disapproved by stakeholder votes.

func (*ChainDB) DropTables

func (pgb *ChainDB) DropTables()

DropTables drops (deletes) all of the known dcrdata tables.

func (*ChainDB) EnableDuplicateCheckOnInsert

func (pgb *ChainDB) EnableDuplicateCheckOnInsert(dupCheck bool)

EnableDuplicateCheckOnInsert specifies whether SQL insertions should check for row conflicts (duplicates), and avoid adding or updating.

func (*ChainDB) FillAddressTransactions

func (pgb *ChainDB) FillAddressTransactions(addrInfo *dbtypes.AddressInfo) error

FillAddressTransactions is used to fill out the transaction details in an explorer.AddressInfo generated by dbtypes.ReduceAddressHistory, usually from the output of AddressHistory. This function also sets the number of unconfirmed transactions for the current best block in the database.

func (*ChainDB) FreshenAddressCaches

func (pgb *ChainDB) FreshenAddressCaches(lazyProjectFund bool, expireAddresses []string) error

FreshenAddressCaches resets the address balance cache by purging data for the addresses listed in expireAddresses, and prefetches the project fund balance if devPrefetch is enabled and not mid-reorg. The project fund update is run asynchronously if lazyProjectFund is true.

func (*ChainDB) FundingOutpointIndxByVinID

func (pgb *ChainDB) FundingOutpointIndxByVinID(id uint64) (uint32, error)

FundingOutpointIndxByVinID retrieves the the transaction output index of the previous outpoint for a transaction input specified by row ID in the vins table, which stores previous outpoints for each vin.

func (*ChainDB) GenesisStamp

func (pgb *ChainDB) GenesisStamp() int64

GenesisStamp returns the stamp of the lowest mainchain block in the database.

func (*ChainDB) GetBlockHash

func (pgb *ChainDB) GetBlockHash(idx int64) (string, error)

GetBlockHash returns the hash of the block at the specified height. TODO: create GetBlockHashes to return all blocks at a given height.

func (*ChainDB) GetBlockHeight

func (pgb *ChainDB) GetBlockHeight(hash string) (int64, error)

GetBlockHeight returns the height of the block with the specified hash.

func (*ChainDB) GetHeight

func (pgb *ChainDB) GetHeight() (int64, error)

GetHeight is for middleware DataSource compatibility. No DB query is performed; the last stored height is used.

func (*ChainDB) GetTicketInfo

func (pgb *ChainDB) GetTicketInfo(txid string) (*apitypes.TicketInfo, error)

GetTicketInfo retrieves information about the pool and spend statuses, the purchase block, the lottery block, and the spending transaction.

func (*ChainDB) HashDB

func (pgb *ChainDB) HashDB() (string, error)

HashDB retrieves the best block hash according to the meta table.

func (*ChainDB) HashDBLegacy

func (pgb *ChainDB) HashDBLegacy() (string, error)

HashDBLegacy queries the blocks table for the best block's hash.

func (*ChainDB) Height

func (pgb *ChainDB) Height() int64

Height is a getter for ChainDB.bestBlock.height.

func (*ChainDB) HeightDB

func (pgb *ChainDB) HeightDB() (int64, error)

HeightDB retrieves the best block height according to the meta table.

func (*ChainDB) HeightDBLegacy

func (pgb *ChainDB) HeightDBLegacy() (int64, error)

HeightDBLegacy queries the blocks table for the best block height. When the tables are empty, the returned height will be -1.

func (*ChainDB) HeightHashDB

func (pgb *ChainDB) HeightHashDB() (int64, string, error)

HeightHashDB retrieves the best block height and hash according to the meta table.

func (*ChainDB) HeightHashDBLegacy

func (pgb *ChainDB) HeightHashDBLegacy() (uint64, string, error)

HeightHashDBLegacy queries the blocks table for the best block's height and hash.

func (*ChainDB) IndexAddressTable

func (pgb *ChainDB) IndexAddressTable(barLoad chan *dbtypes.ProgressBarLoad) error

IndexAddressTable creates the indexes on the address table on the vout ID, block_time, matching_tx_hash and address columns.

func (*ChainDB) IndexAll

func (pgb *ChainDB) IndexAll(barLoad chan *dbtypes.ProgressBarLoad) error

IndexAll creates most indexes in the tables. Exceptions: (1) Use IndexAddressTable to create IndexAddressTableOnVoutID and IndexAddressTableOnAddress. (2) Use IndexTicketsTable to create IndexTicketsTableOnHashes, IndexTicketsTableOnPoolStatus, and IndexTicketsTableOnTxDbID.

func (*ChainDB) IndexTicketsTable

func (pgb *ChainDB) IndexTicketsTable(barLoad chan *dbtypes.ProgressBarLoad) error

IndexTicketsTable creates indexes in the tickets table on ticket hash, ticket pool status and tx DB ID columns.

func (*ChainDB) InitUtxoCache

func (pgb *ChainDB) InitUtxoCache(utxos []dbtypes.UTXO)

InitUtxoCache resets the UTXO cache with the given slice of UTXO data.

func (*ChainDB) InsightAddressTransactions

func (pgb *ChainDB) InsightAddressTransactions(addr []string, recentBlockHeight int64) (txs, recentTxs []chainhash.Hash, err error)

InsightAddressTransactions performs DB queries to get all transaction hashes for the specified addresses in descending order by time, then ascending order by hash. It also returns a list of recently (defined as greater than recentBlockHeight) confirmed transactions that can be used to validate mempool status.

func (*ChainDB) LastPiParserSync

func (pgb *ChainDB) LastPiParserSync() time.Time

LastPiParserSync returns last time value when the piparser run sync on proposals and proposal_votes table.

func (*ChainDB) MissingAddressIndexes

func (pgb *ChainDB) MissingAddressIndexes() (missing []string, descs []string, err error)

MissingAddressIndexes list missing addresses table indexes and their descriptions.

func (*ChainDB) MissingIndexes

func (pgb *ChainDB) MissingIndexes() (missing, descs []string, err error)

MissingIndexes lists missing table indexes and their descriptions.

func (*ChainDB) NumAddressIntervals

func (pgb *ChainDB) NumAddressIntervals(addr string, grouping dbtypes.TimeBasedGrouping) (int64, error)

NumAddressIntervals gets the number of unique time intervals for the specified grouping where there are entries in the addresses table for the given address.

func (*ChainDB) PiProposalsHistory

func (pgb *ChainDB) PiProposalsHistory() (int64, error)

PiProposalsHistory queries the politeia's proposal updates via the parser tool and pushes them to the proposals and proposal_votes tables.

func (*ChainDB) PkScriptByVinID

func (pgb *ChainDB) PkScriptByVinID(id uint64) (pkScript []byte, ver uint16, err error)

PkScriptByVinID retrieves the pkScript and script version for the row of the vouts table corresponding to the previous output of the vin specified by row ID of the vins table.

func (*ChainDB) PkScriptByVoutID

func (pgb *ChainDB) PkScriptByVoutID(id uint64) (pkScript []byte, ver uint16, err error)

PkScriptByVoutID retrieves the pkScript and script version for the row of the vouts table specified by the row ID id.

func (*ChainDB) PoolStatusForTicket

func (pgb *ChainDB) PoolStatusForTicket(txid string) (dbtypes.TicketSpendType, dbtypes.TicketPoolStatus, error)

PoolStatusForTicket retrieves the specified ticket's spend status and ticket pool status, and an error value.

func (*ChainDB) PosIntervals

func (pgb *ChainDB) PosIntervals(limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error)

PosIntervals retrieves the blocks at the respective stakebase windows interval. The term "window" is used here to describe the group of blocks whose count is defined by chainParams.StakeDiffWindowSize. During this chainParams.StakeDiffWindowSize block interval the ticket price and the difficulty value is constant.

func (*ChainDB) PowerlessTickets

func (pgb *ChainDB) PowerlessTickets() (*apitypes.PowerlessTickets, error)

PowerlessTickets fetches all missed and expired tickets, sorted by revocation status.

func (*ChainDB) ProposalVotes

func (pgb *ChainDB) ProposalVotes(proposalToken string) (*dbtypes.ProposalChartsData, error)

ProposalVotes retrieves all the votes data associated with the provided token.

func (*ChainDB) PurgeBestBlocks

func (pgb *ChainDB) PurgeBestBlocks(N int64) (*dbtypes.DeletionSummary, int64, error)

PurgeBestBlocks deletes all data for the N best blocks in the DB.

func (*ChainDB) RegisterCharts

func (pgb *ChainDB) RegisterCharts(charts *cache.ChartData)

RegisterCharts registers chart data fetchers and appenders with the provided ChartData.

func (*ChainDB) ReindexAddressesBlockTime

func (pgb *ChainDB) ReindexAddressesBlockTime() error

ReindexAddressesBlockTime rebuilds the addresses(block_time) index.

func (*ChainDB) SetDBBestBlock

func (pgb *ChainDB) SetDBBestBlock() error

SetDBBestBlock stores ChainDB's BestBlock data in the meta table.

func (*ChainDB) SetVinsMainchainByBlock

func (pgb *ChainDB) SetVinsMainchainByBlock(blockHash string) (int64, []dbtypes.UInt64Array, []dbtypes.UInt64Array, error)

SetVinsMainchainByBlock first retrieves for all transactions in the specified block the vin_db_ids and vout_db_ids arrays, along with mainchain status, from the transactions table, and then sets the is_mainchain flag in the vins table for each row of vins in the vin_db_ids array. The returns are the number of vins updated, the vin row IDs array, the vouts row IDs array, and an error value.

func (*ChainDB) SideChainBlocks

func (pgb *ChainDB) SideChainBlocks() ([]*dbtypes.BlockStatus, error)

SideChainBlocks retrieves all known side chain blocks.

func (*ChainDB) SideChainTips

func (pgb *ChainDB) SideChainTips() ([]*dbtypes.BlockStatus, error)

SideChainTips retrieves the tip/head block for all known side chains.

func (*ChainDB) SpendDetailsForFundingTx

func (pgb *ChainDB) SpendDetailsForFundingTx(fundHash string) ([]*apitypes.SpendByFundingHash, error)

SpendDetailsForFundingTx will return the details of any spending transactions (tx, index, block height) for a given funding transaction.

func (*ChainDB) SpendingTransaction

func (pgb *ChainDB) SpendingTransaction(fundingTxID string,
	fundingTxVout uint32) (string, uint32, int8, error)

SpendingTransaction returns the transaction that spends the specified transaction outpoint, if it is spent. The spending transaction hash, input index, tx tree, and an error value are returned.

func (*ChainDB) SpendingTransactions

func (pgb *ChainDB) SpendingTransactions(fundingTxID string) ([]string, []uint32, []uint32, error)

SpendingTransactions retrieves all transactions spending outpoints from the specified funding transaction. The spending transaction hashes, the spending tx input indexes, and the corresponding funding tx output indexes, and an error value are returned.

func (*ChainDB) StartPiparserHandler

func (pgb *ChainDB) StartPiparserHandler()

StartPiparserHandler controls how piparser update handler will be initiated. This handler should to be run once only when the first sync after startup completes.

func (*ChainDB) Store

func (pgb *ChainDB) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error

Store satisfies BlockDataSaver. Blocks stored this way are considered valid and part of mainchain. Store should not be used for batch block processing; instead, use StoreBlock and specify appropriate flags.

func (*ChainDB) StoreBlock

func (pgb *ChainDB) StoreBlock(msgBlock *wire.MsgBlock, winningTickets []string,
	isValid, isMainchain, updateExistingRecords, updateAddressesSpendingInfo,
	updateTicketsSpendingInfo bool, chainWork string) (
	numVins int64, numVouts int64, numAddresses int64, err error)

StoreBlock processes the input wire.MsgBlock, and saves to the data tables. The number of vins and vouts stored are returned.

func (*ChainDB) SyncChainDB

func (pgb *ChainDB) SyncChainDB(ctx context.Context, client rpcutils.MasterBlockGetter,
	updateAllAddresses, newIndexes bool, updateExplorer chan *chainhash.Hash,
	barLoad chan *dbtypes.ProgressBarLoad) (int64, error)

SyncChainDB stores in the DB all blocks on the main chain available from the RPC client. The table indexes may be force-dropped and recreated by setting newIndexes to true. The quit channel is used to break the sync loop. For example, closing the channel on SIGINT.

func (*ChainDB) SyncChainDBAsync

func (pgb *ChainDB) SyncChainDBAsync(ctx context.Context, res chan dbtypes.SyncResult,
	client rpcutils.MasterBlockGetter, updateAllAddresses, newIndexes bool,
	updateExplorer chan *chainhash.Hash, barLoad chan *dbtypes.ProgressBarLoad)

SyncChainDBAsync is like SyncChainDB except it also takes a result channel on which the caller should wait to receive the result. As such, this method should be called as a goroutine or it will hang on send if the channel is unbuffered.

func (*ChainDB) TicketMiss

func (pgb *ChainDB) TicketMiss(ticketHash string) (string, int64, error)

TicketMiss retrieves the mainchain block in which the specified ticket was called to vote but failed to do so (miss). If the ticket never missed a vote, the returned error will be sql.ErrNoRows.

func (*ChainDB) TicketMisses

func (pgb *ChainDB) TicketMisses(ticketHash string) ([]string, []int64, error)

TicketMisses retrieves all blocks in which the specified ticket was called to vote but failed to do so (miss). There may be multiple since this consideres side chain blocks. See TicketMiss for a mainchain-only version. If the ticket never missed a vote, the returned error will be sql.ErrNoRows.

func (*ChainDB) TicketPoolBlockMaturity

func (pgb *ChainDB) TicketPoolBlockMaturity() int64

TicketPoolBlockMaturity returns the block at which all tickets with height greater than it are immature.

func (*ChainDB) TicketPoolByDateAndInterval

func (pgb *ChainDB) TicketPoolByDateAndInterval(maturityBlock int64,
	interval dbtypes.TimeBasedGrouping) (*dbtypes.PoolTicketsData, error)

TicketPoolByDateAndInterval fetches the tickets ordered by the purchase date interval provided and an error value.

func (*ChainDB) TicketPoolVisualization

func (pgb *ChainDB) TicketPoolVisualization(interval dbtypes.TimeBasedGrouping) (*dbtypes.PoolTicketsData,
	*dbtypes.PoolTicketsData, *dbtypes.PoolTicketsData, int64, error)

TicketPoolVisualization helps block consecutive and duplicate DB queries for the requested ticket pool chart data. If the data for the given interval is cached and fresh, it is returned. If the cached data is stale and there are no queries running to update the cache for the given interval, this launches a query and updates the cache. If there is no cached data for the interval, this will launch a new query for the data if one is not already running, and if one is running, it will wait for the query to complete.

func (*ChainDB) TicketsByInputCount

func (pgb *ChainDB) TicketsByInputCount() (*dbtypes.PoolTicketsData, error)

TicketsByInputCount returns chart data for tickets grouped by number of inputs.

func (*ChainDB) TicketsByPrice

func (pgb *ChainDB) TicketsByPrice(maturityBlock int64) (*dbtypes.PoolTicketsData, error)

TicketsByPrice returns chart data for tickets grouped by price. maturityBlock is used to define when tickets are considered live.

func (*ChainDB) TimeBasedIntervals

func (pgb *ChainDB) TimeBasedIntervals(timeGrouping dbtypes.TimeBasedGrouping,
	limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error)

TimeBasedIntervals retrieves blocks groups by the selected time-based interval. For the consecutive groups the number of blocks grouped together is not uniform.

func (*ChainDB) TipToSideChain

func (pgb *ChainDB) TipToSideChain(mainRoot string) (string, int64, error)

func (*ChainDB) Transaction

func (pgb *ChainDB) Transaction(txHash string) ([]*dbtypes.Tx, error)

Transaction retrieves all rows from the transactions table for the given transaction hash.

func (*ChainDB) TransactionBlock

func (pgb *ChainDB) TransactionBlock(txID string) (string, uint32, int8, error)

TransactionBlock retrieves the hash of the block containing the specified transaction. The index of the transaction within the block, the transaction index, and an error value are also returned.

func (*ChainDB) TransactionBlocks

func (pgb *ChainDB) TransactionBlocks(txHash string) ([]*dbtypes.BlockStatus, []uint32, error)

TransactionBlocks retrieves the blocks in which the specified transaction appears, along with the index of the transaction in each of the blocks. The next and previous block hashes are NOT SET in each BlockStatus.

func (*ChainDB) TxHistoryData

func (pgb *ChainDB) TxHistoryData(address string, addrChart dbtypes.HistoryChart,
	chartGroupings dbtypes.TimeBasedGrouping) (cd *dbtypes.ChartsData, err error)

TxHistoryData fetches the address history chart data for specified chart type and time grouping.

func (*ChainDB) UpdateChainState

func (pgb *ChainDB) UpdateChainState(blockChainInfo *chainjson.GetBlockChainInfoResult)

UpdateChainState updates the blockchain's state, which includes each of the agenda's VotingDone and Activated heights. If the agenda passed (i.e. status is "lockedIn" or "activated"), Activated is set to the height at which the rule change will take(or took) place.

func (*ChainDB) UpdateLastBlock

func (pgb *ChainDB) UpdateLastBlock(msgBlock *wire.MsgBlock, isMainchain bool) error

UpdateLastBlock set the previous block's next block hash in the block_chain table with this block's hash as it is next. If the current block's votes invalidated/disapproved the previous block, it also updates the is_valid columns for the previous block's entries in the following tables: blocks, vins, addresses, and transactions. If the previous block is not on the same chain as this block (as indicated by isMainchain), no updates are performed.

func (*ChainDB) UpdateSpendingInfoInAllAddresses

func (pgb *ChainDB) UpdateSpendingInfoInAllAddresses(barLoad chan *dbtypes.ProgressBarLoad) (int64, error)

UpdateSpendingInfoInAllAddresses completely rebuilds the matching transaction columns for funding rows of the addresses table. This is intended to be use after syncing all other tables and creating their indexes, particularly the indexes on the vins table, and the addresses table index on the funding tx columns. This can be used instead of using updateAddressesSpendingInfo=true with storeBlockTxnTree, which will update these addresses table columns too, but much more slowly for a number of reasons (that are well worth investigating BTW!).

func (*ChainDB) UpdateSpendingInfoInAllTickets

func (pgb *ChainDB) UpdateSpendingInfoInAllTickets() (int64, error)

UpdateSpendingInfoInAllTickets reviews all votes and revokes and sets this spending info in the tickets table.

func (*ChainDB) UpgradeTables

func (pgb *ChainDB) UpgradeTables(dcrdClient BlockGetter, version, needVersion TableVersion) (bool, error)

UpgradeTables upgrades all the tables with the pending updates from the current table versions to the most recent table version supported. A boolean is returned to indicate if the db upgrade was successfully completed.

func (*ChainDB) UseMempoolChecker

func (pgb *ChainDB) UseMempoolChecker(mp rpcutils.MempoolAddressChecker)

UseMempoolChecker assigns a MempoolAddressChecker for searching mempool for transactions involving a certain address.

func (*ChainDB) UseStakeDB

func (pgb *ChainDB) UseStakeDB(stakeDB *stakedb.StakeDatabase)

UseStakeDB is used to assign a stakedb.StakeDatabase for ticket tracking. This may be useful when it is necessary to construct a ChainDB prior to creating or loading a StakeDatabase, such as when dropping tables.

func (*ChainDB) VersionCheck

func (pgb *ChainDB) VersionCheck(client BlockGetter) error

VersionCheck checks the current version of all known tables and notifies when an upgrade is required. If there is no automatic upgrade supported, an error is returned when any table is not of the correct version. An RPC client is passed to implement the supported upgrades if need be.

func (*ChainDB) VinsForTx

func (pgb *ChainDB) VinsForTx(dbTx *dbtypes.Tx) ([]dbtypes.VinTxProperty, []string, []uint16, error)

VinsForTx returns a slice of dbtypes.VinTxProperty values for each vin referenced by the transaction dbTx, along with the pkScript and script version for the corresponding previous outpoints.

func (*ChainDB) VotesInBlock

func (pgb *ChainDB) VotesInBlock(hash string) (int16, error)

VotesInBlock returns the number of votes mined in the block with the specified hash.

func (*ChainDB) VoutValue

func (pgb *ChainDB) VoutValue(txID string, vout uint32) (uint64, error)

VoutValue retrieves the value of the specified transaction outpoint in atoms.

func (*ChainDB) VoutValues

func (pgb *ChainDB) VoutValues(txID string) ([]uint64, []uint32, []int8, error)

VoutValues retrieves the values of each outpoint of the specified transaction. The corresponding indexes in the block and tx trees of the outpoints, and an error value are also returned.

func (*ChainDB) VoutsForTx

func (pgb *ChainDB) VoutsForTx(dbTx *dbtypes.Tx) ([]dbtypes.Vout, error)

VoutsForTx returns a slice of dbtypes.Vout values for each vout referenced by the transaction dbTx.

type ChainDBRPC

type ChainDBRPC struct {
	*ChainDB
	Client *rpcclient.Client
}

ChainDBRPC provides an interface for storing and manipulating extracted and includes the RPC Client blockchain data in a PostgreSQL database.

func NewChainDBRPC

func NewChainDBRPC(chaindb *ChainDB, cl *rpcclient.Client) (*ChainDBRPC, error)

NewChainDBRPC contains ChainDB and RPC client parameters. By default, duplicate row checks on insertion are enabled. also enables rpc client

func (*ChainDBRPC) AddressData

func (pgb *ChainDBRPC) AddressData(address string, limitN, offsetAddrOuts int64,
	txnType dbtypes.AddrTxnViewType) (addrData *dbtypes.AddressInfo, err error)

AddressData returns comprehensive, paginated information for an address.

func (*ChainDBRPC) GetBlockVerboseByHash

func (pgb *ChainDBRPC) GetBlockVerboseByHash(hash string, verboseTx bool) *chainjson.GetBlockVerboseResult

GetBlockVerboseByHash returns a *chainjson.GetBlockVerboseResult for the specified block hash, optionally with transaction details.

func (*ChainDBRPC) GetChainWork

func (pgb *ChainDBRPC) GetChainWork(hash *chainhash.Hash) (string, error)

GetChainWork fetches the chainjson.BlockHeaderVerbose and returns only the ChainWork attribute as a hex-encoded string, without 0x prefix.

func (*ChainDBRPC) GetRawTransaction

func (pgb *ChainDBRPC) GetRawTransaction(txid *chainhash.Hash) (*chainjson.TxRawResult, error)

GetRawTransaction gets a chainjson.TxRawResult for the specified transaction hash.

func (*ChainDBRPC) GetTransactionHex

func (pgb *ChainDBRPC) GetTransactionHex(txid *chainhash.Hash) string

GetTransactionHex returns the full serialized transaction for the specified transaction hash as a hex encode string.

func (*ChainDBRPC) GetTransactionsForBlockByHash

func (pgb *ChainDBRPC) GetTransactionsForBlockByHash(hash string) *apitypes.BlockTransactions

GetTransactionsForBlockByHash returns a *apitypes.BlockTransactions for the block with the specified hash.

func (*ChainDBRPC) InsightSearchRPCAddressTransactions

func (pgb *ChainDBRPC) InsightSearchRPCAddressTransactions(addr string, count,
	skip int) []*chainjson.SearchRawTransactionsResult

InsightSearchRPCAddressTransactions performs a searchrawtransactions for the specified address, max number of transactions, and offset into the transaction list. The search results are in reverse temporal order. TODO: Does this really need all the prev vout extra data?

func (*ChainDBRPC) MissingSideChainBlocks

func (pgb *ChainDBRPC) MissingSideChainBlocks() ([]dbtypes.SideChain, int, error)

MissingSideChainBlocks identifies side chain blocks that are missing from the DB. Side chains known to dcrd are listed via the getchaintips RPC. Each block presence in the postgres DB is checked, and any missing block is returned in a SideChain along with a count of the total number of missing blocks.

func (*ChainDBRPC) NewChainMonitor

func (pgb *ChainDBRPC) NewChainMonitor(ctx context.Context) *ChainMonitor

NewChainMonitor creates a new ChainMonitor.

func (*ChainDBRPC) SendRawTransaction

func (pgb *ChainDBRPC) SendRawTransaction(txhex string) (string, error)

SendRawTransaction attempts to decode the input serialized transaction, passed as hex encoded string, and broadcast it, returning the tx hash.

func (*ChainDBRPC) Store

func (pgb *ChainDBRPC) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error

Store satisfies BlockDataSaver. Blocks stored this way are considered valid and part of mainchain. This calls (*ChainDB).Store after a nil pointer check on the ChainDBRPC receiver

func (*ChainDBRPC) SyncChainDBAsync

func (pgb *ChainDBRPC) SyncChainDBAsync(ctx context.Context, res chan dbtypes.SyncResult,
	client rpcutils.MasterBlockGetter, updateAllAddresses, newIndexes bool,
	updateExplorer chan *chainhash.Hash, barLoad chan *dbtypes.ProgressBarLoad)

SyncChainDBAsync calls (*ChainDB).SyncChainDBAsync after a nil pointer check on the ChainDBRPC receiver.

func (*ChainDBRPC) UpdateChainState

func (pgb *ChainDBRPC) UpdateChainState(blockChainInfo *chainjson.GetBlockChainInfoResult)

UpdateChainState calls (*ChainDB).UpdateChainState after a nil pointer check on the ChainDBRPC receiver.

type ChainDeployments

type ChainDeployments struct {
	// contains filtered or unexported fields
}

ChainDeployments is mutex-protected blockchain deployment data.

type ChainMonitor

type ChainMonitor struct {
	ConnectingLock chan struct{}
	DoneConnecting chan struct{}
	// contains filtered or unexported fields
}

ChainMonitor responds to block connection and chain reorganization.

func (*ChainMonitor) ReorgHandler

func (p *ChainMonitor) ReorgHandler(reorg *txhelpers.ReorgData) (err error)

ReorgHandler processes a blockchain reorganization and initiates a corresponding reorganization of the ChainDB. ReorgHandler satisfies notification.ReorgHandler, and is registered as a handler in main.go.

type CompatAction

type CompatAction int8

CompatAction defines the action to be taken once the current and the required pg table versions are compared.

const (
	Rebuild CompatAction = iota
	Upgrade
	Maintenance
	OK
	TimeTravel
	Unknown
)

These are the recognized CompatActions for upgrading a database from one version to another.

func (CompatAction) String

func (v CompatAction) String() string

String implements Stringer for CompatAction.

type CompatibilityAction

type CompatibilityAction int8

CompatibilityAction defines the action to be taken once the current and the required pg table versions are compared.

func TableVersionCompatible

func TableVersionCompatible(required, actual TableVersion) CompatibilityAction

TableVersionCompatible indicates if the table versions are compatible (equal), and if not, what is the required action (rebuild, upgrade, or reindex).

func (CompatibilityAction) String

func (v CompatibilityAction) String() string

String implements Stringer for CompatibilityAction.

type DBInfo

type DBInfo struct {
	Host, Port, User, Pass, DBName string
	QueryTimeout                   time.Duration
}

DBInfo holds the PostgreSQL database connection information.

type DatabaseUpgrade

type DatabaseUpgrade struct {
	TableName               string
	UpgradeType             CompatAction
	CurrentVer, RequiredVer DatabaseVersion
}

DatabaseUpgrade is used to define a required DB upgrade.

func (DatabaseUpgrade) String

func (s DatabaseUpgrade) String() string

String implements Stringer for DatabaseUpgrade.

type DatabaseVersion

type DatabaseVersion struct {
	// contains filtered or unexported fields
}

DatabaseVersion models a database version.

func DBVersion

func DBVersion(db *sql.DB) (ver DatabaseVersion, err error)

DBVersion retrieves the database version from the meta table. See (*DatabaseVersion).NeededToReach for version comparison.

func NewDatabaseVersion

func NewDatabaseVersion(major, minor, patch uint32) DatabaseVersion

NewDatabaseVersion returns a new DatabaseVersion with the version major.minor.patch

func (*DatabaseVersion) NeededToReach

func (v *DatabaseVersion) NeededToReach(other *DatabaseVersion) CompatAction

NeededToReach describes what action is required for the DatabaseVersion to reach another version provided in the input argument.

func (DatabaseVersion) String

func (v DatabaseVersion) String() string

String implements Stringer for DatabaseVersion.

type MsgBlockPG

type MsgBlockPG struct {
	*wire.MsgBlock
	WinningTickets []string
	Validators     []string
}

MsgBlockPG extends wire.MsgBlock with the winning tickets from the block, WinningTickets, and the tickets from the previous block that may vote on this block's validity, Validators.

type PGSetting

type PGSetting struct {
	Name, Setting, Unit, ShortDesc, Source, SourceFile, SourceLine string
}

PGSetting describes a PostgreSQL setting scanned from pg_settings.

type PGSettings

type PGSettings map[string]PGSetting

PGSettings facilitates looking up a PGSetting based on a setting's Name.

func RetrieveSysSettingsConfFile

func RetrieveSysSettingsConfFile(db *sql.DB) (PGSettings, error)

RetrieveSysSettingsConfFile retrieves settings that are set by a configuration file (rather than default, environment variable, etc.).

func RetrieveSysSettingsPerformance

func RetrieveSysSettingsPerformance(db *sql.DB) (PGSettings, error)

RetrieveSysSettingsPerformance retrieves performance-related settings.

func RetrieveSysSettingsServer

func RetrieveSysSettingsServer(db *sql.DB) (PGSettings, error)

RetrieveSysSettingsServer a key server configuration settings (config_file, data_directory, max_connections, dynamic_shared_memory_type, max_files_per_process, port, unix_socket_directories), which may be helpful in debugging connectivity issues or other DB errors.

func (PGSettings) String

func (pgs PGSettings) String() string

String implements the Stringer interface, generating a table of the settings where the Setting and Unit fields are merged into a single column. The rows of the table are sorted by the PGSettings string key (the setting's Name). This function is not thread-safe, so do not modify PGSettings concurrently.

type ProposalsFetcher

type ProposalsFetcher interface {
	UpdateSignal() <-chan struct{}
	ProposalsHistory() ([]*pitypes.History, error)
	ProposalsHistorySince(since time.Time) ([]*pitypes.History, error)
}

ProposalsFetcher defines the interface of the proposals plug-n-play data source.

type SqlExecutor

type SqlExecutor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
}

SqlExecutor is implemented by both sql.DB and sql.Tx.

type TableUpgrade

type TableUpgrade struct {
	TableName               string
	UpgradeType             CompatibilityAction
	CurrentVer, RequiredVer TableVersion
}

TableUpgrade is used to define a required upgrade for a table

func TableUpgradesRequired

func TableUpgradesRequired(versions map[string]TableVersion) []TableUpgrade

TableUpgradesRequired builds a list of table upgrade information for each of the supported auxiliary db tables. The upgrade information includes the table name, its current & required table versions and the action to be taken after comparing the current & required versions.

func (TableUpgrade) String

func (s TableUpgrade) String() string

type TableUpgradeType

type TableUpgradeType struct {
	TableName string
	// contains filtered or unexported fields
}

type TableVersion

type TableVersion struct {
	// contains filtered or unexported fields
}

TableVersion models a table version by major.minor.patch

func NewTableVersion

func NewTableVersion(major, minor, patch uint32) TableVersion

NewTableVersion returns a new TableVersion with the version major.minor.patch

func (TableVersion) String

func (s TableVersion) String() string

type TicketTxnIDGetter

type TicketTxnIDGetter struct {
	// contains filtered or unexported fields
}

TicketTxnIDGetter provides a cache for DB row IDs of tickets.

func NewTicketTxnIDGetter

func NewTicketTxnIDGetter(db *sql.DB) *TicketTxnIDGetter

NewTicketTxnIDGetter constructs a new TicketTxnIDGetter with an empty cache.

func (*TicketTxnIDGetter) Set

func (t *TicketTxnIDGetter) Set(txid string, txDbID uint64)

Set stores the (transaction hash, DB row ID) pair a map for future access.

func (*TicketTxnIDGetter) SetN

func (t *TicketTxnIDGetter) SetN(txid []string, txDbID []uint64)

SetN stores several (transaction hash, DB row ID) pairs in the map.

func (*TicketTxnIDGetter) TxnDbID

func (t *TicketTxnIDGetter) TxnDbID(txid string, expire bool) (uint64, error)

TxnDbID fetches DB row ID for the ticket specified by the input transaction hash. A cache is checked first. In the event of a cache hit, the DB ID is returned and deleted from the internal cache. In the event of a cache miss, the database is queried. If the database query fails, the error is non-nil.

type VinVoutTypeUpdateData

type VinVoutTypeUpdateData struct {
	VinsDbIDs  dbtypes.UInt64Array
	VoutsDbIDs dbtypes.UInt64Array
	TxType     stake.TxType
}

VinVoutTypeUpdateData defines the fetched details from the transactions table that are needed to undertake the histogram upgrade.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL