db

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const FiatRatesTimeFormat = "20060102150405" // YYYYMMDDhhmmss

FiatRatesTimeFormat is a format string for storing FiatRates timestamps in rocksdb

Variables

View Source
var AssetCache map[uint32]bchain.Asset
View Source
var ErrOperationInterrupted = errors.New("ErrOperationInterrupted")

ErrOperationInterrupted is returned when operation is interrupted by OS signal

View Source
var SetupAssetCacheFirstTime bool = true

Functions

func FiatRatesConvertDate added in v0.3.4

func FiatRatesConvertDate(date string) (*time.Time, error)

FiatRatesConvertDate checks if the date is in correct format and returns the Time object. Possible formats are: YYYYMMDDhhmmss, YYYYMMDDhhmm, YYYYMMDDhh, YYYYMMDD

func RepairRocksDB

func RepairRocksDB(name string) error

RepairRocksDB calls RocksDb db repair function

Types

type AddrContract added in v0.2.0

type AddrContract struct {
	Contract bchain.AddressDescriptor
	Txs      uint
}

AddrContract is Contract address with number of transactions done by given address

type AddrContracts added in v0.2.0

type AddrContracts struct {
	TotalTxs       uint
	NonContractTxs uint
	Contracts      []AddrContract
}

AddrContracts contains number of transactions and contracts for an address

type BulkConnect added in v0.1.0

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 added in v0.1.0

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 added in v0.1.0

func (b *BulkConnect) ConnectBlock(block *bchain.Block, storeBlockTxs bool) error

ConnectBlock connects block in bulk mode

type CurrencyRatesTicker added in v0.3.4

type CurrencyRatesTicker struct {
	Timestamp *time.Time // return as unix timestamp in API
	Rates     map[string]float64
}

CurrencyRatesTicker contains coin ticker data fetched from API

type GetTransactionsCallback added in v0.2.0

type GetTransactionsCallback func(txid string, height uint32, indexes []int32) error

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 GetTxAssetsCallback added in v0.3.4

type GetTxAssetsCallback func(txids []string) error

GetTxAssetsCallback is called by GetTransactions/GetTxAssets for each found tx

type ResultTickerAsString added in v0.3.4

type ResultTickerAsString struct {
	Timestamp int64              `json:"ts,omitempty"`
	Rates     map[string]float64 `json:"rates"`
	Error     string             `json:"error,omitempty"`
}

ResultTickerAsString contains formatted CurrencyRatesTicker data

type ResultTickerListAsString added in v0.3.4

type ResultTickerListAsString struct {
	Timestamp int64    `json:"ts,omitempty"`
	Tickers   []string `json:"available_currencies"`
	Error     string   `json:"error,omitempty"`
}

ResultTickerListAsString contains formatted data about available currency tickers

type ResultTickersAsString added in v0.3.4

type ResultTickersAsString struct {
	Tickers []ResultTickerAsString `json:"tickers"`
}

ResultTickersAsString contains a formatted CurrencyRatesTicker list

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) (d *RocksDB, err error)

NewRocksDB opens an internal handle to RocksDB environment. Close needs to be called to release it.

func (*RocksDB) AddrDescForOutpoint added in v0.2.2

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

func (d *RocksDB) Close() error

Close releases the RocksDB environment opened in NewRocksDB.

func (*RocksDB) ComputeInternalStateColumnStats

func (d *RocksDB) ComputeInternalStateColumnStats(stopCompute chan os.Signal) error

ComputeInternalStateColumnStats computes stats of all db columns and sets them to internal state can be very slow operation

func (*RocksDB) ConnectAllocationInput added in v0.3.5

func (d *RocksDB) ConnectAllocationInput(addrDesc *bchain.AddressDescriptor, balanceAsset *bchain.AssetBalance, btxID []byte, assetInfo *bchain.AssetInfo, blockTxAssetAddresses bchain.TxAssetAddressMap) error

func (*RocksDB) ConnectAllocationOutput added in v0.3.5

func (d *RocksDB) ConnectAllocationOutput(addrDesc *bchain.AddressDescriptor, height uint32, balanceAsset *bchain.AssetBalance, isActivate bool, version int32, btxID []byte, assetInfo *bchain.AssetInfo, assets map[uint32]*bchain.Asset, txAssets bchain.TxAssetMap, blockTxAssetAddresses bchain.TxAssetAddressMap) error

func (*RocksDB) ConnectAssetOutput added in v0.3.4

func (d *RocksDB) ConnectAssetOutput(asset *bchain.Asset, isActivate bool, isAssetTx bool, isAssetSendTx bool, assets map[uint32]*bchain.Asset, mapAssetsIn bchain.AssetsMap) error

func (*RocksDB) ConnectAssetOutputHelper added in v0.3.5

func (d *RocksDB) ConnectAssetOutputHelper(isActivate bool, asset *bchain.Asset, dBAsset *bchain.Asset) error

func (*RocksDB) ConnectBlock

func (d *RocksDB) ConnectBlock(block *bchain.Block) error

ConnectBlock indexes addresses in the block and stores them in db

func (*RocksDB) DatabaseSizeOnDisk

func (d *RocksDB) DatabaseSizeOnDisk() int64

DatabaseSizeOnDisk returns size of the database in bytes

func (*RocksDB) DeleteTx

func (d *RocksDB) DeleteTx(txid string) error

DeleteTx removes transactions from db

func (*RocksDB) DisconnectAllocationInput added in v0.3.5

func (d *RocksDB) DisconnectAllocationInput(addrDesc *bchain.AddressDescriptor, balanceAsset *bchain.AssetBalance, btxID []byte, assetInfo *bchain.AssetInfo, blockTxAssetAddresses bchain.TxAssetAddressMap, assets map[uint32]*bchain.Asset, assetFoundInTx func(asset uint32, btxID []byte) bool) error

func (*RocksDB) DisconnectAllocationOutput added in v0.3.5

func (d *RocksDB) DisconnectAllocationOutput(addrDesc *bchain.AddressDescriptor, balanceAsset *bchain.AssetBalance, btxID []byte, assetInfo *bchain.AssetInfo, blockTxAssetAddresses bchain.TxAssetAddressMap) error

func (*RocksDB) DisconnectAssetOutput added in v0.3.4

func (d *RocksDB) DisconnectAssetOutput(asset *bchain.Asset, isActivate bool, isAssetSendTx bool, assets map[uint32]*bchain.Asset, mapAssetsIn bchain.AssetsMap) error

func (*RocksDB) DisconnectAssetOutputHelper added in v0.3.5

func (d *RocksDB) DisconnectAssetOutputHelper(asset *bchain.Asset, dBAsset *bchain.Asset) error

func (*RocksDB) DisconnectBlockRangeBitcoinType added in v0.2.0

func (d *RocksDB) DisconnectBlockRangeBitcoinType(lower uint32, higher uint32) error

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 added in v0.2.0

func (d *RocksDB) DisconnectBlockRangeEthereumType(lower uint32, higher uint32) error

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 added in v0.3.4

func (d *RocksDB) FiatRatesFindLastTicker() (*CurrencyRatesTicker, error)

FiatRatesFindLastTicker gets the last FiatRates record

func (*RocksDB) FiatRatesFindTicker added in v0.3.4

func (d *RocksDB) FiatRatesFindTicker(tickerTime *time.Time) (*CurrencyRatesTicker, error)

FiatRatesFindTicker gets FiatRates data closest to the specified timestamp

func (*RocksDB) FiatRatesStoreTicker added in v0.3.4

func (d *RocksDB) FiatRatesStoreTicker(ticker *CurrencyRatesTicker) error

FiatRatesStoreTicker stores ticker data at the specified time

func (*RocksDB) FixUtxos added in v0.3.4

func (d *RocksDB) FixUtxos(stop chan os.Signal) error

FixUtxos checks and fixes possible

func (*RocksDB) GetAddrDescBalance added in v0.1.0

func (d *RocksDB) GetAddrDescBalance(addrDesc bchain.AddressDescriptor, detail bchain.AddressBalanceDetail) (*bchain.AddrBalance, error)

GetAddrDescBalance returns AddrBalance for given addrDesc

func (*RocksDB) GetAddrDescContracts added in v0.2.0

func (d *RocksDB) GetAddrDescContracts(addrDesc bchain.AddressDescriptor) (*AddrContracts, error)

GetAddrDescContracts returns AddrContracts for given addrDesc

func (*RocksDB) GetAddrDescTransactions added in v0.1.0

func (d *RocksDB) GetAddrDescTransactions(addrDesc bchain.AddressDescriptor, lower uint32, higher uint32, assetsBitMask bchain.AssetsMask, 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) GetAddressBalance added in v0.1.0

func (d *RocksDB) GetAddressBalance(address string, detail bchain.AddressBalanceDetail) (*bchain.AddrBalance, error)

GetAddressBalance returns address balance for an address or nil if address not found

func (*RocksDB) GetAndResetConnectBlockStats added in v0.1.0

func (d *RocksDB) GetAndResetConnectBlockStats() string

GetAndResetConnectBlockStats gets statistics about cache usage in connect blocks and resets the counters

func (*RocksDB) GetAsset added in v0.3.4

func (d *RocksDB) GetAsset(guid uint32, assets map[uint32]*bchain.Asset) (*bchain.Asset, error)

func (*RocksDB) GetAssetCache added in v0.3.5

func (d *RocksDB) GetAssetCache() *map[uint32]bchain.Asset

func (*RocksDB) GetBestBlock

func (d *RocksDB) GetBestBlock() (uint32, string, error)

GetBestBlock returns the block hash of the block with highest height in the db

func (*RocksDB) GetBlockHash

func (d *RocksDB) GetBlockHash(height uint32) (string, error)

GetBlockHash returns block hash at given height or empty string if not found

func (*RocksDB) GetBlockInfo added in v0.1.0

func (d *RocksDB) GetBlockInfo(height uint32) (*bchain.DbBlockInfo, error)

GetBlockInfo returns block info stored in db

func (*RocksDB) GetMemoryStats added in v0.1.0

func (d *RocksDB) GetMemoryStats() string

GetMemoryStats returns memory usage statistics as reported by RocksDB

func (*RocksDB) GetSetupAssetCacheFirstTime added in v0.3.5

func (d *RocksDB) GetSetupAssetCacheFirstTime() bool

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

func (d *RocksDB) GetTx(txid string) (*bchain.Tx, uint32, error)

GetTx returns transaction stored in db and height of the block containing it

func (*RocksDB) GetTxAddresses added in v0.1.0

func (d *RocksDB) GetTxAddresses(txid string) (*bchain.TxAddresses, error)

GetTxAddresses returns TxAddresses for given txid or nil if not found

func (*RocksDB) GetTxAssets added in v0.3.4

func (d *RocksDB) GetTxAssets(assetGuid uint32, lower uint32, higher uint32, assetsBitMask bchain.AssetsMask, fn GetTxAssetsCallback) (err error)

GetTxAssets finds all asset transactions for each asset Transaction are passed to callback function in the order from newest block to the oldest

func (*RocksDB) InitBulkConnect added in v0.1.0

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

func (d *RocksDB) PutTx(tx *bchain.Tx, height uint32, blockTime int64) error

PutTx stores transactions in db

func (*RocksDB) Reopen

func (d *RocksDB) Reopen() error

Reopen reopens the database It closes and reopens db, nobody can access the database during the operation!

func (*RocksDB) SetInconsistentState added in v0.1.0

func (d *RocksDB) SetInconsistentState(inconsistent bool) error

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) SetSetupAssetCacheFirstTime added in v0.3.5

func (d *RocksDB) SetSetupAssetCacheFirstTime(cacheVal bool)

func (*RocksDB) SetupAssetCache added in v0.3.4

func (d *RocksDB) SetupAssetCache() error

func (*RocksDB) StoreInternalState

func (d *RocksDB) StoreInternalState(is *common.InternalState) error

StoreInternalState stores the internal state to db

type StopIteration added in v0.1.0

type StopIteration struct{}

StopIteration is returned by callback function to signal stop of iteration

func (*StopIteration) Error added in v0.1.0

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

func (*TxCache) GetTransaction

func (c *TxCache) GetTransaction(txid string) (*bchain.Tx, int, error)

GetTransaction returns transaction either from RocksDB or if not present from blockchain it the transaction is confirmed, it is stored in the RocksDB

Jump to

Keyboard shortcuts

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