@@ -131,34 +131,33 @@ func (k BaseViewKeeper) Logger() log.Logger {
131
131
// GetAllBalances returns all the account balances for the given account address.
132
132
func (k BaseViewKeeper ) GetAllBalances (ctx context.Context , addr sdk.AccAddress ) sdk.Coins {
133
133
balances := sdk .NewCoins ()
134
+ // Prov customization can be removed with a version that has https://github.com/cosmos/cosmos-sdk/pull/24148.
134
135
k .IterateAccountBalances (ctx , addr , func (balance sdk.Coin ) bool {
135
- balances = balances . Add ( balance )
136
+ balances = append ( balances , balance )
136
137
return false
137
138
})
138
139
139
- return balances . Sort ()
140
+ return balances
140
141
}
141
142
142
143
// GetAccountsBalances returns all the accounts balances from the store.
143
144
func (k BaseViewKeeper ) GetAccountsBalances (ctx context.Context ) []types.Balance {
144
145
balances := make ([]types.Balance , 0 )
145
- mapAddressToBalancesIdx := make (map [string ]int )
146
146
147
147
k .IterateAllBalances (ctx , func (addr sdk.AccAddress , balance sdk.Coin ) bool {
148
- idx , ok := mapAddressToBalancesIdx [addr .String ()]
149
- if ok {
150
- // address is already on the set of accounts balances
151
- balances [idx ].Coins = balances [idx ].Coins .Add (balance )
152
- balances [idx ].Coins .Sort ()
148
+ addrStr := addr .String ()
149
+ if len (balances ) > 0 && balances [len (balances )- 1 ].Address == addrStr {
150
+ // Same address as last entry = add the coin to it.
151
+ balances [len (balances )- 1 ].Coins = append (balances [len (balances )- 1 ].Coins , balance )
153
152
return false
154
153
}
155
154
155
+ // New address = new entry.
156
156
accountBalance := types.Balance {
157
- Address : addr . String () ,
157
+ Address : addrStr ,
158
158
Coins : sdk .NewCoins (balance ),
159
159
}
160
160
balances = append (balances , accountBalance )
161
- mapAddressToBalancesIdx [addr .String ()] = len (balances ) - 1
162
161
return false
163
162
})
164
163
0 commit comments