Skip to content

Commit

Permalink
use Coin{}
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed May 18, 2022
1 parent fb39fa8 commit 2d30c29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,10 @@ func (coins Coins) AmountOf(denom string) Int {
// AmountOfNoDenomValidation returns the amount of a denom from coins
// without validating the denomination.
func (coins Coins) AmountOfNoDenomValidation(denom string) Int {
_, c := coins.Find(denom)
return c.Amount
if ok, c := coins.Find(denom); ok {
return c.Amount
}
return ZeroInt()
}

// Find returns true and coin if the denom exists in coins. Otherwise it returns false
Expand All @@ -713,14 +715,14 @@ func (coins Coins) AmountOfNoDenomValidation(denom string) Int {
func (coins Coins) Find(denom string) (bool, Coin) {
switch len(coins) {
case 0:
return false, Coin{"", ZeroInt()}
return false, Coin{}

case 1:
coin := coins[0]
if coin.Denom == denom {
return true, coin
}
return false, Coin{"", ZeroInt()}
return false, Coin{}

default:
midIdx := len(coins) / 2 // 2:1, 3:1, 4:2
Expand Down
2 changes: 1 addition & 1 deletion types/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ func (s *coinTestSuite) TestSearch() {
require.Panics(func() { amountOfCases[0].coins.AmountOf("10Invalid") })
})

zeroCoin := sdk.Coin{"", sdk.ZeroInt()}
zeroCoin := sdk.Coin{}
findCases := []struct {
coins sdk.Coins
denom string
Expand Down

0 comments on commit 2d30c29

Please sign in to comment.