jsonrpc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 36 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// FilterTypeLog represents a filter of type log.
	FilterTypeLog = "log"
	// FilterTypeBlock represents a filter of type block.
	FilterTypeBlock = "block"
	// FilterTypePendingTx represent a filter of type pending Tx.
	FilterTypePendingTx = "pendingTx"
)
View Source
const (
	// APIEth represents the eth API prefix.
	APIEth = "eth"
	// APINet represents the net API prefix.
	APINet = "net"
	// APIDebug represents the debug API prefix.
	APIDebug = "debug"
	// APIZKEVM represents the zkevm API prefix.
	APIZKEVM = "zkevm"
	// APITxPool represents the txpool API prefix.
	APITxPool = "txpool"
	// APIWeb3 represents the web3 API prefix.
	APIWeb3 = "web3"
)
View Source
const (
	// DefaultSenderAddress is the address that jRPC will use
	// to communicate with the state for eth_EstimateGas and eth_Call when
	// the From field is not specified because it is optional
	DefaultSenderAddress = "0x1111111111111111111111111111111111111111"
)

Variables

View Source
var ErrFilterInvalidPayload = errors.New("invalid argument 0: cannot specify both BlockHash and FromBlock/ToBlock, choose one or the other")

ErrFilterInvalidPayload indicates there is an invalid payload when creating a filter

View Source
var ErrNotFound = errors.New("object not found")

ErrNotFound represent a not found error.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Host defines the network adapter that will be used to serve the HTTP requests
	Host string `mapstructure:"Host"`

	// Port defines the port to serve the endpoints via HTTP
	Port int `mapstructure:"Port"`

	// ReadTimeout is the HTTP server read timeout
	// check net/http.server.ReadTimeout and net/http.server.ReadHeaderTimeout
	ReadTimeout types.Duration `mapstructure:"ReadTimeout"`

	// WriteTimeout is the HTTP server write timeout
	// check net/http.server.WriteTimeout
	WriteTimeout types.Duration `mapstructure:"WriteTimeout"`

	// MaxRequestsPerIPAndSecond defines how much requests a single IP can
	// send within a single second
	MaxRequestsPerIPAndSecond float64 `mapstructure:"MaxRequestsPerIPAndSecond"`

	// SequencerNodeURI is used allow Non-Sequencer nodes
	// to relay transactions to the Sequencer node
	SequencerNodeURI string `mapstructure:"SequencerNodeURI"`

	// MaxCumulativeGasUsed is the max gas allowed per batch
	MaxCumulativeGasUsed uint64

	// WebSockets configuration
	WebSockets WebSocketsConfig `mapstructure:"WebSockets"`

	// EnableL2SuggestedGasPricePolling enables polling of the L2 gas price to block tx in the RPC with lower gas price.
	EnableL2SuggestedGasPricePolling bool `mapstructure:"EnableL2SuggestedGasPricePolling"`
}

Config represents the configuration of the json rpc

type DebugEndpoints

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

DebugEndpoints is the debug jsonrpc endpoint

func (*DebugEndpoints) TraceBlockByHash

func (d *DebugEndpoints) TraceBlockByHash(hash types.ArgHash, cfg *traceConfig) (interface{}, types.Error)

TraceBlockByHash creates a response for debug_traceBlockByHash request. See https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debugtraceblockbyhash

func (*DebugEndpoints) TraceBlockByNumber

func (d *DebugEndpoints) TraceBlockByNumber(number types.BlockNumber, cfg *traceConfig) (interface{}, types.Error)

TraceBlockByNumber creates a response for debug_traceBlockByNumber request. See https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debugtraceblockbynumber

func (*DebugEndpoints) TraceTransaction

func (d *DebugEndpoints) TraceTransaction(hash types.ArgHash, cfg *traceConfig) (interface{}, types.Error)

TraceTransaction creates a response for debug_traceTransaction request. See https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debugtracetransaction

type EthEndpoints

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

EthEndpoints contains implementations for the "eth" RPC endpoints

func (*EthEndpoints) BlockNumber

func (e *EthEndpoints) BlockNumber() (interface{}, types.Error)

BlockNumber returns current block number

func (*EthEndpoints) Call

func (e *EthEndpoints) Call(arg *types.TxArgs, blockArg *types.BlockNumberOrHash) (interface{}, types.Error)

Call executes a new message call immediately and returns the value of executed contract and potential error. Note, this function doesn't make any changes in the state/blockchain and is useful to execute view/pure methods and retrieve values.

func (*EthEndpoints) ChainId

func (e *EthEndpoints) ChainId() (interface{}, types.Error)

ChainId returns the chain id of the client

func (*EthEndpoints) EstimateGas

func (e *EthEndpoints) EstimateGas(arg *types.TxArgs, blockArg *types.BlockNumberOrHash) (interface{}, types.Error)

EstimateGas generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain. Note that the estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance.

func (*EthEndpoints) GasPrice

func (e *EthEndpoints) GasPrice() (interface{}, types.Error)

GasPrice returns the average gas price based on the last x blocks

func (*EthEndpoints) GetBalance

func (e *EthEndpoints) GetBalance(address types.ArgAddress, blockArg *types.BlockNumberOrHash) (interface{}, types.Error)

GetBalance returns the account's balance at the referenced block

func (*EthEndpoints) GetBlockByHash

func (e *EthEndpoints) GetBlockByHash(hash types.ArgHash, fullTx bool) (interface{}, types.Error)

GetBlockByHash returns information about a block by hash

func (*EthEndpoints) GetBlockByNumber

func (e *EthEndpoints) GetBlockByNumber(number types.BlockNumber, fullTx bool) (interface{}, types.Error)

GetBlockByNumber returns information about a block by block number

func (*EthEndpoints) GetBlockTransactionCountByHash

func (e *EthEndpoints) GetBlockTransactionCountByHash(hash types.ArgHash) (interface{}, types.Error)

GetBlockTransactionCountByHash returns the number of transactions in a block from a block matching the given block hash.

func (*EthEndpoints) GetBlockTransactionCountByNumber

func (e *EthEndpoints) GetBlockTransactionCountByNumber(number *types.BlockNumber) (interface{}, types.Error)

GetBlockTransactionCountByNumber returns the number of transactions in a block from a block matching the given block number.

func (*EthEndpoints) GetCode

func (e *EthEndpoints) GetCode(address types.ArgAddress, blockArg *types.BlockNumberOrHash) (interface{}, types.Error)

GetCode returns account code at given block number

func (*EthEndpoints) GetCompilers

func (e *EthEndpoints) GetCompilers() (interface{}, types.Error)

GetCompilers eth_getCompilers

func (*EthEndpoints) GetFilterChanges

func (e *EthEndpoints) GetFilterChanges(filterID string) (interface{}, types.Error)

GetFilterChanges polling method for a filter, which returns an array of logs which occurred since last poll.

func (*EthEndpoints) GetFilterLogs

func (e *EthEndpoints) GetFilterLogs(filterID string) (interface{}, types.Error)

GetFilterLogs returns an array of all logs matching filter with given id.

func (*EthEndpoints) GetLogs

func (e *EthEndpoints) GetLogs(filter LogFilter) (interface{}, types.Error)

GetLogs returns a list of logs accordingly to the provided filter

func (*EthEndpoints) GetStorageAt

func (e *EthEndpoints) GetStorageAt(address types.ArgAddress, storageKeyStr string, blockArg *types.BlockNumberOrHash) (interface{}, types.Error)

GetStorageAt gets the value stored for an specific address and position

func (*EthEndpoints) GetTransactionByBlockHashAndIndex

func (e *EthEndpoints) GetTransactionByBlockHashAndIndex(hash types.ArgHash, index types.Index) (interface{}, types.Error)

GetTransactionByBlockHashAndIndex returns information about a transaction by block hash and transaction index position.

func (*EthEndpoints) GetTransactionByBlockNumberAndIndex

func (e *EthEndpoints) GetTransactionByBlockNumberAndIndex(number *types.BlockNumber, index types.Index) (interface{}, types.Error)

GetTransactionByBlockNumberAndIndex returns information about a transaction by block number and transaction index position.

func (*EthEndpoints) GetTransactionByHash

func (e *EthEndpoints) GetTransactionByHash(hash types.ArgHash) (interface{}, types.Error)

GetTransactionByHash returns a transaction by his hash

func (*EthEndpoints) GetTransactionCount

func (e *EthEndpoints) GetTransactionCount(address types.ArgAddress, blockArg *types.BlockNumberOrHash) (interface{}, types.Error)

GetTransactionCount returns account nonce

func (*EthEndpoints) GetTransactionReceipt

func (e *EthEndpoints) GetTransactionReceipt(hash types.ArgHash) (interface{}, types.Error)

GetTransactionReceipt returns a transaction receipt by his hash

func (*EthEndpoints) GetUncleByBlockHashAndIndex

func (e *EthEndpoints) GetUncleByBlockHashAndIndex(hash types.ArgHash, index types.Index) (interface{}, types.Error)

GetUncleByBlockHashAndIndex returns information about a uncle of a block by hash and uncle index position

func (*EthEndpoints) GetUncleByBlockNumberAndIndex

func (e *EthEndpoints) GetUncleByBlockNumberAndIndex(number types.BlockNumber, index types.Index) (interface{}, types.Error)

GetUncleByBlockNumberAndIndex returns information about a uncle of a block by number and uncle index position

func (*EthEndpoints) GetUncleCountByBlockHash

func (e *EthEndpoints) GetUncleCountByBlockHash(hash types.ArgAddress) (interface{}, types.Error)

GetUncleCountByBlockHash returns the number of uncles in a block matching the given block hash

func (*EthEndpoints) GetUncleCountByBlockNumber

func (e *EthEndpoints) GetUncleCountByBlockNumber(number types.BlockNumber) (interface{}, types.Error)

GetUncleCountByBlockNumber returns the number of uncles in a block matching the given block number

func (*EthEndpoints) NewBlockFilter

func (e *EthEndpoints) NewBlockFilter() (interface{}, types.Error)

NewBlockFilter creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call eth_getFilterChanges.

func (*EthEndpoints) NewFilter

func (e *EthEndpoints) NewFilter(filter LogFilter) (interface{}, types.Error)

NewFilter creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call eth_getFilterChanges.

func (*EthEndpoints) NewPendingTransactionFilter

func (e *EthEndpoints) NewPendingTransactionFilter() (interface{}, types.Error)

NewPendingTransactionFilter creates a filter in the node, to notify when new pending transactions arrive. To check if the state has changed, call eth_getFilterChanges.

func (*EthEndpoints) ProtocolVersion

func (e *EthEndpoints) ProtocolVersion() (interface{}, types.Error)

ProtocolVersion returns the protocol version.

func (*EthEndpoints) SendRawTransaction

func (e *EthEndpoints) SendRawTransaction(httpRequest *http.Request, input string) (interface{}, types.Error)

SendRawTransaction has two different ways to handle new transactions: - for Sequencer nodes it tries to add the tx to the pool - for Non-Sequencer nodes it relays the Tx to the Sequencer node

func (*EthEndpoints) Subscribe

func (e *EthEndpoints) Subscribe(wsConn *websocket.Conn, name string, logFilter *LogFilter) (interface{}, types.Error)

Subscribe Creates a new subscription over particular events. The node will return a subscription id. For each event that matches the subscription a notification with relevant data is sent together with the subscription id.

func (*EthEndpoints) Syncing

func (e *EthEndpoints) Syncing() (interface{}, types.Error)

Syncing returns an object with data about the sync status or false. https://eth.wiki/json-rpc/API#eth_syncing

func (*EthEndpoints) UninstallFilter

func (e *EthEndpoints) UninstallFilter(filterID string) (interface{}, types.Error)

UninstallFilter uninstalls a filter with given id.

func (*EthEndpoints) Unsubscribe

func (e *EthEndpoints) Unsubscribe(wsConn *websocket.Conn, filterID string) (interface{}, types.Error)

Unsubscribe uninstalls the filter based on the provided filterID

type Filter

type Filter struct {
	ID         string
	Type       FilterType
	Parameters interface{}
	LastPoll   time.Time
	WsConn     *websocket.Conn
}

Filter represents a filter.

type FilterType

type FilterType string

FilterType express the type of the filter, block, logs, pending transactions

type Handler

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

Handler manage services to handle jsonrpc requests

Services are public structures containing public methods matching the name of the jsonrpc method.

Services must be registered with a prefix to identify the service and its methods, for example a service registered with a prefix `eth` will have all the public methods exposed as eth_<methodName> through the json rpc server.

Go public methods requires the first char of its name to be in uppercase, but the exposition of the method will consider it to lower case, for example a method `func MyMethod()` provided by the service registered with `eth` prefix will be triggered when the method eth_myMethod is specified

the public methods must follow the conventions: - return interface{}, rpcError - if the method depend on a Web Socket connection, it must be the first parameters as f(*websocket.Conn) - parameter types must match the type of the data provided for the method

check the `eth.go` file for more example on how the methods are implemented

func (*Handler) Handle

func (h *Handler) Handle(req handleRequest) types.Response

Handle is the function that knows which and how a function should be executed when a JSON RPC request is received

func (*Handler) HandleWs

func (h *Handler) HandleWs(reqBody []byte, wsConn *websocket.Conn) ([]byte, error)

HandleWs handle websocket requests

func (*Handler) RemoveFilterByWsConn

func (h *Handler) RemoveFilterByWsConn(wsConn *websocket.Conn)

RemoveFilterByWsConn uninstalls the filter attached to this websocket connection

type LogFilter

type LogFilter struct {
	BlockHash *common.Hash
	FromBlock *types.BlockNumber
	ToBlock   *types.BlockNumber
	Addresses []common.Address
	Topics    [][]common.Hash
	Since     *time.Time
}

LogFilter is a filter for logs

func (*LogFilter) MarshalJSON

func (f *LogFilter) MarshalJSON() ([]byte, error)

MarshalJSON allows to customize the JSON representation.

func (*LogFilter) Match

func (f *LogFilter) Match(log *types.Log) bool

Match returns whether the receipt includes topics for this filter

func (*LogFilter) UnmarshalJSON

func (f *LogFilter) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a json object

type NetEndpoints

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

NetEndpoints contains implementations for the "net" RPC endpoints

func (*NetEndpoints) Version

func (n *NetEndpoints) Version() (interface{}, types.Error)

Version returns the current network id

type Server

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

Server is an API backend to handle RPC requests

func NewServer

func NewServer(
	cfg Config,
	chainID uint64,
	p types.PoolInterface,
	s types.StateInterface,
	storage storageInterface,
	apis map[string]bool,
) *Server

NewServer returns the JsonRPC server

func (*Server) Start

func (s *Server) Start() error

Start initializes the JSON RPC server to listen for request

func (*Server) Stop

func (s *Server) Stop() error

Stop shutdown the rpc server

type Storage

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

Storage uses memory to store the data related to the json rpc server

func NewStorage

func NewStorage() *Storage

NewStorage creates and initializes an instance of Storage

func (*Storage) GetAllBlockFiltersWithWSConn

func (s *Storage) GetAllBlockFiltersWithWSConn() ([]*Filter, error)

GetAllBlockFiltersWithWSConn returns an array with all filter that have a web socket connection and are filtering by new blocks

func (*Storage) GetAllLogFiltersWithWSConn

func (s *Storage) GetAllLogFiltersWithWSConn() ([]*Filter, error)

GetAllLogFiltersWithWSConn returns an array with all filter that have a web socket connection and are filtering by new logs

func (*Storage) GetFilter

func (s *Storage) GetFilter(filterID string) (*Filter, error)

GetFilter gets a filter by its id

func (*Storage) NewBlockFilter

func (s *Storage) NewBlockFilter(wsConn *websocket.Conn) (string, error)

NewBlockFilter persists a new block log filter

func (*Storage) NewLogFilter

func (s *Storage) NewLogFilter(wsConn *websocket.Conn, filter LogFilter) (string, error)

NewLogFilter persists a new log filter

func (*Storage) NewPendingTransactionFilter

func (s *Storage) NewPendingTransactionFilter(wsConn *websocket.Conn) (string, error)

NewPendingTransactionFilter persists a new pending transaction filter

func (*Storage) UninstallFilter

func (s *Storage) UninstallFilter(filterID string) error

UninstallFilter deletes a filter by its id

func (*Storage) UninstallFilterByWSConn

func (s *Storage) UninstallFilterByWSConn(wsConn *websocket.Conn) error

UninstallFilterByWSConn deletes all filters connected to the provided web socket connection

func (*Storage) UpdateFilterLastPoll

func (s *Storage) UpdateFilterLastPoll(filterID string) error

UpdateFilterLastPoll updates the last poll to now

type StructLogRes

type StructLogRes struct {
	Pc            uint64             `json:"pc"`
	Op            string             `json:"op"`
	Gas           uint64             `json:"gas"`
	GasCost       uint64             `json:"gasCost"`
	Depth         int                `json:"depth"`
	Error         string             `json:"error,omitempty"`
	Stack         *[]types.ArgBig    `json:"stack,omitempty"`
	Memory        *[]string          `json:"memory,omitempty"`
	Storage       *map[string]string `json:"storage,omitempty"`
	RefundCounter uint64             `json:"refund,omitempty"`
}

StructLogRes represents the debug trace information for each opcode

type TxPoolEndpoints

type TxPoolEndpoints struct{}

TxPoolEndpoints is the txpool jsonrpc endpoint

func (*TxPoolEndpoints) Content

func (e *TxPoolEndpoints) Content() (interface{}, types.Error)

Content creates a response for txpool_content request. See https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content.

type Web3Endpoints

type Web3Endpoints struct {
}

Web3Endpoints contains implementations for the "web3" RPC endpoints

func (*Web3Endpoints) ClientVersion

func (e *Web3Endpoints) ClientVersion() (interface{}, types.Error)

ClientVersion returns the client version.

func (*Web3Endpoints) Sha3

func (e *Web3Endpoints) Sha3(data types.ArgBig) (interface{}, types.Error)

Sha3 returns the keccak256 hash of the given data.

type WebSocketsConfig

type WebSocketsConfig struct {
	// Enabled defines if the WebSocket requests are enabled or disabled
	Enabled bool `mapstructure:"Enabled"`

	// Host defines the network adapter that will be used to serve the WS requests
	Host string `mapstructure:"Host"`

	// Port defines the port to serve the endpoints via WS
	Port int `mapstructure:"Port"`
}

WebSocketsConfig has parameters to config the rpc websocket support

type ZKEVMEndpoints

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

ZKEVMEndpoints contains implementations for the "zkevm" RPC endpoints

func (*ZKEVMEndpoints) BatchNumber

func (z *ZKEVMEndpoints) BatchNumber() (interface{}, types.Error)

BatchNumber returns the latest virtualized batch number

func (*ZKEVMEndpoints) BatchNumberByBlockNumber

func (z *ZKEVMEndpoints) BatchNumberByBlockNumber(blockNumber types.ArgUint64) (interface{}, types.Error)

BatchNumberByBlockNumber returns the batch number from which the passed block number is created

func (*ZKEVMEndpoints) ConsolidatedBlockNumber

func (z *ZKEVMEndpoints) ConsolidatedBlockNumber() (interface{}, types.Error)

ConsolidatedBlockNumber returns last block number related to the last verified batch

func (*ZKEVMEndpoints) GetBatchByNumber

func (z *ZKEVMEndpoints) GetBatchByNumber(batchNumber types.BatchNumber, fullTx bool) (interface{}, types.Error)

GetBatchByNumber returns information about a batch by batch number

func (*ZKEVMEndpoints) IsBlockConsolidated

func (z *ZKEVMEndpoints) IsBlockConsolidated(blockNumber types.ArgUint64) (interface{}, types.Error)

IsBlockConsolidated returns the consolidation status of a provided block number

func (*ZKEVMEndpoints) IsBlockVirtualized

func (z *ZKEVMEndpoints) IsBlockVirtualized(blockNumber types.ArgUint64) (interface{}, types.Error)

IsBlockVirtualized returns the virtualization status of a provided block number

func (*ZKEVMEndpoints) VerifiedBatchNumber

func (z *ZKEVMEndpoints) VerifiedBatchNumber() (interface{}, types.Error)

VerifiedBatchNumber returns the latest verified batch number

func (*ZKEVMEndpoints) VirtualBatchNumber

func (z *ZKEVMEndpoints) VirtualBatchNumber() (interface{}, types.Error)

VirtualBatchNumber returns the latest virtualized batch number

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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