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

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
pull/46/head
Alexey Vanin 2023-10-24 13:17:48 +03:00
parent 184fcdc5a7
commit 5124555f05
1 changed files with 4 additions and 4 deletions

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.