observers

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Overview

Package observers provides tools for managing and interacting with Ethereum onchain data such as blocks, transactions, events and logs. It provides a BlockSubscriber structure that allows for subscribing to block headers based on various criteria, such as the latest block or a range of blocks. It also provides a ContractSubscriber structure that allows for subscribing to old or new contracts based on various criteria, such as the latest blocks or a range of blocks. The package is designed to be flexible and efficient, ensuring that Ethereum onchain data can be easily accessed based on the specific needs of the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockSubscriber

type BlockSubscriber struct {
	// contains filtered or unexported fields
}

BlockSubscriber provides methods to subscribe to blockchain block headers.

func NewBlockSubscriber

func NewBlockSubscriber(ctx context.Context, client *clients.ClientPool) (*BlockSubscriber, error)

NewBlockSubscriber creates a new block subscriber with the given context and client pool.

func (*BlockSubscriber) Close

func (b *BlockSubscriber) Close() error

Close terminates the block subscription and releases any associated resources.

func (*BlockSubscriber) IsActive

func (b *BlockSubscriber) IsActive() bool

IsActive checks if the block subscriber is currently active.

func (*BlockSubscriber) Subscribe

func (b *BlockSubscriber) Subscribe(opts *BlockSubscriberOptions, blockCh chan *types.Block) error

Subscribe subscribes to block based on the provided options. It can either subscribe to the latest blocks or a range of blocks.

func (*BlockSubscriber) SubscribeHeader

func (b *BlockSubscriber) SubscribeHeader(opts *BlockSubscriberOptions, blockCh chan *types.Header) error

SubscribeHeader subscribes to block headers based on the provided options. It can either subscribe to the latest block headers or a range of block headers.

type BlockSubscriberOptions

type BlockSubscriberOptions struct {
	NetworkID        int64    `mapstructure:"network_id" yaml:"network_id" json:"network_id"`                         // The network ID of the blockchain.
	Group            string   `mapstructure:"group" yaml:"group" json:"group"`                                        // The group of the blockchain client.
	Type             string   `mapstructure:"type" yaml:"type" json:"type"`                                           // The type of the blockchain client.
	Head             bool     `mapstructure:"head" yaml:"head" json:"head"`                                           // Flag to indicate if subscribing to the latest block.
	StartBlockNumber *big.Int `mapstructure:"start_block_number" yaml:"start_block_number" json:"start_block_number"` // The starting block number for the subscription.
	EndBlockNumber   *big.Int `mapstructure:"end_block_number" yaml:"end_block_number" json:"end_block_number"`       // The ending block number for the subscription.
}

BlockSubscriberOptions defines the options for configuring a block subscriber.

type Contract

type Contract struct {
	NetworkID       int64              `json:"network_id"`    // The network ID of the Ethereum blockchain.
	NetworkGroup    string             `json:"network_group"` // The group identifier for the blockchain client.
	NetworkType     string             `json:"network_type"`  // The type of the blockchain client.
	ContractAddress common.Address     `json:"contract_addr"` // Ethereum address of the contract.
	Block           *types.Block       `json:"block"`         // Block in which the contract transaction was included.
	Transaction     *types.Transaction `json:"transaction"`   // Transaction that created the contract.
	Receipt         *types.Receipt     `json:"receipt"`       // Receipt of the contract creation transaction.
}

Contract represents a blockchain contract with its associated details.

type ContractSubscriber

type ContractSubscriber struct {
	// contains filtered or unexported fields
}

ContractSubscriber provides methods to subscribe to and interact with Ethereum contracts.

func NewContractSubscriber

func NewContractSubscriber(ctx context.Context, client *clients.ClientPool) (*ContractSubscriber, error)

NewContractSubscriber initializes a new contract subscriber with the provided context and client pool.

func (*ContractSubscriber) Close

func (b *ContractSubscriber) Close() error

Close terminates the contract subscription and releases any associated resources.

func (*ContractSubscriber) IsActive

func (b *ContractSubscriber) IsActive() bool

IsActive checks if the contract subscriber is currently active.

func (*ContractSubscriber) Subscribe

func (b *ContractSubscriber) Subscribe(opts *ContractSubscriberOptions, contractsCh chan *Contract) error

Subscribe initiates a subscription based on the provided options. It can either subscribe to the latest blocks or a specific range of blocks.

type ContractSubscriberOptions

type ContractSubscriberOptions struct {
	NetworkID        int64    `mapstructure:"network_id" yaml:"network_id" json:"network_id"`                         // The network ID of the Ethereum blockchain.
	Group            string   `mapstructure:"group" yaml:"group" json:"group"`                                        // The group identifier for the blockchain client.
	Type             string   `mapstructure:"type" yaml:"type" json:"type"`                                           // The type of the blockchain client.
	Head             bool     `mapstructure:"head" yaml:"head" json:"head"`                                           // If true, subscribes to the latest block. Otherwise, subscribes to a range.
	StartBlockNumber *big.Int `mapstructure:"start_block_number" yaml:"start_block_number" json:"start_block_number"` // Starting block number for the subscription.
	EndBlockNumber   *big.Int `mapstructure:"end_block_number" yaml:"end_block_number" json:"end_block_number"`       // Ending block number for the subscription.
}

ContractSubscriberOptions defines the options for configuring a contract subscriber.

Jump to

Keyboard shortcuts

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