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