proxy

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 40 Imported by: 0

Documentation

Overview

Package proxy proxies rpc request to the best rpc node

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyReader

type BodyReader interface {
	io.ReadCloser
}

BodyReader is used for generating a mock of the request body that returns an error

type Confirmable added in v0.0.27

type Confirmable interface {
	// contains filtered or unexported methods
}

Confirmable returns the confirmability of an interface.

type ErrorResponse added in v0.0.9

type ErrorResponse struct {
	Hashes map[string][]ErroredRPCResponse `json:"hashes"`
	Error  string                          `json:"error"`
	// ErroredURLS returned no response at all
	ErroredURLS []string `json:"errored_urls"`
}

ErrorResponse contains error response used for debugging.

type ErroredRPCResponse added in v0.0.9

type ErroredRPCResponse struct {
	Raw json.RawMessage `json:"json_response"`
	URL string          `json:"url"`
}

ErroredRPCResponse contains an errored rpc response thisis mostly used for debugging.

type Forwarder

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

Forwarder creates a request forwarder.

func (*Forwarder) Reset added in v0.0.9

func (f *Forwarder) Reset()

Reset resets the forwarder so it can be reused.

type JSONError added in v0.0.14

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

JSONError is used to hold a json error.

type JSONRPCMessage added in v0.0.14

type JSONRPCMessage struct {
	Version string          `json:"jsonrpc,omitempty"`
	ID      json.RawMessage `json:"id,omitempty"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
	Error   *JSONError      `json:"error,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
}

JSONRPCMessage is A value of this type can a JSON-RPC request, notification, successful response or error response. Which one it is depends on the fields.

type RPCMethod added in v0.0.15

type RPCMethod string

RPCMethod is an enum type for an rpc method.

const (
	// ChainIDMethod is used to retrieve the current chain ID for transaction replay protection.
	ChainIDMethod RPCMethod = "eth_chainId"
	// BlockByHashMethod gets a block by hash.
	BlockByHashMethod RPCMethod = "eth_getBlockByHash"
	// BlockByNumberMethod gets a block by number.
	BlockByNumberMethod RPCMethod = "eth_getBlockByNumber"
	// BlockNumberMethod gets the latest block number.
	BlockNumberMethod RPCMethod = "eth_blockNumber"
	// TransactionByHashMethod returns the transaction with the given hash.
	TransactionByHashMethod RPCMethod = "eth_getTransactionByHash"
	// TransactionByBlockHashAndIndexMethod returns a transaction by its hash and index.
	TransactionByBlockHashAndIndexMethod RPCMethod = "eth_getTransactionByBlockHashAndIndex"
	// TransactionCountByHashMethod get sthe transaction count by hash.
	TransactionCountByHashMethod RPCMethod = "eth_getBlockTransactionCountByHash"
	// TransactionReceiptByHashMethod gets the transaction receipt from a hash.
	TransactionReceiptByHashMethod RPCMethod = "eth_getTransactionReceipt"
	// SyncProgressMethod gets the sync progress.
	SyncProgressMethod RPCMethod = "eth_syncing"
	// GetBalanceMethod gets the balance for a given address.
	GetBalanceMethod RPCMethod = "eth_getBalance"
	// StorageAtMethod returns the value of key in the contract storage of the given account.
	StorageAtMethod RPCMethod = "eth_getStorageAt"
	// GetCodeMethod returns the contract code of the given account.
	GetCodeMethod RPCMethod = "eth_getCode"
	// TransactionCountMethod returns the account nonce of the given account.
	TransactionCountMethod RPCMethod = "eth_getTransactionCount"
	// GetLogsMethod filters logs.
	GetLogsMethod RPCMethod = "eth_getLogs"
	// CallMethod calls a contract.
	CallMethod RPCMethod = "eth_call"
	// GasPriceMethod gets the gas price.
	GasPriceMethod RPCMethod = "eth_gasPrice"
	// MaxPriorityMethod gets the max priority fee.
	MaxPriorityMethod RPCMethod = "eth_maxPriorityFeePerGas"
	// FeeHistoryMethod gets the fee history.
	FeeHistoryMethod RPCMethod = "eth_feeHistory"
	// EstimateGasMethod tries to estimate the gas needed to execute a specific transaction.
	EstimateGasMethod RPCMethod = "eth_estimateGas"
	// PendingTransactionCountMethod gets the pending transaction count.
	PendingTransactionCountMethod RPCMethod = "eth_getBlockTransactionCountByNumber"
	// SendRawTransactionMethod sends a raw tx.
	SendRawTransactionMethod RPCMethod = "eth_sendRawTransaction"
)

NOTE: any changes here must be added to allMethods list below. TODO: this should be replaced by a go:generate in the near future.

func (RPCMethod) Comparable added in v0.0.27

func (r RPCMethod) Comparable() string

Comparable converts an rpc method to lowercase based on a preset map can be used for case sensitive comparison.

type RPCProxy

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

RPCProxy proxies rpc request to the fastest endpoint. Requests fallback in cases where data is not available.

func NewProxy

func NewProxy(config config.Config, clientType omniHTTP.ClientType) *RPCProxy

NewProxy creates a new rpc proxy.

func (*RPCProxy) AcquireForwarder added in v0.0.9

func (r *RPCProxy) AcquireForwarder() *Forwarder

AcquireForwarder allocates a forwarder and allows it to be released when not in use this allows forwarder cycling reducing GC overhead.

func (*RPCProxy) Forward

func (r *RPCProxy) Forward(c *gin.Context, chainID uint32, requiredConfirmationsOverride *uint16)

Forward forwards the rpc request to the servers and makes assertions around confirmation thresholds. required confirmations can be used to override the required confirmations count.

func (*RPCProxy) ReleaseForwarder added in v0.0.9

func (r *RPCProxy) ReleaseForwarder(f *Forwarder)

ReleaseForwarder releases a forwarder object for reuse.

func (*RPCProxy) Run

func (r *RPCProxy) Run(ctx context.Context)

Run runs the rpc server until context cancellation.

type RPCRequest

type RPCRequest struct {
	ID     json.RawMessage   `json:"id"`
	Method string            `json:"method"`
	Params []json.RawMessage `json:"params"`
}

RPCRequest is a raw rpc request format.

type RPCRequests added in v0.0.27

type RPCRequests []RPCRequest

RPCRequests is a list or rpc requests.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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