fakel1

package
v0.0.0-...-b5290a8 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 45 Imported by: 0

Documentation

Overview

Package ethapi implements the general Ethereum API functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckTxFee

func CheckTxFee(gasPrice *big.Int, gas uint64, cap float64) error

CheckTxFee exports a helper function used to check whether the fee is reasonable

func RPCMarshalBlock

func RPCMarshalBlock(ctx context.Context, block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig, backend ReceiptGetter) (map[string]interface{}, error)

RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain transaction hashes.

func RPCMarshalHeader

func RPCMarshalHeader(head *types.Header) map[string]interface{}

RPCMarshalHeader converts the given header to the RPC output .

func SubmitTransaction

func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (common.Hash, error)

SubmitTransaction is a helper function that submits tx to txPool and logs a message.

Types

type AccountResult

type AccountResult struct {
	Address      common.Address  `json:"address"`
	AccountProof []string        `json:"accountProof"`
	Balance      *hexutil.Big    `json:"balance"`
	CodeHash     common.Hash     `json:"codeHash"`
	Nonce        hexutil.Uint64  `json:"nonce"`
	StorageHash  common.Hash     `json:"storageHash"`
	StorageProof []StorageResult `json:"storageProof"`
}

AccountResult structs for GetProof

type Backend

type Backend interface {
	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
	FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, []*big.Int, []float64, error)
	BlobBaseFee(ctx context.Context) *big.Int
	ChainDb() ethdb.Database
	AccountManager() *accounts.Manager
	ExtRPCEnabled() bool
	RPCGasCap() uint64            // global gas cap for eth_call over rpc: DoS protection
	RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection
	RPCTxFeeCap() float64         // global tx fee cap for all transaction related APIs
	UnprotectedAllowed() bool     // allows only for EIP155 transactions.

	// Blockchain API
	SetHead(number uint64)
	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
	HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
	CurrentHeader() *types.Header
	CurrentBlock() *types.Header
	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
	BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
	StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
	StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
	Pending() (*types.Block, types.Receipts, *state.StateDB)
	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
	GetEVM(ctx context.Context, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM
	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription

	// Transaction pool API
	SendTx(ctx context.Context, signedTx *types.Transaction) error
	GetTransaction(ctx context.Context, txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64, error)
	GetPoolTransactions() (types.Transactions, error)
	GetPoolTransaction(txHash common.Hash) *types.Transaction
	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
	Stats() (pending int, queued int)
	TxPoolContent() (map[common.Address][]*types.Transaction, map[common.Address][]*types.Transaction)
	TxPoolContentFrom(addr common.Address) ([]*types.Transaction, []*types.Transaction)
	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription

	ChainConfig() *params.ChainConfig
	Engine() consensus.Engine
	HistoricalRPCService() *rpc.Client
	Genesis() *types.Block

	// This is copied from filters.Backend
	// eth/filters needs to be initialized from this backend type, so methods needed by
	// it must also be included here.
	GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error)
	GetLogs(ctx context.Context, blockHash common.Hash, number uint64) ([][]*types.Log, error)
	SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
	SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
	BloomStatus() (uint64, uint64)
}

Backend interface provides the common API services (that are provided by both full and light clients) with access to necessary functions.

type BlobsStore

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

BlobsStore is a simple in-memory store of blobs, for testing purposes

func NewBlobStore

func NewBlobStore() *BlobsStore

func (*BlobsStore) GetAllSidecars

func (store *BlobsStore) GetAllSidecars(ctx context.Context, l1Timestamp uint64) ([]*eth.BlobSidecar, error)

func (*BlobsStore) GetBlobSidecars

func (store *BlobsStore) GetBlobSidecars(ctx context.Context, ref eth.L1BlockRef, hashes []eth.IndexedBlobHash) ([]*eth.BlobSidecar, error)

func (*BlobsStore) GetBlobs

func (store *BlobsStore) GetBlobs(ctx context.Context, ref eth.L1BlockRef, hashes []eth.IndexedBlobHash) ([]*eth.Blob, error)

func (*BlobsStore) StoreBlob

func (store *BlobsStore) StoreBlob(blockTime uint64, indexedHash eth.IndexedBlobHash, blob *eth.Blob)

type BlockChainAPI

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

BlockChainAPI provides an API to access Ethereum blockchain data.

func NewBlockChainAPI

func NewBlockChainAPI(b Backend) *BlockChainAPI

NewBlockChainAPI creates a new Ethereum blockchain API.

func (*BlockChainAPI) BlockNumber

func (api *BlockChainAPI) BlockNumber() hexutil.Uint64

BlockNumber returns the block number of the chain head.

func (*BlockChainAPI) ChainId

func (api *BlockChainAPI) ChainId() *hexutil.Big

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) GetBalance

func (api *BlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNrOrHash 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 (api *BlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, 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 (api *BlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, 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 (api *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]map[string]interface{}, error)

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

func (*BlockChainAPI) GetCode

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

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

func (*BlockChainAPI) GetHeaderByHash

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

GetHeaderByHash returns the requested header by hash.

func (*BlockChainAPI) GetHeaderByNumber

func (api *BlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (map[string]interface{}, error)

GetHeaderByNumber returns the requested canonical block header.

  • When blockNr is -1 the chain pending header is returned.
  • When blockNr is -2 the chain latest header is returned.
  • When blockNr is -3 the chain finalized header is returned.
  • When blockNr is -4 the chain safe header is returned.

func (*BlockChainAPI) GetProof

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

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

func (*BlockChainAPI) GetStorageAt

func (api *BlockChainAPI) GetStorageAt(ctx context.Context, address common.Address, hexKey string, blockNrOrHash 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) GetUncleByBlockHashAndIndex

func (api *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 (api *BlockChainAPI) GetUncleByBlockNumberAndIndex(ctx context.Context, blockNr 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 (api *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 (api *BlockChainAPI) GetUncleCountByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint

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

type ChainContext

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

ChainContext is an implementation of core.ChainContext. It's main use-case is instantiating a vm.BlockContext without having access to the BlockChain object.

func NewChainContext

func NewChainContext(ctx context.Context, backend ChainContextBackend) *ChainContext

NewChainContext creates a new ChainContext object.

func (*ChainContext) Config

func (context *ChainContext) Config() *params.ChainConfig

func (*ChainContext) Engine

func (context *ChainContext) Engine() consensus.Engine

func (*ChainContext) GetHeader

func (context *ChainContext) GetHeader(hash common.Hash, number uint64) *types.Header

type ChainContextBackend

type ChainContextBackend interface {
	Engine() consensus.Engine
	HeaderByNumber(context.Context, rpc.BlockNumber) (*types.Header, error)
	ChainConfig() *params.ChainConfig
}

ChainContextBackend provides methods required to implement ChainContext.

type DebugAPI

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

DebugAPI is the collection of Ethereum APIs exposed over the debugging namespace.

func NewDebugAPI

func NewDebugAPI(b Backend) *DebugAPI

NewDebugAPI creates a new instance of DebugAPI.

func (*DebugAPI) ChainConfig

func (api *DebugAPI) ChainConfig() *params.ChainConfig

func (*DebugAPI) ChaindbCompact

func (api *DebugAPI) ChaindbCompact() error

ChaindbCompact flattens the entire key-value database into a single level, removing all unused slots and merging all keys.

func (*DebugAPI) ChaindbProperty

func (api *DebugAPI) ChaindbProperty() (string, error)

ChaindbProperty returns leveldb properties of the key-value database.

func (*DebugAPI) GetRawBlock

func (api *DebugAPI) GetRawBlock(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)

GetRawBlock retrieves the RLP encoded for a single block.

func (*DebugAPI) GetRawHeader

func (api *DebugAPI) GetRawHeader(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)

GetRawHeader retrieves the RLP encoding for a single header.

func (*DebugAPI) GetRawReceipts

func (api *DebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error)

GetRawReceipts retrieves the binary-encoded receipts of a single block.

func (*DebugAPI) GetRawTransaction

func (api *DebugAPI) GetRawTransaction(ctx context.Context, hash common.Hash) (hexutil.Bytes, error)

GetRawTransaction returns the bytes of the transaction for the given hash.

func (*DebugAPI) PrintBlock

func (api *DebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error)

PrintBlock retrieves a block and returns its pretty printed form.

func (*DebugAPI) SetHead

func (api *DebugAPI) SetHead(number hexutil.Uint64)

SetHead rewinds the head of the blockchain to a previous block.

type EthereumAPI

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

EthereumAPI provides an API to access Ethereum related information.

func NewEthereumAPI

func NewEthereumAPI(b Backend) *EthereumAPI

NewEthereumAPI creates a new Ethereum protocol API.

func (*EthereumAPI) BlobBaseFee

func (api *EthereumAPI) BlobBaseFee(ctx context.Context) *hexutil.Big

BlobBaseFee returns the base fee for blob gas at the current head.

func (*EthereumAPI) FeeHistory

func (api *EthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error)

FeeHistory returns the fee market history.

func (*EthereumAPI) GasPrice

func (api *EthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error)

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

func (*EthereumAPI) MaxPriorityFeePerGas

func (api *EthereumAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error)

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

type EthereumAccountAPI

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

EthereumAccountAPI provides an API to access accounts managed by this node. It offers only methods that can retrieve accounts.

func NewEthereumAccountAPI

func NewEthereumAccountAPI(am *accounts.Manager) *EthereumAccountAPI

NewEthereumAccountAPI creates a new EthereumAccountAPI.

func (*EthereumAccountAPI) Accounts

func (api *EthereumAccountAPI) Accounts() []common.Address

Accounts returns the collection of accounts this node manages.

type L1Chain

type L1Chain interface {
	GetNonce(addr common.Address) (uint64, error)
	BeaconGenesis() opEth.APIGenesisResponse
	ConfigSpec() opEth.APIConfigResponse
	GetSidecarsBySlot(ctx context.Context, slot uint64) (*opEth.APIGetBlobSidecarsResponse, error)
	GetBlockByHash(hash common.Hash) (*types.Block, error)
	GetBlockByNumber(number uint64) (*types.Block, error)
	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
	GetLatestBlock() (*types.Header, error)
	BuildAndMine(txs []*types.Transaction) error
	Genesis() *core.Genesis
}

L1Chain is the interface for the L1 chain that proof programs expect. This allows us to intercept certain RPC calls and return a custom response.

func NewFakeL1ChainWithGenesis

func NewFakeL1ChainWithGenesis(blobDir string, genesis *core.Genesis, l2GenesisTimestamp uint64) (L1Chain, error)

type L1ProxyServer

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

L1ProxyServer is a proxy server that intercepts RPC and beacon chain requests and returns a response from the fake L1 chain.

func NewL1ProxyServer

func NewL1ProxyServer(log log.Logger, port int, chain L1Chain) *L1ProxyServer

func (*L1ProxyServer) ClientURL

func (p *L1ProxyServer) ClientURL() string

func (*L1ProxyServer) OverrideRequest

func (p *L1ProxyServer) OverrideRequest(ctx context.Context, method string, rawParams json.RawMessage) (json.RawMessage, error)

func (*L1ProxyServer) Run

func (p *L1ProxyServer) Run(ctx context.Context) error

func (*L1ProxyServer) Stop

func (p *L1ProxyServer) Stop()

Stop stops both the proxy server and the underlying client

type NetAPI

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

NetAPI offers network related RPC methods

func NewNetAPI

func NewNetAPI(net *p2p.Server, networkVersion uint64) *NetAPI

NewNetAPI creates a new net API instance.

func (*NetAPI) Listening

func (api *NetAPI) Listening() bool

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

func (*NetAPI) PeerCount

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

PeerCount returns the number of connected peers

func (*NetAPI) Version

func (api *NetAPI) Version() string

Version returns the current ethereum protocol version.

type RPCTransaction

type RPCTransaction struct {
	BlockHash           *common.Hash                 `json:"blockHash"`
	BlockNumber         *hexutil.Big                 `json:"blockNumber"`
	From                common.Address               `json:"from"`
	Gas                 hexutil.Uint64               `json:"gas"`
	GasPrice            *hexutil.Big                 `json:"gasPrice"`
	GasFeeCap           *hexutil.Big                 `json:"maxFeePerGas,omitempty"`
	GasTipCap           *hexutil.Big                 `json:"maxPriorityFeePerGas,omitempty"`
	MaxFeePerBlobGas    *hexutil.Big                 `json:"maxFeePerBlobGas,omitempty"`
	Hash                common.Hash                  `json:"hash"`
	Input               hexutil.Bytes                `json:"input"`
	Nonce               hexutil.Uint64               `json:"nonce"`
	To                  *common.Address              `json:"to"`
	TransactionIndex    *hexutil.Uint64              `json:"transactionIndex"`
	Value               *hexutil.Big                 `json:"value"`
	Type                hexutil.Uint64               `json:"type"`
	Accesses            *types.AccessList            `json:"accessList,omitempty"`
	ChainID             *hexutil.Big                 `json:"chainId,omitempty"`
	BlobVersionedHashes []common.Hash                `json:"blobVersionedHashes,omitempty"`
	AuthorizationList   []types.SetCodeAuthorization `json:"authorizationList,omitempty"`
	V                   *hexutil.Big                 `json:"v"`
	R                   *hexutil.Big                 `json:"r"`
	S                   *hexutil.Big                 `json:"s"`
	YParity             *hexutil.Uint64              `json:"yParity,omitempty"`

	// deposit-tx only
	SourceHash *common.Hash `json:"sourceHash,omitempty"`
	Mint       *hexutil.Big `json:"mint,omitempty"`
	IsSystemTx *bool        `json:"isSystemTx,omitempty"`
	// deposit-tx post-Canyon only
	DepositReceiptVersion *hexutil.Uint64 `json:"depositReceiptVersion,omitempty"`
}

RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction

func NewRPCPendingTransaction

func NewRPCPendingTransaction(tx *types.Transaction, current *types.Header, config *params.ChainConfig) *RPCTransaction

NewRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation

type ReceiptGetter

type ReceiptGetter interface {
	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
}

type StorageResult

type StorageResult struct {
	Key   string       `json:"key"`
	Value *hexutil.Big `json:"value"`
	Proof []string     `json:"proof"`
}

type TxPoolAPI

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

TxPoolAPI offers and API for the transaction pool. It only operates on data that is non-confidential.

func NewTxPoolAPI

func NewTxPoolAPI(b Backend) *TxPoolAPI

NewTxPoolAPI creates a new tx pool service that gives information about the transaction pool.

func (*TxPoolAPI) Content

func (api *TxPoolAPI) Content() map[string]map[string]map[string]*RPCTransaction

Content returns the transactions contained within the transaction pool.

func (*TxPoolAPI) ContentFrom

func (api *TxPoolAPI) ContentFrom(addr common.Address) map[string]map[string]*RPCTransaction

ContentFrom returns the transactions contained within the transaction pool.

func (*TxPoolAPI) Inspect

func (api *TxPoolAPI) Inspect() map[string]map[string]map[string]string

Inspect retrieves the content of the transaction pool and flattens it into an easily inspectable list.

func (*TxPoolAPI) Status

func (api *TxPoolAPI) Status() map[string]hexutil.Uint

Status returns the number of pending and queued transaction in the pool.

Jump to

Keyboard shortcuts

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