Skip to content

Commit

Permalink
bugfix customized fee estimation interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed Apr 8, 2021
1 parent 642f474 commit 7e0143f
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 55 deletions.
9 changes: 5 additions & 4 deletions custom/auth/client/cli/estimate_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ $ terracli tx estimate-fee [file] --gas-adjustment 1.4 --gas-prices 0.015uluna
}

// override gas and fees
txf.WithFees(stdFee.Amount.String())
txf.WithGas(stdFee.Gas)
txf.WithSimulateAndExecute(false)
txf.WithGasPrices("")
txf = txf.
WithFees(stdFee.Amount.String()).
WithGas(stdFee.Gas).
WithSimulateAndExecute(false).
WithGasPrices("")

if err != nil {
return err
Expand Down
51 changes: 28 additions & 23 deletions custom/auth/client/utils/feeutils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package utils

import (
"fmt"
"context"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -55,11 +55,25 @@ func ComputeFeesWithBaseReq(
WithGasPrices(br.GasPrices.String()).
WithGas(gasSetting.Gas).
WithGasAdjustment(gasAdj).
WithAccountNumber(br.AccountNumber).
WithSequence(br.Sequence).
WithMemo(br.Memo).
WithChainID(br.ChainID).
WithSimulateAndExecute(br.Simulate).
WithTxConfig(clientCtx.TxConfig).
WithTimeoutHeight(br.TimeoutHeight)
WithTimeoutHeight(br.TimeoutHeight).
WithAccountRetriever(clientCtx.AccountRetriever)

// Prepare AccountNumber & SequenceNumber when not given
clientCtx.FromAddress, err = sdk.AccAddressFromBech32(br.From)
if err != nil {
return nil, err
}

txf, err := tx.PrepareFactory(clientCtx, txf)
if err != nil {
return nil, err
}

_, adj, err := tx.CalculateGas(clientCtx.QueryWithData, txf, msgs...)

Expand Down Expand Up @@ -117,6 +131,12 @@ func ComputeFeesWithCmd(
clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) (*legacytx.StdFee, error) {
txf := tx.NewFactoryCLI(clientCtx, flagSet)

// Prepare AccountNumber & SequenceNumber when not given
txf, err := tx.PrepareFactory(clientCtx, txf)
if err != nil {
return nil, err
}

gas := txf.Gas()
if txf.SimulateAndExecute() {
_, adj, err := tx.CalculateGas(clientCtx.QueryWithData, txf, msgs...)
Expand Down Expand Up @@ -252,32 +272,17 @@ func computeTax(clientCtx client.Context, taxRate sdk.Dec, principal sdk.Coins)
}

func queryTaxRate(clientCtx client.Context) (sdk.Dec, error) {
queryClient := treasuryexported.NewQueryClient(clientCtx)

// Query tax-rate
res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", treasuryexported.QuerierRoute, treasuryexported.QueryTaxRate), nil)
if err != nil {
return sdk.Dec{}, err
}

var taxRate sdk.Dec
clientCtx.LegacyAmino.MustUnmarshalJSON(res, &taxRate)
return taxRate, nil
res, err := queryClient.TaxRate(context.Background(), &treasuryexported.QueryTaxRateRequest{})
return res.TaxRate, err
}

func queryTaxCap(clientCtx client.Context, denom string) (sdk.Int, error) {
// Query tax-cap

params := treasuryexported.NewQueryTaxCapParams(denom)
bz := clientCtx.LegacyAmino.MustMarshalJSON(params)
res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", treasuryexported.QuerierRoute, treasuryexported.QueryTaxCap), bz)
if err != nil {
return sdk.Int{}, err
}

var taxCap sdk.Int
clientCtx.LegacyAmino.MustUnmarshalJSON(res, &taxCap)
queryClient := treasuryexported.NewQueryClient(clientCtx)

return taxCap, nil
res, err := queryClient.TaxCap(context.Background(), &treasuryexported.QueryTaxCapRequest{Denom: denom})
return res.TaxCap, err
}

// ParseFloat64 parses string to float64
Expand Down
9 changes: 5 additions & 4 deletions custom/bank/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ ignored as it is implied from [from_key_or_address].`,
}

// override gas and fees
txf.WithFees(stdFee.Amount.String())
txf.WithGas(stdFee.Gas)
txf.WithSimulateAndExecute(false)
txf.WithGasPrices("")
txf = txf.
WithFees(stdFee.Amount.String()).
WithGas(stdFee.Gas).
WithSimulateAndExecute(false).
WithGasPrices("")
}

// build and sign the transaction, then broadcast to Tendermint
Expand Down
1 change: 0 additions & 1 deletion scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ $(find "$(pwd)/proto" -maxdepth 5 -name '*.proto')
# move proto files to the right places
cp -r github.com/terra-project/core/* ./
rm -rf github.com

9 changes: 5 additions & 4 deletions x/market/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ $ terracli market swap "1000ukrw" "uusd" "terra1..."
}

// override gas and fees
txf.WithFees(stdFee.Amount.String())
txf.WithGas(stdFee.Gas)
txf.WithSimulateAndExecute(false)
txf.WithGasPrices("")
txf = txf.
WithFees(stdFee.Amount.String()).
WithGas(stdFee.Gas).
WithSimulateAndExecute(false).
WithGasPrices("")
}
} else {
msg = types.NewMsgSwap(fromAddress, offerCoin, askDenom)
Expand Down
9 changes: 5 additions & 4 deletions x/msgauth/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ tx.json should be format of StdTx
}

// override gas and fees
txf.WithFees(stdFee.Amount.String())
txf.WithGas(stdFee.Gas)
txf.WithSimulateAndExecute(false)
txf.WithGasPrices("")
txf = txf.
WithFees(stdFee.Amount.String()).
WithGas(stdFee.Gas).
WithSimulateAndExecute(false).
WithGasPrices("")
}

// build and sign the transaction, then broadcast to Tendermint
Expand Down
5 changes: 2 additions & 3 deletions x/treasury/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ func GetQueryCmd() *cobra.Command {
GetCmdQueryTaxCap(),
GetCmdQueryTaxCaps(),
GetCmdQueryRewardWeight(),
GetCmdQueryParams(),
GetCmdQueryTaxProceeds(),
GetCmdQuerySeigniorageProceeds(),
GetCmdQueryParams(),
GetCmdQueryIndicators(),
GetCmdQueryParams(),
)

return oracleQueryCmd
Expand Down Expand Up @@ -233,7 +232,7 @@ $ terracli query treasury seigniorage-proceeds
return cmd
}

// GetCmdQueryIndicators implements the query params command.
// GetCmdQueryIndicators implements the query indicators command.
func GetCmdQueryIndicators() *cobra.Command {
cmd := &cobra.Command{
Use: "indicators",
Expand Down
9 changes: 5 additions & 4 deletions x/treasury/exported/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
)

var (
NewQueryTaxCapParams = types.NewQueryTaxCapParams
NewQueryClient = types.NewQueryClient
)

QuerierRoute = types.QuerierRoute
QueryTaxRate = types.QueryTaxRate
QueryTaxCap = types.QueryTaxCap
type (
QueryTaxRateRequest = types.QueryTaxRateRequest
QueryTaxCapRequest = types.QueryTaxCapRequest
)
18 changes: 10 additions & 8 deletions x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ $ terracli instantiate 1 '{"arbiter": "terra~~"}' "1000000uluna"
}

// override gas and fees
txf.WithFees(stdFee.Amount.String())
txf.WithGas(stdFee.Gas)
txf.WithSimulateAndExecute(false)
txf.WithGasPrices("")
txf = txf.
WithFees(stdFee.Amount.String()).
WithGas(stdFee.Gas).
WithSimulateAndExecute(false).
WithGasPrices("")
}

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
Expand Down Expand Up @@ -246,10 +247,11 @@ func ExecuteContractCmd() *cobra.Command {
}

// override gas and fees
txf.WithFees(stdFee.Amount.String())
txf.WithGas(stdFee.Gas)
txf.WithSimulateAndExecute(false)
txf.WithGasPrices("")
txf = txf.
WithFees(stdFee.Amount.String()).
WithGas(stdFee.Gas).
WithSimulateAndExecute(false).
WithGasPrices("")
}

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
Expand Down

0 comments on commit 7e0143f

Please sign in to comment.