Skip to content

Commit

Permalink
mint: export reusable errors (#1641)
Browse files Browse the repository at this point in the history
* export

* export

* Update x/mint/types/errors.go

---------

Co-authored-by: Tuan Tran <[email protected]>
  • Loading branch information
pysel and tuantran1702 authored Jun 13, 2024
1 parent 44122b1 commit 12c4c4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 13 additions & 0 deletions x/mint/types/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package types

import "fmt"

type (
ErrInvalidParameter struct {
Type interface{}
}
)

func (e ErrInvalidParameter) Error() string {
return fmt.Sprintf("invalid parameter type: %T", e.Type)
}
12 changes: 6 additions & 6 deletions x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
func validateMintDenom(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
return ErrInvalidParameter{Type: i}
}

if strings.TrimSpace(v) == "" {
Expand All @@ -120,7 +120,7 @@ func validateMintDenom(i interface{}) error {
func validateGenesisEpochProvisions(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
return ErrInvalidParameter{Type: i}
}

if v.LT(sdk.ZeroDec()) {
Expand All @@ -133,7 +133,7 @@ func validateGenesisEpochProvisions(i interface{}) error {
func validateReductionPeriodInEpochs(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
return ErrInvalidParameter{Type: i}
}

if v <= 0 {
Expand All @@ -146,7 +146,7 @@ func validateReductionPeriodInEpochs(i interface{}) error {
func validateReductionFactor(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
return ErrInvalidParameter{Type: i}
}

if v.GT(sdk.OneDec()) {
Expand All @@ -163,7 +163,7 @@ func validateReductionFactor(i interface{}) error {
func validateDistributionProportions(i interface{}) error {
v, ok := i.(DistributionProportions)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
return ErrInvalidParameter{Type: i}
}

if v.Staking.IsNegative() {
Expand Down Expand Up @@ -193,7 +193,7 @@ func validateDistributionProportions(i interface{}) error {
func validateMintingRewardsDistributionStartEpoch(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
return ErrInvalidParameter{Type: i}
}

if v < 0 {
Expand Down

0 comments on commit 12c4c4c

Please sign in to comment.