api

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 54 Imported by: 1

Documentation

Index

Constants

View Source
const BlockGasLimit uint64 = 120_000_000

Variables

View Source
var Version = "development"

Functions

func CheckTimeouts

func CheckTimeouts(logger zerolog.Logger, timeouts *rpc.HTTPTimeouts)

CheckTimeouts ensures that timeout values are meaningful

func SupportedAPIs

func SupportedAPIs(
	blockChainAPI *BlockChainAPI,
	streamAPI *StreamAPI,
	pullAPI *PullAPI,
	debugAPI *DebugAPI,
	walletAPI *WalletAPI,
	config config.Config,
) []rpc.API

Types

type BlockChainAPI

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

func NewBlockChainAPI

func NewBlockChainAPI(
	logger zerolog.Logger,
	config config.Config,
	evm requester.Requester,
	blocks storage.BlockIndexer,
	transactions storage.TransactionIndexer,
	receipts storage.ReceiptIndexer,
	ratelimiter limiter.Store,
	collector metrics.Collector,
	indexingResumedHeight uint64,
) *BlockChainAPI

func (*BlockChainAPI) BlockNumber

func (b *BlockChainAPI) BlockNumber(ctx context.Context) (hexutil.Uint64, error)

BlockNumber returns the block number of the chain head.

func (*BlockChainAPI) Call

func (b *BlockChainAPI) Call(
	ctx context.Context,
	args ethTypes.TransactionArgs,
	blockNumberOrHash *rpc.BlockNumberOrHash,
	stateOverrides *ethTypes.StateOverride,
	_ *ethTypes.BlockOverrides,
) (hexutil.Bytes, error)

Call executes the given transaction on the state for the given block number. Additionally, the caller can specify a batch of contract for fields overriding. Note, this function doesn't make and changes in the state/blockchain and is useful to execute and retrieve values.

func (*BlockChainAPI) ChainId

func (b *BlockChainAPI) ChainId(ctx context.Context) (*hexutil.Big, error)

ChainId is the EIP-155 replay-protection chain id for the current Ethereum chain config.

Note, this method does not conform to EIP-695 because the configured chain ID is always returned, regardless of the current head block. We used to return an error when the chain wasn't synced up to a block where EIP-155 is enabled, but this behavior caused issues in CL clients.

func (*BlockChainAPI) Coinbase

func (b *BlockChainAPI) Coinbase(ctx context.Context) (common.Address, error)

Coinbase is the address that mining rewards will be sent to (alias for Etherbase).

func (*BlockChainAPI) CreateAccessList

func (b *BlockChainAPI) CreateAccessList(
	ctx context.Context,
	args ethTypes.TransactionArgs,
	blockNumberOrHash *rpc.BlockNumberOrHash,
) (*ethTypes.AccessListResult, error)

CreateAccessList creates an EIP-2930 type AccessList for the given transaction. Reexec and blockNumberOrHash can be specified to create the accessList on top of a certain state.

func (*BlockChainAPI) EstimateGas

func (b *BlockChainAPI) EstimateGas(
	ctx context.Context,
	args ethTypes.TransactionArgs,
	blockNumberOrHash *rpc.BlockNumberOrHash,
	stateOverrides *ethTypes.StateOverride,
) (hexutil.Uint64, error)

EstimateGas returns the lowest possible gas limit that allows the transaction to run successfully at block `blockNrOrHash`, or the latest block if `blockNrOrHash` is unspecified. It returns error if the transaction would revert or if there are unexpected failures. The returned value is capped by both `args.Gas` (if non-nil & non-zero) and the backend's RPCGasCap configuration (if non-zero).

func (*BlockChainAPI) FeeHistory

func (b *BlockChainAPI) FeeHistory(
	ctx context.Context,
	blockCount math.HexOrDecimal64,
	lastBlock rpc.BlockNumber,
	rewardPercentiles []float64,
) (*ethTypes.FeeHistoryResult, error)

FeeHistory returns transaction base fee per gas and effective priority fee per gas for the requested/supported block range. blockCount: Requested range of blocks. Clients will return less than the requested range if not all blocks are available. lastBlock: Highest block of the requested range. rewardPercentiles: A monotonically increasing list of percentile values. For each block in the requested range, the transactions will be sorted in ascending order by effective tip per gas and the coresponding effective tip for the percentile will be determined, accounting for gas consumed.

func (*BlockChainAPI) GasPrice

func (b *BlockChainAPI) GasPrice(ctx context.Context) (*hexutil.Big, error)

GasPrice returns a suggestion for a gas price for legacy transactions.

func (*BlockChainAPI) GetBalance

func (b *BlockChainAPI) GetBalance(
	ctx context.Context,
	address common.Address,
	blockNumberOrHash rpc.BlockNumberOrHash,
) (*hexutil.Big, error)

GetBalance returns the amount of wei for the given address in the state of the given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta block numbers are also allowed.

func (*BlockChainAPI) GetBlockByHash

func (b *BlockChainAPI) GetBlockByHash(
	ctx context.Context,
	hash common.Hash,
	fullTx bool,
) (*ethTypes.Block, error)

GetBlockByHash returns the requested block. When fullTx is true all transactions in the block are returned in full detail, otherwise only the transaction hash is returned.

func (*BlockChainAPI) GetBlockByNumber

func (b *BlockChainAPI) GetBlockByNumber(
	ctx context.Context,
	blockNumber rpc.BlockNumber,
	fullTx bool,
) (*ethTypes.Block, error)

GetBlockByNumber returns the requested canonical block.

  • When blockNr is -1 the chain pending block is returned.
  • When blockNr is -2 the chain latest block is returned.
  • When blockNr is -3 the chain finalized block is returned.
  • When blockNr is -4 the chain safe block is returned.
  • When fullTx is true all transactions in the block are returned, otherwise only the transaction hash is returned.

func (*BlockChainAPI) GetBlockReceipts

func (b *BlockChainAPI) GetBlockReceipts(
	ctx context.Context,
	blockNumberOrHash rpc.BlockNumberOrHash,
) ([]map[string]interface{}, error)

GetBlockReceipts returns the block receipts for the given block hash or number or tag.

func (*BlockChainAPI) GetBlockTransactionCountByHash

func (b *BlockChainAPI) GetBlockTransactionCountByHash(
	ctx context.Context,
	blockHash common.Hash,
) (*hexutil.Uint, error)

GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.

func (*BlockChainAPI) GetBlockTransactionCountByNumber

func (b *BlockChainAPI) GetBlockTransactionCountByNumber(
	ctx context.Context,
	blockNumber rpc.BlockNumber,
) (*hexutil.Uint, error)

GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.

func (*BlockChainAPI) GetCode

func (b *BlockChainAPI) GetCode(
	ctx context.Context,
	address common.Address,
	blockNumberOrHash rpc.BlockNumberOrHash,
) (hexutil.Bytes, error)

GetCode returns the code stored at the given address in the state for the given block number.

func (*BlockChainAPI) GetLogs

func (b *BlockChainAPI) GetLogs(
	ctx context.Context,
	criteria filters.FilterCriteria,
) ([]*types.Log, error)

GetLogs returns logs matching the given argument that are stored within the state.

func (*BlockChainAPI) GetProof

func (b *BlockChainAPI) GetProof(
	ctx context.Context,
	address common.Address,
	storageKeys []string,
	blockNumberOrHash rpc.BlockNumberOrHash,
) (*ethTypes.AccountResult, error)

GetProof returns the Merkle-proof for a given account and optionally some storage keys.

func (*BlockChainAPI) GetStorageAt

func (b *BlockChainAPI) GetStorageAt(
	ctx context.Context,
	address common.Address,
	storageSlot string,
	blockNumberOrHash rpc.BlockNumberOrHash,
) (hexutil.Bytes, error)

GetStorageAt returns the storage from the state at the given address, key and block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta block numbers are also allowed.

func (*BlockChainAPI) GetTransactionByBlockHashAndIndex

func (b *BlockChainAPI) GetTransactionByBlockHashAndIndex(
	ctx context.Context,
	blockHash common.Hash,
	index hexutil.Uint,
) (*ethTypes.Transaction, error)

GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.

func (*BlockChainAPI) GetTransactionByBlockNumberAndIndex

func (b *BlockChainAPI) GetTransactionByBlockNumberAndIndex(
	ctx context.Context,
	blockNumber rpc.BlockNumber,
	index hexutil.Uint,
) (*ethTypes.Transaction, error)

GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.

func (*BlockChainAPI) GetTransactionByHash

func (b *BlockChainAPI) GetTransactionByHash(
	ctx context.Context,
	hash common.Hash,
) (*ethTypes.Transaction, error)

GetTransactionByHash returns the transaction for the given hash

func (*BlockChainAPI) GetTransactionCount

func (b *BlockChainAPI) GetTransactionCount(
	ctx context.Context,
	address common.Address,
	blockNumberOrHash rpc.BlockNumberOrHash,
) (*hexutil.Uint64, error)

GetTransactionCount returns the number of transactions the given address has sent for the given block number.

func (*BlockChainAPI) GetTransactionReceipt

func (b *BlockChainAPI) GetTransactionReceipt(
	ctx context.Context,
	hash common.Hash,
) (map[string]interface{}, error)

GetTransactionReceipt returns the transaction receipt for the given transaction hash.

func (*BlockChainAPI) GetUncleByBlockHashAndIndex

func (b *BlockChainAPI) GetUncleByBlockHashAndIndex(
	ctx context.Context,
	blockHash common.Hash,
	index hexutil.Uint,
) (map[string]interface{}, error)

GetUncleByBlockHashAndIndex returns the uncle block for the given block hash and index.

func (*BlockChainAPI) GetUncleByBlockNumberAndIndex

func (b *BlockChainAPI) GetUncleByBlockNumberAndIndex(
	ctx context.Context,
	blockNumber rpc.BlockNumber,
	index hexutil.Uint,
) (map[string]interface{}, error)

GetUncleByBlockNumberAndIndex returns the uncle block for the given block hash and index.

func (*BlockChainAPI) GetUncleCountByBlockHash

func (b *BlockChainAPI) GetUncleCountByBlockHash(
	ctx context.Context,
	blockHash common.Hash,
) *hexutil.Uint

GetUncleCountByBlockHash returns number of uncles in the block for the given block hash

func (*BlockChainAPI) GetUncleCountByBlockNumber

func (b *BlockChainAPI) GetUncleCountByBlockNumber(
	ctx context.Context,
	blockNumber rpc.BlockNumber,
) *hexutil.Uint

GetUncleCountByBlockNumber returns number of uncles in the block for the given block number

func (*BlockChainAPI) Hashrate added in v0.5.0

func (b *BlockChainAPI) Hashrate() hexutil.Uint64

Hashrate returns the number of hashes per second that the node is mining with. This can only return true for proof-of-work networks and may not be available in some clients since The Merge.

func (*BlockChainAPI) MaxPriorityFeePerGas

func (b *BlockChainAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error)

MaxPriorityFeePerGas returns a suggestion for a gas tip cap for dynamic fee transactions.

func (*BlockChainAPI) Mining added in v0.5.0

func (b *BlockChainAPI) Mining() bool

Mining returns true if client is actively mining new blocks. This can only return true for proof-of-work networks and may not be available in some clients since The Merge.

func (*BlockChainAPI) SendRawTransaction

func (b *BlockChainAPI) SendRawTransaction(
	ctx context.Context,
	input hexutil.Bytes,
) (common.Hash, error)

SendRawTransaction will add the signed transaction to the transaction pool. The sender is responsible for signing the transaction and using the correct nonce.

func (*BlockChainAPI) Syncing

func (b *BlockChainAPI) Syncing(ctx context.Context) (interface{}, error)

Syncing returns false in case the node is currently not syncing with the network. It can be up-to-date or has not yet received the latest block headers from its peers. In case it is synchronizing: - startingBlock: block number this node started to synchronize from - currentBlock: block number this node is currently importing - highestBlock: block number of the highest block header this node has received from peers

type DebugAPI added in v0.17.0

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

func NewDebugAPI added in v0.17.0

func NewDebugAPI(
	registerStore *pebble.RegisterStorage,
	tracer storage.TraceIndexer,
	blocks storage.BlockIndexer,
	transactions storage.TransactionIndexer,
	receipts storage.ReceiptIndexer,
	client *requester.CrossSporkClient,
	config config.Config,
	logger zerolog.Logger,
	collector metrics.Collector,
	limiter limiter.Store,
) *DebugAPI

func (*DebugAPI) FlowHeightByBlock added in v1.0.0

func (d *DebugAPI) FlowHeightByBlock(
	ctx context.Context,
	blockNrOrHash rpc.BlockNumberOrHash,
) (uint64, error)

FlowHeightByBlock returns the Flow height for the given EVM block specified either by EVM block height or EVM block hash.

func (*DebugAPI) TraceBlockByHash added in v0.17.0

func (d *DebugAPI) TraceBlockByHash(
	ctx context.Context,
	hash gethCommon.Hash,
	config *tracers.TraceConfig,
) ([]*txTraceResult, error)

func (*DebugAPI) TraceBlockByNumber added in v0.17.0

func (d *DebugAPI) TraceBlockByNumber(
	ctx context.Context,
	number rpc.BlockNumber,
	config *tracers.TraceConfig,
) ([]*txTraceResult, error)

func (*DebugAPI) TraceCall added in v1.0.0

func (d *DebugAPI) TraceCall(
	ctx context.Context,
	args ethTypes.TransactionArgs,
	blockNrOrHash rpc.BlockNumberOrHash,
	config *tracers.TraceCallConfig,
) (interface{}, error)

func (*DebugAPI) TraceTransaction added in v0.17.0

func (d *DebugAPI) TraceTransaction(
	ctx context.Context,
	hash gethCommon.Hash,
	config *tracers.TraceConfig,
) (json.RawMessage, error)

TraceTransaction will return a debug execution trace of a transaction, if it exists.

type NetAPI

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

NetAPI offers network related RPC methods

func NewNetAPI added in v0.21.0

func NewNetAPI(config config.Config) *NetAPI

func (*NetAPI) Listening

func (s *NetAPI) Listening() bool

Listening returns an indication if the node is listening for network connections.

func (*NetAPI) PeerCount

func (s *NetAPI) PeerCount() hexutil.Uint

PeerCount returns the number of connected peers

func (*NetAPI) Version

func (s *NetAPI) Version() string

Version returns the current ethereum protocol version.

type ProfileServer added in v0.36.4

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

func NewProfileServer added in v0.36.4

func NewProfileServer(
	logger zerolog.Logger,
	host string,
	port int,
) *ProfileServer

func (*ProfileServer) Close added in v0.36.4

func (s *ProfileServer) Close() error

func (*ProfileServer) ListenAddr added in v0.36.4

func (s *ProfileServer) ListenAddr() string

func (*ProfileServer) Start added in v0.36.4

func (s *ProfileServer) Start()

func (*ProfileServer) Stop added in v0.36.4

func (s *ProfileServer) Stop() error

type PullAPI added in v0.4.0

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

func NewPullAPI added in v0.4.0

func NewPullAPI(
	logger zerolog.Logger,
	config config.Config,
	blocks storage.BlockIndexer,
	transactions storage.TransactionIndexer,
	receipts storage.ReceiptIndexer,
	ratelimiter limiter.Store,
) *PullAPI

func (*PullAPI) GetFilterChanges added in v0.4.0

func (api *PullAPI) GetFilterChanges(ctx context.Context, id rpc.ID) (any, error)

GetFilterChanges returns the logs for the filter with the given id since last time it was called. This can be used for polling.

For pending transaction and block filters the result is []common.Hash. (pending)Log filters return []Log.

func (*PullAPI) GetFilterLogs added in v0.4.0

func (api *PullAPI) GetFilterLogs(
	ctx context.Context,
	id rpc.ID,
) ([]*gethTypes.Log, error)

GetFilterLogs returns the logs for the filter with the given id. If the filter could not be found or has expired, an error is returned.

func (*PullAPI) NewBlockFilter added in v0.4.0

func (api *PullAPI) NewBlockFilter(ctx context.Context) (rpc.ID, error)

NewBlockFilter creates a filter that fetches blocks that are imported into the chain. It is part of the filter package since polling goes with eth_getFilterChanges.

func (*PullAPI) NewFilter added in v0.4.0

func (api *PullAPI) NewFilter(ctx context.Context, criteria filters.FilterCriteria) (rpc.ID, error)

NewFilter creates a new filter and returns the filter id. It can be used to retrieve logs when the state changes. This method cannot be used to fetch logs that are already stored in the state.

Default criteria for the from and to block are "latest". Using "latest" as block number will return logs for mined blocks. Using "pending" as block number returns logs for not yet mined (pending) blocks. In case logs are removed (chain reorg) previously returned logs are returned again but with the removed property set to true.

In case "fromBlock" > "toBlock" an error is returned.

func (*PullAPI) NewPendingTransactionFilter added in v0.4.0

func (api *PullAPI) NewPendingTransactionFilter(
	ctx context.Context,
	fullTx *bool,
) (rpc.ID, error)

NewPendingTransactionFilter creates a filter that fetches pending transactions as transactions enter the pending state.

It is part of the filter package because this filter can be used through the `eth_getFilterChanges` polling method that is also used for log filters.

func (*PullAPI) UninstallFilter added in v0.4.0

func (api *PullAPI) UninstallFilter(id rpc.ID) bool

type Server added in v0.31.0

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

func NewServer added in v0.31.0

func NewServer(
	logger zerolog.Logger,
	collector metrics.Collector,
	cfg config.Config,
) *Server

func (*Server) EnableRPC added in v0.31.0

func (h *Server) EnableRPC(apis []rpc.API) error

EnableRPC turns on JSON-RPC over HTTP on the server.

func (*Server) EnableWS added in v0.31.0

func (h *Server) EnableWS(apis []rpc.API) error

EnableWS turns on JSON-RPC over WebSocket on the server.

func (*Server) ListenAddr added in v0.31.0

func (h *Server) ListenAddr() string

ListenAddr returns the listening address of the server.

func (*Server) ServeHTTP added in v0.31.0

func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) SetListenAddr added in v0.31.0

func (h *Server) SetListenAddr(host string, port int) error

SetListenAddr configures the listening address of the server. The address can only be set while the server is not running.

func (*Server) Start added in v0.31.0

func (h *Server) Start() error

Start starts the HTTP server if it is enabled and not already running.

func (*Server) Stop added in v0.31.0

func (h *Server) Stop()

Stop shuts down the HTTP server.

type StreamAPI added in v0.6.0

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

func NewStreamAPI added in v0.6.0

func NewStreamAPI(
	logger zerolog.Logger,
	config config.Config,
	blocks storage.BlockIndexer,
	transactions storage.TransactionIndexer,
	receipts storage.ReceiptIndexer,
	blocksPublisher *models.Publisher[*models.Block],
	transactionsPublisher *models.Publisher[*gethTypes.Transaction],
	logsPublisher *models.Publisher[[]*gethTypes.Log],
) *StreamAPI

func (*StreamAPI) Logs added in v0.6.0

func (s *StreamAPI) Logs(ctx context.Context, criteria filters.FilterCriteria) (*rpc.Subscription, error)

Logs creates a subscription that fires for all new log that match the given filter criteria.

func (*StreamAPI) NewHeads added in v0.6.0

func (s *StreamAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error)

NewHeads send a notification each time a new block is appended to the chain.

func (*StreamAPI) NewPendingTransactions added in v0.6.0

func (s *StreamAPI) NewPendingTransactions(ctx context.Context, fullTx *bool) (*rpc.Subscription, error)

NewPendingTransactions creates a subscription that is triggered each time a transaction enters the transaction pool. If fullTx is true the full tx is sent to the client, otherwise the hash is sent.

type TxPool added in v0.12.0

type TxPool struct{}

func NewTxPoolAPI added in v0.12.0

func NewTxPoolAPI() *TxPool

func (*TxPool) Content added in v0.12.0

func (s *TxPool) Content() content

func (*TxPool) ContentFrom added in v0.12.0

func (s *TxPool) ContentFrom(addr common.Address) content

func (*TxPool) Inspect added in v0.12.0

func (s *TxPool) Inspect() content

func (*TxPool) Status added in v0.12.0

func (s *TxPool) Status() map[string]hexutil.Uint

type WalletAPI added in v0.22.0

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

func NewWalletAPI added in v0.22.0

func NewWalletAPI(config config.Config, net *BlockChainAPI) *WalletAPI

func (*WalletAPI) Accounts added in v0.22.0

func (w *WalletAPI) Accounts() ([]common.Address, error)

Accounts returns the collection of accounts this node manages.

func (*WalletAPI) SendTransaction added in v0.22.0

func (w *WalletAPI) SendTransaction(
	ctx context.Context,
	args ethTypes.TransactionArgs,
) (common.Hash, error)

SendTransaction creates a transaction for the given argument, sign it and submit it to the transaction pool.

func (*WalletAPI) Sign added in v0.22.0

func (w *WalletAPI) Sign(
	addr common.Address,
	data hexutil.Bytes,
) (hexutil.Bytes, error)

Sign calculates an ECDSA signature for: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message).

Note, the produced signature conforms to the secp256k1 curve R, S and V values, where the V value will be 27 or 28 for legacy reasons.

The account associated with addr must be unlocked.

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign

func (*WalletAPI) SignTransaction added in v0.22.0

SignTransaction will sign the given transaction with the from account. The node needs to have the private key of the account corresponding with the given from address and it needs to be unlocked.

type Web3API

type Web3API struct{}

Web3API offers helper utils

func (*Web3API) ClientVersion

func (s *Web3API) ClientVersion() string

ClientVersion returns the node name

func (*Web3API) Sha3

func (s *Web3API) Sha3(input hexutil.Bytes) hexutil.Bytes

Sha3 applies the ethereum sha3 implementation on the input. It assumes the input is hex encoded.

Jump to

Keyboard shortcuts

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