diff --git a/pkg/core/native/native_gas.go b/pkg/core/native/native_gas.go index 000f365d1..08683863a 100644 --- a/pkg/core/native/native_gas.go +++ b/pkg/core/native/native_gas.go @@ -58,7 +58,11 @@ func (g *GAS) increaseBalance(_ *interop.Context, _ util.Uint160, si *state.Stor return errors.New("insufficient funds") } acc.Balance.Add(&acc.Balance, amount) - si.Value = acc.Bytes() + if acc.Balance.Sign() != 0 { + si.Value = acc.Bytes() + } else { + si.Value = nil + } return nil } diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index fcd256137..55c119b3f 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -180,7 +180,11 @@ func (n *NEO) increaseBalance(ic *interop.Context, h util.Uint160, si *state.Sto } } acc.Balance.Add(&acc.Balance, amount) - si.Value = acc.Bytes() + if acc.Balance.Sign() != 0 { + si.Value = acc.Bytes() + } else { + si.Value = nil + } return nil } diff --git a/pkg/core/native/native_nep5.go b/pkg/core/native/native_nep5.go index 597a407e0..a1db0ee7d 100644 --- a/pkg/core/native/native_nep5.go +++ b/pkg/core/native/native_nep5.go @@ -180,7 +180,12 @@ func (c *nep5TokenNative) transfer(ic *interop.Context, from, to util.Uint160, a if err := c.incBalance(ic, from, siFrom, inc); err != nil { return err } - if err := ic.DAO.PutStorageItem(c.ContractID, keyFrom, siFrom); err != nil { + if siFrom.Value == nil { + err = ic.DAO.DeleteStorageItem(c.ContractID, keyFrom) + } else { + err = ic.DAO.PutStorageItem(c.ContractID, keyFrom, siFrom) + } + if err != nil { return err } @@ -193,7 +198,12 @@ func (c *nep5TokenNative) transfer(ic *interop.Context, from, to util.Uint160, a if err := c.incBalance(ic, to, siTo, amount); err != nil { return err } - if err := ic.DAO.PutStorageItem(c.ContractID, keyTo, siTo); err != nil { + if siTo.Value == nil { + err = ic.DAO.DeleteStorageItem(c.ContractID, keyTo) + } else { + err = ic.DAO.PutStorageItem(c.ContractID, keyTo, siTo) + } + if err != nil { return err } }