examples: adjust NEP17 and token-sale examples

Do not store zero receiver balance in the contract storage.
This commit is contained in:
Anna Shaleva 2021-11-08 13:55:50 +03:00
parent 5e08ef79fa
commit 5593d51d1a
2 changed files with 7 additions and 2 deletions

View file

@ -186,7 +186,9 @@ func Transfer(from, to interop.Hash160, amount int, _ interface{}) bool {
} }
amountTo := getIntFromDB(ctx, to) amountTo := getIntFromDB(ctx, to)
totalAmountTo := amountTo + amount totalAmountTo := amountTo + amount
storage.Put(ctx, to, totalAmountTo) if totalAmountTo != 0 {
storage.Put(ctx, to, totalAmountTo)
}
return true return true
} }

View file

@ -64,7 +64,10 @@ func (t Token) Transfer(ctx storage.Context, from, to interop.Hash160, amount in
amountTo := getIntFromDB(ctx, to) amountTo := getIntFromDB(ctx, to)
totalAmountTo := amountTo + amount totalAmountTo := amountTo + amount
storage.Put(ctx, to, totalAmountTo) if totalAmountTo != 0 {
storage.Put(ctx, to, totalAmountTo)
}
runtime.Notify("Transfer", from, to, amount) runtime.Notify("Transfer", from, to, amount)
if to != nil && management.GetContract(to) != nil { if to != nil && management.GetContract(to) != nil {
contract.Call(to, "onNEP17Payment", contract.All, from, amount, data) contract.Call(to, "onNEP17Payment", contract.All, from, amount, data)