From 5593d51d1aced9b7d5b07785bec098779ffa2776 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 8 Nov 2021 13:55:50 +0300 Subject: [PATCH] examples: adjust NEP17 and token-sale examples Do not store zero receiver balance in the contract storage. --- examples/token-sale/token_sale.go | 4 +++- examples/token/nep17/nep17.go | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/token-sale/token_sale.go b/examples/token-sale/token_sale.go index f0f66ecf7..8593e9a04 100644 --- a/examples/token-sale/token_sale.go +++ b/examples/token-sale/token_sale.go @@ -186,7 +186,9 @@ func Transfer(from, to interop.Hash160, amount int, _ interface{}) bool { } amountTo := getIntFromDB(ctx, to) totalAmountTo := amountTo + amount - storage.Put(ctx, to, totalAmountTo) + if totalAmountTo != 0 { + storage.Put(ctx, to, totalAmountTo) + } return true } diff --git a/examples/token/nep17/nep17.go b/examples/token/nep17/nep17.go index b52bcd05b..280384bef 100644 --- a/examples/token/nep17/nep17.go +++ b/examples/token/nep17/nep17.go @@ -64,7 +64,10 @@ func (t Token) Transfer(ctx storage.Context, from, to interop.Hash160, amount in amountTo := getIntFromDB(ctx, to) totalAmountTo := amountTo + amount - storage.Put(ctx, to, totalAmountTo) + if totalAmountTo != 0 { + storage.Put(ctx, to, totalAmountTo) + } + runtime.Notify("Transfer", from, to, amount) if to != nil && management.GetContract(to) != nil { contract.Call(to, "onNEP17Payment", contract.All, from, amount, data)