Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ungraceful error on failed client tax query #106

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions custom/auth/client/utils/feeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func (m EstimateFeeReq) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error

// ComputeFeesWithBaseReq returns fee amount with given stdTx.
func ComputeFeesWithBaseReq(
clientCtx client.Context, br rest.BaseReq, msgs ...sdk.Msg) (*legacytx.StdFee, error) {

clientCtx client.Context, br rest.BaseReq, msgs ...sdk.Msg,
) (*legacytx.StdFee, error) {
gasSetting, err := flags.ParseGasSetting(br.Gas)
if err != nil {
return nil, err
Expand Down Expand Up @@ -142,7 +142,8 @@ type ComputeReqParams struct {

// ComputeFeesWithCmd returns fee amount with cli options.
func ComputeFeesWithCmd(
clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) (*legacytx.StdFee, error) {
clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg,
) (*legacytx.StdFee, error) {
txf := tx.NewFactoryCLI(clientCtx, flagSet)

gas := txf.Gas()
Expand Down Expand Up @@ -260,7 +261,6 @@ func FilterMsgAndComputeTax(clientCtx client.Context, msgs ...sdk.Msg) (taxes sd

// computes the stability tax according to tax-rate and tax-cap
func computeTax(clientCtx client.Context, taxRate sdk.Dec, principal sdk.Coins) (taxes sdk.Coins, err error) {

for _, coin := range principal {

taxCap, err := queryTaxCap(clientCtx, coin.Denom)
Expand Down Expand Up @@ -289,13 +289,19 @@ func queryTaxRate(clientCtx client.Context) (sdk.Dec, error) {
queryClient := treasuryexported.NewQueryClient(clientCtx)

res, err := queryClient.TaxRate(context.Background(), &treasuryexported.QueryTaxRateRequest{})
if err != nil {
return sdk.ZeroDec(), err
}
return res.TaxRate, err
}

func queryTaxCap(clientCtx client.Context, denom string) (sdk.Int, error) {
queryClient := treasuryexported.NewQueryClient(clientCtx)

res, err := queryClient.TaxCap(context.Background(), &treasuryexported.QueryTaxCapRequest{Denom: denom})
if err != nil {
return sdk.NewInt(0), err
}
return res.TaxCap, err
}

Expand Down