types

package
v0.9.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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
)

Variables

View Source
var (
	FinalizedBlock = BlockNumberFinality{Block: Finalized}
	LatestBlock    = BlockNumberFinality{Block: Latest}
	SafeBlock      = BlockNumberFinality{Block: Safe}
	PendingBlock   = BlockNumberFinality{Block: Pending}
)

Functions

func ConvertStringToNumber

func ConvertStringToNumber[T any](s string) (T, error)

Types

type BaseEthereumClienter

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 NewBlockHeader(number uint64, hash common.Hash, time uint64, parentHash *common.Hash) *BlockHeader

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 NewBlockName(s string) (BlockName, error)

func (BlockName) ApplyOffset

func (b BlockName) ApplyOffset(blockNumber uint64, offset int64) uint64

func (BlockName) IsConstant

func (b BlockName) IsConstant() bool

func (BlockName) String

func (b BlockName) String() string

func (BlockName) ToBigInt

func (b BlockName) ToBigInt() *big.Int

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

EthClienter defines the methods for an Ethereum RPC client.

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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