multiclient

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: LGPL-3.0 Imports: 28 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTypeCast = errors.New("invalid type cast")
	ErrNoEthClient     = errors.New("no eth client")
)

Functions

func NewRetry added in v1.2.3

func NewRetry(retryLimit int, retryTimeout, retryDelay time.Duration) func(context.Context, []*rpc.Client, RetryFunc) error

NewRetry is an util function to retry with retry limit, timeout and delay

func Retry added in v1.2.3

func Retry(ctx context.Context, retryLimit int, retryTimeout, retryDelay time.Duration, rpcClients []*rpc.Client, fn RetryFunc) error

Retry retries the RetryFunc with limit and timeout and wait some delay during each retry

Types

type Client

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

func New

func New(ctx context.Context, opts ...Option) (*Client, error)

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

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

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

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

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

func (mc *Client) 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.

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) ClientMap added in v1.1.8

func (mc *Client) ClientMap() *Map

func (*Client) Close

func (mc *Client) Close()

Close closes an existing RPC connection.

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) Context added in v1.1.8

func (mc *Client) Context() context.Context

func (*Client) DialClients added in v1.1.8

func (mc *Client) DialClients(ctx context.Context)

func (*Client) EthClients

func (mc *Client) EthClients() []*ethclient.Client

func (*Client) HeaderByHash

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

HeaderByHash returns the block header with the given hash.

func (*Client) HeaderByNumber

func (mc *Client) 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 (*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

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

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

func (*Client) PendingCallContract

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

PendingCallContract executes a message call transaction using the EVM. The state seen by the contract call is the pending state.

func (*Client) PendingNonceAt

func (mc *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

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 (mc *Client) RPCClients() []*rpc.Client

func (*Client) SendTransaction

func (mc *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error

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.

func (*Client) TransactionByHash

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

TransactionByHash returns the transaction with the given hash.

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 Header struct {
	*types.Header
	*rpc.Client
}

Subscribe API

type KubeConfig added in v1.1.3

type KubeConfig struct {
	// The file path to KUBE-CONFIG file
	ConfigPath string
	// The url to override the apiserver address in KUBE-CONFIG file
	APIServer string
}

type Map added in v1.1.1

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

func NewMap added in v1.1.1

func NewMap(newClientCh chan<- string) *Map

func (*Map) Add added in v1.1.12

func (m *Map) Add(key string, value *rpc.Client)

func (*Map) Delete added in v1.1.1

func (m *Map) Delete(key string)

func (*Map) Get added in v1.1.1

func (m *Map) Get(key string) *rpc.Client

func (*Map) GetById added in v1.1.12

func (m *Map) GetById(id uint64) (string, *rpc.Client)

func (*Map) Ids added in v1.1.12

func (m *Map) Ids() []uint64

func (*Map) Keys added in v1.1.2

func (m *Map) Keys() []string

func (*Map) Len added in v1.1.1

func (m *Map) Len() int

func (*Map) List added in v1.1.1

func (m *Map) List() []*rpc.Client

List returns a deep copy of client list

func (*Map) Map added in v1.1.1

func (m *Map) Map() map[string]*rpc.Client

Map returns a deep copy of client map

func (*Map) NilClients added in v1.1.8

func (m *Map) NilClients() []string

func (*Map) Replace added in v1.1.8

func (m *Map) Replace(key string, value *rpc.Client) uint64

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

type Option func(*Client) error

Option represents a Client option

func ConsulDiscovery added in v1.1.1

func ConsulDiscovery(rawURL, serviceID, serviceScheme string) Option

ConsulDiscovery discovers the dynamic ethclient endpoints through consul server. TODO: should watch the change of endpoints

func EthURLs

func EthURLs(urls []string) Option

EthURLs represents static ethclient 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
}

type RetryFunc added in v1.2.3

type RetryFunc func(ctx context.Context, rpcClient *rpc.Client) (retry bool, err error)

RetryFunc is the function we retry

Jump to

Keyboard shortcuts

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