Skip to content

Commit

Permalink
update params
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Feb 22, 2023
1 parent 3654bbf commit d9f5e41
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
6 changes: 5 additions & 1 deletion x/globalfee/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func (a AppModuleBasic) RegisterRESTRoutes(context client.Context, router *mux.R
}

func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err != nil {
// same behavior as in cosmos-sdk
panic(err)
}
}

func (a AppModuleBasic) GetTxCmd() *cobra.Command {
Expand Down
60 changes: 22 additions & 38 deletions x/globalfee/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,37 @@ func validateMinimumGasPrices(i interface{}) error {
return dec.Validate()
}

// Validate checks that the DecCoins are sorted, have nonnegtive amount, with a valid and unique
// denomination (i.e no duplicates). Otherwise, it returns an error.
type DecCoins sdk.DecCoins

// Validate checks that the DecCoins are sorted, have nonnegtive amount, with a valid and unique
// denomination (i.e no duplicates). Otherwise, it returns an error.
func (coins DecCoins) Validate() error {
switch len(coins) {
case 0:
if len(coins) == 0 {
return nil
}

case 1:
// match the denom reg expr
if err := sdk.ValidateDenom(coins[0].Denom); err != nil {
return err
}
if coins[0].IsNegative() {
return fmt.Errorf("coin %s amount is negtive", coins[0])
lowDenom := ""
seenDenoms := make(map[string]bool)

for _, coin := range coins {
if seenDenoms[coin.Denom] {
return fmt.Errorf("duplicate denomination %s", coin.Denom)
}
return nil
default:
// check single coin case
if err := (DecCoins{coins[0]}).Validate(); err != nil {
if err := sdk.ValidateDenom(coin.Denom); err != nil {
return err
}

lowDenom := coins[0].Denom
seenDenoms := make(map[string]bool)
seenDenoms[lowDenom] = true

for _, coin := range coins[1:] {
if seenDenoms[coin.Denom] {
return fmt.Errorf("duplicate denomination %s", coin.Denom)
}
if err := sdk.ValidateDenom(coin.Denom); err != nil {
return err
}
if coin.Denom <= lowDenom {
return fmt.Errorf("denomination %s is not sorted", coin.Denom)
}
if coin.IsNegative() {
return fmt.Errorf("coin %s amount is negtive", coin.Denom)
}

// we compare each coin against the last denom
lowDenom = coin.Denom
seenDenoms[coin.Denom] = true
if coin.Denom <= lowDenom {
return fmt.Errorf("denomination %s is not sorted", coin.Denom)
}
if coin.IsNegative() {
return fmt.Errorf("coin %s amount is negative", coin.Amount)
}

return nil
// we compare each coin against the last denom
lowDenom = coin.Denom
seenDenoms[coin.Denom] = true
}

return nil

}
12 changes: 12 additions & 0 deletions x/globalfee/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ func Test_validateParams(t *testing.T) {
},
true,
},
"negative amount, fail": {
sdk.DecCoins{
sdk.DecCoin{Denom: "photon", Amount: sdk.OneDec().Neg()},
},
true,
},
"invalid denom, fail": {
sdk.DecCoins{
sdk.DecCoin{Denom: "photon!", Amount: sdk.OneDec().Neg()},
},
true,
},
}

for name, test := range tests {
Expand Down

0 comments on commit d9f5e41

Please sign in to comment.