Skip to content

Commit

Permalink
Check for zero shares and dupe addresses (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya authored May 24, 2023
1 parent 2640cf1 commit d249627
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions x/tariff/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,22 @@ func validateDistributionEntityParams(i interface{}) error {
// ensure each denom is only registered one time.
sum := sdk.ZeroDec()
for _, d := range distributionEntities {
_, err := sdk.AccAddressFromBech32(d.Address)
adr, err := sdk.AccAddressFromBech32(d.Address)
if err != nil {
return fmt.Errorf("failed to parse bech32 address: %s", d.Address)
}
count := 0
for _, dd := range distributionEntities {
if dd.Address == adr.String() {
count++
}
}
if count > 1 {
return fmt.Errorf("address is already added as a distribution entity: %s", adr)
}

if d.Share.LT(sdk.ZeroDec()) || d.Share.GT(sdk.OneDec()) {
return fmt.Errorf("distribution entity share is outside of the range of 0 to 100%%: %s", d.Share.String())
if d.Share.LTE(sdk.ZeroDec()) || d.Share.GT(sdk.OneDec()) {
return fmt.Errorf("distribution entity share must be greater than 0 and less than or equal to 100%%: %s", d.Share.String())
}

sum = sum.Add(d.Share)
Expand Down

0 comments on commit d249627

Please sign in to comment.