client

package
v2.10.0-beta0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 44 Imported by: 5

README

EVM Client

Node FSM

stateDiagram-v2
    [*] --> Started : Start()
    
    state Started {
        [*] --> Undialed
        Undialed --> Unusable
        Undialed --> Unreachable
        Undialed --> Dialed
        
        Unreachable --> Dialed 
        
        Dialed --> Unreachable
        Dialed --> InvalidChainID
        Dialed --> Alive
        
        InvalidChainID --> Unreachable
        InvalidChainID --> Alive
        
        Alive --> Unreachable
        Alive --> OutOfSync
        
        OutOfSync --> Unreachable
        OutOfSync --> InvalidChainID    
        OutOfSync --> Alive    
    }
    
    Started --> Closed : Close()
    Closed --> [*]

Documentation

Overview

The simulated backend cannot access old blocks and will return an error if anything other than `latest`, `nil`, or the latest block are passed to `CallContract`.

The simulated client avoids the old block error from the simulated backend by passing `nil` to `CallContract` when calling `CallContext` or `BatchCallContext` and will not return an error when an old block is used.

Index

Constants

View Source
const (
	NonceTooLow = iota
	// Nethermind specific error. Nethermind throws a NonceGap error when the tx nonce is greater than current_nonce + tx_count_in_mempool, instead of keeping the tx in mempool.
	// See: https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.TxPool/Filters/GapNonceFilter.cs
	NonceTooHigh
	ReplacementTransactionUnderpriced
	LimitReached
	TransactionAlreadyInMempool
	TerminallyUnderpriced
	InsufficientEth
	TxFeeExceedsCap
	// Note: L2FeeTooLow/L2FeeTooHigh/L2Full have a very specific meaning specific
	// to L2s (Arbitrum and clones). Do not implement this for non-L2
	// chains. This is potentially confusing because some RPC nodes e.g.
	// Nethermind implement an error called `FeeTooLow` which has distinct
	// meaning from this one.
	L2FeeTooLow
	L2FeeTooHigh
	L2Full
	TransactionAlreadyMined
	Fatal
	ServiceUnavailable
)
View Source
const (
	// NodeStateUndialed is the first state of a virgin node
	NodeStateUndialed = NodeState(iota)
	// NodeStateDialed is after a node has successfully dialed but before it has verified the correct chain ID
	NodeStateDialed
	// NodeStateInvalidChainID is after chain ID verification failed
	NodeStateInvalidChainID
	// NodeStateAlive is a healthy node after chain ID verification succeeded
	NodeStateAlive
	// NodeStateUnreachable is a node that cannot be dialed or has disconnected
	NodeStateUnreachable
	// NodeStateOutOfSync is a node that is accepting connections but exceeded
	// the failure threshold without sending any new heads. It will be
	// disconnected, then put into a revive loop and re-awakened after redial
	// if a new head arrives
	NodeStateOutOfSync
	// NodeStateUnusable is a sendonly node that has an invalid URL that can never be reached
	NodeStateUnusable
	// NodeStateClosed is after the connection has been closed and the node is at the end of its lifecycle
	NodeStateClosed
)
View Source
const (
	NodeSelectionMode_HighestHead     = "HighestHead"
	NodeSelectionMode_RoundRobin      = "RoundRobin"
	NodeSelectionMode_TotalDifficulty = "TotalDifficulty"
	NodeSelectionMode_PriorityLevel   = "PriorityLevel"
)
View Source
const BALANCE_OF_ADDRESS_FUNCTION_SELECTOR = "0x70a08231"
View Source
const NullClientChainID = 0

NullClientChainID the ChainID that nullclient will return 0 is never used as a real chain ID so makes sense as a dummy value here

Variables

View Source
var (
	// PromEVMPoolRPCNodeStates reports current RPC node state
	PromEVMPoolRPCNodeStates = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "evm_pool_rpc_node_states",
		Help: "The number of RPC nodes currently in the given state for the given chain",
	}, []string{"evmChainID", "state"})
)

Functions

func ClassifySendError added in v2.8.0

func ClassifySendError(err error, lggr logger.SugaredLogger, tx *types.Transaction, fromAddress common.Address, isL2 bool) commonclient.SendTxReturnCode

func ContextWithDefaultTimeout added in v2.1.0

func ContextWithDefaultTimeout() (ctx context.Context, cancel context.CancelFunc)

func Name added in v2.8.0

func Name(r *rpcClient) string

func NewClientWithNodes deprecated

func NewClientWithNodes(lggr logger.Logger, selectionMode string, leaseDuration time.Duration, noNewHeadsThreshold time.Duration, primaryNodes []Node, sendOnlyNodes []SendOnlyNode, chainID *big.Int, chainType config.ChainType) (*client, error)

NewClientWithNodes instantiates a client from a list of nodes Currently only supports one primary

Deprecated: use NewChainClient

func ToBlockNumArg

func ToBlockNumArg(number *big.Int) string

Types

type BatchSender

type BatchSender interface {
	BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
}

type CallArgs

type CallArgs struct {
	From common.Address `json:"from"`
	To   common.Address `json:"to"`
	Data hexutil.Bytes  `json:"data"`
}

CallArgs represents the data used to call the balance method of a contract. "To" is the address of the ERC contract. "Data" is the message sent to the contract. "From" is the sender address.

type Client

type Client interface {
	Dial(ctx context.Context) error
	Close()
	// ChainID locally stored for quick access
	ConfiguredChainID() *big.Int
	// ChainID RPC call
	ChainID() (*big.Int, error)

	// NodeStates returns a map of node Name->node state
	// It might be nil or empty, e.g. for mock clients etc
	NodeStates() map[string]string

	TokenBalance(ctx context.Context, address common.Address, contractAddress common.Address) (*big.Int, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	LINKBalance(ctx context.Context, address common.Address, linkAddress common.Address) (*assets.Link, error)

	// Wrapped RPC methods
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
	// BatchCallContextAll calls BatchCallContext for every single node including
	// sendonlys.
	// CAUTION: This should only be used for mass re-transmitting transactions, it
	// might have unexpected effects to use it for anything else.
	BatchCallContextAll(ctx context.Context, b []rpc.BatchElem) error

	// HeadByNumber and HeadByHash is a reimplemented version due to a
	// difference in how block header hashes are calculated by Parity nodes
	// running on Kovan, Avalanche and potentially others. We have to return our own wrapper type to capture the
	// correct hash from the RPC response.
	HeadByNumber(ctx context.Context, n *big.Int) (*evmtypes.Head, error)
	HeadByHash(ctx context.Context, n common.Hash) (*evmtypes.Head, error)
	SubscribeNewHead(ctx context.Context, ch chan<- *evmtypes.Head) (ethereum.Subscription, error)

	SendTransactionReturnCode(ctx context.Context, tx *types.Transaction, fromAddress common.Address) (commonclient.SendTxReturnCode, error)

	// Wrapped Geth client methods
	// blockNumber can be specified as `nil` to imply latest block
	// if blocks, transactions, or receipts are not found - a nil result and an error are returned
	// these methods may not be compatible with non Ethereum chains as return types may follow different formats
	// suggested options: use HeadByNumber/HeadByHash (above) or CallContext and parse with custom types
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error)
	TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
	EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
	LatestBlockHeight(ctx context.Context) (*big.Int, error)

	HeaderByNumber(ctx context.Context, n *big.Int) (*types.Header, error)
	HeaderByHash(ctx context.Context, h common.Hash) (*types.Header, error)

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

	IsL2() bool
}

Client is the interface used to interact with an ethereum node.

func NewChainClient added in v2.8.0

func NewChainClient(
	lggr logger.Logger,
	selectionMode string,
	leaseDuration time.Duration,
	noNewHeadsThreshold time.Duration,
	nodes []commonclient.Node[*big.Int, *evmtypes.Head, RPCClient],
	sendonlys []commonclient.SendOnlyNode[*big.Int, RPCClient],
	chainID *big.Int,
	chainType config.ChainType,
) Client

type ClientErrors

type ClientErrors = map[int]*regexp.Regexp

type JsonError

type JsonError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

go-ethereum@v1.10.0/rpc/json.go

func ExtractRPCError

func ExtractRPCError(baseErr error) (*JsonError, error)

ExtractRPCError attempts to extract a full JsonError (including revert reason details) from an error returned by a CallContract to an external RPC. As per https://github.com/ethereum/go-ethereum/blob/c49e065fea78a5d3759f7853a608494913e5824e/internal/ethapi/api.go#L974 CallContract server side for a revert will return an error which contains either:

  • The error directly from the EVM if there's no data (no revert reason, like an index out of bounds access) which when marshalled will only have a Message.
  • An error which implements rpc.DataError which when marshalled will have a Data field containing the execution result. If the revert not a custom Error (solidity >= 0.8.0), like require(1 == 2, "revert"), then geth and forks will automatically parse the string and put it in the message. If its a custom error, it's up to the client to decode the Data field which will be the abi encoded data of the custom error, i.e. revert MyCustomError(10) -> keccak(MyCustomError(uint256))[:4] || abi.encode(10).

However, it appears that RPCs marshal this in different ways into a JsonError object received client side, some adding "Reverted" prefixes, removing the method signature etc. To avoid RPC specific parsing and support custom errors we return the full object returned from the RPC with a String() method that stringifies all fields for logging so no information is lost. Some examples: kovan (parity) { "error": { "code" : -32015, "data": "Reverted 0xABC123...", "message": "VM execution error." } } // revert reason always omitted from message. rinkeby / ropsten (geth) { "error": { "code": 3, "data": "0xABC123...", "message": "execution reverted: hello world" } } // revert reason automatically parsed if a simple require and included in message.

func ExtractRPCErrorOrNil

func ExtractRPCErrorOrNil(err error) *JsonError

func (JsonError) Error

func (err JsonError) Error() string

func (*JsonError) String

func (err *JsonError) String() string

type Node deprecated

type Node interface {
	Start(ctx context.Context) error
	Close() error

	// State returns NodeState
	State() NodeState
	// StateAndLatest returns NodeState with the latest received block number & total difficulty.
	StateAndLatest() (state NodeState, blockNum int64, totalDifficulty *big.Int)
	// Name is a unique identifier for this node.
	Name() string
	ChainID() *big.Int
	Order() int32
	SubscribersCount() int32
	UnsubscribeAllExceptAliveLoop()

	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
	SendTransaction(ctx context.Context, tx *types.Transaction) 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)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, error)
	BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
	BlockNumber(ctx context.Context) (uint64, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
	EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
	HeaderByHash(context.Context, common.Hash) (*types.Header, error)
	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
	EthSubscribe(ctx context.Context, channel chan<- *evmtypes.Head, args ...interface{}) (ethereum.Subscription, error)

	String() string
}

Node represents a client that connects to an ethereum-compatible RPC node

Deprecated: use pkg/github.com/smartcontractkit/chainlink/v2/common/client.Node

func NewNode deprecated

func NewNode(nodeCfg config.NodePool, noNewHeadsThreshold time.Duration, lggr logger.Logger, wsuri url.URL, httpuri *url.URL, name string, id int32, chainID *big.Int, nodeOrder int32) Node

NewNode returns a new *node as Node

Deprecated: use pkg/github.com/smartcontractkit/chainlink/v2/common/client.NewNode

type NodeSelector deprecated

type NodeSelector interface {
	// Select returns a Node, or nil if none can be selected.
	// Implementation must be thread-safe.
	Select() Node
	// Name returns the strategy name, e.g. "HighestHead" or "RoundRobin"
	Name() string
}

NodeSelector represents a strategy to select the next node from the pool.

Deprecated: use pkg/github.com/smartcontractkit/chainlink/v2/common/client.NodeSelector

func NewPriorityLevelNodeSelector deprecated added in v2.3.0

type NodeState deprecated

type NodeState int

NodeState represents the current state of the node Node is a FSM (finite state machine)

Deprecated: to be removed. It is now internal in common/client

func (NodeState) GoString

func (n NodeState) GoString() string

GoString prints a prettier state

func (NodeState) String

func (n NodeState) String() string

type NullClient

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

NullClient satisfies the Client but has no side effects

func NewNullClient

func NewNullClient(cid *big.Int, lggr logger.Logger) *NullClient

func (*NullClient) BalanceAt

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

func (*NullClient) BatchCallContext

func (nc *NullClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

func (*NullClient) BatchCallContextAll

func (nc *NullClient) BatchCallContextAll(ctx context.Context, b []rpc.BatchElem) error

BatchCallContextAll implements evmclient.Client interface

func (*NullClient) BlockByHash

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

func (*NullClient) BlockByNumber

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

func (*NullClient) CallContext

func (nc *NullClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

func (*NullClient) CallContract

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

func (*NullClient) ChainID

func (nc *NullClient) ChainID() (*big.Int, error)

func (*NullClient) Close

func (nc *NullClient) Close()

func (*NullClient) CodeAt

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

func (*NullClient) ConfiguredChainID added in v2.1.0

func (nc *NullClient) ConfiguredChainID() *big.Int

func (*NullClient) Dial

func (nc *NullClient) Dial(context.Context) error

func (*NullClient) EstimateGas

func (nc *NullClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)

func (*NullClient) FilterLogs

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

func (*NullClient) HeadByHash

func (nc *NullClient) HeadByHash(ctx context.Context, h common.Hash) (*evmtypes.Head, error)

func (*NullClient) HeadByNumber

func (nc *NullClient) HeadByNumber(ctx context.Context, n *big.Int) (*evmtypes.Head, error)

func (*NullClient) HeaderByHash

func (nc *NullClient) HeaderByHash(ctx context.Context, h common.Hash) (*types.Header, error)

func (*NullClient) HeaderByNumber

func (nc *NullClient) HeaderByNumber(ctx context.Context, n *big.Int) (*types.Header, error)

func (*NullClient) IsL2 added in v2.2.0

func (nc *NullClient) IsL2() bool

func (*NullClient) LINKBalance added in v2.1.0

func (nc *NullClient) LINKBalance(ctx context.Context, address common.Address, linkAddress common.Address) (*assets.Link, error)

func (*NullClient) LatestBlockHeight added in v2.1.0

func (nc *NullClient) LatestBlockHeight(ctx context.Context) (*big.Int, error)

func (*NullClient) NodeStates

func (nc *NullClient) NodeStates() map[string]string

NodeStates implements evmclient.Client

func (*NullClient) PendingCallContract added in v2.10.0

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

func (*NullClient) PendingCodeAt

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

func (*NullClient) PendingNonceAt

func (nc *NullClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*NullClient) SendTransaction

func (nc *NullClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*NullClient) SendTransactionReturnCode added in v2.1.0

func (nc *NullClient) SendTransactionReturnCode(ctx context.Context, tx *types.Transaction, sender common.Address) (commonclient.SendTxReturnCode, error)

func (*NullClient) SequenceAt added in v2.1.0

func (nc *NullClient) SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error)

func (*NullClient) SubscribeFilterLogs

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

func (*NullClient) SubscribeNewHead

func (nc *NullClient) SubscribeNewHead(ctx context.Context, ch chan<- *evmtypes.Head) (ethereum.Subscription, error)

func (*NullClient) SuggestGasPrice

func (nc *NullClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*NullClient) SuggestGasTipCap

func (nc *NullClient) SuggestGasTipCap(ctx context.Context) (tipCap *big.Int, err error)

func (*NullClient) TokenBalance added in v2.1.0

func (nc *NullClient) TokenBalance(ctx context.Context, address common.Address, contractAddress common.Address) (*big.Int, error)

func (*NullClient) TransactionByHash added in v2.1.0

func (nc *NullClient) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, error)

func (*NullClient) TransactionReceipt

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

type Pool deprecated

type Pool struct {
	services.StateMachine
	// contains filtered or unexported fields
}

Pool represents an abstraction over one or more primary nodes It is responsible for liveness checking and balancing queries across live nodes

Deprecated: use pkg/github.com/smartcontractkit/chainlink/v2/common/client.MultiNode

func NewPool deprecated

func NewPool(lggr logger.Logger, selectionMode string, leaseDuration time.Duration, noNewHeadsTreshold time.Duration, nodes []Node, sendonlys []SendOnlyNode, chainID *big.Int, chainType config.ChainType) *Pool

NewPool - creates new instance of Pool

Deprecated: use pkg/github.com/smartcontractkit/chainlink/v2/common/client.NewMultiNode

func (*Pool) BalanceAt

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

func (*Pool) BatchCallContext

func (p *Pool) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

func (*Pool) BatchCallContextAll

func (p *Pool) BatchCallContextAll(ctx context.Context, b []rpc.BatchElem) error

BatchCallContextAll calls BatchCallContext for every single node including sendonlys. CAUTION: This should only be used for mass re-transmitting transactions, it might have unexpected effects to use it for anything else.

func (*Pool) BlockByHash

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

func (*Pool) BlockByNumber

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

func (*Pool) BlockNumber added in v2.1.0

func (p *Pool) BlockNumber(ctx context.Context) (uint64, error)

func (*Pool) CallContext

func (p *Pool) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

func (*Pool) CallContract

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

func (*Pool) ChainID

func (p *Pool) ChainID() *big.Int

func (*Pool) ChainType added in v2.1.0

func (p *Pool) ChainType() config.ChainType

func (*Pool) Close

func (p *Pool) Close() error

Close tears down the pool and closes all nodes

func (*Pool) CodeAt

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

func (*Pool) Dial

func (p *Pool) Dial(ctx context.Context) error

Dial starts every node in the pool

Nodes handle their own redialing and runloops, so this function does not return any error if the nodes aren't available

func (*Pool) EstimateGas

func (p *Pool) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)

func (*Pool) EthSubscribe

func (p *Pool) EthSubscribe(ctx context.Context, channel chan<- *evmtypes.Head, args ...interface{}) (ethereum.Subscription, error)

EthSubscribe implements evmclient.Client

func (*Pool) FilterLogs

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

func (*Pool) HeaderByHash

func (p *Pool) HeaderByHash(ctx context.Context, h common.Hash) (*types.Header, error)

func (*Pool) HeaderByNumber

func (p *Pool) HeaderByNumber(ctx context.Context, n *big.Int) (*types.Header, error)

bind.ContractBackend methods

func (*Pool) NonceAt

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

func (*Pool) PendingCallContract added in v2.10.0

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

func (*Pool) PendingCodeAt

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

func (*Pool) PendingNonceAt

func (p *Pool) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*Pool) SendTransaction

func (p *Pool) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction wrapped Geth client methods

func (*Pool) SubscribeFilterLogs

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

func (*Pool) SuggestGasPrice

func (p *Pool) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*Pool) SuggestGasTipCap

func (p *Pool) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

func (*Pool) TransactionByHash added in v2.1.0

func (p *Pool) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, error)

func (*Pool) TransactionReceipt

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

type PoolConfig deprecated

type PoolConfig interface {
	NodeSelectionMode() string
	NodeNoNewHeadsThreshold() time.Duration
	LeaseDuration() time.Duration
}

PoolConfig represents settings for the Pool

Deprecated: to be removed

type RPCClient added in v2.10.0

type RPCClient interface {
	commonclient.RPC[
		*big.Int,
		evmtypes.Nonce,
		common.Address,
		common.Hash,
		*types.Transaction,
		common.Hash,
		types.Log,
		ethereum.FilterQuery,
		*evmtypes.Receipt,
		*assets.Wei,
		*evmtypes.Head,
		rpc.BatchElem,
	]
	BlockByHashGeth(ctx context.Context, hash common.Hash) (b *types.Block, err error)
	BlockByNumberGeth(ctx context.Context, number *big.Int) (b *types.Block, err error)
	HeaderByHash(ctx context.Context, h common.Hash) (head *types.Header, err error)
	HeaderByNumber(ctx context.Context, n *big.Int) (head *types.Header, err error)
	PendingCodeAt(ctx context.Context, account common.Address) (b []byte, err error)
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (s ethereum.Subscription, err error)
	SuggestGasPrice(ctx context.Context) (p *big.Int, err error)
	SuggestGasTipCap(ctx context.Context) (t *big.Int, err error)
	TransactionReceiptGeth(ctx context.Context, txHash common.Hash) (r *types.Receipt, err error)
}

RPCClient includes all the necessary generalized RPC methods along with any additional chain-specific methods.

func NewRPCClient added in v2.8.0

func NewRPCClient(
	lggr logger.Logger,
	wsuri url.URL,
	httpuri *url.URL,
	name string,
	id int32,
	chainID *big.Int,
	tier commonclient.NodeTier,
) RPCClient

NewRPCCLient returns a new *rpcClient as commonclient.RPC

type SendError

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

fatal means this transaction can never be accepted even with a different nonce or higher gas price

func NewFatalSendError

func NewFatalSendError(e error) *SendError

func NewSendError

func NewSendError(e error) *SendError

func NewSendErrorS

func NewSendErrorS(s string) *SendError

func (*SendError) CauseStr

func (s *SendError) CauseStr() string

CauseStr returns the string of the original error

func (*SendError) Error

func (s *SendError) Error() string

func (*SendError) Fatal

func (s *SendError) Fatal() bool

Fatal indicates whether the error should be considered fatal or not Fatal errors mean that no matter how many times the send is retried, no node will ever accept it

func (*SendError) IsCanceled added in v2.10.0

func (s *SendError) IsCanceled() bool

IsCanceled indicates if the error was caused by an context cancellation

func (*SendError) IsInsufficientEth

func (s *SendError) IsInsufficientEth() bool

func (*SendError) IsL2FeeTooHigh

func (s *SendError) IsL2FeeTooHigh() bool

IsL2FeeTooHigh is an l2-specific error returned when total fee is too high

func (*SendError) IsL2Full

func (s *SendError) IsL2Full() bool

IsL2Full is an l2-specific error returned when the queue or mempool is full.

func (*SendError) IsNonceTooHighError

func (s *SendError) IsNonceTooHighError() bool

func (*SendError) IsNonceTooLowError

func (s *SendError) IsNonceTooLowError() bool

func (*SendError) IsReplacementUnderpriced

func (s *SendError) IsReplacementUnderpriced() bool

IsReplacementUnderpriced indicates that a transaction already exists in the mempool with this nonce but a different gas price or payload

func (*SendError) IsServiceUnavailable added in v2.10.0

func (s *SendError) IsServiceUnavailable() bool

IsServiceUnavailable indicates if the error was caused by a service being unavailable

func (*SendError) IsTemporarilyUnderpriced

func (s *SendError) IsTemporarilyUnderpriced() bool

func (*SendError) IsTerminallyUnderpriced

func (s *SendError) IsTerminallyUnderpriced() bool

IsTerminallyUnderpriced indicates that this transaction is so far underpriced the node won't even accept it in the first place

func (*SendError) IsTimeout

func (s *SendError) IsTimeout() bool

IsTimeout indicates if the error was caused by an exceeded context deadline

func (*SendError) IsTransactionAlreadyInMempool

func (s *SendError) IsTransactionAlreadyInMempool() bool

Geth/parity returns this error if the transaction is already in the node's mempool

func (*SendError) IsTransactionAlreadyMined

func (s *SendError) IsTransactionAlreadyMined() bool

IsTransactionAlreadyMined - Harmony returns this error if the transaction has already been mined

func (*SendError) IsTxFeeExceedsCap

func (s *SendError) IsTxFeeExceedsCap() bool

IsTxFeeExceedsCap returns true if the transaction and gas price are combined in some way that makes the total transaction too expensive for the eth node to accept at all. No amount of retrying at this or higher gas prices can ever succeed.

func (*SendError) L2FeeTooLow

func (s *SendError) L2FeeTooLow() bool

L2FeeTooLow is an l2-specific error returned when total fee is too low

type SendOnlyNode deprecated

type SendOnlyNode interface {
	// Start may attempt to connect to the node, but should only return error for misconfiguration - never for temporary errors.
	Start(context.Context) error
	Close() error

	ChainID() (chainID *big.Int)

	SendTransaction(ctx context.Context, tx *types.Transaction) error
	BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

	String() string
	// State returns NodeState
	State() NodeState
	// Name is a unique identifier for this node.
	Name() string
}

SendOnlyNode represents one ethereum node used as a sendonly

Deprecated: use pkg/github.com/smartcontractkit/chainlink/v2/common/client.SendOnlyNode

func NewSendOnlyNode deprecated

func NewSendOnlyNode(lggr logger.Logger, httpuri url.URL, name string, chainID *big.Int) SendOnlyNode

NewSendOnlyNode returns a new sendonly node

Deprecated: use pkg/github.com/smartcontractkit/chainlink/v2/common/client.NewSendOnlyNode

type SimulatedBackendClient

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

SimulatedBackendClient is an Client implementation using a simulated blockchain backend. Note that not all RPC methods are implemented here.

func NewSimulatedBackendClient

func NewSimulatedBackendClient(t testing.TB, b *backends.SimulatedBackend, chainId *big.Int) *SimulatedBackendClient

NewSimulatedBackendClient creates an eth client backed by a simulated backend.

func (*SimulatedBackendClient) Backend

func (*SimulatedBackendClient) BalanceAt

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

BalanceAt gets balance as of a specified block.

func (*SimulatedBackendClient) BatchCallContext

func (c *SimulatedBackendClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

BatchCallContext makes a batch rpc call. The simulated client avoids the old block error from the simulated backend by passing `nil` to `CallContract` when calling `CallContext` or `BatchCallContext` and will not return an error when an old block is used.

func (*SimulatedBackendClient) BatchCallContextAll

func (c *SimulatedBackendClient) BatchCallContextAll(ctx context.Context, b []rpc.BatchElem) error

BatchCallContextAll makes a batch rpc call.

func (*SimulatedBackendClient) BlockByHash

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

BlockByNumber returns a geth block type.

func (*SimulatedBackendClient) BlockByNumber

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

BlockByNumber returns a geth block type.

func (*SimulatedBackendClient) CallContext

func (c *SimulatedBackendClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

CallContext mocks the ethereum client RPC calls used by chainlink, copying the return value into result. The simulated client avoids the old block error from the simulated backend by passing `nil` to `CallContract` when calling `CallContext` or `BatchCallContext` and will not return an error when an old block is used.

func (*SimulatedBackendClient) CallContract

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

CallContract calls a contract.

func (*SimulatedBackendClient) ChainID

func (c *SimulatedBackendClient) ChainID() (*big.Int, error)

ChainID RPC call

func (*SimulatedBackendClient) Close

func (c *SimulatedBackendClient) Close()

Close does nothing. We ought not close the underlying backend here since other simulated clients might still be using it

func (*SimulatedBackendClient) CodeAt

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

CodeAt gets the code associated with an account as of a specified block.

func (*SimulatedBackendClient) Commit

func (c *SimulatedBackendClient) Commit() common.Hash

Commit imports all the pending transactions as a single block and starts a fresh new state.

func (*SimulatedBackendClient) ConfiguredChainID added in v2.1.0

func (c *SimulatedBackendClient) ConfiguredChainID() *big.Int

ChainID returns the ethereum ChainID.

func (*SimulatedBackendClient) Dial

Dial noop for the sim.

func (*SimulatedBackendClient) EstimateGas

func (c *SimulatedBackendClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)

EstimateGas estimates gas for a msg.

func (*SimulatedBackendClient) FilterLogs

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

FilterLogs returns all logs that respect the passed filter query.

func (*SimulatedBackendClient) HeadByHash

func (c *SimulatedBackendClient) HeadByHash(ctx context.Context, h common.Hash) (*evmtypes.Head, error)

HeadByHash returns our own header type.

func (*SimulatedBackendClient) HeadByNumber

func (c *SimulatedBackendClient) HeadByNumber(ctx context.Context, n *big.Int) (*evmtypes.Head, error)

HeadByNumber returns our own header type.

func (*SimulatedBackendClient) HeaderByHash

func (c *SimulatedBackendClient) HeaderByHash(ctx context.Context, h common.Hash) (*types.Header, error)

func (*SimulatedBackendClient) HeaderByNumber

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

HeaderByNumber returns the geth header type.

func (*SimulatedBackendClient) IsL2 added in v2.2.0

func (c *SimulatedBackendClient) IsL2() bool

func (*SimulatedBackendClient) LINKBalance added in v2.1.0

func (c *SimulatedBackendClient) LINKBalance(ctx context.Context, address common.Address, linkAddress common.Address) (*assets.Link, error)

GetLINKBalance get link balance.

func (*SimulatedBackendClient) LatestBlockHeight added in v2.1.0

func (c *SimulatedBackendClient) LatestBlockHeight(ctx context.Context) (*big.Int, error)

func (*SimulatedBackendClient) NodeStates

func (c *SimulatedBackendClient) NodeStates() map[string]string

NodeStates implements evmclient.Client

func (*SimulatedBackendClient) PendingCallContract added in v2.10.0

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

func (*SimulatedBackendClient) PendingCodeAt

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

PendingCodeAt gets the latest code.

func (*SimulatedBackendClient) PendingNonceAt

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

PendingNonceAt gets pending nonce i.e. mempool nonce.

func (*SimulatedBackendClient) SendTransaction

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

SendTransaction sends a transaction.

func (*SimulatedBackendClient) SendTransactionReturnCode added in v2.1.0

func (c *SimulatedBackendClient) SendTransactionReturnCode(ctx context.Context, tx *types.Transaction, fromAddress common.Address) (commonclient.SendTxReturnCode, error)

func (*SimulatedBackendClient) SequenceAt added in v2.1.0

func (c *SimulatedBackendClient) SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error)

NonceAt gets nonce as of a specified block.

func (*SimulatedBackendClient) SubscribeFilterLogs

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

SubscribeFilterLogs registers a subscription for push notifications of logs from a given address.

func (*SimulatedBackendClient) SubscribeNewHead

func (c *SimulatedBackendClient) SubscribeNewHead(
	ctx context.Context,
	channel chan<- *evmtypes.Head,
) (ethereum.Subscription, error)

SubscribeNewHead registers a subscription for push notifications of new blocks. Note the sim's API only accepts types.Head so we have this goroutine to convert those into evmtypes.Head.

func (*SimulatedBackendClient) SuggestGasPrice

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

SuggestGasPrice recommends a gas price.

func (*SimulatedBackendClient) SuggestGasTipCap

func (c *SimulatedBackendClient) SuggestGasTipCap(ctx context.Context) (tipCap *big.Int, err error)

SuggestGasTipCap suggests a gas tip cap.

func (*SimulatedBackendClient) TokenBalance added in v2.1.0

func (c *SimulatedBackendClient) TokenBalance(ctx context.Context, address common.Address, contractAddress common.Address) (balance *big.Int, err error)

func (*SimulatedBackendClient) TransactionByHash added in v2.1.0

func (c *SimulatedBackendClient) TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, err error)

func (*SimulatedBackendClient) TransactionReceipt

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

TransactionReceipt returns the transaction receipt for the given transaction hash.

type TxSender

type TxSender interface {
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	ChainID(context.Context) (*big.Int, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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