Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertStringToNumber[T any](s string) (T, error)
- func IsErrNotFound(err error) bool
- type BaseEthereumClienter
- type BlockHeader
- type BlockHeadersResult
- func (r *BlockHeadersResult) AddError(blockNumber uint64, err error)
- func (r *BlockHeadersResult) AddHeader(blockNumber uint64, header *BlockHeader)
- func (r *BlockHeadersResult) AreAllErrorsNotFound() bool
- func (r *BlockHeadersResult) ComposeError() error
- func (r *BlockHeadersResult) GetOrderedHeaders(blockNumbers []uint64) []*BlockHeader
- func (r *BlockHeadersResult) ListBlocksNumberNotFound() []uint64
- func (r *BlockHeadersResult) Merge(other *BlockHeadersResult)
- func (r *BlockHeadersResult) PartialSuccess() bool
- func (r *BlockHeadersResult) Success() bool
- type BlockName
- type BlockNumberFinality
- func (b *BlockNumberFinality) BlockName() BlockName
- func (b *BlockNumberFinality) BlockNumber(ctx context.Context, requester CustomEthereumClienter) (uint64, error)
- func (c *BlockNumberFinality) CalculateBlockNumber(baseBlockNumber uint64) uint64
- func (b *BlockNumberFinality) Equal(other BlockNumberFinality) bool
- func (b *BlockNumberFinality) HasOffset() bool
- func (b *BlockNumberFinality) IsConstant() bool
- func (b *BlockNumberFinality) IsEmpty() bool
- func (b *BlockNumberFinality) IsFinalized() bool
- func (b *BlockNumberFinality) IsSafe() bool
- func (BlockNumberFinality) JSONSchema() *jsonschema.Schema
- func (b *BlockNumberFinality) LessFinalThan(other BlockNumberFinality) (bool, error)
- func (b *BlockNumberFinality) String() string
- func (b *BlockNumberFinality) ToBigInt() *big.Int
- func (b *BlockNumberFinality) UnmarshalText(data []byte) error
- func (b BlockNumberFinality) Validate() error
- type CustomEthereumClienter
- type EthChainReader
- type EthClienter
- type EthereumClienter
- type ListBlockHeaders
- type MapBlockHeaders
- type MultiDownloaderLegacy
- type RPCClienter
- type SyncerConfig
Constants ¶
const ( ConstantBlockName = "ConstantBlock" SafeBlockName = "SafeBlock" FinalizedBlockName = "FinalizedBlock" LatestBlockName = "LatestBlock" PendingBlockName = "PendingBlock" EmptyBlockName = "" // Maximum positive offset limits for each block finality type MaxPositiveOffsetLatest = int64(0) // LatestBlock cannot have positive offset (cannot go beyond latest) MaxPositiveOffsetFinalized = int64(32) // ~1 epoch on Ethereum MaxPositiveOffsetSafe = int64(64) // ~2 epochs MaxPositiveOffsetPending = int64(0) // Pending blocks don't exist yet, cannot go forward )
const ( Constant = BlockName(rpc.EarliestBlockNumber - 1) Safe = BlockName(rpc.SafeBlockNumber) Finalized = BlockName(rpc.FinalizedBlockNumber) Latest = BlockName(rpc.LatestBlockNumber) Pending = BlockName(rpc.PendingBlockNumber) Empty = BlockName(0) )
Variables ¶
var ( FinalizedBlock = BlockNumberFinality{Block: Finalized} LatestBlock = BlockNumberFinality{Block: Latest} SafeBlock = BlockNumberFinality{Block: Safe} PendingBlock = BlockNumberFinality{Block: Pending} )
var ErrNotFound = errors.New("not found")
ErrNotFound is used when the object is not found
Functions ¶
func ConvertStringToNumber ¶
func IsErrNotFound ¶
IsErrNotFound checks if the error is a "not found" error
Types ¶
type BaseEthereumClienter ¶
type BaseEthereumClienter interface {
ethereum.BlockNumberReader
ethereum.ChainIDReader
EthChainReader
ethereum.ChainStateReader
ethereum.LogFilterer
ethereum.TransactionReader
bind.ContractBackend
CustomEthereumClienter
}
BaseEthereumClienter defines the methods required to interact with an Ethereum client.
type BlockHeader ¶ added in v0.8.0
type BlockHeader struct {
Number uint64 `json:"number"`
Hash common.Hash `json:"hash"`
Time uint64 `json:"timestamp"`
ParentHash *common.Hash `json:"parentHash"`
// the RequestedBlock is the original Block requested
RequestedBlock *BlockNumberFinality
}
func NewBlockHeader ¶ added in v0.8.0
func NewBlockHeaderFromEthHeader ¶ added in v0.8.0
func NewBlockHeaderFromEthHeader(ethHeader *types.Header) *BlockHeader
func (*BlockHeader) Brief ¶
func (gb *BlockHeader) Brief() string
func (*BlockHeader) Empty ¶
func (gb *BlockHeader) Empty() bool
func (*BlockHeader) String ¶ added in v0.8.0
func (gb *BlockHeader) String() string
type BlockHeadersResult ¶
type BlockHeadersResult struct {
// Headers contains successfully retrieved block headers, mapped by block number
Headers map[uint64]*BlockHeader
// Errors contains retrieval errors, mapped by block number
Errors map[uint64]error
}
BlockHeadersResult holds the results of block header retrieval, separating successful headers from failed ones.
func NewBlockHeadersResult ¶
func NewBlockHeadersResult() *BlockHeadersResult
NewBlockHeadersResult creates a new BlockHeadersResult
func (*BlockHeadersResult) AddError ¶
func (r *BlockHeadersResult) AddError(blockNumber uint64, err error)
AddError adds an error for a specific block number
func (*BlockHeadersResult) AddHeader ¶
func (r *BlockHeadersResult) AddHeader(blockNumber uint64, header *BlockHeader)
AddHeader adds a successful header to the result
func (*BlockHeadersResult) AreAllErrorsNotFound ¶
func (r *BlockHeadersResult) AreAllErrorsNotFound() bool
AreAllErrorsNotFound returns true if all errors are "not found" errors
func (*BlockHeadersResult) ComposeError ¶
func (r *BlockHeadersResult) ComposeError() error
ComposeError returns a single error summarizing all errors in the result, or nil if there are no errors
func (*BlockHeadersResult) GetOrderedHeaders ¶
func (r *BlockHeadersResult) GetOrderedHeaders(blockNumbers []uint64) []*BlockHeader
GetOrderedHeaders returns headers in the order of the requested blockNumbers, only for blocks that were retrieved successfully
func (*BlockHeadersResult) ListBlocksNumberNotFound ¶
func (r *BlockHeadersResult) ListBlocksNumberNotFound() []uint64
ListBlocksNumberNotFound returns the list of not-found block numbers ordered by block number
func (*BlockHeadersResult) Merge ¶
func (r *BlockHeadersResult) Merge(other *BlockHeadersResult)
Merge combines another BlockHeadersResult into this one
func (*BlockHeadersResult) PartialSuccess ¶
func (r *BlockHeadersResult) PartialSuccess() bool
PartialSuccess returns true if at least one block was retrieved successfully
func (*BlockHeadersResult) Success ¶
func (r *BlockHeadersResult) Success() bool
Success returns true if all blocks were retrieved successfully
type BlockName ¶
type BlockName int64
func NewBlockName ¶
func (BlockName) ApplyOffset ¶
func (BlockName) IsConstant ¶
type BlockNumberFinality ¶
type BlockNumberFinality struct {
Block BlockName
Offset int64
Specific uint64 // Specific block number, Block must be Constant
}
BlockNumberFinality represents a block finality with an optional offset
func NewBlockNumber ¶ added in v0.7.0
func NewBlockNumber(number uint64) *BlockNumberFinality
func NewBlockNumberFinality ¶
func NewBlockNumberFinality(s string) (*BlockNumberFinality, error)
NewBlockNumberFinality creates a new BlockNumberFinality from a string format: <blockName>[/<offset>] e.g: "SafeBlock", "FinalizedBlock/-5", "LatestBlock/+10" can be directly a number
func (*BlockNumberFinality) BlockName ¶
func (b *BlockNumberFinality) BlockName() BlockName
func (*BlockNumberFinality) BlockNumber ¶ added in v0.7.0
func (b *BlockNumberFinality) BlockNumber( ctx context.Context, requester CustomEthereumClienter, ) (uint64, error)
BlockNumber gets the block number from RPC with offset taken into account
func (*BlockNumberFinality) CalculateBlockNumber ¶
func (c *BlockNumberFinality) CalculateBlockNumber(baseBlockNumber uint64) uint64
func (*BlockNumberFinality) Equal ¶ added in v0.8.0
func (b *BlockNumberFinality) Equal(other BlockNumberFinality) bool
func (*BlockNumberFinality) HasOffset ¶
func (b *BlockNumberFinality) HasOffset() bool
func (*BlockNumberFinality) IsConstant ¶
func (b *BlockNumberFinality) IsConstant() bool
func (*BlockNumberFinality) IsEmpty ¶
func (b *BlockNumberFinality) IsEmpty() bool
IsEmpty returns true if b is empty
func (*BlockNumberFinality) IsFinalized ¶
func (b *BlockNumberFinality) IsFinalized() bool
IsFinalized returns true if b is finalized
func (*BlockNumberFinality) IsSafe ¶
func (b *BlockNumberFinality) IsSafe() bool
IsSafe returns true if b is safe
func (BlockNumberFinality) JSONSchema ¶
func (BlockNumberFinality) JSONSchema() *jsonschema.Schema
JSONSchema returns the JSON schema for BlockNumberFinality
func (*BlockNumberFinality) LessFinalThan ¶ added in v0.7.0
func (b *BlockNumberFinality) LessFinalThan(other BlockNumberFinality) (bool, error)
LessFinalThan returns true if b is less strict commitment level than other. In case commitment level keywords are the same, it compares the offsets. finalized ≤ safe ≤ latest ≤ pending
func (*BlockNumberFinality) String ¶
func (b *BlockNumberFinality) String() string
String returns the string representation of the BlockNumberFinality
func (*BlockNumberFinality) ToBigInt ¶
func (b *BlockNumberFinality) ToBigInt() *big.Int
func (*BlockNumberFinality) UnmarshalText ¶
func (b *BlockNumberFinality) UnmarshalText(data []byte) error
UnmarshalText unmarshalls BlockNumberFinality from text.
func (BlockNumberFinality) Validate ¶ added in v0.8.0
func (b BlockNumberFinality) Validate() error
Validate validates the BlockNumberFinality configuration, ensuring that: - The block name is valid (one of LatestBlock, SafeBlock, FinalizedBlock, or PendingBlock) - The positive offset does not exceed the maximum allowed for the specific block finality type
- LatestBlock: cannot have positive offset (limit = 0)
- PendingBlock: cannot have positive offset (limit = 0) as pending blocks don't exist yet
- SafeBlock: maximum positive offset is MaxPositiveOffsetSafe
- FinalizedBlock: maximum positive offset is MaxPositiveOffsetFinalized (most restrictive)
type CustomEthereumClienter ¶
type CustomEthereumClienter interface {
// Like HeaderByNumber but returns a custom BlockHeader type.
CustomHeaderByNumber(ctx context.Context, number *BlockNumberFinality) (*BlockHeader, error)
// RetrieveBlockHeaders retrieves block headers for the given block numbers.
// Uses batch RPC requests when available, falling back to individual requests otherwise.
RetrieveBlockHeaders(ctx context.Context, blockNumbers []uint64, maxConcurrency int) (*BlockHeadersResult, error)
}
type EthChainReader ¶
type EthChainReader interface {
HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
}
EthChainReader defines methods to read blocks and headers from the Ethereum chain. it's based on ethereum.ChainReader It have been removed HeaderByNumber in favour of CustomHeaderByNumber
type EthClienter ¶
type EthClienter interface {
BaseEthereumClienter
RPCClienter
CustomEthereumClienter
}
EthClienter defines the methods for an Ethereum RPC client.
type EthereumClienter ¶
type EthereumClienter interface {
ethereum.BlockNumberReader
ethereum.ChainIDReader
EthChainReader
ethereum.ChainStateReader
ethereum.LogFilterer
ethereum.TransactionReader
bind.ContractBackend
}
type ListBlockHeaders ¶
type ListBlockHeaders []*BlockHeader
func NewListBlockHeaders ¶
func NewListBlockHeaders(size int) ListBlockHeaders
NewListBlockHeaders creates a new ListBlockHeaders with the given size to zero element
func NewListBlockHeadersEmpty ¶
func NewListBlockHeadersEmpty(preAllocatedSize int) ListBlockHeaders
NewListBlockHeadersEmpty creates a new ListBlockHeaders with pre-allocated items set to nil
func (ListBlockHeaders) BlockNumbers ¶
func (lbs ListBlockHeaders) BlockNumbers() []uint64
func (ListBlockHeaders) BlockRange ¶
func (lbs ListBlockHeaders) BlockRange() aggkitcommon.BlockRange
func (ListBlockHeaders) Len ¶
func (lbs ListBlockHeaders) Len() int
func (ListBlockHeaders) ToMap ¶
func (lbs ListBlockHeaders) ToMap() MapBlockHeaders
type MapBlockHeaders ¶
type MapBlockHeaders map[uint64]*BlockHeader
func NewMapBlockHeadersEmpty ¶
func NewMapBlockHeadersEmpty(preAllocatedSize int) MapBlockHeaders
type MultiDownloaderLegacy ¶
type MultiDownloaderLegacy interface {
ChainID(ctx context.Context) (uint64, error)
BlockNumber(ctx context.Context, finality BlockNumberFinality) (uint64, error)
FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethtypes.Log, error)
// Get block header by number and finality
// if number is nil, it gets the latest block
HeaderByNumber(ctx context.Context, number *BlockNumberFinality) (*BlockHeader, error)
EthClient() BaseEthereumClienter
RegisterSyncer(data SyncerConfig) error
Start(ctx context.Context) error
}
type RPCClienter ¶
type RPCClienter interface {
Call(result any, method string, args ...any) error
CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
}
RPCClienter defines an interface for making generic RPC calls.
type SyncerConfig ¶ added in v0.8.0
type SyncerConfig struct {
// SyncerID is the unique identifier for the syncer
SyncerID string
// ContractAddresses is list of contract addresses to sync
ContractAddresses []common.Address
// Starting block
FromBlock uint64
// Target for final block (e.g. LatestBlock, SafeBlock, FinalizedBlock)
ToBlock BlockNumberFinality
}