backend

package
v2.0.0-evm.7 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Overview

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllTxLogsFromEvents

func AllTxLogsFromEvents(events []abci.Event) ([][]*gethcore.Log, error)

AllTxLogsFromEvents parses all ethereum logs from cosmos events

func DefaultMinGasPrice

func DefaultMinGasPrice() sdkmath.LegacyDec

func GetHexProofs

func GetHexProofs(proof *crypto.ProofOps) []string

GetHexProofs returns list of hex data of proof op

func GetLogsFromBlockResults

func GetLogsFromBlockResults(blockRes *tmrpctypes.ResultBlockResults) ([][]*gethcore.Log, error)

GetLogsFromBlockResults returns the list of event logs from the tendermint block result response

func ParseTxLogsFromEvent

func ParseTxLogsFromEvent(event abci.Event) ([]*gethcore.Log, error)

ParseTxLogsFromEvent parse tx logs from one event

func ShouldIgnoreGasUsed

func ShouldIgnoreGasUsed(res *abci.ResponseDeliverTx) bool

ShouldIgnoreGasUsed returns true if the gasUsed in result should be ignored workaround for issue: https://github.com/cosmos/cosmos-sdk/issues/10832

func TxLogsFromEvents

func TxLogsFromEvents(events []abci.Event, msgIndex int) ([]*gethcore.Log, error)

TxLogsFromEvents parses ethereum logs from cosmos events for specific msg index

Types

type Backend

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

Backend implements the BackendI interface

func NewBackend

func NewBackend(
	ctx *server.Context,
	logger log.Logger,
	clientCtx client.Context,
	allowUnprotectedTxs bool,
	indexer eth.EVMTxIndexer,
) *Backend

NewBackend creates a new Backend instance for cosmos and ethereum namespaces

func (*Backend) Accounts

func (b *Backend) Accounts() ([]common.Address, error)

Accounts returns the list of accounts available to this node.

func (*Backend) BaseFee

func (b *Backend) BaseFee(
	blockRes *tmrpctypes.ResultBlockResults,
) (baseFee *big.Int, err error)

BaseFee returns the base fee tracked by the Fee Market module. If the base fee is not enabled globally, the query returns nil.

func (*Backend) BlockBloom

func (b *Backend) BlockBloom(blockRes *tmrpctypes.ResultBlockResults) (gethcore.Bloom, error)

BlockBloom query block bloom filter from block results

func (*Backend) BlockNumber

func (b *Backend) BlockNumber() (hexutil.Uint64, error)

BlockNumber returns the current block number in abci app state. Because abci app state could lag behind from tendermint latest block, it's more stable for the client to use the latest block number in abci app state than tendermint rpc.

func (*Backend) BlockNumberFromTendermint

func (b *Backend) BlockNumberFromTendermint(blockNrOrHash rpc.BlockNumberOrHash) (rpc.BlockNumber, error)

BlockNumberFromTendermint returns the BlockNumber from BlockNumberOrHash

func (*Backend) BlockNumberFromTendermintByHash

func (b *Backend) BlockNumberFromTendermintByHash(blockHash common.Hash) (*big.Int, error)

BlockNumberFromTendermintByHash returns the block height of given block hash

func (*Backend) BloomStatus

func (b *Backend) BloomStatus() (uint64, uint64)

BloomStatus returns the BloomBitsBlocks and the number of processed sections maintained by the chain indexer.

func (*Backend) ChainConfig

func (b *Backend) ChainConfig() *params.ChainConfig

ChainConfig returns the latest ethereum chain configuration

func (*Backend) ChainID

func (b *Backend) ChainID() (*hexutil.Big, error)

ChainID is the EIP-155 replay-protection chain id for the current ethereum chain config.

func (*Backend) CurrentHeader

func (b *Backend) CurrentHeader() (*gethcore.Header, error)

CurrentHeader returns the latest block header This will return error as per node configuration if the ABCI responses are discarded ('discard_abci_responses' config param)

func (*Backend) DoCall

func (b *Backend) DoCall(
	args evm.JsonTxArgs, blockNr rpc.BlockNumber,
) (*evm.MsgEthereumTxResponse, error)

DoCall performs a simulated call operation through the evmtypes. It returns the estimated gas used on the operation or an error if fails.

func (*Backend) EstimateGas

func (b *Backend) EstimateGas(args evm.JsonTxArgs, blockNrOptional *rpc.BlockNumber) (hexutil.Uint64, error)

EstimateGas returns an estimate of gas usage for the given smart contract call.

func (*Backend) EthBlockByNumber

func (b *Backend) EthBlockByNumber(blockNum rpc.BlockNumber) (*gethcore.Block, error)

EthBlockByNumber returns the Ethereum Block identified by number.

func (*Backend) EthBlockFromTendermintBlock

func (b *Backend) EthBlockFromTendermintBlock(
	resBlock *tmrpctypes.ResultBlock,
	blockRes *tmrpctypes.ResultBlockResults,
) (*gethcore.Block, error)

EthBlockFromTendermintBlock returns an Ethereum Block type from Tendermint block EthBlockFromTendermintBlock

func (*Backend) EthMsgsFromTendermintBlock

func (b *Backend) EthMsgsFromTendermintBlock(
	resBlock *tmrpctypes.ResultBlock,
	blockRes *tmrpctypes.ResultBlockResults,
) []*evm.MsgEthereumTx

EthMsgsFromTendermintBlock returns all real MsgEthereumTxs from a Tendermint block. It also ensures consistency over the correct txs indexes across RPC endpoints

func (*Backend) FeeHistory

func (b *Backend) FeeHistory(
	userBlockCount gethrpc.DecimalOrHex,
	lastBlock gethrpc.BlockNumber,
	rewardPercentiles []float64,
) (*rpc.FeeHistoryResult, error)

FeeHistory returns data relevant for fee estimation based on the specified range of blocks.

func (*Backend) GasPrice

func (b *Backend) GasPrice() (*hexutil.Big, error)

GasPrice returns the current gas price based on Ethermint's gas price oracle.

func (*Backend) GetBalance

func (b *Backend) GetBalance(
	address common.Address,
	blockNrOrHash rpc.BlockNumberOrHash,
) (*hexutil.Big, error)

GetBalance returns the provided account's balance up to the provided block number.

func (*Backend) GetBlockByHash

func (b *Backend) GetBlockByHash(hash common.Hash, fullTx bool) (map[string]interface{}, error)

GetBlockByHash returns the JSON-RPC compatible Ethereum block identified by hash.

func (*Backend) GetBlockByNumber

func (b *Backend) GetBlockByNumber(blockNum rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)

GetBlockByNumber returns the JSON-RPC compatible Ethereum block identified by block number. Depending on fullTx it either returns the full transaction objects or if false only the hashes of the transactions.

func (*Backend) GetBlockTransactionCount

func (b *Backend) GetBlockTransactionCount(block *tmrpctypes.ResultBlock) *hexutil.Uint

GetBlockTransactionCount returns the number of Ethereum transactions in a given block.

func (*Backend) GetBlockTransactionCountByHash

func (b *Backend) GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Uint

GetBlockTransactionCountByHash returns the number of Ethereum transactions in the block identified by hash.

func (*Backend) GetBlockTransactionCountByNumber

func (b *Backend) GetBlockTransactionCountByNumber(blockNum rpc.BlockNumber) *hexutil.Uint

GetBlockTransactionCountByNumber returns the number of Ethereum transactions in the block identified by number.

func (*Backend) GetCode

func (b *Backend) GetCode(
	address common.Address, blockNrOrHash rpc.BlockNumberOrHash,
) (hexutil.Bytes, error)

GetCode returns the contract code at the given address and block number.

func (*Backend) GetGasUsed

func (b *Backend) GetGasUsed(res *eth.TxResult, price *big.Int, gas uint64) uint64

GetGasUsed returns gasUsed from transaction, patching to price * gas in the event the tx is reverted.

func (*Backend) GetLogs

func (b *Backend) GetLogs(hash common.Hash) ([][]*gethcore.Log, error)

GetLogs returns all the logs from all the ethereum transactions in a block.

func (*Backend) GetLogsByHeight

func (b *Backend) GetLogsByHeight(height *int64) ([][]*gethcore.Log, error)

GetLogsByHeight returns all the logs from all the ethereum transactions in a block.

func (*Backend) GetProof

func (b *Backend) GetProof(
	address common.Address,
	storageKeys []string,
	blockNrOrHash rpc.BlockNumberOrHash,
) (*rpc.AccountResult, error)

GetProof returns an account object with proof and any storage proofs

func (*Backend) GetStorageAt

func (b *Backend) GetStorageAt(address common.Address, key string, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)

GetStorageAt returns the contract storage at the given address, block number, and key.

func (*Backend) GetTransactionByBlockAndIndex

func (b *Backend) GetTransactionByBlockAndIndex(block *tmrpctypes.ResultBlock, idx hexutil.Uint) (*rpc.EthTxJsonRPC, error)

GetTransactionByBlockAndIndex is the common code shared by `GetTransactionByBlockNumberAndIndex` and `GetTransactionByBlockHashAndIndex`.

func (*Backend) GetTransactionByBlockHashAndIndex

func (b *Backend) GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexutil.Uint) (*rpc.EthTxJsonRPC, error)

GetTransactionByBlockHashAndIndex returns the transaction identified by hash and index.

func (*Backend) GetTransactionByBlockNumberAndIndex

func (b *Backend) GetTransactionByBlockNumberAndIndex(blockNum rpc.BlockNumber, idx hexutil.Uint) (*rpc.EthTxJsonRPC, error)

GetTransactionByBlockNumberAndIndex returns the transaction identified by number and index.

func (*Backend) GetTransactionByHash

func (b *Backend) GetTransactionByHash(txHash common.Hash) (*rpc.EthTxJsonRPC, error)

GetTransactionByHash returns the Ethereum format transaction identified by Ethereum transaction hash

func (*Backend) GetTransactionCount

func (b *Backend) GetTransactionCount(address common.Address, blockNum rpc.BlockNumber) (*hexutil.Uint64, error)

GetTransactionCount returns the number of transactions at the given address up to the given block number.

func (*Backend) GetTransactionReceipt

func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{}, error)

GetTransactionReceipt returns the transaction receipt identified by hash.

func (*Backend) GetTxByEthHash

func (b *Backend) GetTxByEthHash(hash common.Hash) (*eth.TxResult, error)

GetTxByEthHash uses `/tx_query` to find transaction by ethereum tx hash TODO: Don't need to convert once hashing is fixed on Tendermint https://github.com/cometbft/cometbft/issues/6539

func (*Backend) GetTxByTxIndex

func (b *Backend) GetTxByTxIndex(height int64, index uint) (*eth.TxResult, error)

GetTxByTxIndex uses `/tx_query` to find transaction by tx index of valid ethereum txs

func (*Backend) GlobalMinGasPrice

func (b *Backend) GlobalMinGasPrice() (sdkmath.LegacyDec, error)

GlobalMinGasPrice returns the minimum gas price for all nodes. This is distinct from the individual configuration set by the validator set.

func (*Backend) HeaderByHash

func (b *Backend) HeaderByHash(blockHash common.Hash) (*gethcore.Header, error)

HeaderByHash returns the block header identified by hash.

func (*Backend) HeaderByNumber

func (b *Backend) HeaderByNumber(blockNum rpc.BlockNumber) (*gethcore.Header, error)

HeaderByNumber returns the block header identified by height.

func (*Backend) PendingTransactions

func (b *Backend) PendingTransactions() ([]*sdk.Tx, error)

PendingTransactions returns the transactions that are in the transaction pool and have a from address that is one of the accounts this node manages.

func (*Backend) RPCBlockFromTendermintBlock

func (b *Backend) RPCBlockFromTendermintBlock(
	resBlock *tmrpctypes.ResultBlock,
	blockRes *tmrpctypes.ResultBlockResults,
	fullTx bool,
) (map[string]interface{}, error)

RPCBlockFromTendermintBlock returns a JSON-RPC compatible Ethereum block from a given Tendermint block and its block result.

func (*Backend) RPCBlockRangeCap

func (b *Backend) RPCBlockRangeCap() int32

RPCBlockRangeCap defines the max block range allowed for `eth_getLogs` query.

func (*Backend) RPCEVMTimeout

func (b *Backend) RPCEVMTimeout() time.Duration

RPCEVMTimeout is the global evm timeout for eth-call variants.

func (*Backend) RPCFeeHistoryCap

func (b *Backend) RPCFeeHistoryCap() int32

RPCFeeHistoryCap is the limit for total number of blocks that can be fetched

func (*Backend) RPCFilterCap

func (b *Backend) RPCFilterCap() int32

RPCFilterCap is the limit for total number of filters that can be created

func (*Backend) RPCGasCap

func (b *Backend) RPCGasCap() uint64

RPCGasCap is the global gas cap for eth-call variants.

func (*Backend) RPCLogsCap

func (b *Backend) RPCLogsCap() int32

RPCLogsCap defines the max number of results can be returned from single `eth_getLogs` query.

func (*Backend) RPCMinGasPrice

func (b *Backend) RPCMinGasPrice() int64

func (*Backend) RPCTxFeeCap

func (b *Backend) RPCTxFeeCap() float64

RPCGasCap is the global gas cap for eth-call variants.

func (*Backend) Resend

func (b *Backend) Resend(args evm.JsonTxArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error)

Resend accepts an existing transaction and a new gas price and limit. It will remove the given transaction from the pool and reinsert it with the new gas price and limit.

func (*Backend) SendRawTransaction

func (b *Backend) SendRawTransaction(data hexutil.Bytes) (common.Hash, error)

SendRawTransaction send a raw Ethereum transaction.

func (*Backend) SendTransaction

func (b *Backend) SendTransaction(args evm.JsonTxArgs) (common.Hash, error)

SendTransaction sends transaction based on received args using Node's key to sign it

func (*Backend) SetTxDefaults

func (b *Backend) SetTxDefaults(args evm.JsonTxArgs) (evm.JsonTxArgs, error)

SetTxDefaults populates tx message with default values in case they are not provided on the args

func (*Backend) Sign

func (b *Backend) Sign(address common.Address, data hexutil.Bytes) (hexutil.Bytes, error)

Sign signs the provided data using the private key of address via Geth's signature standard.

func (*Backend) SignTypedData

func (b *Backend) SignTypedData(address common.Address, typedData apitypes.TypedData) (hexutil.Bytes, error)

SignTypedData signs EIP-712 conformant typed data

func (*Backend) SuggestGasTipCap

func (b *Backend) SuggestGasTipCap(baseFee *big.Int) (*big.Int, error)

SuggestGasTipCap: Not yet supported. Returns 0 as the suggested tip cap. After implementing tx prioritization, this function can come to life.

func (*Backend) Syncing

func (b *Backend) Syncing() (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 pears. 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 - pulledStates: number of state entries processed until now - knownStates: number of known state entries that still need to be pulled

func (*Backend) TendermintBlockByHash

func (b *Backend) TendermintBlockByHash(blockHash common.Hash) (*tmrpctypes.ResultBlock, error)

TendermintBlockByHash returns a Tendermint-formatted block by block number

func (*Backend) TendermintBlockByNumber

func (b *Backend) TendermintBlockByNumber(blockNum rpc.BlockNumber) (*tmrpctypes.ResultBlock, error)

TendermintBlockByNumber returns a Tendermint-formatted block for a given block number

func (*Backend) TendermintBlockResultByNumber

func (b *Backend) TendermintBlockResultByNumber(height *int64) (*tmrpctypes.ResultBlockResults, error)

TendermintBlockResultByNumber returns a Tendermint-formatted block result by block number

func (*Backend) TraceBlock

func (b *Backend) TraceBlock(height rpc.BlockNumber,
	config *evm.TraceConfig,
	block *tmrpctypes.ResultBlock,
) ([]*evm.TxTraceResult, error)

TraceBlock configures a new tracer according to the provided configuration, and executes all the transactions contained within. The return value will be one item per transaction, dependent on the requested tracer.

func (*Backend) TraceTransaction

func (b *Backend) TraceTransaction(hash common.Hash, config *evm.TraceConfig) (interface{}, error)

TraceTransaction returns the structured logs created during the execution of EVM and returns them as a JSON object.

func (Backend) UnprotectedAllowed

func (b Backend) UnprotectedAllowed() bool

UnprotectedAllowed returns the node configuration value for allowing unprotected transactions (i.e not replay-protected)

type BackendI

type BackendI interface {
	CosmosBackend
	EVMBackend
}

BackendI implements the Cosmos and EVM backend.

type CosmosBackend

type CosmosBackend interface {
}

CosmosBackend: Currently unused. Backend functionality for the shared "cosmos" RPC namespace. Implements BackendI in combination with EVMBackend. TODO: feat(eth): Implement the cosmos JSON-RPC defined by Wallet Connect V2: https://docs.walletconnect.com/2.0/json-rpc/cosmos.

type EVMBackend

type EVMBackend interface {
	// Node specific queries
	Accounts() ([]common.Address, error)
	Syncing() (interface{}, error)
	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         // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for send-transaction variants. The unit is ether.
	RPCMinGasPrice() int64

	// Sign Tx
	Sign(address common.Address, data hexutil.Bytes) (hexutil.Bytes, error)
	SendTransaction(args evm.JsonTxArgs) (common.Hash, error)
	SignTypedData(address common.Address, typedData apitypes.TypedData) (hexutil.Bytes, error)

	// Blocks Info
	BlockNumber() (hexutil.Uint64, error)
	GetBlockByNumber(blockNum rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)
	GetBlockByHash(hash common.Hash, fullTx bool) (map[string]interface{}, error)
	GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Uint
	GetBlockTransactionCountByNumber(blockNum rpc.BlockNumber) *hexutil.Uint
	TendermintBlockByNumber(blockNum rpc.BlockNumber) (*tmrpctypes.ResultBlock, error)
	TendermintBlockResultByNumber(height *int64) (*tmrpctypes.ResultBlockResults, error)
	TendermintBlockByHash(blockHash common.Hash) (*tmrpctypes.ResultBlock, error)
	BlockNumberFromTendermint(blockNrOrHash rpc.BlockNumberOrHash) (rpc.BlockNumber, error)
	BlockNumberFromTendermintByHash(blockHash common.Hash) (*big.Int, error)
	EthMsgsFromTendermintBlock(block *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) []*evm.MsgEthereumTx
	BlockBloom(blockRes *tmrpctypes.ResultBlockResults) (gethcore.Bloom, error)
	HeaderByNumber(blockNum rpc.BlockNumber) (*gethcore.Header, error)
	HeaderByHash(blockHash common.Hash) (*gethcore.Header, error)
	RPCBlockFromTendermintBlock(resBlock *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults, fullTx bool) (map[string]interface{}, error)
	EthBlockByNumber(blockNum rpc.BlockNumber) (*gethcore.Block, error)
	EthBlockFromTendermintBlock(resBlock *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) (*gethcore.Block, error)

	// Account Info
	GetCode(address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)
	GetBalance(address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error)
	GetStorageAt(address common.Address, key string, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)
	GetProof(address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*rpc.AccountResult, error)
	GetTransactionCount(address common.Address, blockNum rpc.BlockNumber) (*hexutil.Uint64, error)

	// Chain Info
	ChainID() (*hexutil.Big, error)
	ChainConfig() *params.ChainConfig
	// TODO: feat: Dynamic fees
	BaseFee(blockRes *tmrpctypes.ResultBlockResults) (*big.Int, error)
	CurrentHeader() (*gethcore.Header, error)
	PendingTransactions() ([]*sdk.Tx, error)
	FeeHistory(blockCount gethrpc.DecimalOrHex, lastBlock gethrpc.BlockNumber, rewardPercentiles []float64) (*rpc.FeeHistoryResult, error)
	SuggestGasTipCap(baseFee *big.Int) (*big.Int, error)

	// Tx Info
	GetTransactionByHash(txHash common.Hash) (*rpc.EthTxJsonRPC, error)
	GetTxByEthHash(txHash common.Hash) (*eth.TxResult, error)
	GetTxByTxIndex(height int64, txIndex uint) (*eth.TxResult, error)
	GetTransactionByBlockAndIndex(block *tmrpctypes.ResultBlock, idx hexutil.Uint) (*rpc.EthTxJsonRPC, error)
	GetTransactionReceipt(hash common.Hash) (map[string]interface{}, error)
	GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexutil.Uint) (*rpc.EthTxJsonRPC, error)
	GetTransactionByBlockNumberAndIndex(blockNum rpc.BlockNumber, idx hexutil.Uint) (*rpc.EthTxJsonRPC, error)

	// Send Transaction
	Resend(args evm.JsonTxArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error)
	SendRawTransaction(data hexutil.Bytes) (common.Hash, error)
	SetTxDefaults(args evm.JsonTxArgs) (evm.JsonTxArgs, error)
	EstimateGas(args evm.JsonTxArgs, blockNrOptional *rpc.BlockNumber) (hexutil.Uint64, error)
	DoCall(args evm.JsonTxArgs, blockNr rpc.BlockNumber) (*evm.MsgEthereumTxResponse, error)
	GasPrice() (*hexutil.Big, error)

	// Filter API
	GetLogs(hash common.Hash) ([][]*gethcore.Log, error)
	GetLogsByHeight(height *int64) ([][]*gethcore.Log, error)
	BloomStatus() (uint64, uint64)

	// Tracing
	TraceTransaction(hash common.Hash, config *evm.TraceConfig) (interface{}, error)
	TraceBlock(
		height rpc.BlockNumber,
		config *evm.TraceConfig,
		block *tmrpctypes.ResultBlock,
	) ([]*evm.TxTraceResult, error)
}

EVMBackend implements the functionality shared within ethereum namespaces as defined by EIP-1474: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md Implemented by Backend.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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