eth

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 15 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) ClientID added in v0.1.6

func (c *ChainProviderImpl) ClientID() string

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) EnableMetrics added in v0.1.6

func (c *ChainProviderImpl) EnableMetrics(m telemetry.Metrics)

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) TxPoolContentFrom

func (c *ChainProviderImpl) TxPoolContentFrom(ctx context.Context, address common.Address) (
	map[string]map[uint64]*types.Transaction, error,
)

TxPoolContentFrom returns the pending and queued transactions of this address. Example response:

{
	"pending": {
		1: {
			// transaction details...
		},
		...
	},
	"queued": {
		3: {
			// transaction details...
		},
		...
	}
}

func (*ChainProviderImpl) TxPoolInspect

func (c *ChainProviderImpl) TxPoolInspect(ctx context.Context) (
	map[string]map[common.Address]map[uint64]string, error,
)

TxPoolInspect returns the textual summary of all pending and queued transactions. Example response:

{
	"pending": {
		"0x12345": {
			1: "0x12345789: 1 wei + 2 gas x 3 wei"
		},
		...
	},
	"queued": {
		"0x67890": {
			2: "0x12345789: 1 wei + 2 gas x 3 wei"
		},
		...
	}
}

type Client

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

func NewChainProviderImpl

func NewChainProviderImpl(pool ConnectionPool, cfg ConnectionPoolConfig) Client

NewChainProviderImpl creates a new ChainProviderImpl with the given ConnectionPool.

type ConnectionPool

type ConnectionPool interface {
	GetHTTP() (Client, bool)
	GetWS() (Client, 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() (Client, bool)

func (*ConnectionPoolImpl) GetWS

func (c *ConnectionPoolImpl) GetWS() (Client, bool)

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) ClientID added in v0.1.6

func (c *ExtendedEthClient) ClientID() string

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) TxPoolContentFrom

func (c *ExtendedEthClient) TxPoolContentFrom(
	ctx context.Context, address common.Address,
) (map[string]map[uint64]*ethcoretypes.Transaction, error)

func (*ExtendedEthClient) TxPoolInspect

func (c *ExtendedEthClient) TxPoolInspect(
	ctx context.Context,
) (map[string]map[common.Address]map[uint64]string, 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) ClientID added in v0.1.6

func (c *HealthCheckedClient) ClientID() string

func (*HealthCheckedClient) DialContextWithTimeout added in v0.1.6

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

func (*HealthCheckedClient) Health added in v0.1.6

func (c *HealthCheckedClient) Health() 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)

	/*
		TxPoolContentFrom returns the pending and queued transactions of this address.
		Example response:

		{
			"pending": {
				1: {
					// transaction details...
				},
				...
			},
			"queued": {
				3: {
					// transaction details...
				},
				...
			}
		}
	*/
	TxPoolContentFrom(ctx context.Context, address common.Address) (
		map[string]map[uint64]*ethcoretypes.Transaction, error,
	)

	/*
		TxPoolInspect returns the textual summary of all pending and queued transactions.
		Example response:

		{
			"pending": {
				"0x12345": {
					1: "0x12345789: 1 wei + 2 gas x 3 wei"
				},
				...
			},
			"queued": {
				"0x67890": {
					2: "0x12345789: 1 wei + 2 gas x 3 wei"
				},
				...
			}
		}
	*/
	TxPoolInspect(ctx context.Context) (map[string]map[common.Address]map[uint64]string, error)
}

Reader is the eth reader interface.

type Writer

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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