[#45] nns: Fix inconsistent fee of register operations

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
Alexey Vanin 2023-10-24 13:17:48 +03:00
parent 3e9d423220
commit 1542e825fe

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.