Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
rpc: use evm denom for tx fee
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze committed Jun 24, 2021
1 parent 1c06553 commit cabf38a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 49 deletions.
27 changes: 24 additions & 3 deletions ethereum/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 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())

Expand Down Expand Up @@ -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 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())

Expand Down Expand Up @@ -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 query evm params")
return nil, err
}

fees := sdk.Coins{sdk.NewCoin(res.Params.EvmDenom, sdk.NewIntFromBigInt(msg.Fee()))}
txBuilder.SetFeeAmount(fees)
txBuilder.SetGasLimit(gas)

Expand Down
46 changes: 0 additions & 46 deletions ethereum/rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit cabf38a

Please sign in to comment.