Documentation
¶
Index ¶
- Constants
- Variables
- func EthStoreConfig() *storeConfig
- func RequireContinuous(slice []*EpochData, currentEpoch uint64) error
- func StoreConfig() *storeConfig
- type Block
- type BlockExtra
- type BlockSummary
- type CacheStore
- type Configurable
- type EpochData
- type EpochDataOpAffects
- type EpochDataOpNumAlters
- type EpochDataType
- type EpochOpType
- type EpochRemoveOption
- type EthData
- type Log
- type LogExtra
- type LogFilter
- type LogFilterType
- type LogSlice
- type Prunable
- type Readable
- type ReceiptExtra
- type StackOperable
- type Store
- type StoreDisabler
- type Transaction
- type TransactionExtra
- type TransactionReceipt
- type VariadicValue
Constants ¶
const ( // Log filter constants MaxLogBlockHashesSize int = 128 MaxLogEpochRange uint64 = 1000 MaxLogBlockRange uint64 = 1000 MaxLogLimit uint64 = 10000 // adjust max log limit accordingly // Log filter types LogFilterTypeBlockHash LogFilterType = 1 << iota // 0001 LogFilterTypeEpochRange // 0010 LogFilterTypeBlockRange // 0100 )
const ( EpochRemoveAll EpochRemoveOption = 0xff EpochRemoveBlock = 0x01 << 0 EpochRemoveTransaction = 0x01 << 1 EpochRemoveLog = 0x01 << 2 )
Variables ¶
var ( TimeoutGetLogs = 3 * time.Second ErrGetLogsQuerySetTooLarge = errors.New( "query set is too large, please narrow down your filter condition", ) ErrGetLogsResultSetTooLarge = errors.Errorf( "result set to be queried is too large with more than %v logs, %v", MaxLogLimit, "please narrow down your filter condition", ) ErrGetLogsTimeout = errors.Errorf( "query timeout with duration exceeds %v(s)", TimeoutGetLogs, ) )
var ( // custom errors ErrNotFound = errors.New("not found") ErrUnsupported = errors.New("not supported") ErrEpochPivotSwitched = errors.New("epoch pivot switched") ErrContinousEpochRequired = errors.New("continous epoch required") ErrAlreadyPruned = errors.New("data already pruned") ErrChainReorged = errors.New("chain re-orged") // operationable epoch data types OpEpochDataTypes = []EpochDataType{ EpochBlock, EpochTransaction, EpochLog, } )
Functions ¶
func EthStoreConfig ¶
func EthStoreConfig() *storeConfig
func RequireContinuous ¶
func StoreConfig ¶
func StoreConfig() *storeConfig
Types ¶
type Block ¶
type Block struct {
CfxBlock *types.Block
Extra *BlockExtra
}
type BlockExtra ¶
type BlockExtra struct {
// extended fields for ETH block
BaseFeePerGas *hexutil.Big `json:"baseFeePerGas,omitempty"`
MixHash *common.Hash `json:"mixHash,omitempty"`
TotalDifficulty *hexutil.Big `json:"totalDifficulty,omitempty"`
Sha3Uncles *common.Hash `json:"sha3Uncles,omitempty"`
TxnExts []*TransactionExtra `json:"-"`
}
custom block fields for extention
func ExtractEthBlockExt ¶
func ExtractEthBlockExt(ethBlock *web3Types.Block) *BlockExtra
type BlockSummary ¶
type BlockSummary struct {
CfxBlockSummary *types.BlockSummary
Extra *BlockExtra
}
type CacheStore ¶
type Configurable ¶
type EpochData ¶
type EpochData struct {
Number uint64 // epoch number
Blocks []*types.Block // blocks in order and the last one is pivot block
Receipts map[types.Hash]*types.TransactionReceipt
// custom extra extentions
BlockExts []*BlockExtra
ReceiptExts map[types.Hash]*ReceiptExtra
}
EpochData wraps the blockchain data of an epoch.
func QueryEpochData ¶
QueryEpochData queries blockchain data for the specified epoch number.
func (*EpochData) GetPivotBlock ¶
type EpochDataOpAffects ¶
type EpochDataOpAffects struct {
OpType EpochOpType // op type
PushUpFromEpoch uint64 // for push op
PushUpToEpoch uint64 // for push op
PopUntilEpoch uint64 // for pop op
DequeueUntilEpoch uint64 // for dequeue op
NumAlters EpochDataOpNumAlters // num of adds/deletes for epoch op
}
EpochDataOpAffects to record affects for epoch data op
func NewEpochDataOpAffects ¶
func NewEpochDataOpAffects(opType EpochOpType, opEpochs ...uint64) *EpochDataOpAffects
func (EpochDataOpAffects) Merge ¶
func (affects EpochDataOpAffects) Merge(na EpochDataOpNumAlters)
Merge merges operation history into the receiver
func (EpochDataOpAffects) String ¶
func (affects EpochDataOpAffects) String() string
type EpochDataOpNumAlters ¶
type EpochDataOpNumAlters map[EpochDataType]int64
EpochDataOpNumAlters to record num of alters (add or delete) for epoch data op
type EpochDataType ¶
type EpochDataType uint
Epoch data type
const ( EpochDataNil EpochDataType = iota EpochTransaction EpochLog EpochBlock )
func (EpochDataType) Name ¶
func (edt EpochDataType) Name() string
func (EpochDataType) ToDequeOption ¶
func (edt EpochDataType) ToDequeOption() EpochOpType
func (EpochDataType) ToRemoveOption ¶
func (edt EpochDataType) ToRemoveOption() EpochRemoveOption
type EpochOpType ¶
type EpochOpType uint8
Epoch data operation type
const ( EpochOpPush EpochOpType = iota + 1 EpochOpPop EpochOpDequeueBlock EpochOpDequeueTx EpochOpDequeueLog )
type EthData ¶
type EthData struct {
Number uint64 // block number
Block *web3Types.Block // block body
Receipts map[common.Hash]*web3Types.Receipt // receipts
}
EthData wraps the evm space blockchain data.
func QueryEthData ¶
QueryEthData queries blockchain data for the specified block number.
type Log ¶
type LogExtra ¶
type LogExtra struct {
// extended fields for ETH log
LogType *string `json:"logType,omitempty"`
Removed *bool `json:"removed,,omitempty"`
}
custom event log fields for extention
func ExtractEthLogExt ¶
type LogFilter ¶
type LogFilter struct {
BlockFrom uint64
BlockTo uint64
Contracts VariadicValue
Topics []VariadicValue // event hash and indexed data 1, 2, 3
// contains filtered or unexported fields
}
func ParseCfxLogFilter ¶
func ParseEthLogFilter ¶
func ParseEthLogFilter(blockFrom, blockTo uint64, filter *web3Types.FilterQuery, networkId uint32) LogFilter
type LogFilterType ¶
type LogFilterType int
func ParseEthLogFilterType ¶
func ParseEthLogFilterType(filter *web3Types.FilterQuery) (LogFilterType, bool)
func ParseLogFilterType ¶
func ParseLogFilterType(filter *types.LogFilter) (LogFilterType, bool)
type Prunable ¶
type Prunable interface {
GetBlockEpochRange() (uint64, uint64, error)
GetTransactionEpochRange() (uint64, uint64, error)
GetLogEpochRange() (uint64, uint64, error)
GetNumBlocks() (uint64, error)
GetNumTransactions() (uint64, error)
GetNumLogs() (uint64, error)
// DequeueBlocks removes epoch blocks from the store like dequeuing a queue,
// which is deleting data from the oldest epoch to some new epoch
DequeueBlocks(epochUntil uint64) error
// DequeueTransactions removes epoch transactions from the store like dequeuing a queue,
// which is deleting data from the oldest epoch to some new epoch
DequeueTransactions(epochUntil uint64) error
// DequeueLogs removes epoch logs from the store like dequeuing a queue,
// which is deleting data from the oldest epoch to some new epoch
DequeueLogs(epochUntil uint64) error
}
Prunable is used to prune historical data.
type Readable ¶
type Readable interface {
GetLogs(ctx context.Context, filter LogFilter) ([]*Log, error)
GetTransaction(ctx context.Context, txHash types.Hash) (*Transaction, error)
GetReceipt(ctx context.Context, txHash types.Hash) (*TransactionReceipt, error)
GetBlocksByEpoch(ctx context.Context, epochNumber uint64) ([]types.Hash, error)
GetBlockByEpoch(ctx context.Context, epochNumber uint64) (*Block, error)
GetBlockSummaryByEpoch(ctx context.Context, epochNumber uint64) (*BlockSummary, error)
GetBlockByHash(ctx context.Context, blockHash types.Hash) (*Block, error)
GetBlockSummaryByHash(ctx context.Context, blockHash types.Hash) (*BlockSummary, error)
GetBlockByBlockNumber(ctx context.Context, blockNumber uint64) (*Block, error)
GetBlockSummaryByBlockNumber(ctx context.Context, blockNumber uint64) (*BlockSummary, error)
}
Readable is used for RPC to read cached data from database.
type ReceiptExtra ¶
type ReceiptExtra struct {
// extended fields for ETH receipt
CumulativeGasUsed *uint64 `json:"cumulativeGasUsed,omitempty"`
EffectiveGasPrice *uint64 `json:"effectiveGasPrice,omitempty"`
Type *uint `json:"type,omitempty"`
LogExts []*LogExtra `json:"-"`
}
custom receipt fields for extention
func ExtractEthReceiptExt ¶
func ExtractEthReceiptExt(ethRcpt *web3Types.Receipt) *ReceiptExtra
type StackOperable ¶
type StackOperable interface {
// Push appends epoch data to the store
Push(data *EpochData) error
Pushn(dataSlice []*EpochData) error
// Pop removes epoch data from the store like popping a stack, which is deleting
// data from the most recently appended epoch to some old epoch
Popn(epochUntil uint64) error
}
type Store ¶
type Store interface {
Readable
Prunable
Configurable
StackOperable
io.Closer
IsRecordNotFound(err error) bool
GetGlobalEpochRange() (uint64, uint64, error)
}
Store is implemented by any object that persist blockchain data, especially for event logs.
type StoreDisabler ¶
type Transaction ¶
type Transaction struct {
CfxTransaction *types.Transaction
Extra *TransactionExtra
}
type TransactionExtra ¶
type TransactionExtra struct {
// extended fields for ETH transaction
Accesses gethTypes.AccessList `json:"accessList,omitempty"`
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
MaxFeePerGas *hexutil.Big `json:"maxFeePerGas,omitempty"`
MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
Type *uint64 `json:"type,omitempty"`
StandardV *hexutil.Big `json:"standardV,omitempty"`
}
custom transaction fields for extention
func ExtractEthTransactionExt ¶
func ExtractEthTransactionExt(ethTxn *web3Types.TransactionDetail) *TransactionExtra
type TransactionReceipt ¶
type TransactionReceipt struct {
CfxReceipt *types.TransactionReceipt
Extra *ReceiptExtra
}
type VariadicValue ¶
type VariadicValue struct {
// contains filtered or unexported fields
}
VariadicValue represents an union value, including null, single value or multiple values.
func NewVariadicValue ¶
func NewVariadicValue(values ...string) VariadicValue
func (*VariadicValue) Count ¶
func (vv *VariadicValue) Count() int
func (*VariadicValue) FlatMultiple ¶
func (vv *VariadicValue) FlatMultiple() ([]string, bool)
func (*VariadicValue) IsNull ¶
func (vv *VariadicValue) IsNull() bool
func (*VariadicValue) Single ¶
func (vv *VariadicValue) Single() (string, bool)
func (*VariadicValue) ToSlice ¶
func (vv *VariadicValue) ToSlice() []string