native: drop accounts with zero balance
They make no sense. Fixes preview2 testnet state problem: file BlockStorage_100000/dump-block-70000.json: block 69935: state mismatch for key ffffffff1454a6cb279fbcedc66162ad4ad5d1d910202b92743e000000000000000000000005: Deleted vs Added
This commit is contained in:
parent
a77357227a
commit
fccad11716
3 changed files with 22 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue