Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertStringToNumber[T any](s string) (T, error)
- type BaseEthereumClienter
- type BlockHeader
- 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 MultiDownloader
- 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} )
Functions ¶
func ConvertStringToNumber ¶
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) String ¶ added in v0.8.0
func (gb *BlockHeader) String() string
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)
}
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 MultiDownloader ¶ added in v0.8.0
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 *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
// 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
}