From e136e63be2407f445ae425852848b41f9fd72109 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 30 Sep 2021 17:05:23 +0300 Subject: [PATCH] [#125] Add migration Signed-off-by: Denis Kirillov --- nns/nns_contract.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/nns/nns_contract.go b/nns/nns_contract.go index 6a5f4ff..c301db3 100644 --- a/nns/nns_contract.go +++ b/nns/nns_contract.go @@ -88,6 +88,32 @@ func Update(nef []byte, manifest string) { // _deploy initializes defaults (total supply and registration price) on contract deploy. func _deploy(data interface{}, isUpdate bool) { if isUpdate { + ctx := storage.GetContext() + it := storage.Find(ctx, []byte{prefixRecord}, storage.DeserializeValues) + for iterator.Next(it) { + oldRec := iterator.Value(it).(struct { + key string + rec RecordState + }) + newRec := RecordState{ + Name: oldRec.rec.Name, + Type: oldRec.rec.Type, + Data: oldRec.rec.Data, + ID: 0, + } + newKey := append([]byte(oldRec.key), newRec.ID) + rec := std.Serialize(newRec) + storage.Put(ctx, newKey, rec) + storage.Delete(ctx, oldRec.key) + } + + maxExpire := 1<<31 - 1 + domains := storage.Find(ctx, []byte{prefixName}, storage.ValuesOnly|storage.DeserializeValues) + for iterator.Next(domains) { + ns := iterator.Value(domains).(NameState) + putSoaRecord(ctx, ns.Name, "ops@nspcc.ru", 86400, 7200, maxExpire, 3600) + } + return } ctx := storage.GetContext()