dcrpg

package
v2.1.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2018 License: ISC Imports: 31 Imported by: 0

README

package dcrpg

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

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, particuarly 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 by PgTune. During initial table population, it is also OK to turn off autovacuum, full page writes, and possibly fsync. Remember to change settings back to production ready values.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 CreateTable

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

CreateTable creates one of the known tables by name

func CreateTables

func CreateTables(db *sql.DB) error

func CreateTypes

func CreateTypes(db *sql.DB) error

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 DeindexBlockTableOnHash

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

func DeindexMissesTableOnHash

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

func DeindexTicketsTableOnHash

func DeindexTicketsTableOnHash(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 DeindexVotesTableOnCandidate

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

func DeindexVotesTableOnHash

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

func DeindexVotesTableOnVoteVersion

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

func DeindexVoutTableOnTxHashIdx

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

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 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 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)

func ExistsIndex

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

func IndexAddressTableOnAddress

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

func IndexAddressTableOnTxHash

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

func IndexAddressTableOnVoutID

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

func IndexBlockTableOnHash

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

func IndexMissesTableOnHashes

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

func IndexTicketsTableOnHashes

func IndexTicketsTableOnHashes(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 IndexVotesTableOnCandidate

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

func IndexVotesTableOnHashes

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

func IndexVotesTableOnVoteVersion

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

func IndexVoutTableOnTxHashIdx

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

func InsertAddressOut

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

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

func InsertAddressOuts

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

func InsertBlock

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

func InsertBlockPrevNext

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

func InsertTickets

func InsertTickets(db *sql.DB, dbTxns []*dbtypes.Tx, txDbIDs []uint64, checked 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 bool) (uint64, error)

func InsertTxns

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

func InsertVin

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

func InsertVins

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

func InsertVotes

func InsertVotes(db *sql.DB, dbTxns []*dbtypes.Tx, _ []uint64,
	fTx *TicketTxnIDGetter, msgBlock *MsgBlockPG, checked bool) ([]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).

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) (uint64, error)

func InsertVouts

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

func IsUniqueIndex

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

func RetrieveAddressCreditTxns

func RetrieveAddressCreditTxns(db *sql.DB, address string, N, offset int64) (ids []uint64, addressRows []*dbtypes.AddressRow, err error)

func RetrieveAddressDebitTxns

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

func RetrieveAddressIDsByOutpoint

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

RetrieveAddressIDsByOutpoint fetches all address row IDs for a given outpoint (hash:index). Update Vin due to DCRD AMOUNTIN - START - DO NOT MERGE CHANGES IF DCRD FIXED

func RetrieveAddressRecvCount

func RetrieveAddressRecvCount(db *sql.DB, address string) (count int64, err error)

func RetrieveAddressSpent

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

func RetrieveAddressSpentUnspent

func RetrieveAddressSpentUnspent(db *sql.DB, address string) (numSpent, numUnspent,
	totalSpent, totalUnspent int64, err error)

func RetrieveAddressTxnOutputWithTransaction

func RetrieveAddressTxnOutputWithTransaction(db *sql.DB, address string, currentBlockHeight int64) ([]apitypes.AddressTxnOutput, error)

func RetrieveAddressTxns

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

func RetrieveAddressTxnsAlt

func RetrieveAddressTxnsAlt(db *sql.DB, address string, N, offset int64) ([]uint64, []*dbtypes.AddressRow, error)

func RetrieveAddressTxnsByFundingTx

func RetrieveAddressTxnsByFundingTx(db *sql.DB, fundTxHash string,
	addresses []string) (aSpendByFunHash []*apitypes.AddressSpendByFunHash, err error)

Retrieve all Transactions related to a set of addresses and funded by a specific transaction

func RetrieveAddressTxnsOrdered

func RetrieveAddressTxnsOrdered(db *sql.DB, addresses []string, recentBlockHeight int64) (txs []string, recenttxs []string)

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 RetrieveAddressUnspent

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

func RetrieveAllAddressTxns

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

func RetrieveAllRevokesDbIDHashHeight

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

func RetrieveAllVinDbIDs

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

func RetrieveAllVotesDbIDsHeightsTicketDbIDs

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

func RetrieveBestBlockHeight

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

func RetrieveBlockChainDbID

func RetrieveBlockChainDbID(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 RetrieveBlockHash

func RetrieveBlockHash(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(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 RetrieveBlockSummaryByTimeRange

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

func RetrieveBlockVoteCount

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

RetrieveBlockVoteCount gets the number of votes mined in a block.

func RetrieveDbTxByHash

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

func RetrieveFullTxByHash

func RetrieveFullTxByHash(db *sql.DB, txHash string) (id uint64,
	blockHash string, blockHeight int64, blockTime int64, time int64,
	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,
	err error)

func RetrieveFundingOutpointByTxIn

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

func RetrieveFundingOutpointByVinID

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

func RetrieveFundingTxByTxIn

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

func RetrieveFundingTxByVinDbID

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

func RetrieveFundingTxsByTx

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

func RetrieveMissedVotesInBlock

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

func RetrievePkScriptByID

func RetrievePkScriptByID(db *sql.DB, id uint64) (pkScript []byte, err error)

func RetrieveRegularTxByHash

func RetrieveRegularTxByHash(db *sql.DB, txHash string) (id uint64, blockHash string, blockInd uint32, err error)

func RetrieveSpendingTxByTxOut

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

func RetrieveSpendingTxByVinID

func RetrieveSpendingTxByVinID(db *sql.DB, vinDbID uint64) (tx string,
	voutIndex uint32, tree int8, err error)

func RetrieveSpendingTxsByFundingTx

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

func RetrieveStakeTxByHash

func RetrieveStakeTxByHash(db *sql.DB, txHash string) (id uint64, blockHash string, blockInd uint32, err error)

func RetrieveTicketIDByHash

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

func RetrieveTicketIDHeightByHash

func RetrieveTicketIDHeightByHash(db *sql.DB, ticketHash string) (id uint64, blockHeight int64, err error)

func RetrieveTicketIDsByHashes

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

func RetrieveTicketStatusByHash

func RetrieveTicketStatusByHash(db *sql.DB, ticketHash string) (id uint64, spend_status dbtypes.TicketSpendType,
	pool_status dbtypes.TicketPoolStatus, err error)

func RetrieveTxByHash

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

func RetrieveTxIDHeightByHash

func RetrieveTxIDHeightByHash(db *sql.DB, txHash string) (id uint64, blockHeight int64, err error)

func RetrieveTxsByBlockHash

func RetrieveTxsByBlockHash(db *sql.DB, blockHash string) (ids []uint64, txs []string, blockInds []uint32, trees []int8, err error)

func RetrieveUnspentTickets

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

func RetrieveVinByID

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

func RetrieveVoutIDByOutpoint

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

func RetrieveVoutValue

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

func RetrieveVoutValues

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

func SetPoolStatusForTickets

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

func SetPoolStatusForTicketsByHash

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

func SetSpendingByVinID

func SetSpendingByVinID(db *sql.DB, vinDbID uint64, spendingTxDbID uint64,
	spendingTxHash string, spendingTxVinIndex uint32, checked bool) (int64, error)

SetSpendingByVinID is for when you got a new spending tx (vin entry) and you need to get the funding (previous output) tx info, and then update the corresponding row in the addresses table with the spending tx info.

func SetSpendingForAddressDbID

func SetSpendingForAddressDbID(db *sql.DB, addrDbID uint64, spendingTxDbID uint64,
	spendingTxHash string, spendingTxVinIndex uint32, vinDbID uint64) error

func SetSpendingForFundingOP

func SetSpendingForFundingOP(db *sql.DB,
	fundingTxHash string, fundingTxVoutIndex uint32,
	spendingTxDbID uint64, spendingTxHash string, spendingTxVinIndex uint32,
	vinDbID uint64) (int64, error)

func SetSpendingForTickets

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

func SetSpendingForVinDbID

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

func SetSpendingForVinDbIDs

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

func TableExists

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

func TableVersionCompatible

func TableVersionCompatible(required, actual TableVersion) string

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

func TableVersions

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

func TypeExists

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

func UpdateBlockNext

func UpdateBlockNext(db *sql.DB, blockDbID uint64, next string) error

func UpdateLastBlock

func UpdateLastBlock(db *sql.DB, blockDbID uint64, isValid bool) error

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

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type ChainDB

type ChainDB struct {
	DevFundBalance *DevFundBalance

	InBatchSync 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 bool) (*ChainDB, error)

NewChainDB constructs a ChainDB for the given connection and Decred network parameters. By default, duplicate row checks on insertion are enabled.

func (*ChainDB) AddressHistory

func (pgb *ChainDB) AddressHistory(address string, N, offset int64,
	txnType dbtypes.AddrTxnType) ([]*dbtypes.AddressRow, *explorer.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, *explorer.AddressBalance, error)

AddressHistoryAll queries the database for all rows of the addresses table for the given address.

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.AddrTxnType) (*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.AddrTxnType) ([]*apitypes.AddressTxRaw, error)

TODO: finish

func (*ChainDB) AddressTransactions

func (pgb *ChainDB) AddressTransactions(address string, N, offset int64,
	txnType dbtypes.AddrTxnType) (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) 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) 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) 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) (spendingTxDbIDs []uint64, spendTypes []dbtypes.TicketSpendType,
	ticketHashes []string, ticketDbIDs []uint64, err error)

func (*ChainDB) DeindexAddressTable

func (pgb *ChainDB) DeindexAddressTable() error

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

func (*ChainDB) DeindexAll

func (pgb *ChainDB) DeindexAll() error

DeindexAll drops all of the indexes in all tables

func (*ChainDB) DeindexTicketsTable

func (pgb *ChainDB) DeindexTicketsTable() error

DeindexTicketsTable drops the ticket hash and tx DB ID column indexes for the tickets table.

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) DeleteDuplicateVotes

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

func (*ChainDB) DeleteDuplicateVouts

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

func (*ChainDB) DeleteDuplicates

func (pgb *ChainDB) DeleteDuplicates() error

func (*ChainDB) DeleteDuplicatesRecovery

func (pgb *ChainDB) DeleteDuplicatesRecovery() error

func (*ChainDB) DevBalance

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

DevBalance returns the current development/project fund balance, updating the cached balance if it is stale.

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) ExistsIndexAddressesVoutIDAddress

func (pgb *ChainDB) ExistsIndexAddressesVoutIDAddress() (bool, error)

func (*ChainDB) ExistsIndexVinOnVins

func (pgb *ChainDB) ExistsIndexVinOnVins() (bool, error)

func (*ChainDB) ExistsIndexVoutOnTxHashIdx

func (pgb *ChainDB) ExistsIndexVoutOnTxHashIdx() (bool, error)

func (*ChainDB) FillAddressTransactions

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

FillAddressTransactions is used to fill out the transaction details in an explorer.AddressInfo generated by explorer.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) GetAddressBalance

func (pgb *ChainDB) GetAddressBalance(address string, N, offset int64) *explorer.AddressBalance

GetAddressBalance returns a *explorer.AddressBalance for the specified address, transaction count limit, and transaction number offset.

func (*ChainDB) GetAddressSpendByFunHash

func (pgb *ChainDB) GetAddressSpendByFunHash(addresses []string, fundHash string) []*apitypes.AddressSpendByFunHash

GetAddressSpendByFunHash will return the address that fundex a tx

func (*ChainDB) GetAddressUTXO

func (pgb *ChainDB) GetAddressUTXO(address string) []apitypes.AddressTxnOutput

GetAddressUTXO returns the unspent transaction outputs (UTXOs) paying to the specified address in a []apitypes.AddressTxnOutput.

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) GetBlockSummaryTimeRange

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

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

func (*ChainDB) GetHeight

func (pgb *ChainDB) GetHeight() int

GetHeight returns the current best block height.

func (*ChainDB) HashDB

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

HashDB queries the DB for the best block's hash.

func (*ChainDB) Height

func (pgb *ChainDB) Height() uint64

Height uses the last stored height.

func (*ChainDB) HeightDB

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

HeightDB queries the DB for the best block height.

func (*ChainDB) IndexAddressTable

func (pgb *ChainDB) IndexAddressTable() error

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

func (*ChainDB) IndexAll

func (pgb *ChainDB) IndexAll() error

IndexAll creates all of the indexes in all tables

func (*ChainDB) IndexTicketsTable

func (pgb *ChainDB) IndexTicketsTable() error

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

func (*ChainDB) InsightPgGetAddressTransactions

func (pgb *ChainDB) InsightPgGetAddressTransactions(addr []string,
	recentBlockHeight int64) ([]string, []string)

InsightPgGetAddressTransactions performs a db query to pull all txids for the specified addresses ordered desc by time.

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) RetrieveAddressIDsByOutpoint

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

Update Vin due to DCRD AMOUNTIN - START

func (*ChainDB) RetrieveAddressSpentUnspent

func (pgb *ChainDB) RetrieveAddressSpentUnspent(address string) (int64, int64, int64, int64, error)

RetrieveAddressSpentUnspent retrieves balance information for a specific address.

func (*ChainDB) SetupTables

func (pgb *ChainDB) SetupTables() error

SetupTables creates the required tables and type, and prints table versions stored in the table comments when debug level logging is enabled.

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) Store

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

Store satisfies BlockDataSaver

func (*ChainDB) StoreBlock

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

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

func (*ChainDB) SyncChainDB

func (db *ChainDB) SyncChainDB(client rpcutils.MasterBlockGetter, quit chan struct{},
	updateAllAddresses, updateAllVotes, newIndexes bool) (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 (db *ChainDB) SyncChainDBAsync(res chan dbtypes.SyncResult,
	client rpcutils.MasterBlockGetter, quit chan struct{}, updateAllAddresses,
	updateAllVotes, newIndexes bool)

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) 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) UpdateDevBalance

func (pgb *ChainDB) UpdateDevBalance() (bool, error)

UpdateDevBalance forcibly updates the cached development/project fund balance via DB queries. The bool output inidcates if the cached balance was updated (if it was stale).

func (*ChainDB) UpdateSpendingInfoInAllAddresses

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

UpdateSpendingInfoInAllAddresses completely rebuilds the spending transaction info columns of the address 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 storeTxns, 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) 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() error

VersionCheck checks the current version of all known tables and notifies when an upgrade is required. Since there is presently no automatic upgrade, an error is returned when any table is not of the correct version.

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.

type ChainDBRPC

type ChainDBRPC struct {
	ChainDB *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) GetBlockVerboseByHash

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

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

func (*ChainDBRPC) GetRawTransaction

func (pgb *ChainDBRPC) GetRawTransaction(txid string) (*dcrjson.TxRawResult, error)

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

func (*ChainDBRPC) GetTransactionHex

func (pgb *ChainDBRPC) GetTransactionHex(txid string) 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) InsightGetAddressTransactions

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

InsightGetAddressTransactions performs a searchrawtransactions for the specfied 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) SendRawTransaction

func (db *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.

type DBInfo

type DBInfo struct {
	Host, Port, User, Pass, DBName string
}

DBInfo holds the PostgreSQL database connection information.

type DevFundBalance

type DevFundBalance struct {
	sync.RWMutex
	*explorer.AddressBalance

	Height int64
	Hash   chainhash.Hash
	// contains filtered or unexported fields
}

DevFundBalance is a block-stamped wrapper for explorer.AddressBalance. It is intended to be used for the project address.

func (*DevFundBalance) Balance

func (d *DevFundBalance) Balance() *explorer.AddressBalance

Balance is a thread-safe accessor for the explorer.AddressBalance.

func (*DevFundBalance) BlockHash

func (d *DevFundBalance) BlockHash() chainhash.Hash

BlockHash is a thread-safe accessor for the block hash.

func (*DevFundBalance) BlockHeight

func (d *DevFundBalance) BlockHeight() int64

BlockHeight is a thread-safe accessor for the block height.

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 TableUpgrade

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

TableUpgrade is used to define a required upgrade for a table

func TableUpgradesRequired

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

func (TableUpgrade) String

func (s TableUpgrade) String() string

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 {
	sync.RWMutex
	// 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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