Documentation
¶
Index ¶
- Constants
- Variables
- type BaseEthereumClienter
- type BlockHeader
- type BlockNumber
- type BlockNumberFinality
- func (b *BlockNumberFinality) BlockHeader(ctx context.Context, requester ethereum.ChainReader) (*types.Header, error)
- func (b *BlockNumberFinality) BlockNumber(ctx context.Context, requester ethereum.ChainReader) (uint64, error)
- func (b *BlockNumberFinality) Equal(other BlockNumberFinality) 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
- func (b *BlockNumberFinality) String() string
- func (b *BlockNumberFinality) UnmarshalText(data []byte) error
- func (b BlockNumberFinality) Validate() error
- type DefaultEthClient
- type EthClienter
- type MultiDownloader
- type NoopRPCClient
- type RPCClienter
- type SyncerConfig
Constants ¶
const ( 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 ( Safe = BlockNumber(rpc.SafeBlockNumber) Finalized = BlockNumber(rpc.FinalizedBlockNumber) Latest = BlockNumber(rpc.LatestBlockNumber) Pending = BlockNumber(rpc.PendingBlockNumber) Empty = BlockNumber(0) )
Variables ¶
var ( FinalizedBlock = BlockNumberFinality{Block: Finalized} LatestBlock = BlockNumberFinality{Block: Latest} SafeBlock = BlockNumberFinality{Block: Safe} PendingBlock = BlockNumberFinality{Block: Pending} )
Functions ¶
This section is empty.
Types ¶
type BaseEthereumClienter ¶
type BaseEthereumClienter interface {
ethereum.BlockNumberReader
ethereum.ChainIDReader
ethereum.ChainReader
ethereum.ChainStateReader
ethereum.LogFilterer
ethereum.TransactionReader
bind.ContractBackend
}
BaseEthereumClienter defines the methods required to interact with an Ethereum client.
type BlockHeader ¶
type BlockHeader struct {
Number uint64 `json:"number"`
Hash common.Hash `json:"hash"`
Time uint64 `json:"timestamp"`
ParentHash *common.Hash `json:"parentHash"`
}
func NewBlockHeader ¶
func NewBlockHeaderFromEthHeader ¶
func NewBlockHeaderFromEthHeader(ethHeader *types.Header) *BlockHeader
func (*BlockHeader) String ¶
func (gb *BlockHeader) String() string
type BlockNumber ¶
type BlockNumber int64
func NewBlockNumber ¶ added in v0.7.0
func NewBlockNumber(s string) (BlockNumber, error)
func (BlockNumber) ApplyOffset ¶ added in v0.7.0
func (b BlockNumber) ApplyOffset(blockNumber uint64, offset int64) uint64
func (BlockNumber) String ¶ added in v0.7.0
func (b BlockNumber) String() string
type BlockNumberFinality ¶
type BlockNumberFinality struct {
Block BlockNumber
Offset int64
}
BlockNumberFinality represents a block finality with an optional offset
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"
func (*BlockNumberFinality) BlockHeader ¶ added in v0.7.1
func (b *BlockNumberFinality) BlockHeader( ctx context.Context, requester ethereum.ChainReader, ) (*types.Header, error)
BlockHeader gets the block header from RPC with offset taken into account
func (*BlockNumberFinality) BlockNumber ¶ added in v0.7.0
func (b *BlockNumberFinality) BlockNumber( ctx context.Context, requester ethereum.ChainReader, ) (uint64, error)
BlockNumber gets the block number from RPC with offset taken into account
func (*BlockNumberFinality) Equal ¶
func (b *BlockNumberFinality) Equal(other BlockNumberFinality) 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
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) UnmarshalText ¶
func (b *BlockNumberFinality) UnmarshalText(data []byte) error
UnmarshalText unmarshalls BlockNumberFinality from text.
func (BlockNumberFinality) Validate ¶
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 DefaultEthClient ¶
type DefaultEthClient struct {
BaseEthereumClienter
RPCClienter
}
DefaultEthClient is the default implementation of EthClienter.
func NewDefaultEthClient ¶
func NewDefaultEthClient(baseClient BaseEthereumClienter, rpcClient RPCClienter) *DefaultEthClient
NewDefaultEthClient creates a new DefaultEthClient.
type EthClienter ¶
type EthClienter interface {
BaseEthereumClienter
RPCClienter
}
EthClienter defines the methods for an Ethereum RPC client.
func DialWithRetry ¶ added in v0.7.0
func DialWithRetry(ctx context.Context, url string, retryHandler commontypes.RetryHandler) (EthClienter, error)
DialWithRetry attempts to connect to an Ethereum client with retries and exponential backoff. It returns an EthClienter on success or an error if all attempts fail.
type MultiDownloader ¶
type MultiDownloader interface {
ChainID(ctx context.Context) (uint64, error)
BlockNumber(ctx context.Context, finality BlockNumberFinality) (uint64, error)
// TODO: delete this method because it's only required for a intermediate fix of old RerogDetector
BlockHeader(ctx context.Context, finality BlockNumberFinality) (*BlockHeader, error)
FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethtypes.Log, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*BlockHeader, error)
EthClient() BaseEthereumClienter
RegisterSyncer(data SyncerConfig) error
Start(ctx context.Context) error
}
type NoopRPCClient ¶
type NoopRPCClient struct{}
NoopRPCClient is no operation implementation for the RPCClienter interface
func (*NoopRPCClient) BatchCallContext ¶
type RPCClienter ¶
type RPCClienter interface {
Call(result any, method string, args ...any) error
BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
}
RPCClienter defines an interface for making generic RPC calls.
type SyncerConfig ¶
type SyncerConfig struct {
// SyncerID is the unique identifier for the syncer
SyncerID string
// ContractAddr is list of contract addresses to sync
ContractsAddr []common.Address
// Starting block
FromBlock uint64
// Target for final block (e.g. LatestBlock, SafeBlock, FinalizedBlock)
ToBlock BlockNumberFinality
}