@@ -175,39 +175,14 @@ func (k BaseKeeper) GetSupply(ctx sdk.Context, denom string) sdk.Coin {
175
175
}
176
176
}
177
177
178
- var coin sdk.Coin
179
- err := k .cdc .UnmarshalBinaryBare (bz , & coin )
180
- if err != nil {
181
- panic (err )
178
+ amount , ok := sdk .NewIntFromString (string (bz ))
179
+ if ! ok {
180
+ panic ("unexpected supply" )
182
181
}
183
182
184
- return coin
185
- }
186
-
187
- // SetSupply sets the Supply to store
188
- func (k BaseKeeper ) setSupply (ctx sdk.Context , supply sdk.Coins ) {
189
- store := ctx .KVStore (k .storeKey )
190
- supplyStore := prefix .NewStore (store , types .SupplyKey )
191
-
192
- var newSupply []sdk.Coin
193
- storeSupply := k .GetTotalSupply (ctx )
194
-
195
- // update supply for coins which have non zero amount
196
- for _ , coin := range storeSupply {
197
- if supply .AmountOf (coin .Denom ).IsZero () {
198
- zeroCoin := & sdk.Coin {
199
- Denom : coin .Denom ,
200
- Amount : sdk .NewInt (0 ),
201
- }
202
- bz := k .cdc .MustMarshalBinaryBare (zeroCoin )
203
- supplyStore .Set ([]byte (coin .Denom ), bz )
204
- }
205
- }
206
- newSupply = append (newSupply , supply ... )
207
-
208
- for i := range newSupply {
209
- bz := k .cdc .MustMarshalBinaryBare (& supply [i ])
210
- supplyStore .Set ([]byte (supply [i ].Denom ), bz )
183
+ return sdk.Coin {
184
+ Denom : denom ,
185
+ Amount : amount ,
211
186
}
212
187
}
213
188
@@ -359,7 +334,7 @@ func (k BaseKeeper) UndelegateCoinsFromModuleToAccount(
359
334
360
335
// MintCoins creates new coins from thin air and adds it to the module account.
361
336
// It will panic if the module account does not exist or is unauthorized.
362
- func (k BaseKeeper ) MintCoins (ctx sdk.Context , moduleName string , amt sdk.Coins ) error {
337
+ func (k BaseKeeper ) MintCoins (ctx sdk.Context , moduleName string , amounts sdk.Coins ) error {
363
338
acc := k .ak .GetModuleAccount (ctx , moduleName )
364
339
if acc == nil {
365
340
panic (sdkerrors .Wrapf (sdkerrors .ErrUnknownAddress , "module account %s does not exist" , moduleName ))
@@ -369,31 +344,31 @@ func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins)
369
344
panic (sdkerrors .Wrapf (sdkerrors .ErrUnauthorized , "module account %s does not have permissions to mint tokens" , moduleName ))
370
345
}
371
346
372
- err := k .addCoins (ctx , acc .GetAddress (), amt )
347
+ err := k .addCoins (ctx , acc .GetAddress (), amounts )
373
348
if err != nil {
374
349
return err
375
350
}
376
351
377
- // update total supply
378
- supply := k .GetTotalSupply (ctx )
379
- supply = supply .Add (amt ... )
380
-
381
- k . setSupply ( ctx , supply )
352
+ for _ , amount := range amounts {
353
+ supply := k .GetSupply (ctx , amount . GetDenom () )
354
+ supply = supply .Add (amount )
355
+ k . setSupply ( ctx , supply )
356
+ }
382
357
383
358
logger := k .Logger (ctx )
384
- logger .Info ("minted coins from module account" , "amount" , amt .String (), "from" , moduleName )
359
+ logger .Info ("minted coins from module account" , "amount" , amounts .String (), "from" , moduleName )
385
360
386
361
// emit mint event
387
362
ctx .EventManager ().EmitEvent (
388
- types .NewCoinMintEvent (acc .GetAddress (), amt ),
363
+ types .NewCoinMintEvent (acc .GetAddress (), amounts ),
389
364
)
390
365
391
366
return nil
392
367
}
393
368
394
369
// BurnCoins burns coins deletes coins from the balance of the module account.
395
370
// It will panic if the module account does not exist or is unauthorized.
396
- func (k BaseKeeper ) BurnCoins (ctx sdk.Context , moduleName string , amt sdk.Coins ) error {
371
+ func (k BaseKeeper ) BurnCoins (ctx sdk.Context , moduleName string , amounts sdk.Coins ) error {
397
372
acc := k .ak .GetModuleAccount (ctx , moduleName )
398
373
if acc == nil {
399
374
panic (sdkerrors .Wrapf (sdkerrors .ErrUnknownAddress , "module account %s does not exist" , moduleName ))
@@ -403,28 +378,35 @@ func (k BaseKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins)
403
378
panic (sdkerrors .Wrapf (sdkerrors .ErrUnauthorized , "module account %s does not have permissions to burn tokens" , moduleName ))
404
379
}
405
380
406
- err := k .subUnlockedCoins (ctx , acc .GetAddress (), amt )
381
+ err := k .subUnlockedCoins (ctx , acc .GetAddress (), amounts )
407
382
if err != nil {
408
383
return err
409
384
}
410
385
411
- // update total supply
412
- supply := k .GetTotalSupply (ctx )
413
- supply = supply .Sub (amt )
414
-
415
- k . setSupply ( ctx , supply )
386
+ for _ , amount := range amounts {
387
+ supply := k .GetSupply (ctx , amount . GetDenom () )
388
+ supply = supply .Sub (amount )
389
+ k . setSupply ( ctx , supply )
390
+ }
416
391
417
392
logger := k .Logger (ctx )
418
- logger .Info ("burned tokens from module account" , "amount" , amt .String (), "from" , moduleName )
393
+ logger .Info ("burned tokens from module account" , "amount" , amounts .String (), "from" , moduleName )
419
394
420
395
// emit burn event
421
396
ctx .EventManager ().EmitEvent (
422
- types .NewCoinBurnEvent (acc .GetAddress (), amt ),
397
+ types .NewCoinBurnEvent (acc .GetAddress (), amounts ),
423
398
)
424
399
425
400
return nil
426
401
}
427
402
403
+ func (k BaseKeeper ) setSupply (ctx sdk.Context , coin sdk.Coin ) {
404
+ store := ctx .KVStore (k .storeKey )
405
+ supplyStore := prefix .NewStore (store , types .SupplyKey )
406
+
407
+ supplyStore .Set ([]byte (coin .GetDenom ()), []byte (coin .Amount .String ()))
408
+ }
409
+
428
410
func (k BaseKeeper ) trackDelegation (ctx sdk.Context , addr sdk.AccAddress , balance , amt sdk.Coins ) error {
429
411
acc := k .ak .GetAccount (ctx , addr )
430
412
if acc == nil {
@@ -463,8 +445,15 @@ func (k BaseViewKeeper) IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bo
463
445
defer iterator .Close ()
464
446
465
447
for ; iterator .Valid (); iterator .Next () {
466
- var balance sdk.Coin
467
- k .cdc .MustUnmarshalBinaryBare (iterator .Value (), & balance )
448
+ amount , ok := sdk .NewIntFromString (string (iterator .Value ()))
449
+ if ! ok {
450
+ panic ("unexpected supply" )
451
+ }
452
+
453
+ balance := sdk.Coin {
454
+ Denom : string (iterator .Key ()),
455
+ Amount : amount ,
456
+ }
468
457
469
458
if cb (balance ) {
470
459
break
0 commit comments