types

package
v0.4.9-rc9 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// adjust the order to match ethereum
	// the order was changed in ethereum at:
	// https://github.com/ethereum/go-ethereum/pull/27219/files#diff-064c12cf00b0f549b40fa9dff4231b1d1d3c143a2e47cd051a87f5b04d429949R68
	EthLatestBlockNumber   = BlockNumber(-2)
	EthPendingBlockNumber  = BlockNumber(-1)
	EthEarliestBlockNumber = BlockNumber(0)
)
View Source
const (
	BlockParamEarliest  = "earliest"
	BlockParamLatest    = "latest"
	BlockParamFinalized = "finalized"
	BlockParamSafe      = "safe"
	BlockParamPending   = "pending"
)
View Source
const ExceedBlockGasLimitError = "out of gas in location: block gas meter; gasWanted:"

ExceedBlockGasLimitError defines the error message when txs execution exceeds the block gas limit. The txs fee is deducted in ante handler, so it shouldn't be ignored in JSON-RPC API.

Variables

This section is empty.

Functions

func BaseFeeFromEvents

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

BaseFeeFromEvents parses the fee basefee from cosmos events

func BlockMaxGasFromConsensusParams

func BlockMaxGasFromConsensusParams(ctx context.Context, clientCtx client.Context, blockHeight int64) (int64, error)

BlockMaxGasFromConsensusParams returns the gas limit for the current block from the chain consensus params.

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 txs is _reasonable_(under the cap).

func ContextWithHeight

func ContextWithHeight(height int64) context.Context

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 are processed and removed by tendermint layer, so it wont be accessible at gRPC server level.

func EthHeaderFromTendermint

func EthHeaderFromTendermint(header tmtypes.Header, bloom ethtypes.Bloom, baseFee *big.Int) *ethtypes.Header

EthHeaderFromTendermint is an util function that returns an Ethereum Header from a tendermint Header.

func FormatBlock

func FormatBlock(
	header tmtypes.Header, size int, gasLimit int64,
	gasUsed *big.Int, transactions []interface{}, bloom ethtypes.Bloom,
	validatorAddr common.Address, baseFee *big.Int,
) map[string]interface{}

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

func NewRPCRawTransactionFromBlockIndex

func NewRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.Bytes

newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.

func ParseTxIndexerResult

func ParseTxIndexerResult(txResult *tmrpctypes.ResultTx, tx sdk.Tx, getter func(*ParsedTxs) *ParsedTx) (*types.TxResult, error)

ParseTxIndexerResult parse tm txs result to a format compatible with the custom txs indexer.

func RawTxToEthTx

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

RawTxToEthTx returns a evm MsgEthereum txs from raw txs bytes.

func TxExceedBlockGasLimit

func TxExceedBlockGasLimit(res *abci.ResponseDeliverTx) bool

TxExceedBlockGasLimit returns true if the txs exceeds block gas limit.

func TxSuccessOrExceedsBlockGasLimit

func TxSuccessOrExceedsBlockGasLimit(res *abci.ResponseDeliverTx) bool

TxSuccessOrExceedsBlockGasLimit returnsrue if the txs was successful or if it failed with an ExceedBlockGasLimit error

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 txs 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 txs is being signed.

func (*AddrLocker) UnlockAddr

func (l *AddrLocker) UnlockAddr(address common.Address)

UnlockAddr unlocks the mutex of the given account.

type Backend

type Backend interface {
	CurrentHeader() (*types.Header, error)

	Accounts() []common.Address
	GetBalance(address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error)
	ArtBlockByNumber(ctx context.Context, number rpc.BlockNumber) (*Block, error)
	BlockByHash(ctx context.Context, hash common.Hash) (*Block, error)
	ChainConfig() *params.ChainConfig
}

Backend defines the common interfaces

type Block

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

func EthBlockToBlock

func EthBlockToBlock(block *ethtypes.Block) *Block

func (*Block) Body

func (b *Block) Body() *ethtypes.Body

func (*Block) EthBlock

func (b *Block) EthBlock() *ethtypes.Block

func (*Block) Hash

func (b *Block) Hash() common.Hash

func (*Block) Header

func (b *Block) Header() *ethtypes.Header

func (*Block) Number

func (b *Block) Number() *big.Int

func (*Block) SetHash

func (b *Block) SetHash(hash common.Hash)

func (*Block) Size

func (b *Block) Size() uint64

func (*Block) Transaction

func (b *Block) Transaction(hash common.Hash) *ethtypes.Transaction

func (*Block) Transactions

func (b *Block) Transactions() ethtypes.Transactions

func (*Block) Uncles

func (b *Block) Uncles() []*ethtypes.Header

func (*Block) Withdrawals

func (b *Block) Withdrawals() ethtypes.Withdrawals

type BlockChainBackend

type BlockChainBackend interface {
	Backend

	GetProof(address common.Address, storageKeys []string, blockNrOrHash BlockNumberOrHash) (*AccountResult, error)
	DoCall(args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash) (*txs.MsgEthereumTxResponse, error)
	EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error)

	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)
	CurrentBlock() *Block
	ArtBlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*Block, error)
	CosmosBlockByHash(blockHash common.Hash) (*tmrpctypes.ResultBlock, error)
	CosmosBlockByNumber(blockNum rpc.BlockNumber) (*tmrpctypes.ResultBlock, error)
	GetCode(address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)
	GetStorageAt(address common.Address, key string, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)
	GetCoinbase() (sdk.AccAddress, error)
}

BlockChainBackend defines the block chain interfaces

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

func (bn BlockNumber) Int64() int64

Int64 converts block number to primitive type

func (BlockNumber) TmHeight

func (bn BlockNumber) TmHeight() *int64

TmHeight is a util function used for the Tendermint 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) 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 DebugBackend

type DebugBackend interface {
	BlockChainBackend
	TrancsactionBackend

	TraceTransaction(hash common.Hash, config *evmsupport.TraceConfig) (interface{}, error)
	TraceBlock(height rpc.BlockNumber,
		config *evmsupport.TraceConfig,
		block *tmrpctypes.ResultBlock,
	) ([]*evmtxs.TxTraceResult, error)
	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)

	DBProperty(property string) (string, error)
	DBCompact(start []byte, limit []byte) error
}

type EthereumBackend

type EthereumBackend interface {
	Backend

	SuggestGasTipCap(baseFee *big.Int) (*big.Int, error)
	GasPrice(ctx context.Context) (*hexutil.Big, error)
	FeeHistory(blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*FeeHistoryResult, error)

	Engine() consensus.Engine
	Syncing() (interface{}, error)
}

EthereumBackend defines the chain related interfaces

type EventFormat

type EventFormat int

EventFormat is the format version of the events.

To fix the issue of txs 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"`
}

type NetBackend

type NetBackend interface {
	PeerCount() hexutil.Uint
	Listening() bool
	Version() string
}

NetBackend is the collection of methods required to satisfy the net RPC DebugAPI.

type NetworkingStack

type NetworkingStack interface {
	// IsExtRPCEnabled returns true if the networking stack is configured to expose JSON-RPC APIs.
	ExtRPCEnabled() bool

	// RegisterHandler manually registers a new handler into the networking stack.
	RegisterHandler(string, string, http.Handler)

	// RegisterAPIs registers JSON-RPC handlers for the networking stack.
	RegisterAPIs([]rpc.API)

	// Start starts the networking stack.
	Start() error
}

NetworkingStack defines methods that allow a Polaris chain to build and expose JSON-RPC apis.

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:"states"`
	StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
}

OverrideAccount indicates the overriding fields of account during the execution of a message call. Note, states and stateDiff can't be specified at the same time. If states is set, message execution will only use the data in the given states. Otherwise if statDiff is set, all diff will be applied first and then execute the call message.

type ParsedTx

type ParsedTx struct {
	MsgIndex int

	// the following fields are parsed from events
	From common.Address

	Hash common.Hash
	// -1 means uninitialized
	EthTxIndex int32
	GasUsed    uint64
	Failed     bool
}

ParsedTx is the txs infos parsed from events.

func NewParsedTx

func NewParsedTx(msgIndex int) ParsedTx

NewParsedTx initialize a ParsedTx

type ParsedTxs

type ParsedTxs struct {
	// one item per message
	Txs []ParsedTx
	// map txs hash to msg index
	TxHashes map[common.Hash]int
}

ParsedTxs is the txs infos parsed from eth txs events.

func ParseTxResult

func ParseTxResult(result *abci.ResponseDeliverTx, tx sdk.Tx) (*ParsedTxs, error)

ParseTxResult parse eth txs infos from cosmos-sdk events. It supports two event formats, the formats are described in the comments of the format constants.

func (*ParsedTxs) AccumulativeGasUsed

func (p *ParsedTxs) AccumulativeGasUsed(msgIndex int) (result uint64)

AccumulativeGasUsed calculates the accumulated gas used within the batch of txs

func (*ParsedTxs) GetTxByHash

func (p *ParsedTxs) GetTxByHash(hash common.Hash) *ParsedTx

GetTxByHash find ParsedTx by txs hash, returns nil if not exists.

func (*ParsedTxs) GetTxByMsgIndex

func (p *ParsedTxs) GetTxByMsgIndex(i int) *ParsedTx

GetTxByMsgIndex returns ParsedTx by msg index

func (*ParsedTxs) GetTxByTxIndex

func (p *ParsedTxs) GetTxByTxIndex(txIndex int) *ParsedTx

GetTxByTxIndex returns ParsedTx by txs index

type PersonalBackend

type PersonalBackend interface {
	TrancsactionBackend

	NewAccount(password string) (common.AddressEIP55, error)
	ImportRawKey(privkey, password string) (common.Address, error)
}

type QueryClient

type QueryClient struct {
	tx.ServiceClient
	evmtypes.QueryClient
	FeeMarket feetypes.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 tendermint 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"`
	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"`
	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 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

func NewRPCTransactionFromBlockIndex

func NewRPCTransactionFromBlockIndex(b *types.Block, blockHash common.Hash, index uint64, config *params.ChainConfig) *RPCTransaction

newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.

func NewTransactionFromMsg

func NewTransactionFromMsg(
	msg *txs.MsgEthereumTx,
	blockHash common.Hash,
	blockNumber, index uint64,
	baseFee *big.Int,
	cfg *params.ChainConfig,
) *RPCTransaction

NewTransactionFromMsg returns a txs 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:"txs"`
}

SignTransactionResult represents a RLP encoded signed txs.

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

type TrancsactionBackend

type TrancsactionBackend interface {
	BlockChainBackend
	EthereumBackend

	SendTx(ctx context.Context, signedTx *types.Transaction) error
	GetTransaction(ctx context.Context, txHash common.Hash) (*RPCTransaction, error)
	GetTransactionCount(address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error)
	GetTxMsg(ctx context.Context, txHash common.Hash) (*txs.MsgEthereumTx, error)
	SignTransaction(args *TransactionArgs) (*types.Transaction, error)
	GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error)
	RPCTxFeeCap() float64
	UnprotectedAllowed() bool

	PendingTransactions() ([]*sdk.Tx, error)
	GetResendArgs(args TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (TransactionArgs, error)
	Sign(address common.Address, data hexutil.Bytes) (hexutil.Bytes, error)
	GetSender(msg *txs.MsgEthereumTx, chainID *big.Int) (from common.Address, err error)
}

TrancsactionBackend defines the block chain interfaces

type TransactionArgs

type TransactionArgs struct {
	From                 *common.Address `json:"from"`
	To                   *common.Address `json:"to"`
	Gas                  *hexutil.Uint64 `json:"gas"`
	GasPrice             *hexutil.Big    `json:"gasPrice"`
	MaxFeePerGas         *hexutil.Big    `json:"maxFeePerGas"`
	MaxPriorityFeePerGas *hexutil.Big    `json:"maxPriorityFeePerGas"`
	Value                *hexutil.Big    `json:"value"`
	Nonce                *hexutil.Uint64 `json:"nonce"`

	// We accept "data" and "input" for backwards-compatibility reasons.
	// "input" is the newer name and should be preferred by clients.
	// Issue detail: https://github.com/ethereum/go-ethereum/issues/15628
	Data  *hexutil.Bytes `json:"data"`
	Input *hexutil.Bytes `json:"input"`

	// Introduced by AccessListTxType transaction.
	AccessList *types.AccessList `json:"accessList,omitempty"`
	ChainID    *hexutil.Big      `json:"chainId,omitempty"`
}

TransactionArgs represents the arguments to construct a new transaction or a message call.

func (*TransactionArgs) FromAddr

func (args *TransactionArgs) FromAddr() common.Address

from retrieves the transaction sender address.

func (*TransactionArgs) GetData

func (args *TransactionArgs) GetData() []byte

func (*TransactionArgs) SetDefaults

func (args *TransactionArgs) SetDefaults(ctx context.Context, b TrancsactionBackend) error

setDefaults fills in default values for unspecified tx fields.

func (*TransactionArgs) ToEVMTransaction

func (args *TransactionArgs) ToEVMTransaction() *txs.MsgEthereumTx

func (*TransactionArgs) ToMessage

func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (*core.Message, error)

ToMessage converts the transaction arguments to the Message type used by the core evm. This method is used in calls and traces that do not require a real live transaction.

func (*TransactionArgs) ToTransaction

func (args *TransactionArgs) ToTransaction() *types.Transaction

ToTransaction converts the arguments to a transaction. This assumes that setDefaults has been called.

type TxPoolBackend

type TxPoolBackend interface {
	TrancsactionBackend

	PendingTransactionsCount() (int, error)
}

type Web3Backend

type Web3Backend interface {
	ClientVersion() string
}

Web3Backend is the collection of methods required to satisfy the net RPC DebugAPI.

Jump to

Keyboard shortcuts

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