Documentation
¶
Index ¶
- Constants
- Variables
- func EthStoreConfig() *persistConfig
- func GetBlockByBlockNumberOrHash(ctx context.Context, w3c *web3go.Client, bnh types.BlockNumberOrHash, ...) (*types.Block, error)
- func IsBoundChecksEnabled(ctx context.Context) bool
- func MustInit()
- func NewContextWithBoundChecksDisabled(ctx context.Context) context.Context
- func NewSuggestedFilterQuerySetTooLargeError[T SuggestedFilterRange](suggestedRange *T) error
- func NewSuggestedFilterResultSetTooLargeError[T SuggestedFilterRange](suggestedRange *T) error
- func QueryEthReceipt(ctx context.Context, w3c *web3go.Client, bnh types.BlockNumberOrHash, ...) ([]*types.Receipt, error)
- func RequireContinuous[T ChainData](slice []T, currentEpoch uint64) error
- func StoreConfig() *persistConfig
- type BlockLike
- type ChainData
- type ChainDataFilter
- type EpochBlockAdapter
- type EpochData
- func (e EpochData) ExtractBlocks() []BlockLike
- func (e EpochData) ExtractLogs() (logs []LogLike)
- func (e EpochData) ExtractReceipts() map[string]ReceiptLike
- func (epoch *EpochData) GetPivotBlock() *types.Block
- func (e EpochData) Hash() string
- func (epoch *EpochData) IsContinuousTo(prev *EpochData) (continuous bool, desc string)
- func (e EpochData) Number() uint64
- type EpochLogAdapter
- func (a EpochLogAdapter) Address() string
- func (a EpochLogAdapter) AsStoreLog() *Log
- func (a EpochLogAdapter) BlockHash() string
- func (a EpochLogAdapter) Data() []byte
- func (a EpochLogAdapter) LogIndex() uint64
- func (a EpochLogAdapter) Topics() []string
- func (a EpochLogAdapter) TransactionHash() string
- type EpochReceiptAdapter
- type EpochTransactionAdapter
- type EthBlockAdapter
- type EthData
- type EthLogAdapter
- func (a EthLogAdapter) Address() string
- func (a EthLogAdapter) AsStoreLog() *Log
- func (a EthLogAdapter) BlockHash() string
- func (a EthLogAdapter) BlockNumber() uint64
- func (a EthLogAdapter) Data() []byte
- func (a EthLogAdapter) LogIndex() uint64
- func (a EthLogAdapter) Topics() []string
- func (a EthLogAdapter) TransactionHash() string
- type EthReceiptAdapter
- type EthReceiptMethod
- type EthReceiptMethodDetector
- type EthReceiptOption
- type EthTransactionAdapter
- type Log
- type LogFilter
- type LogLike
- type LogSlice
- type QueryOption
- type ReceiptLike
- type SuggestedBlockRange
- type SuggestedEpochRange
- type SuggestedFilterOversizedError
- type SuggestedFilterRange
- type TransactionLike
- type VariadicValue
- type VariadicValuer
Constants ¶
const ( EthReceiptMethodAutoDetect = iota EthReceiptMethodEthBlockReceipts EthReceiptMethodParityBlockReceipts EthReceiptMethodEthTxnReceipt EthReceiptMethodEnd )
const ( // max number of event logs to return MaxLogLimit = uint64(10000) // max timeout to get event logs from store TimeoutGetLogs = 3 * time.Second )
const ( PersistTypeBlock persistType = "block" PersistTypeTransaction persistType = "transaction" PersistTypeReceipt persistType = "receipt" PersistTypeLog persistType = "log" )
Variables ¶
var ( ErrFilterQuerySetTooLarge = errors.New("the query set is too large, please narrow down your filter condition") ErrFilterResultSetTooLarge = errors.Errorf( "the result set exceeds the max limit of %v logs, please narrow down your filter conditions", MaxLogLimit, ) ErrGetLogsTimeout = errors.Errorf( "the query timed out after exceeding the maximum duration of %v seconds", TimeoutGetLogs, ) )
var ( MaxLogBlockHashesSize int MaxLogFilterAddrCount int MaxLogFilterTopicCount int MaxLogEpochRange uint64 MaxLogBlockRange uint64 )
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") ErrLeaderRenewal = errors.New("leadership renewal failure") )
var AllPersistTypes = []persistType{ PersistTypeBlock, PersistTypeTransaction, PersistTypeReceipt, PersistTypeLog, }
All supported persist types
Functions ¶
func EthStoreConfig ¶
func EthStoreConfig() *persistConfig
func IsBoundChecksEnabled ¶
IsBoundChecksEnabled checks if bound checks are enabled for getLogs Defaults to true if not explicitly disabled
func NewContextWithBoundChecksDisabled ¶
NewContextWithBoundChecksDisabled returns a context that marks bound checks as disabled for getLogs
func NewSuggestedFilterQuerySetTooLargeError ¶
func NewSuggestedFilterQuerySetTooLargeError[T SuggestedFilterRange](suggestedRange *T) error
func NewSuggestedFilterResultSetTooLargeError ¶
func NewSuggestedFilterResultSetTooLargeError[T SuggestedFilterRange](suggestedRange *T) error
func QueryEthReceipt ¶
func QueryEthReceipt( ctx context.Context, w3c *web3go.Client, bnh types.BlockNumberOrHash, opts ...EthReceiptOption, ) ([]*types.Receipt, error)
func RequireContinuous ¶
func StoreConfig ¶
func StoreConfig() *persistConfig
Types ¶
type BlockLike ¶
type BlockLike interface {
Hash() string
Number() uint64
Transactions() []TransactionLike
}
type ChainDataFilter ¶
type EpochBlockAdapter ¶
func (EpochBlockAdapter) Hash ¶
func (a EpochBlockAdapter) Hash() string
func (EpochBlockAdapter) MarshalJSON ¶
func (a EpochBlockAdapter) MarshalJSON() ([]byte, error)
func (EpochBlockAdapter) Number ¶
func (a EpochBlockAdapter) Number() uint64
func (EpochBlockAdapter) Transactions ¶
func (a EpochBlockAdapter) Transactions() []TransactionLike
type EpochData ¶
type EpochData struct {
EpochNo uint64 // epoch number
PivotHash *types.Hash // pivot hash
Blocks []*types.Block // blocks in order and the last one is pivot block
Receipts map[types.Hash]*types.TransactionReceipt
}
EpochData wraps the blockchain data of an epoch.
func QueryEpochData ¶
QueryEpochData queries blockchain data for the specified epoch number.
func (EpochData) ExtractBlocks ¶
func (EpochData) ExtractLogs ¶
func (EpochData) ExtractReceipts ¶
func (e EpochData) ExtractReceipts() map[string]ReceiptLike
func (*EpochData) GetPivotBlock ¶
func (*EpochData) IsContinuousTo ¶
IsContinuousTo checks if this epoch is continuous to the previous epoch.
type EpochLogAdapter ¶
func (EpochLogAdapter) Address ¶
func (a EpochLogAdapter) Address() string
func (EpochLogAdapter) AsStoreLog ¶
func (a EpochLogAdapter) AsStoreLog() *Log
func (EpochLogAdapter) BlockHash ¶
func (a EpochLogAdapter) BlockHash() string
func (EpochLogAdapter) Data ¶
func (a EpochLogAdapter) Data() []byte
func (EpochLogAdapter) LogIndex ¶
func (a EpochLogAdapter) LogIndex() uint64
func (EpochLogAdapter) Topics ¶
func (a EpochLogAdapter) Topics() []string
func (EpochLogAdapter) TransactionHash ¶
func (a EpochLogAdapter) TransactionHash() string
type EpochReceiptAdapter ¶
type EpochReceiptAdapter struct {
*types.TransactionReceipt
}
func (EpochReceiptAdapter) Logs ¶
func (a EpochReceiptAdapter) Logs() []LogLike
func (EpochReceiptAdapter) Status ¶
func (a EpochReceiptAdapter) Status() *uint64
func (EpochReceiptAdapter) TransactionHash ¶
func (a EpochReceiptAdapter) TransactionHash() string
type EpochTransactionAdapter ¶
type EpochTransactionAdapter struct {
*types.Transaction
}
func (EpochTransactionAdapter) Executed ¶
func (a EpochTransactionAdapter) Executed() bool
func (EpochTransactionAdapter) From ¶
func (a EpochTransactionAdapter) From() string
func (EpochTransactionAdapter) Hash ¶
func (a EpochTransactionAdapter) Hash() string
func (EpochTransactionAdapter) To ¶
func (a EpochTransactionAdapter) To() string
func (EpochTransactionAdapter) Value ¶
func (a EpochTransactionAdapter) Value() *big.Int
type EthBlockAdapter ¶
func (EthBlockAdapter) Hash ¶
func (a EthBlockAdapter) Hash() string
func (EthBlockAdapter) MarshalJSON ¶
func (a EthBlockAdapter) MarshalJSON() ([]byte, error)
func (EthBlockAdapter) Number ¶
func (a EthBlockAdapter) Number() uint64
func (EthBlockAdapter) Transactions ¶
func (a EthBlockAdapter) Transactions() []TransactionLike
type EthData ¶
type EthData struct {
BlockNo uint64 // block number
Block *types.Block // block body
Receipts map[common.Hash]*types.Receipt // receipts
}
EthData wraps the evm space blockchain data.
func QueryEthData ¶
func QueryEthData( ctx context.Context, w3c *web3go.Client, blockNumber uint64, opts ...QueryOption, ) (*EthData, error)
QueryEthData queries blockchain data for the specified block number.
func (EthData) ExtractBlocks ¶
func (EthData) ExtractLogs ¶
func (EthData) ExtractReceipts ¶
func (e EthData) ExtractReceipts() map[string]ReceiptLike
func (*EthData) IsContinuousTo ¶
IsContinuousTo checks if this block is continuous to the previous block.
type EthLogAdapter ¶
func (EthLogAdapter) Address ¶
func (a EthLogAdapter) Address() string
func (EthLogAdapter) AsStoreLog ¶
func (a EthLogAdapter) AsStoreLog() *Log
func (EthLogAdapter) BlockHash ¶
func (a EthLogAdapter) BlockHash() string
func (EthLogAdapter) BlockNumber ¶
func (a EthLogAdapter) BlockNumber() uint64
func (EthLogAdapter) Data ¶
func (a EthLogAdapter) Data() []byte
func (EthLogAdapter) LogIndex ¶
func (a EthLogAdapter) LogIndex() uint64
func (EthLogAdapter) Topics ¶
func (a EthLogAdapter) Topics() []string
func (EthLogAdapter) TransactionHash ¶
func (a EthLogAdapter) TransactionHash() string
type EthReceiptAdapter ¶
func (EthReceiptAdapter) Logs ¶
func (a EthReceiptAdapter) Logs() []LogLike
func (EthReceiptAdapter) Status ¶
func (a EthReceiptAdapter) Status() *uint64
func (EthReceiptAdapter) TransactionHash ¶
func (a EthReceiptAdapter) TransactionHash() string
type EthReceiptMethod ¶
type EthReceiptMethod uint32
func (EthReceiptMethod) IsConcrete ¶
func (m EthReceiptMethod) IsConcrete() bool
IsConcrete returns true if the method is a concrete receipt retrieval method (excluding auto-detect).
func (EthReceiptMethod) String ¶
func (m EthReceiptMethod) String() string
String returns the string representation of the EthReceiptMethod
type EthReceiptMethodDetector ¶
type EthReceiptMethodDetector struct {
// contains filtered or unexported fields
}
EthReceiptMethodDetector detects the best method for retrieving Ethereum receipts. The detection occurs only once to optimize performance by caching the result.
func (*EthReceiptMethodDetector) Detect ¶
func (d *EthReceiptMethodDetector) Detect( ctx context.Context, client *web3go.Client, bnh types.BlockNumberOrHash, ) (EthReceiptMethod, error)
Detect determines the best receipt retrieval method. If a method has already been detected, it returns the cached method. Otherwise, it attempts to detect the best method.
type EthReceiptOption ¶
type EthReceiptOption struct {
Method EthReceiptMethod
Concurrency int
// Pre-fetched data can be used to accelerate the query eg., block header etc.
Prefetched interface{}
}
var (
DefaultReceiptOption EthReceiptOption
)
type EthTransactionAdapter ¶
type EthTransactionAdapter struct {
*types.TransactionDetail
}
func (*EthTransactionAdapter) Executed ¶
func (a *EthTransactionAdapter) Executed() bool
func (EthTransactionAdapter) From ¶
func (a EthTransactionAdapter) From() string
func (EthTransactionAdapter) Hash ¶
func (a EthTransactionAdapter) Hash() string
func (EthTransactionAdapter) To ¶
func (a EthTransactionAdapter) To() string
func (EthTransactionAdapter) Value ¶
func (a EthTransactionAdapter) Value() *big.Int
type Log ¶
type Log struct {
ID uint64
BlockNumber uint64
Epoch uint64
Topic0 string
Topic1 string
Topic2 string
Topic3 string
LogIndex uint64
Extra []byte
}
func ParseEthLog ¶
type LogFilter ¶
type LogFilter struct {
BlockFrom uint64
BlockTo uint64
Contracts VariadicValue[string]
Topics []VariadicValue[string] // 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) LogFilter
ParseEthLogFilter parses store log filter from eSpace log filter
type QueryOption ¶
type QueryOption struct {
ReceiptConfig EthReceiptOption
Filter ChainDataFilter
EnableLogsOptimization bool // use `eth_getLogs` for better performance if possible
}
type ReceiptLike ¶
type SuggestedBlockRange ¶
type SuggestedBlockRange struct {
citypes.RangeUint64
// the maximum possible epoch for suggesting an epoch range
// a value of 0 indicates that no maximum epoch is provided
MaxEndEpoch uint64
}
func NewSuggestedBlockRange ¶
func NewSuggestedBlockRange(from, to, maxEndEpoch uint64) SuggestedBlockRange
type SuggestedEpochRange ¶
type SuggestedEpochRange struct {
citypes.RangeUint64
}
func NewSuggestedEpochRange ¶
func NewSuggestedEpochRange(from, to uint64) SuggestedEpochRange
type SuggestedFilterOversizedError ¶
type SuggestedFilterOversizedError[T SuggestedFilterRange] struct { SuggestedRange T // contains filtered or unexported fields }
func NewSuggestedFilterOversizeError ¶
func NewSuggestedFilterOversizeError[T SuggestedFilterRange](inner error, suggestedRange T) *SuggestedFilterOversizedError[T]
func (*SuggestedFilterOversizedError[T]) Error ¶
func (e *SuggestedFilterOversizedError[T]) Error() string
func (*SuggestedFilterOversizedError[T]) Unwrap ¶
func (e *SuggestedFilterOversizedError[T]) Unwrap() error
type SuggestedFilterRange ¶
type SuggestedFilterRange interface {
SuggestedBlockRange | SuggestedEpochRange
}
type TransactionLike ¶
type VariadicValue ¶
type VariadicValue[T comparable] struct { // contains filtered or unexported fields }
VariadicValue represents an union value, including null, single value or multiple values.
func NewVariadicValue ¶
func NewVariadicValue[T comparable](values ...T) VariadicValue[T]
func (VariadicValue[T]) Count ¶
func (vv VariadicValue[T]) Count() int
func (*VariadicValue[T]) FlatMultiple ¶
func (vv *VariadicValue[T]) FlatMultiple() ([]T, bool)
func (VariadicValue[T]) IsNull ¶
func (vv VariadicValue[T]) IsNull() bool
func (*VariadicValue[T]) Single ¶
func (vv *VariadicValue[T]) Single() (v T, _ bool)
func (*VariadicValue[T]) ToSlice ¶
func (vv *VariadicValue[T]) ToSlice() []T
func (VariadicValue[T]) Values ¶
func (vv VariadicValue[T]) Values() []any
type VariadicValuer ¶
func ToVariadicValuers ¶
func ToVariadicValuers[T comparable](vals ...VariadicValue[T]) []VariadicValuer