Documentation ¶
Index ¶
- func Connect(host, port, user, pass, dbname string) (*sql.DB, error)
- func CreateTable(db *sql.DB, tableName string) error
- func CreateTables(db *sql.DB) error
- func CreateTypes(db *sql.DB) error
- func DeindexAddressTableOnAddress(db *sql.DB) (err error)
- func DeindexAddressTableOnTxHash(db *sql.DB) (err error)
- func DeindexAddressTableOnVoutID(db *sql.DB) (err error)
- func DeindexBlockTableOnHash(db *sql.DB) (err error)
- func DeindexTransactionTableOnBlockIn(db *sql.DB) (err error)
- func DeindexTransactionTableOnHashes(db *sql.DB) (err error)
- func DeindexVinTableOnPrevOuts(db *sql.DB) (err error)
- func DeindexVinTableOnVins(db *sql.DB) (err error)
- func DeindexVoutTableOnTxHash(db *sql.DB) (err error)
- func DeindexVoutTableOnTxHashIdx(db *sql.DB) (err error)
- func DisableLog()
- func DropTables(db *sql.DB)
- func IndexAddressTableOnAddress(db *sql.DB) (err error)
- func IndexAddressTableOnTxHash(db *sql.DB) (err error)
- func IndexAddressTableOnVoutID(db *sql.DB) (err error)
- func IndexBlockTableOnHash(db *sql.DB) (err error)
- func IndexTransactionTableOnBlockIn(db *sql.DB) (err error)
- func IndexTransactionTableOnHashes(db *sql.DB) (err error)
- func IndexVinTableOnPrevOuts(db *sql.DB) (err error)
- func IndexVinTableOnVins(db *sql.DB) (err error)
- func IndexVoutTableOnTxHash(db *sql.DB) (err error)
- func IndexVoutTableOnTxHashIdx(db *sql.DB) (err error)
- func InsertAddressOut(db *sql.DB, dbA *dbtypes.AddressRow) (uint64, error)
- func InsertAddressOuts(db *sql.DB, dbAs []*dbtypes.AddressRow) ([]uint64, error)
- func InsertBlock(db *sql.DB, dbBlock *dbtypes.Block, isValid, checked bool) (uint64, error)
- func InsertBlockPrevNext(db *sql.DB, blockDbID uint64, hash, prev, next string) error
- func InsertTx(db *sql.DB, dbTx *dbtypes.Tx, checked bool) (uint64, error)
- func InsertTxns(db *sql.DB, dbTxns []*dbtypes.Tx, checked bool) ([]uint64, error)
- func InsertVin(db *sql.DB, dbVin dbtypes.VinTxProperty) (id uint64, err error)
- func InsertVins(db *sql.DB, dbVins dbtypes.VinTxPropertyARRAY) ([]uint64, error)
- func InsertVout(db *sql.DB, dbVout *dbtypes.Vout, checked bool) (uint64, error)
- func InsertVouts(db *sql.DB, dbVouts []*dbtypes.Vout, checked bool) ([]uint64, []dbtypes.AddressRow, error)
- func RetrieveAddressIDsByOutpoint(db *sql.DB, txHash string, voutIndex uint32) ([]uint64, []string, error)
- func RetrieveAddressRecvCount(db *sql.DB, address string) (count int64, err error)
- func RetrieveAddressSpent(db *sql.DB, address string) (count, totalAmount int64, err error)
- func RetrieveAddressSpentUnspent(db *sql.DB, address string) (numSpent, numUnspent, totalSpent, totalUnspent int64, err error)
- func RetrieveAddressTxns(db *sql.DB, address string, N, offset int64) ([]uint64, []*dbtypes.AddressRow, error)
- func RetrieveAddressTxnsAlt(db *sql.DB, address string, N, offset int64) ([]uint64, []*dbtypes.AddressRow, error)
- func RetrieveAddressUnspent(db *sql.DB, address string) (count, totalAmount int64, err error)
- func RetrieveAllAddressTxns(db *sql.DB, address string) ([]uint64, []*dbtypes.AddressRow, error)
- func RetrieveAllVinDbIDs(db *sql.DB) (vinDbIDs []uint64, err error)
- func RetrieveBestBlockHeight(db *sql.DB) (height uint64, hash string, id uint64, err error)
- func RetrieveBlockVerJson(db *sql.DB) (*dbtypes.BlockVerJson, error)
- func RetrieveBlocksizejson(db *sql.DB, N, offset int64) ([]uint64, *dbtypes.BlocksizeJson, error)
- func RetrieveDbTxByHash(db *sql.DB, txHash string) (id uint64, dbTx *dbtypes.Tx, err error)
- func RetrieveDiffChartData(db *sql.DB) ([]*dbtypes.DiffData, error)
- func RetrieveDiffData(db *sql.DB) ([]*dbtypes.DiffData, error)
- func RetrieveFeesStat(db *sql.DB) (res []*dbtypes.FeesStat)
- func RetrieveFeesStatLastDay(db *sql.DB) (d int64, isInit bool, err error)
- func RetrieveFullTxByHash(db *sql.DB, txHash string) (id uint64, blockHash string, blockHeight int64, blockTime int64, time int64, ...)
- func RetrieveFundingOutpointByTxIn(db *sql.DB, txHash string, vinIndex uint32) (id uint64, tx string, index uint32, tree int8, err error)
- func RetrieveFundingOutpointByVinID(db *sql.DB, vinDbID uint64) (tx string, index uint32, tree int8, err error)
- func RetrieveFundingTxByTxIn(db *sql.DB, txHash string, vinIndex uint32) (id uint64, tx string, err error)
- func RetrieveFundingTxsByTx(db *sql.DB, txHash string) ([]uint64, []*dbtypes.Tx, error)
- func RetrieveHashratejson(db *sql.DB) (*dbtypes.HashRateJson, error)
- func RetrieveMempoolHistoryKline(db *sql.DB) (res []*dbtypes.MempoolHistory)
- func RetrieveMempoolHistoryKlineLastDay(db *sql.DB) (d int64, isInit bool, err error)
- func RetrieveMempoolRecentHistory(db *sql.DB) (res []*dbtypes.MempoolHistory)
- func RetrieveOpReturnChartData(db *sql.DB) (*dbtypes.OPReturnChartData, int, error)
- func RetrieveOpReturnListData(db *sql.DB, N, offset int64) ([]*dbtypes.OPReturnListData, error)
- func RetrievePkScriptByID(db *sql.DB, id uint64) (pkScript []byte, err error)
- func RetrieveRegularTxByHash(db *sql.DB, txHash string) (id uint64, blockHash string, blockInd uint32, err error)
- func RetrieveScriptTypejson(db *sql.DB, N, offset int64) (scriptTypejson *dbtypes.ScriptTypejson, err error)
- func RetrieveSpendingTxByTxOut(db *sql.DB, txHash string, voutIndex uint32) (id uint64, tx string, vin uint32, tree int8, err error)
- func RetrieveSpendingTxByVinID(db *sql.DB, vinDbID uint64) (tx string, voutIndex uint32, tree int8, err error)
- func RetrieveSpendingTxsByFundingTx(db *sql.DB, fundingTxID string) (dbIDs []uint64, txns []string, vinInds []uint32, voutInds []uint32, err error)
- func RetrieveStakeTxByHash(db *sql.DB, txHash string) (id uint64, blockHash string, blockInd uint32, err error)
- func RetrieveTicketPricejson(db *sql.DB) (*dbtypes.TicketPrice, error)
- func RetrieveTop100Address(db *sql.DB, N, offset int64) ([]uint64, []*dbtypes.TopAddressRow, error)
- func RetrieveTxByHash(db *sql.DB, txHash string) (id uint64, blockHash string, blockInd uint32, tree int8, err error)
- func RetrieveTxsByBlockHash(db *sql.DB, blockHash string) (ids []uint64, txs []string, blockInds []uint32, trees []int8, err error)
- func RetrieveVinByID(db *sql.DB, vinDbID uint64) (prevOutHash string, prevOutVoutInd uint32, prevOutTree int8, txHash string, ...)
- func RetrieveVoutIDByOutpoint(db *sql.DB, txHash string, voutIndex uint32) (id uint64, err error)
- func RetrieveVoutValue(db *sql.DB, txHash string, voutIndex uint32) (value uint64, err error)
- func RetrieveVoutValues(db *sql.DB, txHash string) (values []uint64, txInds []uint32, txTrees []int8, err error)
- func RetriveChartValue(db *sql.DB) (*dbtypes.ChartValue, error)
- func SetSpendingByVinID(db *sql.DB, vinDbID uint64, spendingTxDbID uint64, spendingTxHash string, ...) (int64, error)
- func SetSpendingForAddressDbID(db *sql.DB, addrDbID uint64, spendingTxDbID uint64, spendingTxHash string, ...) error
- func SetSpendingForFundingOP(db *sql.DB, fundingTxHash string, fundingTxVoutIndex uint32, ...) (int64, error)
- func SetSpendingForVinDbID(db *sql.DB, vinDbID uint64) (int64, error)
- func SetSpendingForVinDbIDs(db *sql.DB, vinDbIDs []uint64) ([]int64, int64, error)
- func TableExists(db *sql.DB, tableName string) (bool, error)
- func TableVersions(db *sql.DB) map[string]int32
- func TypeExists(db *sql.DB, tableName string) (bool, error)
- func UpdateBlockNext(db *sql.DB, blockDbID uint64, next string) error
- func UpdateFeesStatOneDay(db *sql.DB, day time.Time) (err error)
- func UpdateLastBlock(db *sql.DB, blockDbID uint64, isValid bool) error
- func UpdateMempoolHistory(db *sql.DB, t time.Time, size, bytes int64) (id int, err error)
- func UpdateMempoolHistoryKlineOneDay(db *sql.DB, day time.Time) (err error)
- func UseLogger(logger btclog.Logger)
- type ChainDB
- func (pgb *ChainDB) AddNode(Ip string) error
- func (pgb *ChainDB) AddressHistory(address string, N, offset int64) ([]*dbtypes.AddressRow, *explorer.AddressBalance, error)
- func (pgb *ChainDB) BlockTransactions(blockHash string) ([]string, []uint32, []int8, error)
- func (pgb *ChainDB) Close() error
- func (pgb *ChainDB) DeindexAddressTable() error
- func (pgb *ChainDB) DeindexAll() error
- func (pgb *ChainDB) DropTables()
- func (pgb *ChainDB) EnableDuplicateCheckOnInsert(dupCheck bool)
- func (pgb *ChainDB) FillAddressTransactions(addrInfo *explorer.AddressInfo) error
- func (pgb *ChainDB) GetBlockverjson() (*dbtypes.BlockVerJson, error)
- func (pgb *ChainDB) GetBloksizejson() (*dbtypes.BlocksizeJson, error)
- func (pgb *ChainDB) GetChartValue() (*dbtypes.ChartValue, error)
- func (pgb *ChainDB) GetDiff() ([]*dbtypes.DiffData, error)
- func (pgb *ChainDB) GetDiffChartData() ([]*dbtypes.DiffData, error)
- func (pgb *ChainDB) GetFeesStat() ([]*dbtypes.FeesStat, error)
- func (pgb *ChainDB) GetHashrateJson() (*dbtypes.HashRateJson, error)
- func (pgb *ChainDB) GetMempoolHistory() (h []*dbtypes.MempoolHistory, k []*dbtypes.MempoolHistory, err error)
- func (pgb *ChainDB) GetNodeInfo() ([]*dbtypes.NodeInfo, error)
- func (pgb *ChainDB) GetOPReturnChartData() (*dbtypes.OPReturnChartData, int, error)
- func (pgb *ChainDB) GetOPReturnListData(N, offset int64) ([]*dbtypes.OPReturnListData, error)
- func (pgb *ChainDB) GetScriptTypejson() (*dbtypes.ScriptTypejson, error)
- func (pgb *ChainDB) GetTicketPricejson() (*dbtypes.TicketPrice, error)
- func (pgb *ChainDB) GetTop100Addresses() ([]*dbtypes.TopAddressRow, error)
- func (pgb *ChainDB) Height() uint64
- func (pgb *ChainDB) HeightDB() (uint64, error)
- func (pgb *ChainDB) IndexAddressTable() error
- func (pgb *ChainDB) IndexAll() error
- func (pgb *ChainDB) SetupTables() error
- func (pgb *ChainDB) SpendingTransaction(fundingTxID string, fundingTxVout uint32) (string, uint32, int8, error)
- func (pgb *ChainDB) SpendingTransactions(fundingTxID string) ([]string, []uint32, []uint32, error)
- func (pgb *ChainDB) Store(_ *blockdata.BlockData, msgBlock *wire.MsgBlock) error
- func (pgb *ChainDB) StoreBlock(msgBlock *wire.MsgBlock, isValid, updateAddressesSpendingInfo bool) (numVins int64, numVouts int64, err error)
- func (pgb *ChainDB) SyncAddresses() error
- func (db *ChainDB) SyncChainDB(client *hcrpcclient.Client, quit chan struct{}, ...) (int64, error)
- func (db *ChainDB) SyncChainDBAsync(res chan dbtypes.SyncResult, client *hcrpcclient.Client, quit chan struct{}, ...)
- func (pgb *ChainDB) TransactionBlock(txID string) (string, uint32, int8, error)
- func (pgb *ChainDB) UpdateAddressBelong(address string, belong string) error
- func (pgb *ChainDB) UpdateFeesStatAndMempoolHistory(client *hcrpcclient.Client)
- func (pgb *ChainDB) UpdateNodeInfo(nodeClient *hcrpcclient.Client) error
- func (pgb *ChainDB) UpdateScriptInfo() error
- func (pgb *ChainDB) UpdateSpendingInfoInAllAddresses() (int64, error)
- func (pgb *ChainDB) VoutValue(txID string, vout uint32) (uint64, error)
- func (pgb *ChainDB) VoutValues(txID string) ([]uint64, []uint32, []int8, error)
- type DBInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
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 ¶
CreateTable creates one of the known tables by name
func CreateTables ¶
func CreateTypes ¶
func DeindexBlockTableOnHash ¶
func DeindexVinTableOnVins ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
func DropTables ¶
func IndexBlockTableOnHash ¶
func IndexVinTableOnPrevOuts ¶
func IndexVinTableOnVins ¶
func IndexVoutTableOnTxHash ¶
func InsertAddressOut ¶
func InsertAddressOuts ¶
func InsertBlock ¶
func InsertBlockPrevNext ¶
func InsertVins ¶
func InsertVouts ¶
func RetrieveAddressSpent ¶
func RetrieveAddressTxns ¶
func RetrieveAddressTxnsAlt ¶
func RetrieveAddressUnspent ¶
func RetrieveAllAddressTxns ¶
func RetrieveBestBlockHeight ¶
func RetrieveBlockVerJson ¶
func RetrieveBlockVerJson(db *sql.DB) (*dbtypes.BlockVerJson, error)
func RetrieveBlocksizejson ¶
func RetrieveDbTxByHash ¶
func RetrieveFeesStatLastDay ¶
update fees stat
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 RetrieveFundingTxByTxIn ¶
func RetrieveFundingTxsByTx ¶
func RetrieveHashratejson ¶
func RetrieveHashratejson(db *sql.DB) (*dbtypes.HashRateJson, error)
func RetrieveMempoolHistoryKline ¶
func RetrieveMempoolHistoryKline(db *sql.DB) (res []*dbtypes.MempoolHistory)
get mempool history kline
func RetrieveMempoolHistoryKlineLastDay ¶
update mempool history kline
func RetrieveMempoolRecentHistory ¶
func RetrieveMempoolRecentHistory(db *sql.DB) (res []*dbtypes.MempoolHistory)
get mempool history
func RetrievePkScriptByID ¶
func RetrieveRegularTxByHash ¶
func RetrieveScriptTypejson ¶
func RetrieveStakeTxByHash ¶
func RetrieveTicketPricejson ¶
func RetrieveTicketPricejson(db *sql.DB) (*dbtypes.TicketPrice, error)
func RetrieveTop100Address ¶
func RetrieveTxByHash ¶
func RetrieveTxsByBlockHash ¶
func RetrieveVinByID ¶
func RetrieveVoutValue ¶
func RetrieveVoutValues ¶
func RetriveChartValue ¶
func RetriveChartValue(db *sql.DB) (*dbtypes.ChartValue, error)
func SetSpendingByVinID ¶
func SetSpendingByVinID(db *sql.DB, vinDbID uint64, spendingTxDbID uint64, spendingTxHash string, spendingTxVinIndex uint32) (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 SetSpendingForFundingOP ¶
func SetSpendingForVinDbIDs ¶
func UpdateMempoolHistory ¶
update mempool history
Types ¶
type ChainDB ¶
type ChainDB struct {
// contains filtered or unexported fields
}
ChainDB provides an interface for storing and manipulating extracted blockchain data in a PostgreSQL database.
func NewChainDB ¶
NewChainDB constructs a ChainDB for the given connection and Hcd network parameters. By default, duplicate row checks on insertion are enabled.
func (*ChainDB) AddressHistory ¶
func (pgb *ChainDB) AddressHistory(address string, N, offset int64) ([]*dbtypes.AddressRow, *explorer.AddressBalance, error)
AddressHistory queries the database for all rows of the addresses table for the given address.
func (*ChainDB) BlockTransactions ¶
BlockTransactions retrieves all transactions in the specified block, their indexes in the block, their tree, and an error value.
func (*ChainDB) DeindexAddressTable ¶
DeindexAddressTable drops the vin ID and address column indexes for the address table.
func (*ChainDB) DeindexAll ¶
DeindexAll drops all of the indexes in all tables
func (*ChainDB) DropTables ¶
func (pgb *ChainDB) DropTables()
DropTables drops (deletes) all of the known hcexplorer tables.
func (*ChainDB) EnableDuplicateCheckOnInsert ¶
EnableDuplicateCheckOnInsert specifies whether SQL insertions should check for row conflicts (duplicates), and avoid adding or updating.
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) GetBlockverjson ¶
func (pgb *ChainDB) GetBlockverjson() (*dbtypes.BlockVerJson, error)
func (*ChainDB) GetBloksizejson ¶
func (pgb *ChainDB) GetBloksizejson() (*dbtypes.BlocksizeJson, error)
func (*ChainDB) GetChartValue ¶
func (pgb *ChainDB) GetChartValue() (*dbtypes.ChartValue, error)
func (*ChainDB) GetDiffChartData ¶
func (*ChainDB) GetHashrateJson ¶
func (pgb *ChainDB) GetHashrateJson() (*dbtypes.HashRateJson, error)
func (*ChainDB) GetMempoolHistory ¶
func (pgb *ChainDB) GetMempoolHistory() (h []*dbtypes.MempoolHistory, k []*dbtypes.MempoolHistory, err error)
func (*ChainDB) GetOPReturnChartData ¶
func (pgb *ChainDB) GetOPReturnChartData() (*dbtypes.OPReturnChartData, int, error)
func (*ChainDB) GetOPReturnListData ¶
func (pgb *ChainDB) GetOPReturnListData(N, offset int64) ([]*dbtypes.OPReturnListData, error)
func (*ChainDB) GetScriptTypejson ¶
func (pgb *ChainDB) GetScriptTypejson() (*dbtypes.ScriptTypejson, error)
func (*ChainDB) GetTicketPricejson ¶
func (pgb *ChainDB) GetTicketPricejson() (*dbtypes.TicketPrice, error)
func (*ChainDB) GetTop100Addresses ¶
func (pgb *ChainDB) GetTop100Addresses() ([]*dbtypes.TopAddressRow, error)
func (*ChainDB) IndexAddressTable ¶
IndexAddressTable creates the indexes on the address table on the vout ID and address columns, separately.
func (*ChainDB) SetupTables ¶
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 ¶
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) StoreBlock ¶
func (pgb *ChainDB) StoreBlock(msgBlock *wire.MsgBlock, isValid, updateAddressesSpendingInfo 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) SyncAddresses ¶
func (*ChainDB) SyncChainDB ¶
func (db *ChainDB) SyncChainDB(client *hcrpcclient.Client, quit chan struct{}, updateAllAddresses, 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 *hcrpcclient.Client, quit chan struct{}, updateAllAddresses, 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 ¶
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) UpdateAddressBelong ¶
func (*ChainDB) UpdateFeesStatAndMempoolHistory ¶
func (pgb *ChainDB) UpdateFeesStatAndMempoolHistory(client *hcrpcclient.Client)
update fees stat and mempool history
func (*ChainDB) UpdateNodeInfo ¶
func (pgb *ChainDB) UpdateNodeInfo(nodeClient *hcrpcclient.Client) error
func (*ChainDB) UpdateScriptInfo ¶
func (*ChainDB) UpdateSpendingInfoInAllAddresses ¶
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!).