Skip to content

Commit

Permalink
fix: Consider uppercase for addr uniqueness check in FractionalBalanc…
Browse files Browse the repository at this point in the history
…es.Validate()
  • Loading branch information
drklee3 committed May 10, 2024
1 parent 38e25a2 commit 7008c87
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions x/precisebank/types/fractional_balances.go
Expand Up @@ -2,6 +2,7 @@ package types

import (
fmt "fmt"
"strings"
)

// FractionalBalances is a slice of FractionalBalance
Expand All @@ -17,13 +18,17 @@ func (fbs FractionalBalances) Validate() error {
return fmt.Errorf("invalid fractional balance for %s: %w", fb.Address, err)
}

// Make addresses all lowercase for unique check, as ALL UPPER is also
// a valid address.
lowerAddr := strings.ToLower(fb.Address)

// If this is a duplicate address, return an error
if _, found := seenAddresses[fb.Address]; found {
return fmt.Errorf("duplicate address %v", fb.Address)
if _, found := seenAddresses[lowerAddr]; found {
return fmt.Errorf("duplicate address %v", lowerAddr)
}

// Mark it as seen
seenAddresses[fb.Address] = struct{}{}
seenAddresses[lowerAddr] = struct{}{}
}

return nil
Expand Down

0 comments on commit 7008c87

Please sign in to comment.