From 0f3a346cdc33555b0728229fdcc3a69c25ad0afc Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Thu, 24 Jun 2021 04:22:36 -0400 Subject: [PATCH] rpc: use evm denom for tx fee (#181) * rpc: use evm denom for tx fee * changelog --- CHANGELOG.md | 1 + ethereum/rpc/namespaces/eth/api.go | 27 ++++++++++++++++-- ethereum/rpc/types/utils.go | 46 ------------------------------ 3 files changed, 25 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aabf3083..4ec2d886 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (rpc) [tharsis#181](https://github.com/tharsis/ethermint/pull/181) Use evm denomination for params on tx fee. * (deps) [tharsis#165](https://github.com/tharsis/ethermint/pull/165) Bump Cosmos SDK and Tendermint versions to [v0.42.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.42.6) and [v0.34.11](https://github.com/tendermint/tendermint/releases/tag/v0.34.11), respectively. * (evm) [tharsis#66](https://github.com/tharsis/ethermint/issues/66) Support legacy transaction types for signing. * (evm) [tharsis#24](https://github.com/tharsis/ethermint/pull/24) Implement metrics for `MsgEthereumTx`, state transitions, `BeginBlock` and `EndBlock`. diff --git a/ethereum/rpc/namespaces/eth/api.go b/ethereum/rpc/namespaces/eth/api.go index c663f326..a9bffd0c 100644 --- a/ethereum/rpc/namespaces/eth/api.go +++ b/ethereum/rpc/namespaces/eth/api.go @@ -395,7 +395,14 @@ func (e *PublicAPI) SendTransaction(args rpctypes.SendTxArgs) (common.Hash, erro e.logger.WithError(err).Panicln("builder.SetMsgs failed") } - fees := sdk.NewCoins(ethermint.NewPhotonCoin(sdk.NewIntFromBigInt(msg.Fee()))) + // Query params to use the EVM denomination + res, err := e.queryClient.QueryClient.Params(e.ctx, &evmtypes.QueryParamsRequest{}) + if err != nil { + e.logger.WithError(err).Errorln("failed to query evm params") + return common.Hash{}, err + } + + fees := sdk.Coins{sdk.NewCoin(res.Params.EvmDenom, sdk.NewIntFromBigInt(msg.Fee()))} builder.SetFeeAmount(fees) builder.SetGasLimit(msg.GetGas()) @@ -462,7 +469,14 @@ func (e *PublicAPI) SendRawTransaction(data hexutil.Bytes) (common.Hash, error) e.logger.WithError(err).Panicln("builder.SetMsgs failed") } - fees := sdk.NewCoins(ethermint.NewPhotonCoin(sdk.NewIntFromBigInt(ethereumTx.Fee()))) + // Query params to use the EVM denomination + res, err := e.queryClient.QueryClient.Params(e.ctx, &evmtypes.QueryParamsRequest{}) + if err != nil { + e.logger.WithError(err).Errorln("failed to query evm params") + return common.Hash{}, err + } + + fees := sdk.Coins{sdk.NewCoin(res.Params.EvmDenom, sdk.NewIntFromBigInt(ethereumTx.Fee()))} builder.SetFeeAmount(fees) builder.SetGasLimit(ethereumTx.GetGas()) @@ -593,7 +607,14 @@ func (e *PublicAPI) doCall( log.Panicln("builder.SetMsgs failed") } - fees := sdk.NewCoins(ethermint.NewPhotonCoin(sdk.NewIntFromBigInt(msg.Fee()))) + // Query params to use the EVM denomination + res, err := e.queryClient.QueryClient.Params(e.ctx, &evmtypes.QueryParamsRequest{}) + if err != nil { + e.logger.WithError(err).Errorln("failed to query evm params") + return nil, err + } + + fees := sdk.Coins{sdk.NewCoin(res.Params.EvmDenom, sdk.NewIntFromBigInt(msg.Fee()))} txBuilder.SetFeeAmount(fees) txBuilder.SetGasLimit(gas) diff --git a/ethereum/rpc/types/utils.go b/ethereum/rpc/types/utils.go index 53534840..da7933ce 100644 --- a/ethereum/rpc/types/utils.go +++ b/ethereum/rpc/types/utils.go @@ -10,13 +10,9 @@ import ( tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - ethermint "github.com/tharsis/ethermint/types" evmtypes "github.com/tharsis/ethermint/x/evm/types" "github.com/ethereum/go-ethereum/common" @@ -204,48 +200,6 @@ func FormatBlock( } } -// BuildEthereumTx builds and signs a Cosmos transaction from a MsgEthereumTx and returns the tx -func BuildEthereumTx(clientCtx client.Context, msg *evmtypes.MsgEthereumTx, accNumber, seq uint64, privKey cryptotypes.PrivKey) ([]byte, error) { - // TODO: user defined evm coin - fees := sdk.NewCoins(ethermint.NewPhotonCoin(sdk.NewIntFromBigInt(msg.Fee()))) - signMode := clientCtx.TxConfig.SignModeHandler().DefaultMode() - signerData := authsigning.SignerData{ - ChainID: clientCtx.ChainID, - AccountNumber: accNumber, - Sequence: seq, - } - - // Create a TxBuilder - txBuilder := clientCtx.TxConfig.NewTxBuilder() - if err := txBuilder.SetMsgs(msg); err != nil { - return nil, err - - } - txBuilder.SetFeeAmount(fees) - txBuilder.SetGasLimit(msg.GetGas()) - - // sign with the private key - sigV2, err := tx.SignWithPrivKey( - signMode, signerData, - txBuilder, privKey, clientCtx.TxConfig, seq, - ) - - if err != nil { - return nil, err - } - - if err := txBuilder.SetSignatures(sigV2); err != nil { - return nil, err - } - - txBytes, err := clientCtx.TxConfig.TxEncoder()(txBuilder.GetTx()) - if err != nil { - return nil, err - } - - return txBytes, nil -} - func DecodeTx(clientCtx client.Context, txBz tmtypes.Tx) (sdk.Tx, uint64) { var gasUsed uint64 txDecoder := clientCtx.TxConfig.TxDecoder()