Documentation
¶
Index ¶
- Constants
- Variables
- func RepairRocksDB(name string) error
- type AddrBalance
- type AddrContract
- type AddrContracts
- type AddressBalanceDetail
- type AggregateFn
- type BlockInfo
- type BlockInternalDataError
- type BulkConnect
- type GetTransactionsCallback
- type Ids
- type MultiTokenValues
- type RocksDB
- func (d *RocksDB) AddrDescForOutpoint(outpoint bchain.Outpoint) (bchain.AddressDescriptor, *big.Int)
- func (d *RocksDB) Close() error
- func (d *RocksDB) ComputeInternalStateColumnStats(stopCompute chan os.Signal) error
- func (d *RocksDB) ConnectBlock(block *bchain.Block) error
- func (d *RocksDB) DatabaseSizeOnDisk() int64
- func (d *RocksDB) DeleteTx(txid string) error
- func (d *RocksDB) DisconnectBlockRangeBitcoinType(lower uint32, higher uint32) error
- func (d *RocksDB) DisconnectBlockRangeEthereumType(lower uint32, higher uint32) error
- func (d *RocksDB) FiatRatesFindLastTicker(vsCurrency string, token string) (*common.CurrencyRatesTicker, error)
- func (d *RocksDB) FiatRatesFindTicker(tickerTime *time.Time, vsCurrency string, token string) (*common.CurrencyRatesTicker, error)
- func (d *RocksDB) FiatRatesGetAllTickers(fn func(ticker *common.CurrencyRatesTicker) error) error
- func (d *RocksDB) FiatRatesGetSpecialTickers(key string) (*[]common.CurrencyRatesTicker, error)
- func (d *RocksDB) FiatRatesGetTicker(tickerTime *time.Time) (*common.CurrencyRatesTicker, error)
- func (d *RocksDB) FiatRatesStoreSpecialTickers(key string, tickers *[]common.CurrencyRatesTicker) error
- func (d *RocksDB) FiatRatesStoreTicker(wb *grocksdb.WriteBatch, ticker *common.CurrencyRatesTicker) error
- func (d *RocksDB) FixUtxos(stop chan os.Signal) error
- func (d *RocksDB) GetAddrDescBalance(addrDesc bchain.AddressDescriptor, detail AddressBalanceDetail) (*AddrBalance, error)
- func (d *RocksDB) GetAddrDescContracts(addrDesc bchain.AddressDescriptor) (*AddrContracts, error)
- func (d *RocksDB) GetAddrDescTransactions(addrDesc bchain.AddressDescriptor, lower uint32, higher uint32, ...) (err error)
- func (d *RocksDB) GetAddressAlias(address string) string
- func (d *RocksDB) GetAddressBalance(address string, detail AddressBalanceDetail) (*AddrBalance, error)
- func (d *RocksDB) GetAndResetConnectBlockStats() string
- func (d *RocksDB) GetBestBlock() (uint32, string, error)
- func (d *RocksDB) GetBlockHash(height uint32) (string, error)
- func (d *RocksDB) GetBlockInfo(height uint32) (*BlockInfo, error)
- func (d *RocksDB) GetBlockInternalDataErrorsEthereumType() ([]BlockInternalDataError, error)
- func (d *RocksDB) GetContractInfo(contract bchain.AddressDescriptor, typeFromContext bchain.TokenTypeName) (*bchain.ContractInfo, error)
- func (d *RocksDB) GetContractInfoForAddress(address string) (*bchain.ContractInfo, error)
- func (d *RocksDB) GetEthereumInternalData(txid string) (*bchain.EthereumInternalData, error)
- func (d *RocksDB) GetFourByteSignature(fourBytes uint32, id uint32) (*bchain.FourByteSignature, error)
- func (d *RocksDB) GetFourByteSignatures(fourBytes uint32) (*[]bchain.FourByteSignature, error)
- func (d *RocksDB) GetInternalState() *common.InternalState
- func (d *RocksDB) GetMemoryStats() string
- func (d *RocksDB) GetTransactions(address string, lower uint32, higher uint32, fn GetTransactionsCallback) (err error)
- func (d *RocksDB) GetTx(txid string) (*bchain.Tx, uint32, error)
- func (d *RocksDB) GetTxAddresses(txid string) (*TxAddresses, error)
- func (d *RocksDB) HasExtendedIndex() bool
- func (d *RocksDB) InitAddressAliasRecords() (int, error)
- func (d *RocksDB) InitBulkConnect() (*BulkConnect, error)
- func (d *RocksDB) LoadInternalState(rpcCoin string) (*common.InternalState, error)
- func (d *RocksDB) PutTx(tx *bchain.Tx, height uint32, blockTime int64) error
- func (d *RocksDB) ReconnectInternalDataToBlockEthereumType(block *bchain.Block) error
- func (d *RocksDB) Reopen() error
- func (d *RocksDB) SetInconsistentState(inconsistent bool) error
- func (d *RocksDB) SetInternalState(is *common.InternalState)
- func (d *RocksDB) SortAddressContracts(stop chan os.Signal) error
- func (d *RocksDB) StoreBlockInternalDataErrorEthereumType(wb *grocksdb.WriteBatch, block *bchain.Block, message string, retryCount uint8) error
- func (d *RocksDB) StoreContractInfo(contractInfo *bchain.ContractInfo) error
- func (d *RocksDB) StoreFourByteSignature(wb *grocksdb.WriteBatch, fourBytes uint32, id uint32, ...) error
- func (d *RocksDB) StoreInternalState(is *common.InternalState) error
- func (d *RocksDB) WriteBatch(wb *grocksdb.WriteBatch) error
- type StopIteration
- type SyncWorker
- type TxAddresses
- type TxCache
- type TxInput
- type TxOutput
- type Utxo
Constants ¶
const ( // AddressBalanceDetailNoUTXO returns address balance without utxos AddressBalanceDetailNoUTXO = 0 // AddressBalanceDetailUTXO returns address balance with utxos AddressBalanceDetailUTXO = 1 )
const ContractIndexOffset = 2
const FiatRatesTimeFormat = "20060102150405" // YYYYMMDDhhmmss
FiatRatesTimeFormat is a format string for storing FiatRates timestamps in rocksdb
const InternalTxIndexOffset = 1
Variables ¶
var ErrOperationInterrupted = errors.New("ErrOperationInterrupted")
ErrOperationInterrupted is returned when operation is interrupted by OS signal
Functions ¶
func RepairRocksDB ¶
RepairRocksDB calls RocksDb db repair function
Types ¶
type AddrBalance ¶
type AddrBalance struct { Txs uint32 SentSat big.Int BalanceSat big.Int Utxos []Utxo // contains filtered or unexported fields }
AddrBalance stores number of transactions and balances of an address
func (*AddrBalance) ReceivedSat ¶
func (ab *AddrBalance) ReceivedSat() *big.Int
ReceivedSat computes received amount from total balance and sent amount
type AddrContract ¶
type AddrContract struct { Type bchain.TokenType Contract bchain.AddressDescriptor Txs uint Value big.Int // single value of ERC20 Ids Ids // multiple ERC721 tokens MultiTokenValues MultiTokenValues // multiple ERC1155 tokens }
AddrContract is Contract address with number of transactions done by given address
type AddrContracts ¶
type AddrContracts struct { TotalTxs uint NonContractTxs uint InternalTxs uint Contracts []AddrContract }
AddrContracts contains number of transactions and contracts for an address
type AddressBalanceDetail ¶
type AddressBalanceDetail int
AddressBalanceDetail specifies what data are returned by GetAddressBalance
type BlockInfo ¶
type BlockInfo struct { Hash string Time int64 Txs uint32 Size uint32 Height uint32 // Height is not packed! }
BlockInfo holds information about blocks kept in column height
type BlockInternalDataError ¶
type BulkConnect ¶
type BulkConnect struct {
// contains filtered or unexported fields
}
BulkConnect is used to connect blocks in bulk, faster but if interrupted inconsistent way
func (*BulkConnect) Close ¶
func (b *BulkConnect) Close() error
Close flushes the cached data and switches DB from inconsistent state open after Close, the BulkConnect cannot be used
func (*BulkConnect) ConnectBlock ¶
func (b *BulkConnect) ConnectBlock(block *bchain.Block, storeBlockTxs bool) error
ConnectBlock connects block in bulk mode
type GetTransactionsCallback ¶
GetTransactionsCallback is called by GetTransactions/GetAddrDescTransactions for each found tx indexes contain array of indexes (input negative, output positive) in tx where is given address
type MultiTokenValues ¶
type MultiTokenValues []bchain.MultiTokenValue
type RocksDB ¶
type RocksDB struct {
// contains filtered or unexported fields
}
RocksDB handle
func NewRocksDB ¶
func NewRocksDB(path string, cacheSize, maxOpenFiles int, parser bchain.BlockChainParser, metrics *common.Metrics, extendedIndex bool) (d *RocksDB, err error)
NewRocksDB opens an internal handle to RocksDB environment. Close needs to be called to release it.
func (*RocksDB) AddrDescForOutpoint ¶
func (d *RocksDB) AddrDescForOutpoint(outpoint bchain.Outpoint) (bchain.AddressDescriptor, *big.Int)
AddrDescForOutpoint is a function that returns address descriptor and value for given outpoint or nil if outpoint not found
func (*RocksDB) ComputeInternalStateColumnStats ¶
ComputeInternalStateColumnStats computes stats of all db columns and sets them to internal state can be very slow operation
func (*RocksDB) ConnectBlock ¶
ConnectBlock indexes addresses in the block and stores them in db
func (*RocksDB) DatabaseSizeOnDisk ¶
DatabaseSizeOnDisk returns size of the database in bytes
func (*RocksDB) DisconnectBlockRangeBitcoinType ¶
DisconnectBlockRangeBitcoinType removes all data belonging to blocks in range lower-higher it is able to disconnect only blocks for which there are data in the blockTxs column
func (*RocksDB) DisconnectBlockRangeEthereumType ¶
DisconnectBlockRangeEthereumType removes all data belonging to blocks in range lower-higher it is able to disconnect only blocks for which there are data in the blockTxs column
func (*RocksDB) FiatRatesFindLastTicker ¶
func (d *RocksDB) FiatRatesFindLastTicker(vsCurrency string, token string) (*common.CurrencyRatesTicker, error)
FiatRatesFindLastTicker gets the last FiatRates record, of the base currency, vsCurrency or the token if specified
func (*RocksDB) FiatRatesFindTicker ¶
func (d *RocksDB) FiatRatesFindTicker(tickerTime *time.Time, vsCurrency string, token string) (*common.CurrencyRatesTicker, error)
FiatRatesFindTicker gets FiatRates data closest to the specified timestamp, of the base currency, vsCurrency or the token if specified
func (*RocksDB) FiatRatesGetAllTickers ¶
func (d *RocksDB) FiatRatesGetAllTickers(fn func(ticker *common.CurrencyRatesTicker) error) error
FiatRatesGetAllTickers gets FiatRates data closest to the specified timestamp, of the base currency, vsCurrency or the token if specified
func (*RocksDB) FiatRatesGetSpecialTickers ¶
func (d *RocksDB) FiatRatesGetSpecialTickers(key string) (*[]common.CurrencyRatesTicker, error)
func (*RocksDB) FiatRatesGetTicker ¶
FiatRatesGetTicker gets FiatRates ticker at the specified timestamp if it exist
func (*RocksDB) FiatRatesStoreSpecialTickers ¶
func (d *RocksDB) FiatRatesStoreSpecialTickers(key string, tickers *[]common.CurrencyRatesTicker) error
func (*RocksDB) FiatRatesStoreTicker ¶
func (d *RocksDB) FiatRatesStoreTicker(wb *grocksdb.WriteBatch, ticker *common.CurrencyRatesTicker) error
FiatRatesStoreTicker stores ticker data at the specified time
func (*RocksDB) GetAddrDescBalance ¶
func (d *RocksDB) GetAddrDescBalance(addrDesc bchain.AddressDescriptor, detail AddressBalanceDetail) (*AddrBalance, error)
GetAddrDescBalance returns AddrBalance for given addrDesc
func (*RocksDB) GetAddrDescContracts ¶
func (d *RocksDB) GetAddrDescContracts(addrDesc bchain.AddressDescriptor) (*AddrContracts, error)
GetAddrDescContracts returns AddrContracts for given addrDesc
func (*RocksDB) GetAddrDescTransactions ¶
func (d *RocksDB) GetAddrDescTransactions(addrDesc bchain.AddressDescriptor, lower uint32, higher uint32, fn GetTransactionsCallback) (err error)
GetAddrDescTransactions finds all input/output transactions for address descriptor Transaction are passed to callback function in the order from newest block to the oldest
func (*RocksDB) GetAddressAlias ¶
func (*RocksDB) GetAddressBalance ¶
func (d *RocksDB) GetAddressBalance(address string, detail AddressBalanceDetail) (*AddrBalance, error)
GetAddressBalance returns address balance for an address or nil if address not found
func (*RocksDB) GetAndResetConnectBlockStats ¶
GetAndResetConnectBlockStats gets statistics about cache usage in connect blocks and resets the counters
func (*RocksDB) GetBestBlock ¶
GetBestBlock returns the block hash of the block with highest height in the db
func (*RocksDB) GetBlockHash ¶
GetBlockHash returns block hash at given height or empty string if not found
func (*RocksDB) GetBlockInfo ¶
GetBlockInfo returns block info stored in db
func (*RocksDB) GetBlockInternalDataErrorsEthereumType ¶
func (d *RocksDB) GetBlockInternalDataErrorsEthereumType() ([]BlockInternalDataError, error)
func (*RocksDB) GetContractInfo ¶
func (d *RocksDB) GetContractInfo(contract bchain.AddressDescriptor, typeFromContext bchain.TokenTypeName) (*bchain.ContractInfo, error)
GetContractInfo gets contract from cache or DB and possibly updates the type from typeFromContext it is hard to guess the type of the contract using API, it is easier to set it the first time the contract is processed in a tx
func (*RocksDB) GetContractInfoForAddress ¶
func (d *RocksDB) GetContractInfoForAddress(address string) (*bchain.ContractInfo, error)
func (*RocksDB) GetEthereumInternalData ¶
func (d *RocksDB) GetEthereumInternalData(txid string) (*bchain.EthereumInternalData, error)
GetEthereumInternalData gets transaction internal data from DB
func (*RocksDB) GetFourByteSignature ¶
func (d *RocksDB) GetFourByteSignature(fourBytes uint32, id uint32) (*bchain.FourByteSignature, error)
GetFourByteSignature gets all 4byte signature of given fourBytes and id
func (*RocksDB) GetFourByteSignatures ¶
func (d *RocksDB) GetFourByteSignatures(fourBytes uint32) (*[]bchain.FourByteSignature, error)
GetFourByteSignatures gets all 4byte signatures of given fourBytes (there may be more than one signature starting with the same four bytes)
func (*RocksDB) GetInternalState ¶
func (d *RocksDB) GetInternalState() *common.InternalState
GetInternalState gets the InternalState
func (*RocksDB) GetMemoryStats ¶
GetMemoryStats returns memory usage statistics as reported by RocksDB
func (*RocksDB) GetTransactions ¶
func (d *RocksDB) GetTransactions(address string, lower uint32, higher uint32, fn GetTransactionsCallback) (err error)
GetTransactions finds all input/output transactions for address Transaction are passed to callback function.
func (*RocksDB) GetTx ¶
GetTx returns transaction stored in db and height of the block containing it
func (*RocksDB) GetTxAddresses ¶
func (d *RocksDB) GetTxAddresses(txid string) (*TxAddresses, error)
GetTxAddresses returns TxAddresses for given txid or nil if not found
func (*RocksDB) HasExtendedIndex ¶
HasExtendedIndex returns true if the DB indexes input txids and spending data
func (*RocksDB) InitAddressAliasRecords ¶
InitAddressAliasRecords loads all records to cache
func (*RocksDB) InitBulkConnect ¶
func (d *RocksDB) InitBulkConnect() (*BulkConnect, error)
InitBulkConnect initializes bulk connect and switches DB to inconsistent state
func (*RocksDB) LoadInternalState ¶
func (d *RocksDB) LoadInternalState(rpcCoin string) (*common.InternalState, error)
LoadInternalState loads from db internal state or initializes a new one if not yet stored
func (*RocksDB) ReconnectInternalDataToBlockEthereumType ¶
ReconnectInternalDataToBlockEthereumType adds missing internal data to the block and stores them in db
func (*RocksDB) Reopen ¶
Reopen reopens the database It closes and reopens db, nobody can access the database during the operation!
func (*RocksDB) SetInconsistentState ¶
SetInconsistentState sets the internal state to DbStateInconsistent or DbStateOpen based on inconsistent parameter db in left in DbStateInconsistent state cannot be used and must be recreated
func (*RocksDB) SetInternalState ¶
func (d *RocksDB) SetInternalState(is *common.InternalState)
SetInternalState sets the InternalState to be used by db to collect internal state
func (*RocksDB) SortAddressContracts ¶
func (*RocksDB) StoreBlockInternalDataErrorEthereumType ¶
func (*RocksDB) StoreContractInfo ¶
func (d *RocksDB) StoreContractInfo(contractInfo *bchain.ContractInfo) error
StoreContractInfo stores contractInfo in DB if CreatedInBlock==0 and DestructedInBlock!=0, it is evaluated as a destruction of a contract, the contract info is updated in all other cases the contractInfo overwrites previously stored data in DB (however it should not really happen as contract is created only once)
func (*RocksDB) StoreFourByteSignature ¶
func (d *RocksDB) StoreFourByteSignature(wb *grocksdb.WriteBatch, fourBytes uint32, id uint32, signature *bchain.FourByteSignature) error
StoreFourByteSignature stores 4byte signature in DB
func (*RocksDB) StoreInternalState ¶
func (d *RocksDB) StoreInternalState(is *common.InternalState) error
StoreInternalState stores the internal state to db
func (*RocksDB) WriteBatch ¶
func (d *RocksDB) WriteBatch(wb *grocksdb.WriteBatch) error
type StopIteration ¶
type StopIteration struct{}
StopIteration is returned by callback function to signal stop of iteration
func (*StopIteration) Error ¶
func (e *StopIteration) Error() string
type SyncWorker ¶
type SyncWorker struct {
// contains filtered or unexported fields
}
SyncWorker is handle to SyncWorker
func NewSyncWorker ¶
func NewSyncWorker(db *RocksDB, chain bchain.BlockChain, syncWorkers, syncChunk int, minStartHeight int, dryRun bool, chanOsSignal chan os.Signal, metrics *common.Metrics, is *common.InternalState) (*SyncWorker, error)
NewSyncWorker creates new SyncWorker and returns its handle
func (*SyncWorker) ConnectBlocksParallel ¶
func (w *SyncWorker) ConnectBlocksParallel(lower, higher uint32) error
ConnectBlocksParallel uses parallel goroutines to get data from blockchain daemon
func (*SyncWorker) DisconnectBlocks ¶
func (w *SyncWorker) DisconnectBlocks(lower uint32, higher uint32, hashes []string) error
DisconnectBlocks removes all data belonging to blocks in range lower-higher,
func (*SyncWorker) ResyncIndex ¶
func (w *SyncWorker) ResyncIndex(onNewBlock bchain.OnNewBlockFunc, initialSync bool) error
ResyncIndex synchronizes index to the top of the blockchain onNewBlock is called when new block is connected, but not in initial parallel sync
type TxAddresses ¶
type TxAddresses struct { Height uint32 Inputs []TxInput Outputs []TxOutput // extended index properties VSize uint32 }
TxAddresses stores transaction inputs and outputs with amounts
type TxCache ¶
type TxCache struct {
// contains filtered or unexported fields
}
TxCache is handle to TxCacheServer
func NewTxCache ¶
func NewTxCache(db *RocksDB, chain bchain.BlockChain, metrics *common.Metrics, is *common.InternalState, enabled bool) (*TxCache, error)
NewTxCache creates new TxCache interface and returns its handle
type TxInput ¶
type TxInput struct { AddrDesc bchain.AddressDescriptor ValueSat big.Int // extended index properties Txid string Vout uint32 }
TxInput holds input data of the transaction in TxAddresses