nns: migrate data from the old version

The old contract was compiled in a such way that `Update` used
all flags except `AllowCall`. Because of this it is impossible to
calculate the key of any record as it requires `Crypto` native contract.
Thus we iterate over all records and transform them into the
serialized representation (`std.Serialize` doesn't work either).
The `Name` field in the resulting structure is empty but this is not a
big deal, `getRecord` continues to work.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-09-15 15:56:43 +03:00 committed by Alex Vanin
parent effa9b3863
commit 978a43cec2

View file

@ -82,6 +82,19 @@ func Update(nef []byte, manifest string) {
// _deploy initializes defaults (total supply and registration price) on contract deploy. // _deploy initializes defaults (total supply and registration price) on contract deploy.
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
if isUpdate { if isUpdate {
ctx := storage.GetContext()
it := storage.Find(ctx, []byte{prefixRecord}, storage.None)
for iterator.Next(it) {
val := iterator.Value(it).([]interface{})
key := val[0].(string)
oldRec := val[1].(string)
newRec := []byte{0x41, 3} // struct with 3 fields
newRec = append(newRec, 0x28, 0) // empty name
newRec = append(newRec, 0x21, 1, byte(TXT)) // 1-byte integer
newRec = append(newRec, 0x28, byte(len(oldRec))) // 1-byte len (40)
newRec = append(newRec, oldRec...)
storage.Put(ctx, key, newRec)
}
return return
} }
ctx := storage.GetContext() ctx := storage.GetContext()