From cfa156577209e2a32fe37184106b10fea4264519 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 30 Dec 2024 17:49:09 +0800 Subject: [PATCH] Problem: negative coin amount error when query supply liquid of non BaseCoinUnit --- CHANGELOG.md | 1 + x/supply/keeper/keeper.go | 8 ++++++-- x/supply/types/expected_keepers.go | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee1ea37ad..3f6891c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - [#1088](https://github.com/crypto-org-chain/chain-main/pull/1088) Upgrade solomachine to `v0.1.4` and ibc-go to `v8.5.1`. * [#1091](https://github.com/crypto-org-chain/chain-main/pull/1091) Update cometbft to `0.38.13`, sdk to `v0.50.10` and memiavl to latest. - [#1091](https://github.com/crypto-org-chain/chain-main/pull/1091) Upgrade cometbft to v0.38.13, cosmos-sdk to `v0.50.10`. +- [#1097](https://github.com/crypto-org-chain/chain-main/pull/1097) Avoid negative coin amount error when query supply liquid of non BaseCoinUnit. *Dec 6, 2023* diff --git a/x/supply/keeper/keeper.go b/x/supply/keeper/keeper.go index 1db991f33..6175d798d 100644 --- a/x/supply/keeper/keeper.go +++ b/x/supply/keeper/keeper.go @@ -6,7 +6,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/crypto-org-chain/chain-main/v4/config" "github.com/crypto-org-chain/chain-main/v4/x/supply/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -92,7 +91,12 @@ func (k Keeper) GetVestingAccounts(ctx sdk.Context) types.VestingAccounts { // GetTotalSupply returns the current total supply in the system func (k Keeper) GetTotalSupply(ctx sdk.Context) sdk.Coins { - return sdk.NewCoins(k.bankKeeper.GetSupply(ctx, config.BaseCoinUnit)) + var totalSupply sdk.Coins + k.bankKeeper.IterateTotalSupply(ctx, func(coin sdk.Coin) bool { + totalSupply = totalSupply.Add(coin) + return false + }) + return totalSupply } // GetUnvestedSupply returns total unvested supply diff --git a/x/supply/types/expected_keepers.go b/x/supply/types/expected_keepers.go index 9202b4ee1..a51487364 100644 --- a/x/supply/types/expected_keepers.go +++ b/x/supply/types/expected_keepers.go @@ -11,6 +11,7 @@ import ( type BankKeeper interface { GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins GetSupply(ctx context.Context, denom string) sdk.Coin + IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool) LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins }