types

package
v0.0.0-...-74c1675 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: LGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EthPendingBlockNumber  = BlockNumber(-2)
	EthLatestBlockNumber   = BlockNumber(-1)
	EthEarliestBlockNumber = BlockNumber(0)
)
View Source
const (
	BlockParamEarliest  = "earliest"
	BlockParamLatest    = "latest"
	BlockParamFinalized = "finalized"
	BlockParamSafe      = "safe"
	BlockParamPending   = "pending"
)

Variables

This section is empty.

Functions

func BaseFeeFromEvents

func BaseFeeFromEvents(events []abci.Event) *big.Int

BaseFeeFromEvents parses the x/feemarket BaseFee from CometBFT 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 BloomFromEvents

func BloomFromEvents(events []abci.Event) *ethtypes.Bloom

BloomFromEvents parses the x/evm block bloom from CometBFT events

func CheckTxFee

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

CheckTxFee is an internal function used to check whether the fee of the given transaction is _reasonable_(under the cap).

func ContextWithHeight

func ContextWithHeight(height int64) context.Context

ContextWithHeight wraps a context with the 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 are processed and removed by CometBFT layer, so it won't be accessible at gRPC server level.

func EthHeaderFromCometBFT

func EthHeaderFromCometBFT(header cmttypes.Header, bloom ethtypes.Bloom, baseFee *big.Int) *ethtypes.Header

EthHeaderFromCometBFT is an util function that returns an Ethereum Header from a CometBFT Header.

func FormatBlock

func FormatBlock(
	header cmttypes.Header,
	chainID *big.Int,
	size int,
	gasLimit int64, gasUsed *big.Int, baseFee *big.Int,
	transactions ethtypes.Transactions, fullTx bool,
	receipts ethtypes.Receipts,
	bloom ethtypes.Bloom,
	validatorAddr common.Address,
	logger log.Logger,
) map[string]interface{}

FormatBlock creates an ethereum block from a CometBFT header and ethereum-formatted transactions.

func RawTxToEthTx

func RawTxToEthTx(clientCtx client.Context, txBz cmttypes.Tx) ([]*evmtypes.MsgEthereumTx, error)

RawTxToEthTx returns a evm MsgEthereum transaction from raw tx bytes.

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

func (bn BlockNumber) CometBftHeight() *int64

CometBftHeight is an 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 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"`
}

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
}

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"`
}

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 {
	Hash common.Hash
	// -1 means uninitialized
	EthTxIndex int32
	Failed     bool
}

ParsedTx is the tx infos parsed from events.

func ParseTxResult

func ParseTxResult(result *abci.ExecTxResult, tx sdk.Tx) (*ParsedTx, error)

ParseTxResult parse eth tx infos from Cosmos-SDK events.

type QueryClient

type QueryClient struct {
	sdktxtypes.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, *tmcrypto.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 RPCReceipt

type RPCReceipt struct {
	// Consensus fields: These fields are defined by the Yellow Paper
	Status            hexutil.Uint    `json:"status"`
	CumulativeGasUsed hexutil.Uint64  `json:"cumulativeGasUsed"`
	Bloom             ethtypes.Bloom  `json:"logsBloom"`
	Logs              []*ethtypes.Log `json:"logs"`

	// Implementation fields: These fields are added by geth when processing a transaction.
	// They are stored in the chain database.
	TransactionHash common.Hash     `json:"transactionHash"`
	ContractAddress *common.Address `json:"contractAddress,omitempty"`
	GasUsed         hexutil.Uint64  `json:"gasUsed"`

	// Inclusion information: These fields provide information about the inclusion of the
	// transaction corresponding to this receipt.
	BlockHash        common.Hash    `json:"blockHash"`
	BlockNumber      hexutil.Uint64 `json:"blockNumber"`
	TransactionIndex hexutil.Uint64 `json:"transactionIndex"`
	Type             hexutil.Uint   `json:"type"`

	// sender and receiver (contract or EOA) addresses
	From common.Address  `json:"from"`
	To   *common.Address `json:"to"`

	// others
	EffectiveGasPrice *hexutil.Big `json:"effectiveGasPrice,omitempty"`
}

RPCReceipt represents a receipt (of a transaction) that will serialize to the RPC representation of the receipt

func NewRPCReceiptFromReceipt

func NewRPCReceiptFromReceipt(
	ethMsg *evmtypes.MsgEthereumTx,
	ethReceipt *ethtypes.Receipt,
	effectiveGasPrice *big.Int,
) (receipt *RPCReceipt, err error)

func (*RPCReceipt) AsEthReceipt

func (r *RPCReceipt) AsEthReceipt() *ethtypes.Receipt

func (*RPCReceipt) Compare

func (r *RPCReceipt) Compare(other *RPCReceipt) (equals bool, diff string)

Compare is used for testing purpose

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"`
	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"`
	V                *hexutil.Big         `json:"v"`
	R                *hexutil.Big         `json:"r"`
	S                *hexutil.Big         `json:"s"`
}

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

func NewRPCTransaction

func NewRPCTransaction(
	tx *ethtypes.Transaction, blockHash common.Hash, blockNumber, index uint64, baseFee *big.Int,
	chainID *big.Int,
) (*RPCTransaction, error)

NewRPCTransaction returns a transaction that will serialize to the RPC representation, with the given location metadata set (if available).

func NewTransactionFromMsg

func NewTransactionFromMsg(
	msg *evmtypes.MsgEthereumTx,
	blockHash common.Hash,
	blockNumber, index uint64,
	baseFee *big.Int,
	chainID *big.Int,
) (*RPCTransaction, error)

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.

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

Jump to

Keyboard shortcuts

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