store

package
v1.6.11-testnet Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EthReceiptMethodAutoDetect = iota
	EthReceiptMethodEthBlockReceipts
	EthReceiptMethodParityBlockReceipts
	EthReceiptMethodEthTxnReceipt
	EthReceiptMethodEnd
)
View Source
const (
	// max number of event logs to return
	MaxLogLimit = uint64(10000)

	// max timeout to get event logs from store
	TimeoutGetLogs = 3 * time.Second
)
View Source
const (
	PersistTypeBlock       persistType = "block"
	PersistTypeTransaction persistType = "transaction"
	PersistTypeReceipt     persistType = "receipt"
	PersistTypeLog         persistType = "log"
)

Variables

View Source
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,
	)
)
View Source
var (
	MaxLogBlockHashesSize  int
	MaxLogFilterAddrCount  int
	MaxLogFilterTopicCount int

	MaxLogEpochRange uint64
	MaxLogBlockRange uint64
)
View Source
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")
)

All supported persist types

Functions

func EthStoreConfig

func EthStoreConfig() *persistConfig

func GetBlockByBlockNumberOrHash

func GetBlockByBlockNumberOrHash(
	ctx context.Context,
	w3c *web3go.Client,
	bnh types.BlockNumberOrHash,
	isFull bool,
) (*types.Block, error)

func IsBoundChecksEnabled

func IsBoundChecksEnabled(ctx context.Context) bool

IsBoundChecksEnabled checks if bound checks are enabled for getLogs Defaults to true if not explicitly disabled

func MustInit

func MustInit()

func NewContextWithBoundChecksDisabled

func NewContextWithBoundChecksDisabled(ctx context.Context) context.Context

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 RequireContinuous[T ChainData](slice []T, currentEpoch uint64) error

func StoreConfig

func StoreConfig() *persistConfig

Types

type BlockLike

type BlockLike interface {
	Hash() string
	Number() uint64
	Transactions() []TransactionLike
}

type ChainData

type ChainData interface {
	Hash() string
	Number() uint64
	ExtractBlocks() []BlockLike
	ExtractReceipts() map[string]ReceiptLike
	ExtractLogs() []LogLike
}

type ChainDataFilter

type ChainDataFilter interface {
	IsBlockDisabled() bool
	IsTxnDisabled() bool
	IsReceiptDisabled() bool
	IsLogDisabled() bool
}

type EpochBlockAdapter

type EpochBlockAdapter struct {
	*types.Block
}

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

func QueryEpochData(cfx sdk.ClientOperator, epochNumber uint64, useBatch bool) (EpochData, error)

QueryEpochData queries blockchain data for the specified epoch number.

func (EpochData) ExtractBlocks

func (e EpochData) ExtractBlocks() []BlockLike

func (EpochData) ExtractLogs

func (e EpochData) ExtractLogs() (logs []LogLike)

func (EpochData) ExtractReceipts

func (e EpochData) ExtractReceipts() map[string]ReceiptLike

func (*EpochData) GetPivotBlock

func (epoch *EpochData) GetPivotBlock() *types.Block

func (EpochData) Hash

func (e EpochData) Hash() string

func (*EpochData) IsContinuousTo

func (epoch *EpochData) IsContinuousTo(prev *EpochData) (continuous bool, desc string)

IsContinuousTo checks if this epoch is continuous to the previous epoch.

func (EpochData) Number

func (e EpochData) Number() uint64

type EpochLogAdapter

type EpochLogAdapter struct {
	*types.Log
}

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 (EpochTransactionAdapter) Hash

func (EpochTransactionAdapter) To

func (EpochTransactionAdapter) Value

func (a EpochTransactionAdapter) Value() *big.Int

type EthBlockAdapter

type EthBlockAdapter struct {
	*types.Block
}

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 (e EthData) ExtractBlocks() []BlockLike

func (EthData) ExtractLogs

func (e EthData) ExtractLogs() []LogLike

func (EthData) ExtractReceipts

func (e EthData) ExtractReceipts() map[string]ReceiptLike

func (EthData) Hash

func (e EthData) Hash() string

func (*EthData) IsContinuousTo

func (current *EthData) IsContinuousTo(prev *EthData) (continuous bool, desc string)

IsContinuousTo checks if this block is continuous to the previous block.

func (EthData) Number

func (e EthData) Number() uint64

type EthLogAdapter

type EthLogAdapter struct {
	*types.Log
}

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

type EthReceiptAdapter struct {
	*types.Receipt
	// contains filtered or unexported fields
}

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

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

func ParseCfxLog(log *types.Log, bn uint64) *Log

func ParseEthLog

func ParseEthLog(log *web3go.Log) *Log

func (*Log) ToCfxLog

func (log *Log) ToCfxLog() (*types.Log, error)

func (*Log) ToEthLog

func (log *Log) ToEthLog() (*web3go.Log, error)

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 ParseCfxLogFilter(blockFrom, blockTo uint64, filter *types.LogFilter) LogFilter

func ParseEthLogFilter

func ParseEthLogFilter(blockFrom, blockTo uint64, filter *web3Types.FilterQuery) LogFilter

ParseEthLogFilter parses store log filter from eSpace log filter

func (LogFilter) Cfx

func (f LogFilter) Cfx() *types.LogFilter

Cfx returns original core space log filter

type LogLike

type LogLike interface {
	Address() string
	Topics() []string
	Data() []byte
	AsStoreLog() *Log
}

type LogSlice

type LogSlice []*Log

func (LogSlice) Len

func (s LogSlice) Len() int

func (LogSlice) Less

func (s LogSlice) Less(i, j int) bool

func (LogSlice) Swap

func (s LogSlice) Swap(i, j int)

type QueryOption

type QueryOption struct {
	ReceiptConfig          EthReceiptOption
	Filter                 ChainDataFilter
	EnableLogsOptimization bool // use `eth_getLogs` for better performance if possible
}

type ReceiptLike

type ReceiptLike interface {
	Status() *uint64
	Logs() []LogLike
	TransactionHash() string
}

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 TransactionLike interface {
	Hash() string
	From() string
	To() string
	Value() *big.Int
	Executed() bool
}

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

type VariadicValuer interface {
	IsNull() bool
	Count() int
	Values() []any
}

func ToVariadicValuers

func ToVariadicValuers[T comparable](vals ...VariadicValue[T]) []VariadicValuer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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