Documentation
¶
Index ¶
- Constants
- Variables
- func BaseFeeFromEvents(events []abci.Event) *big.Int
- func BlockMaxGasFromConsensusParams(goCtx context.Context, clientCtx client.Context, blockHeight int64) (int64, error)
- func CalcBaseFee(config *ethparams.ChainConfig, parent *ethtypes.Header, ...) (*big.Int, error)
- func CheckTxFee(gasPrice *big.Int, gas uint64, minCap float64) error
- func ContextWithHeight(height int64) context.Context
- func EffectiveGasPrice(tx *ethtypes.Transaction, baseFee *big.Int) *big.Int
- func EthHeaderFromComet(header cmttypes.Header, bloom ethtypes.Bloom, baseFee *big.Int) *ethtypes.Header
- func MakeHeader(cmtHeader cmttypes.Header, gasLimit int64, validatorAddr common.Address, ...) *ethtypes.Header
- func ParseTxIndexerResult(txResult *cmtrpctypes.ResultTx, tx sdk.Tx, getter func(*ParsedTxs) *ParsedTx) (*types.TxResult, error)
- func RPCMarshalBlock(block *ethtypes.Block, cmtBlock *cmtrpccore.ResultBlock, ...) (map[string]interface{}, error)
- func RPCMarshalHeader(head *ethtypes.Header, blockHash []byte) map[string]interface{}
- func RPCMarshalReceipt(receipt *ethtypes.Receipt, tx *ethtypes.Transaction, from common.Address) (map[string]interface{}, error)
- func RawTxToEthTx(clientCtx client.Context, txBz cmttypes.Tx) ([]*evmtypes.MsgEthereumTx, error)
- func TxExceedBlockGasLimit(res *abci.ExecTxResult) bool
- func TxStateDBCommitError(res *abci.ExecTxResult) bool
- func TxSucessOrExpectedFailure(res *abci.ExecTxResult) bool
- type AccessListResult
- type AccountResult
- type AddrLocker
- type BlockNumber
- type BlockNumberOrHash
- type EventFormat
- type FeeHistoryResult
- type OneFeeHistory
- type OverrideAccount
- type ParsedTx
- type ParsedTxs
- type QueryClient
- type RPCTransaction
- func NewRPCPendingTransaction(tx *ethtypes.Transaction, current *ethtypes.Header, ...) *RPCTransaction
- func NewRPCTransaction(tx *ethtypes.Transaction, blockHash common.Hash, blockNumber, blockTime uint64, ...) *RPCTransaction
- func NewTransactionFromMsg(msg *evmtypes.MsgEthereumTx, blockHash common.Hash, ...) *RPCTransaction
- type SignTransactionResult
- type StateOverride
- type StorageResult
- type TraceConfig
Constants ¶
const ( EthEarliestBlockNumber = BlockNumber(-5) EthSafeBlockNumber = BlockNumber(-4) EthFinalizedBlockNumber = BlockNumber(-3) EthLatestBlockNumber = BlockNumber(-2) EthPendingBlockNumber = BlockNumber(-1) )
const ( BlockParamEarliest = "earliest" BlockParamLatest = "latest" BlockParamFinalized = "finalized" BlockParamSafe = "safe" BlockParamPending = "pending" )
const ExceedBlockGasLimitError = "out of gas in location: block gas meter; gasWanted:"
ExceedBlockGasLimitError defines the error message when tx execution exceeds the block gas limit. The tx fee is deducted in ante handler, so it shouldn't be ignored in JSON-RPC API.
const (
// ProtocolVersion is the latest supported version of the eth protocol.
ProtocolVersion = eth65
)
Constants to match up protocol versions and messages
const StateDBCommitError = "failed to commit stateDB"
StateDBCommitError defines the error message when commit after executing EVM transaction, for example transfer native token to a distribution module account 0x93354845030274cD4bf1686Abd60AB28EC52e1a7 using an evm type transaction note: the transfer amount cannot be set to 0, otherwise this problem will not be triggered
Variables ¶
var ErrProfilingDisabled = errors.New("profiling disabled in the debug namespace")
Functions ¶
func BaseFeeFromEvents ¶
BaseFeeFromEvents parses the feemarket basefee from cosmos events
func BlockMaxGasFromConsensusParams ¶
func BlockMaxGasFromConsensusParams(goCtx context.Context, clientCtx client.Context, blockHeight int64) (int64, error)
BlockMaxGasFromConsensusParams returns the gas limit for the current block from the chain consensus params.
func CalcBaseFee ¶ added in v0.5.0
func CalcBaseFee(config *ethparams.ChainConfig, parent *ethtypes.Header, p feemarkettypes.Params) (*big.Int, error)
CalcBaseFee calculates the basefee of the header.
func CheckTxFee ¶
CheckTxFee is an internal function used to check whether the fee of the given transaction is _reasonable_(under the minimum cap).
func ContextWithHeight ¶
ContextWithHeight wraps a context with the a gRPC block height header. If the provided height is 0, it will return an empty context and the gRPC query will use the latest block height for querying. Note that all metadata is processed and removed by the CometBFT layer, so it won't be accessible at gRPC server level.
func EffectiveGasPrice ¶ added in v0.5.0
EffectiveGasPrice computes the transaction gas fee, based on the given basefee value.
price = min(gasTipCap + baseFee, gasFeeCap)
This method refers to go-ethereum v1.16.3 internal package method, effectiveGasPrice. (https://github.com/ethereum/go-ethereum/blob/d818a9af7bd5919808df78f31580f59382c53150/internal/ethapi/api.go#L1083-L1093)
func EthHeaderFromComet ¶ added in v0.4.0
func EthHeaderFromComet(header cmttypes.Header, bloom ethtypes.Bloom, baseFee *big.Int) *ethtypes.Header
EthHeaderFromComet is an util function that returns an Ethereum Header from a CometBFT Header.
TODO: Remove this function. Currently, this function is only used in rpc/stream package for websocket api. But there are many missing fields in returned eth header. When kv_indexer is improved and we can get eth header from indexer, we can remove this function.
func MakeHeader ¶ added in v0.5.0
func MakeHeader( cmtHeader cmttypes.Header, gasLimit int64, validatorAddr common.Address, baseFee *big.Int, ) *ethtypes.Header
MakeHeader make initial ethereum header based on cometbft header.
This method refers to chainMaker.makeHeader method of go-ethereum v1.16.3 (https://github.com/ethereum/go-ethereum/blob/d818a9af7bd5919808df78f31580f59382c53150/core/chain_makers.go#L596-L623)
func ParseTxIndexerResult ¶
func ParseTxIndexerResult(txResult *cmtrpctypes.ResultTx, tx sdk.Tx, getter func(*ParsedTxs) *ParsedTx) (*types.TxResult, error)
ParseTxIndexerResult parse tm tx result to a format compatible with the custom tx indexer.
func RPCMarshalBlock ¶ added in v0.5.0
func RPCMarshalBlock(block *ethtypes.Block, cmtBlock *cmtrpccore.ResultBlock, msgs []*evmtypes.MsgEthereumTx, inclTx bool, fullTx bool, config *ethparams.ChainConfig) (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.
This method refers to go-ethereum v1.16.3 internal package method - RPCMarshalBlock (https://github.com/ethereum/go-ethereum/blob/d818a9af7bd5919808df78f31580f59382c53150/internal/ethapi/api.go#L929-L962)
func RPCMarshalHeader ¶ added in v0.5.0
RPCMarshalHeader converts the given header to the RPC output .
This method refers to internal package method of go-ethereum v1.16.3 - RPCMarshalHeader (https://github.com/ethereum/go-ethereum/blob/d818a9af7bd5919808df78f31580f59382c53150/internal/ethapi/api.go#L888-L927) but it uses the cometbft Header to get the block hash.
func RPCMarshalReceipt ¶ added in v0.5.0
func RPCMarshalReceipt(receipt *ethtypes.Receipt, tx *ethtypes.Transaction, from common.Address) (map[string]interface{}, error)
RPCMarshalReceipt marshals a transaction receipt into a JSON object.
This method refers to go-ethereum v1.16.3 internal package method marshalReceipt (https://github.com/ethereum/go-ethereum/blob/d818a9af7bd5919808df78f31580f59382c53150/internal/ethapi/api.go#L1478-L1518)
func RawTxToEthTx ¶
RawTxToEthTx returns a evm MsgEthereum transaction from raw tx bytes.
func TxExceedBlockGasLimit ¶
func TxExceedBlockGasLimit(res *abci.ExecTxResult) bool
TxExceedBlockGasLimit returns true if the tx exceeds block gas limit.
func TxStateDBCommitError ¶
func TxStateDBCommitError(res *abci.ExecTxResult) bool
TxStateDBCommitError returns true if the evm tx commit error.
func TxSucessOrExpectedFailure ¶
func TxSucessOrExpectedFailure(res *abci.ExecTxResult) bool
TxSucessOrExpectedFailure returns true if the transaction was successful or if it failed with an ExceedBlockGasLimit error or TxStateDBCommitError error
Types ¶
type AccessListResult ¶ added in v0.5.0
type AccessListResult struct {
AccessList *ethtypes.AccessList `json:"accessList"`
GasUsed *hexutil.Uint64 `json:"gasUsed"`
Error string `json:"error,omitempty"`
}
AccessListResult represents the access list and gas used for a transaction
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 struct for account proof
type AddrLocker ¶
type AddrLocker struct {
// contains filtered or unexported fields
}
AddrLocker is a mutex structure used to avoid querying outdated account data
func (*AddrLocker) LockAddr ¶
func (l *AddrLocker) LockAddr(address common.Address)
LockAddr locks an account's mutex. This is used to prevent another tx getting the same nonce until the lock is released. The mutex prevents the (an identical nonce) from being read again during the time that the first transaction is being signed.
func (*AddrLocker) UnlockAddr ¶
func (l *AddrLocker) UnlockAddr(address common.Address)
UnlockAddr unlocks the mutex of the given account.
type BlockNumber ¶
type BlockNumber int64
BlockNumber represents decoding hex string to block values
func NewBlockNumber ¶
func NewBlockNumber(n *big.Int) BlockNumber
NewBlockNumber creates a new BlockNumber instance.
func (BlockNumber) CmtHeight ¶ added in v0.4.0
func (bn BlockNumber) CmtHeight() *int64
CmtHeight is a util function used for the CometBFT RPC client. It returns nil if the block number is "latest". Otherwise, it returns the pointer of the int64 value of the height.
func (BlockNumber) Int64 ¶
func (bn BlockNumber) Int64() int64
Int64 converts block number to primitive type
func (*BlockNumber) UnmarshalJSON ¶
func (bn *BlockNumber) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports: - "latest", "finalized", "earliest" or "pending" as string arguments - the block number Returned errors: - an invalid block number error when the given argument isn't a known strings - an out of range error when the given block number is either too little or too large
type BlockNumberOrHash ¶
type BlockNumberOrHash struct {
BlockNumber *BlockNumber `json:"blockNumber,omitempty"`
BlockHash *common.Hash `json:"blockHash,omitempty"`
}
BlockNumberOrHash represents a block number or a block hash.
func (*BlockNumberOrHash) UnmarshalJSON ¶
func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error
type EventFormat ¶
type EventFormat int
EventFormat is the format version of the events.
To fix the issue of tx exceeds block gas limit, we changed the event format in a breaking way. But to avoid forcing clients to re-sync from scatch, we make json-rpc logic to be compatible with both formats.
type FeeHistoryResult ¶
type FeeHistoryResult struct {
OldestBlock *hexutil.Big `json:"oldestBlock"`
Reward [][]*hexutil.Big `json:"reward,omitempty"`
BaseFee []*hexutil.Big `json:"baseFeePerGas,omitempty"`
GasUsedRatio []float64 `json:"gasUsedRatio"`
BlobBaseFee []*hexutil.Big `json:"baseFeePerBlobGas,omitempty"`
BlobGasUsedRatio []float64 `json:"blobGasUsedRatio,omitempty"`
}
type OneFeeHistory ¶
type OneFeeHistory struct {
BaseFee, NextBaseFee *big.Int // base fee for each block
Reward []*big.Int // each element of the array will have the tip provided to miners for the percentile given
GasUsedRatio float64 // the ratio of gas used to the gas limit for each block
BlobBaseFee, NextBlobBaseFee *big.Int // blob base fee for each block
BlobGasUsedRatio float64 // the ratio of blob gas used to the blob gas limit for each block
}
type OverrideAccount ¶
type OverrideAccount struct {
Nonce *hexutil.Uint64 `json:"nonce"`
Code *hexutil.Bytes `json:"code"`
Balance **hexutil.Big `json:"balance"`
State *map[common.Hash]common.Hash `json:"state"`
StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
MovePrecompileTo *common.Address `json:"movePrecompileToAddress"`
}
OverrideAccount indicates the overriding fields of account during the execution of a message call. Note, state and stateDiff can't be specified at the same time. If state is set, message execution will only use the data in the given state. Otherwise if statDiff is set, all diff will be applied first and then execute the call message.
type ParsedTx ¶
type ParsedTx struct {
MsgIndex int
Hash common.Hash
// -1 means uninitialized
EthTxIndex int32
GasUsed uint64
Failed bool
}
ParsedTx is the tx infos parsed from events.
type ParsedTxs ¶
type ParsedTxs struct {
// one item per message
Txs []ParsedTx
// map tx hash to msg index
TxHashes map[common.Hash]int
}
ParsedTxs is the tx infos parsed from eth tx events.
func ParseTxResult ¶
ParseTxResult parse eth tx infos from cosmos-sdk events. It supports two event formats, the formats are described in the comments of the format constants.
func (*ParsedTxs) AccumulativeGasUsed ¶
AccumulativeGasUsed calculates the accumulated gas used within the batch of txs
func (*ParsedTxs) GetTxByHash ¶
GetTxByHash find ParsedTx by tx hash, returns nil if not exists.
func (*ParsedTxs) GetTxByMsgIndex ¶
GetTxByMsgIndex returns ParsedTx by msg index
func (*ParsedTxs) GetTxByTxIndex ¶
GetTxByTxIndex returns ParsedTx by tx index
type QueryClient ¶
type QueryClient struct {
tx.ServiceClient
evmtypes.QueryClient
FeeMarket feemarkettypes.QueryClient
}
QueryClient defines a gRPC Client used for:
- Transaction simulation
- EVM module queries
- Fee market module queries
func NewQueryClient ¶
func NewQueryClient(clientCtx client.Context) *QueryClient
NewQueryClient creates a new gRPC query client
func (QueryClient) GetProof ¶
func (QueryClient) GetProof(clientCtx client.Context, storeKey string, key []byte) ([]byte, *crypto.ProofOps, error)
GetProof performs an ABCI query with the given key and returns a merkle proof. The desired CometBFT height to perform the query should be set in the client context. The query will be performed at one below this height (at the IAVL version) in order to obtain the correct merkle proof. Proof queries at height less than or equal to 2 are not supported. Issue: https://github.com/cosmos/cosmos-sdk/issues/6567
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 *ethtypes.AccessList `json:"accessList,omitempty"`
ChainID *hexutil.Big `json:"chainId,omitempty"`
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
AuthorizationList []ethtypes.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"`
}
RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
func NewRPCPendingTransaction ¶ added in v0.5.0
func NewRPCPendingTransaction(tx *ethtypes.Transaction, current *ethtypes.Header, config *ethparams.ChainConfig) *RPCTransaction
NewRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation
func NewRPCTransaction ¶
func NewRPCTransaction( tx *ethtypes.Transaction, blockHash common.Hash, blockNumber, blockTime uint64, index uint64, baseFee *big.Int, config *ethparams.ChainConfig, ) *RPCTransaction
NewTransactionFromData returns a transaction that will serialize to the RPC representation, with the given location metadata set (if available).
This method refers to internal package method of go-ethereum v1.16.3 - newRPCTransaction (https://github.com/ethereum/go-ethereum/blob/d818a9af7bd5919808df78f31580f59382c53150/internal/ethapi/api.go#L991-L1081)
func NewTransactionFromMsg ¶
func NewTransactionFromMsg( msg *evmtypes.MsgEthereumTx, blockHash common.Hash, blockNumber, blockTime, index uint64, baseFee *big.Int, config *ethparams.ChainConfig, ) *RPCTransaction
NewTransactionFromMsg returns a transaction that will serialize to the RPC representation, with the given location metadata set (if available).
type SignTransactionResult ¶
type SignTransactionResult struct {
Raw hexutil.Bytes `json:"raw"`
Tx *ethtypes.Transaction `json:"tx"`
}
SignTransactionResult represents a RLP encoded signed transaction.
type StateOverride ¶
type StateOverride map[common.Address]OverrideAccount
StateOverride is the collection of overridden accounts.
func (*StateOverride) Apply ¶ added in v0.5.0
func (diff *StateOverride) Apply(db *statedb.StateDB, precompiles vm.PrecompiledContracts) error
Apply overrides the fields of specified accounts into the given state.
type StorageResult ¶
type StorageResult struct {
Key string `json:"key"`
Value *hexutil.Big `json:"value"`
Proof []string `json:"proof"`
}
StorageResult defines the format for storage proof return
type TraceConfig ¶ added in v0.4.0
type TraceConfig struct {
evmtypes.TraceConfig
TracerConfig json.RawMessage `json:"tracerConfig"`
}
Embedded TraceConfig type to store raw JSON data of config in custom field