store

package
v1.3.3-testnet Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

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 (
	EpochRemoveAll         EpochRemoveOption = 0xff
	EpochRemoveBlock                         = 0x01 << 0
	EpochRemoveTransaction                   = 0x01 << 1
	EpochRemoveLog                           = 0x01 << 2
)

Variables

View Source
var (
	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,
	)
)
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")

	// operationable epoch data types
	OpEpochDataTypes = []EpochDataType{
		EpochBlock,
		EpochTransaction,
		EpochLog,
	}
)

Functions

func EthStoreConfig

func EthStoreConfig() *storeConfig

func MustInit

func MustInit()

func RequireContinuous

func RequireContinuous(slice []*EpochData, currentEpoch uint64) error

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 CacheStore interface {
	Store

	// Flush deletes all kv pairs in cache
	Flush() error
}

type Configurable

type Configurable interface {
	// LoadConfig load configurations with specified names
	LoadConfig(confNames ...string) (map[string]interface{}, error)
	// StoreConfig stores configuration name to value pair
	StoreConfig(confName string, confVal interface{}) error
}

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

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

QueryEpochData queries blockchain data for the specified epoch number.

func (*EpochData) GetPivotBlock

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

func (*EpochData) IsContinuousTo

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

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

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 EpochRemoveOption

type EpochRemoveOption uint8

Epoch data remove option

type EthData

type EthData struct {
	Number   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(w3c *web3go.Client, blockNumber uint64, useBatch bool) (*EthData, error)

QueryEthData queries blockchain data for the specified block number.

func (*EthData) IsContinuousTo

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

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

type Log

type Log struct {
	ID          uint64
	ContractID  uint64
	BlockNumber uint64
	Epoch       uint64
	Topic0      string
	Topic1      string
	Topic2      string
	Topic3      string
	LogIndex    uint64
	Extra       []byte
}

func ParseCfxLog

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

func (*Log) ToCfxLog

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

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

func ExtractEthLogExt(ethLog *web3Types.Log) *LogExtra

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

func ParseEthLogFilter

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

ParseEthLogFilter parses store log filter from eSpace log filter but also with contract address bridged to core space

func ParseEthLogFilterRaw

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

ParseEthLogFilterRaw parses store log filter from eSpace log filter without any bridge or mod

func (LogFilter) Cfx

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

Cfx returns original core space log filter

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 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 StoreDisabler interface {
	IsChainBlockDisabled() bool
	IsChainTxnDisabled() bool
	IsChainReceiptDisabled() bool
	IsChainLogDisabled() bool
	IsDisabledForType(edt EpochDataType) bool
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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