ethrpc

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StandardABISerializer

func StandardABISerializer() *abi.Serializer

The serializer we should use in all places that go from ABI validated data, back down to JSON that might be: 1) Passed to end-users over a JSON/RPC API 2) Passed to domain plugins over a gRPC API

Types

type BlockHeaderJSONRPC

type BlockHeaderJSONRPC struct {
	Number           ethtypes.HexUint64          `json:"number" ffstruct:"BlockInfoJSONRPC"`
	Hash             ethtypes.HexBytes0xPrefix   `json:"hash" ffstruct:"BlockInfoJSONRPC"`
	MixHash          ethtypes.HexBytes0xPrefix   `json:"mixHash" ffstruct:"BlockInfoJSONRPC"`
	ParentHash       ethtypes.HexBytes0xPrefix   `json:"parentHash" ffstruct:"BlockInfoJSONRPC"`
	Nonce            ethtypes.HexBytes0xPrefix   `json:"nonce" ffstruct:"BlockInfoJSONRPC"`
	SHA3Uncles       ethtypes.HexBytes0xPrefix   `json:"sha3Uncles" ffstruct:"BlockInfoJSONRPC"`
	LogsBloom        ethtypes.HexBytes0xPrefix   `json:"logsBloom" ffstruct:"BlockInfoJSONRPC"`
	TransactionsRoot ethtypes.HexBytes0xPrefix   `json:"transactionsRoot" ffstruct:"BlockInfoJSONRPC"`
	StateRoot        ethtypes.HexBytes0xPrefix   `json:"stateRoot" ffstruct:"BlockInfoJSONRPC"`
	ReceiptsRoot     ethtypes.HexBytes0xPrefix   `json:"receiptsRoot" ffstruct:"BlockInfoJSONRPC"`
	Miner            *ethtypes.Address0xHex      `json:"miner" ffstruct:"BlockInfoJSONRPC"`
	Difficulty       *ethtypes.HexInteger        `json:"difficulty" ffstruct:"BlockInfoJSONRPC"`
	TotalDifficulty  *ethtypes.HexInteger        `json:"totalDifficulty" ffstruct:"BlockInfoJSONRPC"`
	ExtraData        ethtypes.HexBytes0xPrefix   `json:"extraData" ffstruct:"BlockInfoJSONRPC"`
	BaseFeePerGas    *ethtypes.HexInteger        `json:"baseFeePerGas" ffstruct:"BlockInfoJSONRPC"`
	Size             *ethtypes.HexInteger        `json:"size" ffstruct:"BlockInfoJSONRPC"`
	GasLimit         *ethtypes.HexInteger        `json:"gasLimit" ffstruct:"BlockInfoJSONRPC"`
	GasUsed          *ethtypes.HexInteger        `json:"gasUsed" ffstruct:"BlockInfoJSONRPC"`
	Timestamp        ethtypes.HexUint64          `json:"timestamp" ffstruct:"BlockInfoJSONRPC"`
	Uncles           []ethtypes.HexBytes0xPrefix `json:"uncles" ffstruct:"BlockInfoJSONRPC"`
}

func (*BlockHeaderJSONRPC) FormatMap added in v1.5.3

func (b *BlockHeaderJSONRPC) FormatMap() map[string]any

func (*BlockHeaderJSONRPC) ToBlockInfo

func (b *BlockHeaderJSONRPC) ToBlockInfo(includeLogsBloom bool) *BlockInfoJSONRPC

type BlockInfoJSONRPC

type BlockInfoJSONRPC struct {
	Number        ethtypes.HexUint64          `json:"number" ffstruct:"BlockInfoJSONRPC"`
	Hash          ethtypes.HexBytes0xPrefix   `json:"hash" ffstruct:"BlockInfoJSONRPC"`
	ParentHash    ethtypes.HexBytes0xPrefix   `json:"parentHash" ffstruct:"BlockInfoJSONRPC"`
	Timestamp     ethtypes.HexUint64          `json:"timestamp" ffstruct:"BlockInfoJSONRPC"`
	GasLimit      *ethtypes.HexInteger        `json:"gasLimit" ffstruct:"BlockInfoJSONRPC"`
	BaseFeePerGas *ethtypes.HexInteger        `json:"baseFeePerGas,omitempty" ffstruct:"BlockInfoJSONRPC"`
	LogsBloom     ethtypes.HexBytes0xPrefix   `json:"logsBloom" ffstruct:"BlockInfoJSONRPC"`
	Transactions  []ethtypes.HexBytes0xPrefix `json:"transactions" ffstruct:"BlockInfoJSONRPC"`
}

BlockInfoJSONRPC are the info fields we parse from the JSON/RPC response, and cache

func (*BlockInfoJSONRPC) Equal

func (bi *BlockInfoJSONRPC) Equal(bi2 *BlockInfoJSONRPC) bool

func (*BlockInfoJSONRPC) FormatMap added in v1.5.3

func (bi *BlockInfoJSONRPC) FormatMap() map[string]any

func (*BlockInfoJSONRPC) IsParentOf

func (bi *BlockInfoJSONRPC) IsParentOf(other *BlockInfoJSONRPC) bool

func (*BlockInfoJSONRPC) MarshalFormat

func (bi *BlockInfoJSONRPC) MarshalFormat(jss *JSONSerializerSet, opts ...MarshalOption) (json.RawMessage, error)

func (*BlockInfoJSONRPC) SupportsEIP1559 added in v1.5.2

func (bi *BlockInfoJSONRPC) SupportsEIP1559() bool

SupportsEIP1559 returns true if the block includes baseFeePerGas (EIP-1559 / post-London).

func (*BlockInfoJSONRPC) ToMinimalBlockInfo

func (bi *BlockInfoJSONRPC) ToMinimalBlockInfo() *MinimalBlockInfo

type Client added in v1.5.2

type Client interface {
	rpcbackend.RPC

	// Connect establishes the WebSocket connection if one is configured, and is a no-op
	// otherwise. It is idempotent so can be called multiple times, but fails after Close.
	Connect() error

	// Subscribe establishes a subscription on the WebSocket connection. It is an error to
	// call this when no WebSocket is configured - check HasWebSocket first.
	Subscribe(ctx context.Context, params ...interface{}) (rpcbackend.Subscription, *rpcbackend.RPCError)

	// HasWebSocket returns true if a WebSocket connection is configured. Note this is
	// independent of the routing mode - a WebSocket can be configured purely to carry
	// subscriptions, with all JSON/RPC calls going over HTTP.
	HasWebSocket() bool

	// RoutingMode returns the mode this client was constructed with.
	RoutingMode() RoutingMode

	// Close unsubscribes and closes the WebSocket connection (currently does not
	// prevent use of HTTP RPC calls after close)
	Close()
}

Client is the single JSON/RPC entry point for the connector. It owns both the HTTP connection pool and the WebSocket connection (when one is configured), and decides which of them each call goes on based on the method name and the configured RoutingMode.

Call sites do not choose a connection - they just call CallRPC.

If Connect() is not called, every call routes to HTTP regardless of mode.

func NewClient added in v1.5.2

func NewClient(ctx context.Context, conf *Config) (Client, error)

NewClient builds a Client from config

func NewClientWithBackends added in v1.5.2

func NewClientWithBackends(ctx context.Context, mode RoutingMode, httpBackend rpcbackend.RPC, wsBackend rpcbackend.WebSocketRPCClient) (Client, error)

NewClientWithBackends builds a client with existing backends already constructed

type Config added in v1.5.2

type Config struct {
	RoutingMode           RoutingMode
	HTTP                  *ffresty.Config
	WS                    *wsclient.WSConfig // nil when no WebSocket is configured
	MaxConcurrentRequests int64
}

Config is the configuration for a Client built from connection configuration.

type EVMBlockWithTransactionsJSONRPC

type EVMBlockWithTransactionsJSONRPC struct {
	BlockHeaderJSONRPC
	Transactions []*TxInfoJSONRPC `json:"transactions" ffstruct:"BlockInfoJSONRPC"`
}

EVMBlockWithTransactionsJSONRPC is the full JSON/RPC structure you get with "true" on eth_getBlockByNumber / eth_getBlockByHash

func (*EVMBlockWithTransactionsJSONRPC) FormatMap added in v1.5.3

func (b *EVMBlockWithTransactionsJSONRPC) FormatMap() map[string]any

func (*EVMBlockWithTransactionsJSONRPC) MarshalFormat

func (*EVMBlockWithTransactionsJSONRPC) ToBlockInfo

func (b *EVMBlockWithTransactionsJSONRPC) ToBlockInfo(includeLogsBloom bool) *BlockInfoJSONRPC

type EVMBlockWithTxHashesJSONRPC

type EVMBlockWithTxHashesJSONRPC struct {
	BlockHeaderJSONRPC
	Transactions []ethtypes.HexBytes0xPrefix `json:"transactions" ffstruct:"BlockInfoJSONRPC"`
}

EVMBlockWithTxHashesJSONRPC is the full JSON/RPC structure you get with "false" on eth_getBlockByNumber / eth_getBlockByHash

func (*EVMBlockWithTxHashesJSONRPC) FormatMap added in v1.5.3

func (b *EVMBlockWithTxHashesJSONRPC) FormatMap() map[string]any

func (*EVMBlockWithTxHashesJSONRPC) MarshalFormat

func (*EVMBlockWithTxHashesJSONRPC) ToBlockInfo

func (b *EVMBlockWithTxHashesJSONRPC) ToBlockInfo(includeLogsBloom bool) *BlockInfoJSONRPC

type JSONFormatOptions

type JSONFormatOptions string
const DefaultJSONFormatOptions JSONFormatOptions = ""

func (JSONFormatOptions) GetABISerializer

func (jfo JSONFormatOptions) GetABISerializer(ctx context.Context) (serializer *abi.Serializer, err error)

func (JSONFormatOptions) GetABISerializerIgnoreErrors

func (jfo JSONFormatOptions) GetABISerializerIgnoreErrors(ctx context.Context) *abi.Serializer

func (JSONFormatOptions) GetSerializerSet

func (jfo JSONFormatOptions) GetSerializerSet(ctx context.Context, skipErrors bool) (ss *JSONSerializerSet, err error)

type JSONSerializerSet

type JSONSerializerSet struct {
	Mode    abi.FormattingMode
	Integer abi.IntSerializer
	Float   abi.FloatSerializer
	Bytes   abi.ByteSerializer
	Address abi.AddressSerializer
	Pretty  bool
}

func StandardSerializerSet

func StandardSerializerSet() *JSONSerializerSet

func (*JSONSerializerSet) ABISerializer

func (ss *JSONSerializerSet) ABISerializer() *abi.Serializer

func (*JSONSerializerSet) MarshalFormattedMap

func (ss *JSONSerializerSet) MarshalFormattedMap(value map[string]any, opts ...MarshalOption) (data json.RawMessage, err error)

MarshalFormattedMap takes a map that contains certain pre-selected types (see below switch) and does JSON marshalling adhering to the request of the users.

type LogFilterJSONRPC

type LogFilterJSONRPC struct {
	FromBlock *ethtypes.HexInteger          `json:"fromBlock,omitempty" ffstruct:"LogFilterJSONRPC"`
	ToBlock   *ethtypes.HexInteger          `json:"toBlock,omitempty" ffstruct:"LogFilterJSONRPC"`
	Address   []*ethtypes.Address0xHex      `json:"address,omitempty" ffstruct:"LogFilterJSONRPC"`
	Topics    [][]ethtypes.HexBytes0xPrefix `json:"topics,omitempty" ffstruct:"LogFilterJSONRPC"`
}

See https://ethereum.org/hr/developers/docs/apis/json-rpc/#eth_newfilter The address, as well as the entries in the topic array, can be DATA|Array. We just use array in all cases.

type LogJSONRPC

type LogJSONRPC struct {
	Removed          bool                        `json:"removed" ffstruct:"LogJSONRPC"`
	LogIndex         ethtypes.HexUint64          `json:"logIndex" ffstruct:"LogJSONRPC"`
	TransactionIndex ethtypes.HexUint64          `json:"transactionIndex" ffstruct:"LogJSONRPC"`
	BlockNumber      ethtypes.HexUint64          `json:"blockNumber" ffstruct:"LogJSONRPC"`
	TransactionHash  ethtypes.HexBytes0xPrefix   `json:"transactionHash" ffstruct:"LogJSONRPC"`
	BlockHash        ethtypes.HexBytes0xPrefix   `json:"blockHash" ffstruct:"LogJSONRPC"`
	Address          *ethtypes.Address0xHex      `json:"address" ffstruct:"LogJSONRPC"`
	Data             ethtypes.HexBytes0xPrefix   `json:"data" ffstruct:"LogJSONRPC"`
	Topics           []ethtypes.HexBytes0xPrefix `json:"topics" ffstruct:"LogJSONRPC"`
}

func (*LogJSONRPC) FormatMap added in v1.5.3

func (l *LogJSONRPC) FormatMap() map[string]any

func (*LogJSONRPC) MarshalFormat

func (l *LogJSONRPC) MarshalFormat(jss *JSONSerializerSet, opts ...MarshalOption) (json.RawMessage, error)

type MarshalOption

type MarshalOption struct {
	RedactFields   []string // helpful when you want to trim large fields
	OmitNullFields []string // a simplified approach to "omitempty" on JSON struct formatting tags
}

Marshalling options specific to the structure that is being marshalled, rather than JSONFormatOptions which are specific to the way to represent data in JSON

type MinimalBlockInfo

type MinimalBlockInfo struct {
	BlockNumber fftypes.FFuint64          `json:"blockNumber" ffstruct:"MinimalBlockInfo"`
	BlockHash   ethtypes.HexBytes0xPrefix `json:"blockHash" ffstruct:"MinimalBlockInfo"`
	ParentHash  ethtypes.HexBytes0xPrefix `json:"parentHash" ffstruct:"MinimalBlockInfo"`
}

func (*MinimalBlockInfo) Equal

func (c *MinimalBlockInfo) Equal(other *MinimalBlockInfo) bool

func (*MinimalBlockInfo) IsParentOf

func (c *MinimalBlockInfo) IsParentOf(other *MinimalBlockInfo) bool

type RoutingMode added in v1.5.2

type RoutingMode string

RoutingMode determines which of the two connections a given JSON/RPC method is sent on.

const (
	// RoutingModeHTTP sends every JSON/RPC call over the HTTP connection pool.
	RoutingModeHTTP RoutingMode = "http"
	// RoutingModeWS sends every JSON/RPC call over the WebSocket connection.
	RoutingModeWS RoutingMode = "ws"
	// RoutingModeAuto picks the connection per method: node-sticky calls go over the
	// WebSocket, and stateless calls over the HTTP connection pool.
	// See httpRoutedMethods for the split.
	RoutingModeAuto RoutingMode = "auto"
	// RoutingModeLegacy reproduces the routing that existed before this was configurable.
	// See wsRoutedMethodsLegacy for exactly what it does, and for the two places
	// it cannot match the old behavior precisely.
	RoutingModeLegacy RoutingMode = "legacy"
)

type TxInfoJSONRPC

type TxInfoJSONRPC struct {
	BlockHash            ethtypes.HexBytes0xPrefix `json:"blockHash" ffstruct:"TxInfoJSONRPC"`   // null if pending
	BlockNumber          ethtypes.HexUint64        `json:"blockNumber" ffstruct:"TxInfoJSONRPC"` // null if pending
	ChainID              *ethtypes.HexInteger      `json:"chainId" ffstruct:"TxInfoJSONRPC"`
	From                 *ethtypes.Address0xHex    `json:"from" ffstruct:"TxInfoJSONRPC"`
	Gas                  *ethtypes.HexInteger      `json:"gas" ffstruct:"TxInfoJSONRPC"`
	GasPrice             *ethtypes.HexInteger      `json:"gasPrice" ffstruct:"TxInfoJSONRPC"`
	MaxFeePerGas         *ethtypes.HexInteger      `json:"maxFeePerGas" ffstruct:"TxInfoJSONRPC"`
	MaxPriorityFeePerGas *ethtypes.HexInteger      `json:"maxPriorityFeePerGas" ffstruct:"TxInfoJSONRPC"`
	Hash                 ethtypes.HexBytes0xPrefix `json:"hash" ffstruct:"TxInfoJSONRPC"`
	Input                ethtypes.HexBytes0xPrefix `json:"input" ffstruct:"TxInfoJSONRPC"`
	Nonce                *ethtypes.HexInteger      `json:"nonce" ffstruct:"TxInfoJSONRPC"`
	To                   *ethtypes.Address0xHex    `json:"to" ffstruct:"TxInfoJSONRPC"`
	TransactionIndex     *ethtypes.HexUint64       `json:"transactionIndex" ffstruct:"TxInfoJSONRPC"` // null if pending
	Type                 *ethtypes.HexUint64       `json:"type" ffstruct:"TxInfoJSONRPC"`
	Value                *ethtypes.HexInteger      `json:"value" ffstruct:"TxInfoJSONRPC"`
	V                    *ethtypes.HexInteger      `json:"v" ffstruct:"TxInfoJSONRPC"`
	R                    *ethtypes.HexInteger      `json:"r" ffstruct:"TxInfoJSONRPC"`
	S                    *ethtypes.HexInteger      `json:"s" ffstruct:"TxInfoJSONRPC"`
}

TxInfoJSONRPC is the transaction info obtained over JSON/RPC from the ethereum client, with input data

func (*TxInfoJSONRPC) FormatMap added in v1.5.3

func (txi *TxInfoJSONRPC) FormatMap() map[string]any

func (*TxInfoJSONRPC) MarshalFormat

func (txi *TxInfoJSONRPC) MarshalFormat(jss *JSONSerializerSet, opts ...MarshalOption) (json.RawMessage, error)

type TxReceiptJSONRPC

type TxReceiptJSONRPC struct {
	TransactionHash   ethtypes.HexBytes0xPrefix `json:"transactionHash" ffstruct:"TxReceiptJSONRPC"`
	TransactionIndex  ethtypes.HexUint64        `json:"transactionIndex" ffstruct:"TxReceiptJSONRPC"`
	BlockHash         ethtypes.HexBytes0xPrefix `json:"blockHash" ffstruct:"TxReceiptJSONRPC"`
	BlockNumber       ethtypes.HexUint64        `json:"blockNumber" ffstruct:"TxReceiptJSONRPC"`
	From              *ethtypes.Address0xHex    `json:"from" ffstruct:"TxReceiptJSONRPC"`
	To                *ethtypes.Address0xHex    `json:"to" ffstruct:"TxReceiptJSONRPC"`
	CumulativeGasUsed *ethtypes.HexInteger      `json:"cumulativeGasUsed" ffstruct:"TxReceiptJSONRPC"`
	EffectiveGasPrice *ethtypes.HexInteger      `json:"effectiveGasPrice" ffstruct:"TxReceiptJSONRPC"`
	GasUsed           *ethtypes.HexInteger      `json:"gasUsed" ffstruct:"TxReceiptJSONRPC"`
	ContractAddress   *ethtypes.Address0xHex    `json:"contractAddress" ffstruct:"TxReceiptJSONRPC"`
	Logs              []*LogJSONRPC             `json:"logs" ffstruct:"TxReceiptJSONRPC"`
	LogsBloom         ethtypes.HexBytes0xPrefix `json:"logsBloom" ffstruct:"TxReceiptJSONRPC"`
	Type              *ethtypes.HexUint64       `json:"type" ffstruct:"TxReceiptJSONRPC"`
	Status            *ethtypes.HexUint64       `json:"status" ffstruct:"TxReceiptJSONRPC"`
	RevertReason      ethtypes.HexBytes0xPrefix `json:"revertReason" ffstruct:"TxReceiptJSONRPC"`
}

TxReceiptJSONRPC is the receipt obtained over JSON/RPC from the ethereum client, with gas used, logs and contract address

func (*TxReceiptJSONRPC) FormatMap added in v1.5.3

func (txr *TxReceiptJSONRPC) FormatMap() map[string]any

func (*TxReceiptJSONRPC) MarshalFormat

func (txr *TxReceiptJSONRPC) MarshalFormat(jss *JSONSerializerSet, opts ...MarshalOption) (json.RawMessage, error)

Jump to

Keyboard shortcuts

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