Fix inconsistent creation fee for free containers #45

Merged
alexvanin merged 1 commit from alexvanin/frostfs-contract:fix/cnr-create-gas/v0.18 into support/v0.18 2024-09-04 19:51:17 +00:00

View file

@ -458,13 +458,13 @@ func updateBalance(ctx storage.Context, tokenId []byte, acc interop.Hash160, dif
balanceKey := append([]byte{prefixBalance}, acc...)
var balance int
if b := storage.Get(ctx, balanceKey); b != nil {
balance = b.(int)
balance = common.FromFixedWidth64(b.([]byte))
}
balance += diff
if balance == 0 {
storage.Delete(ctx, balanceKey)
} else {
storage.Put(ctx, balanceKey, balance)
storage.Put(ctx, balanceKey, common.ToFixedWidth64(balance))
}
tokenKey := getTokenKey(tokenId)
@ -488,14 +488,14 @@ func postTransfer(from, to interop.Hash160, tokenID []byte, data interface{}) {
// getTotalSupply returns total supply from storage.
func getTotalSupply(ctx storage.Context) int {
val := storage.Get(ctx, []byte{prefixTotalSupply})
return val.(int)
return common.FromFixedWidth64(val.([]byte))
}
// updateTotalSupply adds the specified diff to the total supply.
func updateTotalSupply(ctx storage.Context, diff int) {
tsKey := []byte{prefixTotalSupply}
ts := getTotalSupply(ctx)
storage.Put(ctx, tsKey, ts+diff)
storage.Put(ctx, tsKey, common.ToFixedWidth64(ts+diff))
}
// getTokenKey computes hash160 from the given tokenID.