Merge pull request #2599 from nspcc-dev/nns-cleanup

nft-nd-nns: clean up old entries on re-registration, fix #2570
This commit is contained in:
Roman Khimov 2022-07-14 11:45:16 +03:00 committed by GitHub
commit 54849ef3e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -265,6 +265,10 @@ func Register(name string, owner interop.Hash160) bool {
} }
oldOwner = ns.Owner oldOwner = ns.Owner
updateBalance(ctx, []byte(name), oldOwner, -1) updateBalance(ctx, []byte(name), oldOwner, -1)
it := storage.Find(ctx, append([]byte{prefixRecord}, tokenKey...), storage.KeysOnly)
for iterator.Next(it) {
storage.Delete(ctx, iterator.Value(it))
}
} else { } else {
updateTotalSupply(ctx, +1) updateTotalSupply(ctx, +1)
} }

View file

@ -132,6 +132,9 @@ func TestExpiration(t *testing.T) {
b5.Timestamp = b4.Timestamp + 1000 b5.Timestamp = b4.Timestamp + 1000
require.NoError(t, bc.AddBlock(e.SignBlock(b5))) require.NoError(t, bc.AddBlock(e.SignBlock(b5)))
e.CheckFault(t, tx.Hash(), "name has expired") e.CheckFault(t, tx.Hash(), "name has expired")
cAcc.Invoke(t, true, "register", "first.com", acc.ScriptHash()) // Re-register.
cAcc.Invoke(t, stackitem.Null{}, "resolve", "first.com", int64(nns.TXT))
} }
const millisecondsInYear = 365 * 24 * 3600 * 1000 const millisecondsInYear = 365 * 24 * 3600 * 1000