Documentation ¶
Index ¶
- Variables
- func NewRetry(retryLimit int, retryTimeout, retryDelay time.Duration) func(context.Context, []*rpc.Client, RetryFunc) error
- func Retry(ctx context.Context, retryLimit int, retryTimeout, retryDelay time.Duration, ...) error
- type Client
- func (mc *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
- func (mc *Client) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
- func (mc *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
- func (mc *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
- func (mc *Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
- func (mc *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
- func (mc *Client) ClientMap() *Map
- func (mc *Client) Close()
- func (mc *Client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
- func (mc *Client) Context() context.Context
- func (mc *Client) DialClients(ctx context.Context)
- func (mc *Client) EthClients() []*ethclient.Client
- func (mc *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
- func (mc *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
- func (mc *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
- func (mc *Client) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
- func (mc *Client) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
- func (mc *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
- func (mc *Client) RPCClients() []*rpc.Client
- func (mc *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (mc *Client) SubscribeNewHead(ctx context.Context, ch chan<- *Header) (ethereum.Subscription, error)
- func (mc *Client) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error)
- type ClientError
- type Header
- type KubeConfig
- type Map
- func (m *Map) Add(key string, value *rpc.Client)
- func (m *Map) Delete(key string)
- func (m *Map) Get(key string) *rpc.Client
- func (m *Map) GetById(id uint64) (string, *rpc.Client)
- func (m *Map) Ids() []uint64
- func (m *Map) Keys() []string
- func (m *Map) Len() int
- func (m *Map) List() []*rpc.Client
- func (m *Map) Map() map[string]*rpc.Client
- func (m *Map) NilClients() []string
- func (m *Map) Replace(key string, value *rpc.Client) uint64
- type MultipleError
- type Option
- type RetryConfig
- type RetryFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidTypeCast = errors.New("invalid type cast") ErrNoEthClient = errors.New("no eth client") )
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) BalanceAt ¶
func (mc *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
BalanceAt returns the wei balance of the given account. The block number can be nil, in which case the balance is taken from the latest known block.
func (*Client) BatchCallContext ¶
BatchCall sends all given requests as a single batch and waits for the server to return a response for all of them. The wait duration is bounded by the context's deadline.
In contrast to CallContext, BatchCallContext only returns errors that have occurred while sending the request. Any error specific to a request is reported through the Error field of the corresponding BatchElem.
Note that batch calls may not be executed atomically on the server side.
func (*Client) BlockByHash ¶
BlockByHash returns the given full block.
Note that loading full blocks requires two requests. Use HeaderByHash if you don't need all transactions or uncle headers.
func (*Client) BlockByNumber ¶
BlockByNumber returns a block from the current canonical chain. If number is nil, the latest known block is returned.
Note that loading full blocks requires two requests. Use HeaderByNumber if you don't need all transactions or uncle headers.
func (*Client) CallContext ¶
func (mc *Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
CallContext performs a JSON-RPC call with the given arguments. If the context is canceled before the call has successfully returned, CallContext returns immediately.
The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.
func (*Client) CallContract ¶
func (mc *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
CallContract executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.
blockNumber selects the block height at which the call runs. It can be nil, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available.
func (*Client) CodeAt ¶
func (mc *Client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
CodeAt returns the contract code of the given account. The block number can be nil, in which case the code is taken from the latest known block.
func (*Client) DialClients ¶ added in v1.1.8
func (*Client) EthClients ¶
func (*Client) HeaderByHash ¶
HeaderByHash returns the block header with the given hash.
func (*Client) HeaderByNumber ¶
HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.
func (*Client) NonceAt ¶
func (mc *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
NonceAt returns the account nonce of the given account. The block number can be nil, in which case the nonce is taken from the latest known block.
func (*Client) PendingBalanceAt ¶
PendingBalanceAt returns the wei balance of the given account in the pending state.
func (*Client) PendingCallContract ¶
PendingCallContract executes a message call transaction using the EVM. The state seen by the contract call is the pending state.
func (*Client) PendingNonceAt ¶
PendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.
func (*Client) RPCClients ¶ added in v1.1.7
func (*Client) SendTransaction ¶
SendTransaction injects a signed transaction into the pending pool for execution. Return all errors if multiple errors have occurred.
If the transaction was a contract creation use the TransactionReceipt method to get the contract address after the transaction has been mined.
func (*Client) SubscribeNewHead ¶ added in v1.1.1
func (mc *Client) SubscribeNewHead(ctx context.Context, ch chan<- *Header) (ethereum.Subscription, error)
SubscribeNewHead subscribes to notifications about the current blockchain head on the given channel.
type ClientError ¶ added in v1.2.5
type ClientError struct {
// contains filtered or unexported fields
}
func NewClientError ¶ added in v1.2.5
func NewClientError(client string, err error) *ClientError
func (*ClientError) Client ¶ added in v1.2.5
func (e *ClientError) Client() string
func (*ClientError) Error ¶ added in v1.2.5
func (e *ClientError) Error() string
func (*ClientError) GetError ¶ added in v1.2.6
func (e *ClientError) GetError() error
type KubeConfig ¶ added in v1.1.3
type Map ¶ added in v1.1.1
type Map struct {
// contains filtered or unexported fields
}
func (*Map) NilClients ¶ added in v1.1.8
type MultipleError ¶ added in v1.2.4
type MultipleError struct {
// contains filtered or unexported fields
}
func NewMultipleError ¶ added in v1.2.4
func NewMultipleError(errs []error) *MultipleError
func (*MultipleError) Error ¶ added in v1.2.4
func (e *MultipleError) Error() string
func (*MultipleError) GetErrors ¶ added in v1.2.4
func (e *MultipleError) GetErrors() []error
type Option ¶
Option represents a Client option
func ConsulDiscovery ¶ added in v1.1.1
ConsulDiscovery discovers the dynamic ethclient endpoints through consul server. TODO: should watch the change of endpoints
func K8sEndpointsDiscovery ¶ added in v1.1.3
func K8sEndpointsDiscovery(namespace, name, scheme string, kubeconfig *KubeConfig) Option
K8sEndpointsDiscovery discovers the dynamic ethclient endpoints in k8s cluster. There are two ways to access k8s cluster: 1. `kubeconfig` is nil means will build in-cluster config with service account token assigned to k8s pod. 2. `kubeconfig` is given means access k8s cluster with given apiserver address and KUBE-CONFIG file.
func WithRetryConfig ¶ added in v1.2.3
func WithRetryConfig(retry RetryConfig) Option
WithRetryConfig configures the parameters for request retry.
type RetryConfig ¶ added in v1.2.3
type RetryConfig struct { // Limit is the total retry times. Set to 0 means retry time is according to the number of eth clients. Limit int // Timeout is the timeout for each retry. Set to 0 means use default timeout 5 seconds. Timeout time.Duration // Delay is the delay duration for each retry. Set to 0 means use default delay 1 second. Delay time.Duration }