eth

package
v0.0.0-...-80ff8fe Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyDial = errors.New("client is already dialed, please Close() before dialing again")
	ErrClosed      = errors.New("client is already closed, please Dial() before closing again")
)
View Source
var (
	ErrClientNotFound = errors.New("client not found")
)

ErrClientNotFound is an error that is returned when a client is not found.

Functions

This section is empty.

Types

type ChainProviderImpl

type ChainProviderImpl struct {
	ConnectionPool
	// contains filtered or unexported fields
}

ChainProviderImpl is an implementation of the ChainProvider interface.

func (*ChainProviderImpl) BalanceAt

func (c *ChainProviderImpl) BalanceAt(
	ctx context.Context, address common.Address, blockNumber *big.Int) (*big.Int, error)

BalanceAt returns the balance of the given address at the given block number.

func (*ChainProviderImpl) BlockByNumber

func (c *ChainProviderImpl) BlockByNumber(
	ctx context.Context, num *big.Int) (*types.Block, error)

BlockByNumber returns the block for the given number.

func (*ChainProviderImpl) BlockNumber

func (c *ChainProviderImpl) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber returns the current block number.

func (*ChainProviderImpl) BlockReceipts

func (c *ChainProviderImpl) BlockReceipts(
	ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error)

BlockReceipts returns the receipts for the given block number or hash.

func (*ChainProviderImpl) CallContract

func (c *ChainProviderImpl) CallContract(
	ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int,
) ([]byte, error)

CallContract calls a contract with the given message at the given block number.

func (*ChainProviderImpl) ChainID

func (c *ChainProviderImpl) ChainID(ctx context.Context) (*big.Int, error)

ChainID returns the current chain ID.

func (*ChainProviderImpl) CodeAt

func (c *ChainProviderImpl) CodeAt(
	ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)

CodeAt returns the code of the given account at the given block number.

func (*ChainProviderImpl) EstimateGas

func (c *ChainProviderImpl) EstimateGas(
	ctx context.Context, msg ethereum.CallMsg) (uint64, error)

EstimateGas estimates the gas needed to execute a specific transaction.

func (*ChainProviderImpl) FilterLogs

func (c *ChainProviderImpl) FilterLogs(
	ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

FilterLogs returns the logs that satisfy the given filter query.

func (*ChainProviderImpl) HeaderByNumber

func (c *ChainProviderImpl) HeaderByNumber(
	ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber returns the header of the block with the given number.

func (*ChainProviderImpl) Health

func (c *ChainProviderImpl) Health() bool

func (*ChainProviderImpl) NonceAt

func (c *ChainProviderImpl) NonceAt(
	ctx context.Context, account common.Address, bn *big.Int) (uint64, error)

PendingNonceAt returns the nonce of the given account in the pending state.

func (*ChainProviderImpl) PendingCodeAt

func (c *ChainProviderImpl) PendingCodeAt(
	ctx context.Context, account common.Address) ([]byte, error)

PendingCodeAt returns the code of the given account in the pending state.

func (*ChainProviderImpl) PendingNonceAt

func (c *ChainProviderImpl) PendingNonceAt(
	ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt returns the nonce of the given account in the pending state.

func (*ChainProviderImpl) SendTransaction

func (c *ChainProviderImpl) SendTransaction(
	ctx context.Context, tx *types.Transaction) error

SendTransaction sends the given transaction.

func (*ChainProviderImpl) SubscribeFilterLogs

func (c *ChainProviderImpl) SubscribeFilterLogs(
	ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log,
) (ethereum.Subscription, error)

SubscribeFilterLogs subscribes to new log events that satisfy the given filter query.

func (*ChainProviderImpl) SubscribeNewHead

func (c *ChainProviderImpl) SubscribeNewHead(
	ctx context.Context) (chan *types.Header, ethereum.Subscription, error)

SubscribeNewHead subscribes to new head events.

func (*ChainProviderImpl) SuggestGasPrice

func (c *ChainProviderImpl) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice suggests a gas price.

func (*ChainProviderImpl) SuggestGasTipCap

func (c *ChainProviderImpl) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

SuggestGasTipCap suggests a gas tip cap.

func (*ChainProviderImpl) TransactionByHash

func (c *ChainProviderImpl) TransactionByHash(
	ctx context.Context, hash common.Hash,
) (*types.Transaction, bool, error)

TransactionByHash returns the transaction with the given hash.

func (*ChainProviderImpl) TransactionReceipt

func (c *ChainProviderImpl) TransactionReceipt(
	ctx context.Context, txHash common.Hash) (*types.Receipt, error)

TransactionReceipt returns the receipt for the given transaction hash.

func (*ChainProviderImpl) TxPoolContent

func (c *ChainProviderImpl) TxPoolContent(ctx context.Context) (
	map[string]map[string]map[string]*types.Transaction, error,
)

type Client

type Client interface {
	DialContext(ctx context.Context, rawurl string) error
	Close() error
	Health() bool
	Reader
	Writer
}

func NewChainProviderImpl

func NewChainProviderImpl(pool ConnectionPool, cfg ConnectionPoolConfig) (Client, error)

NewChainProviderImpl creates a new ChainProviderImpl with the given ConnectionPool.

type ConnectionPool

type ConnectionPool interface {
	GetHTTP() (*HealthCheckedClient, bool)
	GetWS() (*HealthCheckedClient, bool)
	RemoveChainClient(string) error
	Close() error
	Dial(string) error
	DialContext(context.Context, string) error
}

func NewConnectionPoolImpl

func NewConnectionPoolImpl(cfg ConnectionPoolConfig, logger log.Logger) (ConnectionPool, error)

type ConnectionPoolConfig

type ConnectionPoolConfig struct {
	EthHTTPURLs         []string
	EthWSURLs           []string
	DefaultTimeout      time.Duration
	HealthCheckInterval time.Duration
}

func DefaultConnectPoolConfig

func DefaultConnectPoolConfig() *ConnectionPoolConfig

type ConnectionPoolImpl

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

func (*ConnectionPoolImpl) Close

func (c *ConnectionPoolImpl) Close() error

func (*ConnectionPoolImpl) Dial

func (c *ConnectionPoolImpl) Dial(string) error

func (*ConnectionPoolImpl) DialContext

func (c *ConnectionPoolImpl) DialContext(ctx context.Context, _ string) error

func (*ConnectionPoolImpl) GetHTTP

func (c *ConnectionPoolImpl) GetHTTP() (*HealthCheckedClient, bool)

func (*ConnectionPoolImpl) GetWS

func (*ConnectionPoolImpl) RemoveChainClient

func (c *ConnectionPoolImpl) RemoveChainClient(clientAddr string) error

type ExtendedEthClient

type ExtendedEthClient struct {
	*ethclient.Client
	// contains filtered or unexported fields
}

client is the indexer eth client.

func NewExtendedEthClient

func NewExtendedEthClient(c *ethclient.Client, rpcTimeout time.Duration) *ExtendedEthClient

func (*ExtendedEthClient) Close

func (c *ExtendedEthClient) Close() error

Close closes the client.

func (*ExtendedEthClient) DialContext

func (c *ExtendedEthClient) DialContext(ctx context.Context, rawurl string) error

func (*ExtendedEthClient) GetReceipts

GetReceipts returns the receipts for the given transactions.

func (*ExtendedEthClient) Health

func (c *ExtendedEthClient) Health() bool

func (*ExtendedEthClient) SubscribeFilterLogs

func (c *ExtendedEthClient) SubscribeFilterLogs(
	ctx context.Context,
	q ethereum.FilterQuery, ch chan<- ethcoretypes.Log) (ethereum.Subscription, error)

func (*ExtendedEthClient) SubscribeNewHead

func (c *ExtendedEthClient) SubscribeNewHead(
	ctx context.Context) (chan *ethcoretypes.Header, ethereum.Subscription, error)

SubscribeNewHead subscribes to new block headers.

func (*ExtendedEthClient) TxPoolContent

func (c *ExtendedEthClient) TxPoolContent(
	ctx context.Context,
) (map[string]map[string]map[string]*ethcoretypes.Transaction, error)

type HealthCheckedClient

type HealthCheckedClient struct {
	*ExtendedEthClient
	// contains filtered or unexported fields
}

func NewHealthCheckedClient

func NewHealthCheckedClient(
	healthCheckInterval time.Duration, logger log.Logger,
) *HealthCheckedClient

func (*HealthCheckedClient) DialContext

func (c *HealthCheckedClient) DialContext(
	ctx context.Context, rawurl string, rpcTimeout time.Duration,
) error

func (*HealthCheckedClient) Healthy

func (c *HealthCheckedClient) Healthy() bool

func (*HealthCheckedClient) SetHealthy

func (c *HealthCheckedClient) SetHealthy(healthy bool)

func (*HealthCheckedClient) StartHealthCheck

func (c *HealthCheckedClient) StartHealthCheck(ctx context.Context)

type Reader

type Reader interface {
	BlockByNumber(ctx context.Context, number *big.Int) (*ethcoretypes.Block, error)
	BlockReceipts(
		ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash,
	) ([]*ethcoretypes.Receipt, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*ethcoretypes.Receipt, error)
	SubscribeNewHead(ctx context.Context) (chan *ethcoretypes.Header, ethereum.Subscription, error)
	BlockNumber(ctx context.Context) (uint64, error)
	ChainID(ctx context.Context) (*big.Int, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethcoretypes.Log, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*ethcoretypes.Header, error)
	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery,
		ch chan<- ethcoretypes.Log) (ethereum.Subscription, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
	TransactionByHash(ctx context.Context, hash common.Hash,
	) (tx *ethcoretypes.Transaction, isPending bool, err error)
	TxPoolContent(
		ctx context.Context) (
		map[string]map[string]map[string]*ethcoretypes.Transaction, error)
}

Reader is the eth reader interface.

type Writer

type Writer interface {
	SendTransaction(ctx context.Context, tx *ethcoretypes.Transaction) error
}

Jump to

Keyboard shortcuts

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