diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a81ebc3f50b..354643bb6cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (types) [#18440](https://github.com/cosmos/cosmos-sdk/pull/18440) Add `AmountOfNoValidation` to `sdk.DecCoins`. * (x/gov) [#18428](https://github.com/cosmos/cosmos-sdk/pull/18428) Extend governance config * (x/gov) [#18189](https://github.com/cosmos/cosmos-sdk/pull/18189) Limit the accepted deposit coins for a proposal to the minimum proposal deposit denoms. * (x/gov) [#18025](https://github.com/cosmos/cosmos-sdk/pull/18025) Improve ` q gov proposer` by querying directly a proposal instead of tx events. It is an alias of `q gov proposal` as the proposer is a field of the proposal. diff --git a/types/dec_coin.go b/types/dec_coin.go index 9919cf9bcd45..b844301f8c84 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -451,10 +451,16 @@ func (coins DecCoins) Empty() bool { return len(coins) == 0 } -// AmountOf returns the amount of a denom from deccoins +// AmountOf returns the amount of a denom from deccoins. It panics if the denom +// is invalid. func (coins DecCoins) AmountOf(denom string) math.LegacyDec { mustValidateDenom(denom) + return coins.AmountOfNoValidation(denom) +} +// AmountOfNoValidation returns the amount of a denom from deccoins without checking +// the correctness of the denom. +func (coins DecCoins) AmountOfNoValidation(denom string) math.LegacyDec { switch len(coins) { case 0: return math.LegacyZeroDec() @@ -472,11 +478,11 @@ func (coins DecCoins) AmountOf(denom string) math.LegacyDec { switch { case denom < coin.Denom: - return coins[:midIdx].AmountOf(denom) + return coins[:midIdx].AmountOfNoValidation(denom) case denom == coin.Denom: return coin.Amount default: - return coins[midIdx+1:].AmountOf(denom) + return coins[midIdx+1:].AmountOfNoValidation(denom) } } }