From 4893faa374655e749d378b0350238a823af88493 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 12 Feb 2021 23:23:24 +0300 Subject: [PATCH] core: remove NEP17BalanceState if balance is null [addTokens] Affects states. --- pkg/core/native/native_nep17.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/core/native/native_nep17.go b/pkg/core/native/native_nep17.go index 7c2a0f1c7..359f65f25 100644 --- a/pkg/core/native/native_nep17.go +++ b/pkg/core/native/native_nep17.go @@ -258,13 +258,19 @@ func (c *nep17TokenNative) addTokens(ic *interop.Context, h util.Uint160, amount if err := c.incBalance(ic, h, si, amount); err != nil { panic(err) } - if err := ic.DAO.PutStorageItem(c.ID, key, si); err != nil { + var err error + if si.Value == nil { + err = ic.DAO.DeleteStorageItem(c.ID, key) + } else { + err = ic.DAO.PutStorageItem(c.ID, key, si) + } + if err != nil { panic(err) } supply := c.getTotalSupply(ic.DAO) supply.Add(supply, amount) - err := c.saveTotalSupply(ic.DAO, supply) + err = c.saveTotalSupply(ic.DAO, supply) if err != nil { panic(err) }