From 1af1d4c46088f817af3f714251f65b102b40da41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:11:26 +0100 Subject: [PATCH 1/2] fixes --- types/dec_coin.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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) } } } From 9d51df11341e667012714fe4f54673d98bf8d12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Fri, 10 Nov 2023 18:23:57 +0100 Subject: [PATCH 2/2] c++ --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a01a7359e891..5c70948b9c35 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) [#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. * (client) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Add `client.Context{}.WithAddressCodec`, `WithValidatorAddressCodec`, `WithConsensusAddressCodec` to provide address codecs to the client context. See the [UPGRADING.md](./UPGRADING.md) for more details.