ethclients

package module
v0.0.0-...-82f5269 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 8 Imported by: 5

README

iwinswap-ethclients

A Go library that provides foundational interfaces, mocks, and utility wrappers for Ethereum clients, designed to promote testable and decoupled application architecture.


Overview

When you build Go applications that interact with Ethereum, writing modular, easily testable code usually means depending on interfaces rather than concrete client implementations.

iwinswap-ethclients supplies those essentials:

Component Purpose
ETHClient interface A thin abstraction that mirrors the methods of ethclient.Client (and satisfies interfaces like bind.ContractBackend). Depend on this instead of the concrete go‑ethereum client.
TestETHClient mock A powerful in‑memory mock so unit tests need no live RPC endpoint.
ETHClientWithMaxConcurrentCalls wrapper Drop‑in decorator that limits the number of in‑flight RPC calls — handy for rate‑limited endpoints.

Use the package directly or as the bedrock for higher‑level helpers (e.g., a client manager).


Installation

go get github.com/Iwinswap/iwinswap-ethclients

Core Components

1. ETHClient Interface

The heart of the package. It standardises Ethereum‑node interactions:

type ETHClient interface {
    BlockNumber(ctx context.Context) (uint64, error)
    // …other methods that match ethclient.Client and bind.ContractBackend
}

Write your business logic against ETHClient; swap in real, mock, or wrapped clients without touching your code.


2. TestETHClient — Built‑in Mock

Unit‑test without spinning up Ganache/Anvil/mainnet:

mock := ethclients.NewTestETHClient()

expected := uint64(12345678)
mock.SetBlockNumberHandler(func(ctx context.Context) (uint64, error) {
    return expected, nil
})

svc := yourapp.NewBlockService(mock)

got, err := svc.GetLatestBlock(context.Background())

No RPC, no flakes — just pure Go tests.


3. ETHClientWithMaxConcurrentCalls — Concurrency Limiter

Protects rate‑limited endpoints or keeps CPU/RAM in check:

raw, _ := ethclient.Dial("https://mainnet.infura.io/v3/YOUR_KEY")

limited, _ := ethclients.NewETHClientWithMaxConcurrentCalls(raw, 10) // max 10 concurrent calls

blockNum, _ := limited.BlockNumber(context.Background())
log.Printf("latest block: %d", blockNum)

Any goroutine over the 10th blocks until a slot is free.


Example: Testing with TestETHClient

package yourapp

import (
    "context"
    "testing"

    "github.com/Iwinswap/iwinswap-ethclients"
    "github.com/stretchr/testify/assert"
)

type BlockService struct{ c ethclients.ETHClient }

func NewBlockService(c ethclients.ETHClient) *BlockService { return &BlockService{c} }

func (s *BlockService) GetLatestBlock(ctx context.Context) (uint64, error) {
    return s.c.BlockNumber(ctx)
}

func TestBlockService(t *testing.T) {
    mock := ethclients.NewTestETHClient()

    want := uint64(12345678)
    mock.SetBlockNumberHandler(func(ctx context.Context) (uint64, error) { return want, nil })

    svc := NewBlockService(mock)

    got, err := svc.GetLatestBlock(context.Background())
    assert.NoError(t, err)
    assert.Equal(t, want, got)
}

Contributing

Pull requests and issues are welcome!

go fmt ./...
go test ./...

License

iwinswap-ethclients is released under the MIT License — see LICENSE for full text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ETHClient

type ETHClient interface {
	// Close closes the underlying RPC connection.
	Close()
	// Client gets the underlying RPC client.
	Client() *rpc.Client

	// ChainID retrieves the current chain ID for transaction replay protection.
	ChainID(ctx context.Context) (*big.Int, error)
	// BlockByHash returns the given full block.
	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
	// BlockByNumber returns a block from the current canonical chain. If number is nil, the
	// latest known block is returned.
	BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
	// BlockNumber returns the most recent block number.
	BlockNumber(ctx context.Context) (uint64, error)
	// PeerCount returns the number of p2p peers.
	PeerCount(ctx context.Context) (uint64, error)
	// BlockReceipts returns the receipts of a given block number or hash.
	BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error)
	// HeaderByHash returns the block header with the given hash.
	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
	// HeaderByNumber returns a block header from the current canonical chain. If number is
	// nil, the latest known header is returned.
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
	// TransactionByHash returns the transaction with the given hash.
	TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
	// TransactionSender returns the sender address of the given transaction.
	TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
	// TransactionCount returns the total number of transactions in the given block.
	TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
	// TransactionInBlock returns a single transaction at index in the given block.
	TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
	// TransactionReceipt returns the receipt of a transaction by transaction hash.
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	// SyncProgress retrieves the current progress of the sync algorithm.
	SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
	// SubscribeNewHead subscribes to notifications about the current blockchain head.
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

	// NetworkID returns the network ID.
	NetworkID(ctx context.Context) (*big.Int, error)
	// BalanceAt returns the wei balance of the given account at a specific block number.
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	// BalanceAtHash returns the wei balance of the given account at a specific block hash.
	BalanceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (*big.Int, error)
	// StorageAt returns the value of key in the contract storage of the given account at a specific block number.
	StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
	// StorageAtHash returns the value of key in the contract storage of the given account at a specific block hash.
	StorageAtHash(ctx context.Context, account common.Address, key common.Hash, blockHash common.Hash) ([]byte, error)
	// CodeAt returns the contract code of the given account at a specific block number.
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	// CodeAtHash returns the contract code of the given account at a specific block hash.
	CodeAtHash(ctx context.Context, account common.Address, blockHash common.Hash) ([]byte, error)
	// NonceAt returns the account nonce of the given account at a specific block number.
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	// NonceAtHash returns the account nonce of the given account at a specific block hash.
	NonceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (uint64, error)

	// FilterLogs executes a filter query.
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
	// SubscribeFilterLogs subscribes to the results of a streaming filter query.
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

	// PendingBalanceAt returns the wei balance of the given account in the pending state.
	PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
	// PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.
	PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
	// PendingCodeAt returns the contract code of the given account in the pending state.
	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
	// PendingNonceAt returns the account nonce of the given account in the pending state.
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	// PendingTransactionCount returns the total number of transactions in the pending state.
	PendingTransactionCount(ctx context.Context) (uint, error)

	// CallContract executes a message call transaction at a specific block number.
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	// CallContractAtHash executes a message call transaction at a specific block hash.
	CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
	// PendingCallContract executes a message call transaction using the pending state.
	PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
	// SuggestGasPrice retrieves the currently suggested gas price.
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	// SuggestGasTipCap retrieves the currently suggested gas tip cap.
	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
	// FeeHistory retrieves the fee market history.
	FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error)
	// EstimateGas tries to estimate the gas needed to execute a specific transaction.
	EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
	// SendTransaction injects a signed transaction into the pending pool.
	SendTransaction(ctx context.Context, tx *types.Transaction) error
}

ETHClient defines the methods exposed by an Ethereum RPC client. This interface abstracts the concrete implementation (*ethclient.Client) allowing for easier testing and dependency injection.

type ETHClientWithMaxConcurrentCalls

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

func NewETHClientWithMaxConcurrentCalls

func NewETHClientWithMaxConcurrentCalls(client ETHClient, max int) (*ETHClientWithMaxConcurrentCalls, error)

func (*ETHClientWithMaxConcurrentCalls) BalanceAt

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

BalanceAt returns the wei balance of the given account at a specific block number.

func (*ETHClientWithMaxConcurrentCalls) BalanceAtHash

func (c *ETHClientWithMaxConcurrentCalls) BalanceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (*big.Int, error)

BalanceAtHash returns the wei balance of the given account at a specific block hash.

func (*ETHClientWithMaxConcurrentCalls) BlockByHash

BlockByHash returns the given full block.

func (*ETHClientWithMaxConcurrentCalls) BlockByNumber

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

BlockByNumber returns a block from the current canonical chain. If number is nil, the latest known block is returned.

func (*ETHClientWithMaxConcurrentCalls) BlockNumber

BlockNumber returns the most recent block number.

func (*ETHClientWithMaxConcurrentCalls) BlockReceipts

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

BlockReceipts returns the receipts of a given block number or hash.

func (*ETHClientWithMaxConcurrentCalls) CallContract

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

CallContract is the most called and the slowest method it is the most important to limit the number of concurrent calls

func (*ETHClientWithMaxConcurrentCalls) CallContractAtHash

func (c *ETHClientWithMaxConcurrentCalls) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)

CallContractAtHash executes a message call transaction at a specific block hash.

func (*ETHClientWithMaxConcurrentCalls) ChainID

ChainID retrieves the current chain ID for transaction replay protection.

func (*ETHClientWithMaxConcurrentCalls) Client

func (c *ETHClientWithMaxConcurrentCalls) Client() (_ *rpc.Client)

Client gets the underlying RPC client.

func (*ETHClientWithMaxConcurrentCalls) Close

Close closes the underlying RPC connection.

func (*ETHClientWithMaxConcurrentCalls) CodeAt

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

CodeAt returns the contract code of the given account at a specific block number.

func (*ETHClientWithMaxConcurrentCalls) CodeAtHash

func (c *ETHClientWithMaxConcurrentCalls) CodeAtHash(ctx context.Context, account common.Address, blockHash common.Hash) ([]byte, error)

CodeAtHash returns the contract code of the given account at a specific block hash.

func (*ETHClientWithMaxConcurrentCalls) EstimateGas

EstimateGas tries to estimate the gas needed to execute a specific transaction.

func (*ETHClientWithMaxConcurrentCalls) FeeHistory

func (c *ETHClientWithMaxConcurrentCalls) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error)

FeeHistory retrieves the fee market history.

func (*ETHClientWithMaxConcurrentCalls) FilterLogs

FilterLogs executes a filter query.

func (*ETHClientWithMaxConcurrentCalls) HeaderByHash

HeaderByHash returns the block header with the given hash.

func (*ETHClientWithMaxConcurrentCalls) HeaderByNumber

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

HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*ETHClientWithMaxConcurrentCalls) NetworkID

NetworkID returns the network ID.

func (*ETHClientWithMaxConcurrentCalls) NonceAt

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

NonceAt returns the account nonce of the given account at a specific block number.

func (*ETHClientWithMaxConcurrentCalls) NonceAtHash

func (c *ETHClientWithMaxConcurrentCalls) NonceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (uint64, error)

NonceAtHash returns the account nonce of the given account at a specific block hash.

func (*ETHClientWithMaxConcurrentCalls) PeerCount

PeerCount returns the number of p2p peers.

func (*ETHClientWithMaxConcurrentCalls) PendingBalanceAt

func (c *ETHClientWithMaxConcurrentCalls) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)

PendingBalanceAt returns the wei balance of the given account in the pending state.

func (*ETHClientWithMaxConcurrentCalls) PendingCallContract

func (c *ETHClientWithMaxConcurrentCalls) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)

PendingCallContract executes a message call transaction using the pending state.

func (*ETHClientWithMaxConcurrentCalls) PendingCodeAt

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

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

func (*ETHClientWithMaxConcurrentCalls) PendingNonceAt

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

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

func (*ETHClientWithMaxConcurrentCalls) PendingStorageAt

func (c *ETHClientWithMaxConcurrentCalls) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)

PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.

func (*ETHClientWithMaxConcurrentCalls) PendingTransactionCount

func (c *ETHClientWithMaxConcurrentCalls) PendingTransactionCount(ctx context.Context) (uint, error)

PendingTransactionCount returns the total number of transactions in the pending state.

func (*ETHClientWithMaxConcurrentCalls) SendTransaction

SendTransaction injects a signed transaction into the pending pool.

func (*ETHClientWithMaxConcurrentCalls) StorageAt

func (c *ETHClientWithMaxConcurrentCalls) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)

StorageAt returns the value of key in the contract storage of the given account at a specific block number.

func (*ETHClientWithMaxConcurrentCalls) StorageAtHash

func (c *ETHClientWithMaxConcurrentCalls) StorageAtHash(ctx context.Context, account common.Address, key common.Hash, blockHash common.Hash) ([]byte, error)

StorageAtHash returns the value of key in the contract storage of the given account at a specific block hash.

func (*ETHClientWithMaxConcurrentCalls) SubscribeFilterLogs

SubscribeFilterLogs subscribes to the results of a streaming filter query.

func (*ETHClientWithMaxConcurrentCalls) SubscribeNewHead

func (c *ETHClientWithMaxConcurrentCalls) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

SubscribeNewHead subscribes to notifications about the current blockchain head.

func (*ETHClientWithMaxConcurrentCalls) SuggestGasPrice

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

SuggestGasPrice retrieves the currently suggested gas price.

func (*ETHClientWithMaxConcurrentCalls) SuggestGasTipCap

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

SuggestGasTipCap retrieves the currently suggested gas tip cap.

func (*ETHClientWithMaxConcurrentCalls) SyncProgress

SyncProgress retrieves the current progress of the sync algorithm.

func (*ETHClientWithMaxConcurrentCalls) TransactionByHash

func (c *ETHClientWithMaxConcurrentCalls) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)

TransactionByHash returns the transaction with the given hash.

func (*ETHClientWithMaxConcurrentCalls) TransactionCount

func (c *ETHClientWithMaxConcurrentCalls) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)

TransactionCount returns the total number of transactions in the given block.

func (*ETHClientWithMaxConcurrentCalls) TransactionInBlock

func (c *ETHClientWithMaxConcurrentCalls) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)

TransactionInBlock returns a single transaction at index in the given block.

func (*ETHClientWithMaxConcurrentCalls) TransactionReceipt

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

TransactionReceipt returns the receipt of a transaction by transaction hash.

func (*ETHClientWithMaxConcurrentCalls) TransactionSender

func (c *ETHClientWithMaxConcurrentCalls) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)

TransactionSender returns the sender address of the given transaction.

type TestETHClient

type TestETHClient struct {

	// CloseFunc func() // Close doesn't return, simple tracking might be better if needed
	ClientFunc func() *rpc.Client

	// Blockchain Access Handlers
	ChainIDFunc            func(ctx context.Context) (*big.Int, error)
	BlockByHashFunc        func(ctx context.Context, hash common.Hash) (*types.Block, error)
	BlockByNumberFunc      func(ctx context.Context, number *big.Int) (*types.Block, error)
	BlockNumberFunc        func(ctx context.Context) (uint64, error)
	PeerCountFunc          func(ctx context.Context) (uint64, error)
	BlockReceiptsFunc      func(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error)
	HeaderByHashFunc       func(ctx context.Context, hash common.Hash) (*types.Header, error)
	HeaderByNumberFunc     func(ctx context.Context, number *big.Int) (*types.Header, error)
	TransactionByHashFunc  func(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
	TransactionSenderFunc  func(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
	TransactionCountFunc   func(ctx context.Context, blockHash common.Hash) (uint, error)
	TransactionInBlockFunc func(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
	TransactionReceiptFunc func(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	SyncProgressFunc       func(ctx context.Context) (*ethereum.SyncProgress, error)
	SubscribeNewHeadFunc   func(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

	// State Access Handlers
	NetworkIDFunc     func(ctx context.Context) (*big.Int, error)
	BalanceAtFunc     func(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	BalanceAtHashFunc func(ctx context.Context, account common.Address, blockHash common.Hash) (*big.Int, error)
	StorageAtFunc     func(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
	StorageAtHashFunc func(ctx context.Context, account common.Address, key common.Hash, blockHash common.Hash) ([]byte, error)
	CodeAtFunc        func(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	CodeAtHashFunc    func(ctx context.Context, account common.Address, blockHash common.Hash) ([]byte, error)
	NonceAtFunc       func(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	NonceAtHashFunc   func(ctx context.Context, account common.Address, blockHash common.Hash) (uint64, error)

	// Filters Handlers
	FilterLogsFunc          func(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
	SubscribeFilterLogsFunc func(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

	// Pending State Handlers
	PendingBalanceAtFunc        func(ctx context.Context, account common.Address) (*big.Int, error)
	PendingStorageAtFunc        func(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
	PendingCodeAtFunc           func(ctx context.Context, account common.Address) ([]byte, error)
	PendingNonceAtFunc          func(ctx context.Context, account common.Address) (uint64, error)
	PendingTransactionCountFunc func(ctx context.Context) (uint, error)

	// Contract Calling Handlers
	CallContractFunc        func(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	CallContractAtHashFunc  func(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
	PendingCallContractFunc func(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
	SuggestGasPriceFunc     func(ctx context.Context) (*big.Int, error)
	SuggestGasTipCapFunc    func(ctx context.Context) (*big.Int, error)
	FeeHistoryFunc          func(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error)
	EstimateGasFunc         func(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
	SendTransactionFunc     func(ctx context.Context, tx *types.Transaction) error
	// contains filtered or unexported fields
}

TestETHClient provides a mock implementation of the ETHClient interface. It defaults to returning nil/zero values but allows registering custom handler functions for specific methods using Set...Handler methods.

func NewTestETHClient

func NewTestETHClient() *TestETHClient

NewTestETHClient creates a new TestETHClient mock instance.

func (*TestETHClient) BalanceAt

func (m *TestETHClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)

func (*TestETHClient) BalanceAtHash

func (m *TestETHClient) BalanceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (*big.Int, error)

func (*TestETHClient) BlockByHash

func (m *TestETHClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)

func (*TestETHClient) BlockByNumber

func (m *TestETHClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

func (*TestETHClient) BlockNumber

func (m *TestETHClient) BlockNumber(ctx context.Context) (uint64, error)

func (*TestETHClient) BlockReceipts

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

func (*TestETHClient) CallContract

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

func (*TestETHClient) CallContractAtHash

func (m *TestETHClient) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)

func (*TestETHClient) ChainID

func (m *TestETHClient) ChainID(ctx context.Context) (*big.Int, error)

func (*TestETHClient) Client

func (m *TestETHClient) Client() *rpc.Client

func (*TestETHClient) Close

func (m *TestETHClient) Close()

func (*TestETHClient) CloseCalled

func (m *TestETHClient) CloseCalled() bool

CloseCalled returns true if Close() was invoked.

func (*TestETHClient) CodeAt

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

func (*TestETHClient) CodeAtHash

func (m *TestETHClient) CodeAtHash(ctx context.Context, account common.Address, blockHash common.Hash) ([]byte, error)

func (*TestETHClient) EstimateGas

func (m *TestETHClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

func (*TestETHClient) FeeHistory

func (m *TestETHClient) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error)

func (*TestETHClient) FilterLogs

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

func (*TestETHClient) HeaderByHash

func (m *TestETHClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)

func (*TestETHClient) HeaderByNumber

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

func (*TestETHClient) NetworkID

func (m *TestETHClient) NetworkID(ctx context.Context) (*big.Int, error)

func (*TestETHClient) NonceAt

func (m *TestETHClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)

func (*TestETHClient) NonceAtHash

func (m *TestETHClient) NonceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (uint64, error)

func (*TestETHClient) PeerCount

func (m *TestETHClient) PeerCount(ctx context.Context) (uint64, error)

func (*TestETHClient) PendingBalanceAt

func (m *TestETHClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)

func (*TestETHClient) PendingCallContract

func (m *TestETHClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)

func (*TestETHClient) PendingCodeAt

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

func (*TestETHClient) PendingNonceAt

func (m *TestETHClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*TestETHClient) PendingStorageAt

func (m *TestETHClient) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)

func (*TestETHClient) PendingTransactionCount

func (m *TestETHClient) PendingTransactionCount(ctx context.Context) (uint, error)

func (*TestETHClient) SendTransaction

func (m *TestETHClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*TestETHClient) SetBalanceAtHandler

func (m *TestETHClient) SetBalanceAtHandler(f func(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error))

func (*TestETHClient) SetBalanceAtHashHandler

func (m *TestETHClient) SetBalanceAtHashHandler(f func(ctx context.Context, account common.Address, blockHash common.Hash) (*big.Int, error))

func (*TestETHClient) SetBlockByHashHandler

func (m *TestETHClient) SetBlockByHashHandler(f func(ctx context.Context, hash common.Hash) (*types.Block, error))

func (*TestETHClient) SetBlockByNumberHandler

func (m *TestETHClient) SetBlockByNumberHandler(f func(ctx context.Context, number *big.Int) (*types.Block, error))

func (*TestETHClient) SetBlockNumberHandler

func (m *TestETHClient) SetBlockNumberHandler(f func(ctx context.Context) (uint64, error))

func (*TestETHClient) SetBlockReceiptsHandler

func (m *TestETHClient) SetBlockReceiptsHandler(f func(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error))

func (*TestETHClient) SetCallContractAtHashHandler

func (m *TestETHClient) SetCallContractAtHashHandler(f func(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error))

func (*TestETHClient) SetCallContractHandler

func (m *TestETHClient) SetCallContractHandler(f func(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error))

func (*TestETHClient) SetChainIDHandler

func (m *TestETHClient) SetChainIDHandler(f func(ctx context.Context) (*big.Int, error))

func (*TestETHClient) SetClientHandler

func (m *TestETHClient) SetClientHandler(f func() *rpc.Client)

func (*TestETHClient) SetCodeAtHandler

func (m *TestETHClient) SetCodeAtHandler(f func(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error))

func (*TestETHClient) SetCodeAtHashHandler

func (m *TestETHClient) SetCodeAtHashHandler(f func(ctx context.Context, account common.Address, blockHash common.Hash) ([]byte, error))

func (*TestETHClient) SetEstimateGasHandler

func (m *TestETHClient) SetEstimateGasHandler(f func(ctx context.Context, msg ethereum.CallMsg) (uint64, error))

func (*TestETHClient) SetFeeHistoryHandler

func (m *TestETHClient) SetFeeHistoryHandler(f func(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error))

func (*TestETHClient) SetFilterLogsHandler

func (m *TestETHClient) SetFilterLogsHandler(f func(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error))

func (*TestETHClient) SetHeaderByHashHandler

func (m *TestETHClient) SetHeaderByHashHandler(f func(ctx context.Context, hash common.Hash) (*types.Header, error))

func (*TestETHClient) SetHeaderByNumberHandler

func (m *TestETHClient) SetHeaderByNumberHandler(f func(ctx context.Context, number *big.Int) (*types.Header, error))

func (*TestETHClient) SetNetworkIDHandler

func (m *TestETHClient) SetNetworkIDHandler(f func(ctx context.Context) (*big.Int, error))

func (*TestETHClient) SetNonceAtHandler

func (m *TestETHClient) SetNonceAtHandler(f func(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error))

func (*TestETHClient) SetNonceAtHashHandler

func (m *TestETHClient) SetNonceAtHashHandler(f func(ctx context.Context, account common.Address, blockHash common.Hash) (uint64, error))

func (*TestETHClient) SetPeerCountHandler

func (m *TestETHClient) SetPeerCountHandler(f func(ctx context.Context) (uint64, error))

func (*TestETHClient) SetPendingBalanceAtHandler

func (m *TestETHClient) SetPendingBalanceAtHandler(f func(ctx context.Context, account common.Address) (*big.Int, error))

func (*TestETHClient) SetPendingCallContractHandler

func (m *TestETHClient) SetPendingCallContractHandler(f func(ctx context.Context, msg ethereum.CallMsg) ([]byte, error))

func (*TestETHClient) SetPendingCodeAtHandler

func (m *TestETHClient) SetPendingCodeAtHandler(f func(ctx context.Context, account common.Address) ([]byte, error))

func (*TestETHClient) SetPendingNonceAtHandler

func (m *TestETHClient) SetPendingNonceAtHandler(f func(ctx context.Context, account common.Address) (uint64, error))

func (*TestETHClient) SetPendingStorageAtHandler

func (m *TestETHClient) SetPendingStorageAtHandler(f func(ctx context.Context, account common.Address, key common.Hash) ([]byte, error))

func (*TestETHClient) SetPendingTransactionCountHandler

func (m *TestETHClient) SetPendingTransactionCountHandler(f func(ctx context.Context) (uint, error))

func (*TestETHClient) SetSendTransactionHandler

func (m *TestETHClient) SetSendTransactionHandler(f func(ctx context.Context, tx *types.Transaction) error)

func (*TestETHClient) SetStorageAtHandler

func (m *TestETHClient) SetStorageAtHandler(f func(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error))

func (*TestETHClient) SetStorageAtHashHandler

func (m *TestETHClient) SetStorageAtHashHandler(f func(ctx context.Context, account common.Address, key common.Hash, blockHash common.Hash) ([]byte, error))

func (*TestETHClient) SetSubscribeFilterLogsHandler

func (m *TestETHClient) SetSubscribeFilterLogsHandler(f func(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error))

func (*TestETHClient) SetSubscribeNewHeadHandler

func (m *TestETHClient) SetSubscribeNewHeadHandler(f func(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error))

func (*TestETHClient) SetSuggestGasPriceHandler

func (m *TestETHClient) SetSuggestGasPriceHandler(f func(ctx context.Context) (*big.Int, error))

func (*TestETHClient) SetSuggestGasTipCapHandler

func (m *TestETHClient) SetSuggestGasTipCapHandler(f func(ctx context.Context) (*big.Int, error))

func (*TestETHClient) SetSyncProgressHandler

func (m *TestETHClient) SetSyncProgressHandler(f func(ctx context.Context) (*ethereum.SyncProgress, error))

func (*TestETHClient) SetTransactionByHashHandler

func (m *TestETHClient) SetTransactionByHashHandler(f func(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error))

func (*TestETHClient) SetTransactionCountHandler

func (m *TestETHClient) SetTransactionCountHandler(f func(ctx context.Context, blockHash common.Hash) (uint, error))

func (*TestETHClient) SetTransactionInBlockHandler

func (m *TestETHClient) SetTransactionInBlockHandler(f func(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error))

func (*TestETHClient) SetTransactionReceiptHandler

func (m *TestETHClient) SetTransactionReceiptHandler(f func(ctx context.Context, txHash common.Hash) (*types.Receipt, error))

func (*TestETHClient) SetTransactionSenderHandler

func (m *TestETHClient) SetTransactionSenderHandler(f func(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error))

func (*TestETHClient) StorageAt

func (m *TestETHClient) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)

func (*TestETHClient) StorageAtHash

func (m *TestETHClient) StorageAtHash(ctx context.Context, account common.Address, key common.Hash, blockHash common.Hash) ([]byte, error)

func (*TestETHClient) SubscribeFilterLogs

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

func (*TestETHClient) SubscribeNewHead

func (m *TestETHClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

func (*TestETHClient) SuggestGasPrice

func (m *TestETHClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*TestETHClient) SuggestGasTipCap

func (m *TestETHClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

func (*TestETHClient) SyncProgress

func (m *TestETHClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)

func (*TestETHClient) TransactionByHash

func (m *TestETHClient) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)

func (*TestETHClient) TransactionCount

func (m *TestETHClient) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)

func (*TestETHClient) TransactionInBlock

func (m *TestETHClient) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)

func (*TestETHClient) TransactionReceipt

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

func (*TestETHClient) TransactionSender

func (m *TestETHClient) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)

type TestSubscription

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

func NewTestSubscription

func NewTestSubscription(unsubscribe func(), err func() <-chan error) *TestSubscription

func (*TestSubscription) Err

func (s *TestSubscription) Err() <-chan error

func (*TestSubscription) Unsubscribe

func (s *TestSubscription) Unsubscribe()

Jump to

Keyboard shortcuts

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