forked from cerc-io/laconicd-deprecated
rpc: use evm denom for tx fee (#181)
* rpc: use evm denom for tx fee * changelog
This commit is contained in:
parent
b7f00d5a07
commit
0f3a346cdc
@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
### Improvements
|
### 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.
|
* (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#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`.
|
* (evm) [tharsis#24](https://github.com/tharsis/ethermint/pull/24) Implement metrics for `MsgEthereumTx`, state transitions, `BeginBlock` and `EndBlock`.
|
||||||
|
@ -395,7 +395,14 @@ func (e *PublicAPI) SendTransaction(args rpctypes.SendTxArgs) (common.Hash, erro
|
|||||||
e.logger.WithError(err).Panicln("builder.SetMsgs failed")
|
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.SetFeeAmount(fees)
|
||||||
builder.SetGasLimit(msg.GetGas())
|
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")
|
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.SetFeeAmount(fees)
|
||||||
builder.SetGasLimit(ethereumTx.GetGas())
|
builder.SetGasLimit(ethereumTx.GetGas())
|
||||||
|
|
||||||
@ -593,7 +607,14 @@ func (e *PublicAPI) doCall(
|
|||||||
log.Panicln("builder.SetMsgs failed")
|
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.SetFeeAmount(fees)
|
||||||
txBuilder.SetGasLimit(gas)
|
txBuilder.SetGasLimit(gas)
|
||||||
|
|
||||||
|
@ -10,13 +10,9 @@ import (
|
|||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"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"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
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"
|
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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) {
|
func DecodeTx(clientCtx client.Context, txBz tmtypes.Tx) (sdk.Tx, uint64) {
|
||||||
var gasUsed uint64
|
var gasUsed uint64
|
||||||
txDecoder := clientCtx.TxConfig.TxDecoder()
|
txDecoder := clientCtx.TxConfig.TxDecoder()
|
||||||
|
Loading…
Reference in New Issue
Block a user