jsonrpc

package
v0.0.1-RC3 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: GPL-3.0 Imports: 31 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// PendingBlockNumber represents the pending block number
	PendingBlockNumber = BlockNumber(-3)
	// LatestBlockNumber represents the latest block number
	LatestBlockNumber = BlockNumber(-2)
	// EarliestBlockNumber represents the earliest block number
	EarliestBlockNumber = BlockNumber(-1)

	// Earliest contains the string to represent the earliest block known.
	Earliest = "earliest"
	// Latest contains the string to represent the latest block known.
	Latest = "latest"
	// Pending contains the string to represent pending blocks.
	Pending = "pending"
)
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"
)

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 BlockNumber

type BlockNumber int64

BlockNumber is the number of a ethereum block

func (*BlockNumber) UnmarshalJSON

func (b *BlockNumber) UnmarshalJSON(buffer []byte) error

UnmarshalJSON automatically decodes the user input for the block number, when a JSON RPC method is called

type Config

type Config struct {
	Host              string        `mapstructure:"Host"`
	Port              int           `mapstructure:"Port"`
	ReadTimeoutInSec  time.Duration `mapstructure:"ReadTimeoutInSec"`
	WriteTimeoutInSec time.Duration `mapstructure:"WriteTimeoutInSec"`

	MaxRequestsPerIPAndSecond float64 `mapstructure:"MaxRequestsPerIPAndSecond"`

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

	// BroadcastURI is the URL of the Trusted State broadcast service
	BroadcastURI string `mapstructure:"BroadcastURI"`

	// 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 string `mapstructure:"DefaultSenderAddress"`

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

	// ChainID is the L2 ChainID provided by the Network Config
	ChainID uint64

	// RPC Database COnfig
	DB db.Config `mapstructure:"DB"`
}

Config represents the configuration of the json rpc

type Debug

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

Debug is the debug jsonrpc endpoint

func (*Debug) TraceTransaction

func (d *Debug) TraceTransaction(hash common.Hash, cfg *traceConfig) (interface{}, rpcError)

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

type ErrorObject

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

ErrorObject is a jsonrpc error

type Eth

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

Eth contains implementations for the "eth" RPC endpoints

func (*Eth) BlockNumber

func (e *Eth) BlockNumber() (interface{}, rpcError)

BlockNumber returns current block number

func (*Eth) Call

func (e *Eth) Call(arg *txnArgs, number *BlockNumber) (interface{}, rpcError)

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 (*Eth) ChainId

func (e *Eth) ChainId() (interface{}, rpcError)

ChainId returns the chain id of the client

func (*Eth) EstimateGas

func (e *Eth) EstimateGas(arg *txnArgs, number *BlockNumber) (interface{}, rpcError)

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 (*Eth) GasPrice

func (e *Eth) GasPrice() (interface{}, rpcError)

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

func (*Eth) GetBalance

func (e *Eth) GetBalance(address common.Address, number *BlockNumber) (interface{}, rpcError)

GetBalance returns the account's balance at the referenced block

func (*Eth) GetBlockByHash

func (e *Eth) GetBlockByHash(hash common.Hash, fullTx bool) (interface{}, rpcError)

GetBlockByHash returns information about a block by hash

func (*Eth) GetBlockByNumber

func (e *Eth) GetBlockByNumber(number BlockNumber, fullTx bool) (interface{}, rpcError)

GetBlockByNumber returns information about a block by block number

func (*Eth) GetBlockTransactionCountByHash

func (e *Eth) GetBlockTransactionCountByHash(hash common.Hash) (interface{}, rpcError)

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

func (*Eth) GetBlockTransactionCountByNumber

func (e *Eth) GetBlockTransactionCountByNumber(number *BlockNumber) (interface{}, rpcError)

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

func (*Eth) GetCode

func (e *Eth) GetCode(address common.Address, number *BlockNumber) (interface{}, rpcError)

GetCode returns account code at given block number

func (*Eth) GetCompilers

func (e *Eth) GetCompilers() (interface{}, rpcError)

GetCompilers eth_getCompilers

func (*Eth) GetFilterChanges

func (e *Eth) GetFilterChanges(filterID argUint64) (interface{}, rpcError)

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

func (*Eth) GetFilterLogs

func (e *Eth) GetFilterLogs(filterID argUint64) (interface{}, rpcError)

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

func (*Eth) GetLogs

func (e *Eth) GetLogs(filter *LogFilter) (interface{}, rpcError)

GetLogs returns a list of logs accordingly to the provided filter

func (*Eth) GetStorageAt

func (e *Eth) GetStorageAt(address common.Address, position common.Hash, number *BlockNumber) (interface{}, rpcError)

GetStorageAt gets the value stored for an specific address and position

func (*Eth) GetTransactionByBlockHashAndIndex

func (e *Eth) GetTransactionByBlockHashAndIndex(hash common.Hash, index Index) (interface{}, rpcError)

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

func (*Eth) GetTransactionByBlockNumberAndIndex

func (e *Eth) GetTransactionByBlockNumberAndIndex(number *BlockNumber, index Index) (interface{}, rpcError)

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

func (*Eth) GetTransactionByHash

func (e *Eth) GetTransactionByHash(hash common.Hash) (interface{}, rpcError)

GetTransactionByHash returns a transaction by his hash

func (*Eth) GetTransactionCount

func (e *Eth) GetTransactionCount(address common.Address, number *BlockNumber) (interface{}, rpcError)

GetTransactionCount returns account nonce

func (*Eth) GetTransactionReceipt

func (e *Eth) GetTransactionReceipt(hash common.Hash) (interface{}, rpcError)

GetTransactionReceipt returns a transaction receipt by his hash

func (*Eth) GetUncleByBlockHashAndIndex

func (e *Eth) GetUncleByBlockHashAndIndex() (interface{}, rpcError)

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

func (*Eth) GetUncleByBlockNumberAndIndex

func (e *Eth) GetUncleByBlockNumberAndIndex() (interface{}, rpcError)

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

func (*Eth) GetUncleCountByBlockHash

func (e *Eth) GetUncleCountByBlockHash() (interface{}, rpcError)

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

func (*Eth) GetUncleCountByBlockNumber

func (e *Eth) GetUncleCountByBlockNumber() (interface{}, rpcError)

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

func (*Eth) NewBlockFilter

func (e *Eth) NewBlockFilter() (interface{}, rpcError)

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 (*Eth) NewFilter

func (e *Eth) NewFilter(filter *LogFilter) (interface{}, rpcError)

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 (*Eth) NewPendingTransactionFilter

func (e *Eth) NewPendingTransactionFilter(filterID argUint64) (interface{}, rpcError)

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 (*Eth) ProtocolVersion

func (e *Eth) ProtocolVersion() (interface{}, rpcError)

ProtocolVersion returns the protocol version.

func (*Eth) SendRawTransaction

func (e *Eth) SendRawTransaction(input string) (interface{}, rpcError)

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 (*Eth) Syncing

func (e *Eth) Syncing() (interface{}, rpcError)

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

func (*Eth) UninstallFilter

func (e *Eth) UninstallFilter(filterID argUint64) (interface{}, rpcError)

UninstallFilter uninstalls a filter with given id. Should always be called when wlock is no longer needed. Additionally Filters timeout when they aren’t requested with eth_getFilterChanges for a period of time.

type Filter

type Filter struct {
	ID         uint64
	Type       string
	Parameters string
	LastPoll   time.Time
}

Filter represents a filter.

type Handler

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

Handler handles jsonrpc requests

func (*Handler) Handle

func (d *Handler) Handle(req Request) Response

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

type Index

type Index int64

Index of a item

func (*Index) UnmarshalJSON

func (i *Index) UnmarshalJSON(buffer []byte) error

UnmarshalJSON automatically decodes the user input for the block number, when a JSON RPC method is called

type LogFilter

type LogFilter struct {
	BlockHash *common.Hash
	FromBlock *BlockNumber
	ToBlock   *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 LogFilterRequest

type LogFilterRequest struct {
	BlockHash *common.Hash  `json:"blockHash,omitempty"`
	FromBlock *string       `json:"fromBlock,omitempty"`
	ToBlock   *string       `json:"toBlock,omitempty"`
	Address   interface{}   `json:"address,omitempty"`
	Topics    []interface{} `json:"topics,omitempty"`
}

LogFilterRequest represents a log filter request.

type Net

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

Net contains implementations for the "net" RPC endpoints

func (*Net) Version

func (n *Net) Version() (interface{}, rpcError)

Version returns the current network id

type PostgresStorage

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

PostgresStorage uses a postgres database to store the data related to the json rpc server

func NewPostgresStorage

func NewPostgresStorage(cfg db.Config) (*PostgresStorage, error)

NewPostgresStorage creates and initializes an instance of PostgresStorage

func (*PostgresStorage) GetFilter

func (s *PostgresStorage) GetFilter(filterID uint64) (*Filter, error)

GetFilter gets a filter by its id

func (*PostgresStorage) NewBlockFilter

func (s *PostgresStorage) NewBlockFilter() (uint64, error)

NewBlockFilter persists a new block log filter

func (*PostgresStorage) NewLogFilter

func (s *PostgresStorage) NewLogFilter(filter LogFilter) (uint64, error)

NewLogFilter persists a new log filter

func (*PostgresStorage) NewPendingTransactionFilter

func (s *PostgresStorage) NewPendingTransactionFilter() (uint64, error)

NewPendingTransactionFilter persists a new pending transaction filter

func (*PostgresStorage) UninstallFilter

func (s *PostgresStorage) UninstallFilter(filterID uint64) (bool, error)

UninstallFilter deletes a filter by its id

func (*PostgresStorage) UpdateFilterLastPoll

func (s *PostgresStorage) UpdateFilterLastPoll(filterID uint64) error

UpdateFilterLastPoll updates the last poll to now

type RPCError

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

RPCError represents an RPC error.

func (*RPCError) Error

func (e *RPCError) Error() string

Error returns the error message.

func (*RPCError) ErrorCode

func (e *RPCError) ErrorCode() int

ErrorCode returns the error code.

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request is a jsonrpc request

type Response

type Response struct {
	JSONRPC string
	ID      interface{}
	Result  json.RawMessage
	Error   *ErrorObject
}

Response is a jsonrpc success response

func JSONRPCCall

func JSONRPCCall(url, method string, parameters ...interface{}) (Response, error)

JSONRPCCall executes a 2.0 JSON RPC HTTP Post Request to the provided URL with the provided method and parameters, which is compatible with the Ethereum JSON RPC Server.

func NewResponse

func NewResponse(req Request, reply *[]byte, err rpcError) Response

NewResponse returns Success/Error response object

func (Response) MarshalJSON

func (r Response) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON representation of the response.

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,
	p jsonRPCTxPool,
	s stateInterface,
	gpe gasPriceEstimator,
	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 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         *[]argBig          `json:"stack,omitempty"`
	Memory        *argBytes          `json:"memory,omitempty"`
	Storage       *map[string]string `json:"storage,omitempty"`
	RefundCounter uint64             `json:"refund,omitempty"`
}

StructLogRes represents a log response.

type TxPool

type TxPool struct{}

TxPool is the txpool jsonrpc endpoint

func (*TxPool) Content

func (t *TxPool) Content() (interface{}, rpcError)

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

type Web3

type Web3 struct {
}

Web3 contains implementations for the "web3" RPC endpoints

func (*Web3) ClientVersion

func (w *Web3) ClientVersion() (interface{}, rpcError)

ClientVersion returns the client version.

func (*Web3) Sha3

func (w *Web3) Sha3(data argBig) (interface{}, rpcError)

Sha3 returns the keccak256 hash of the given data.

type ZKEVM

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

ZKEVM contains implementations for the "zkevm" RPC endpoints

func (*ZKEVM) BatchNumberOfL2Block

func (h *ZKEVM) BatchNumberOfL2Block(blockNumber uint64) (interface{}, rpcError)

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

func (*ZKEVM) ConsolidatedBlockNumber

func (h *ZKEVM) ConsolidatedBlockNumber() (interface{}, rpcError)

ConsolidatedBlockNumber returns current block number for consolidated blocks

func (*ZKEVM) GetBroadcastURI

func (h *ZKEVM) GetBroadcastURI() (interface{}, rpcError)

GetBroadcastURI returns the IP:PORT of the broadcast service provided by the Trusted Sequencer JSON RPC server

func (*ZKEVM) IsL2BlockConsolidated

func (h *ZKEVM) IsL2BlockConsolidated(blockNumber int) (interface{}, rpcError)

IsL2BlockConsolidated returns the consolidation status of a provided block number

func (*ZKEVM) IsL2BlockVirtualized

func (h *ZKEVM) IsL2BlockVirtualized(blockNumber int) (interface{}, rpcError)

IsL2BlockVirtualized returns the virtualisation status of a provided block number

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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