Skip to content

Commit

Permalink
Collect keys and iterate over keys
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Nov 6, 2023
1 parent d42f94b commit 85057f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions migrations/account_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,36 @@ func (i *AccountStorage) ForEachValue(

iterator := storageMap.Iterator(inter)

for key, value := iterator.Next(); key != nil; key, value = iterator.Next() {
// Read the keys first, so the iteration wouldn't be affected
// by the modification of the storage values.
var keys []string
for key, _ := iterator.Next(); key != nil; key, _ = iterator.Next() {
identifier := string(key.(interpreter.StringAtreeValue))
keys = append(keys, identifier)
}

for _, key := range keys {
storageKey := interpreter.StringStorageMapKey(key)

value := storageMap.ReadValue(nil, storageKey)

newValue, updated := valueConverter(value)
if newValue == nil && !updated {
continue
}

identifier := string(key.(interpreter.StringAtreeValue))

if newValue != nil {
// If the converter returns a new value, then replace the existing value with the new one.
storageMap.SetValue(
inter,
interpreter.StringStorageMapKey(identifier),
storageKey,
newValue,
)
}

reporter.Report(i.address, domain, identifier)
if reporter != nil {
reporter.Report(i.address, domain, key)
}
}
}
}
2 changes: 1 addition & 1 deletion migrations/account_type/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func TestNestedTypeValueMigration(t *testing.T) {
inter,
locationRange,
atree.Address(account),
true,
false,
nil,
nil,
)
Expand Down

0 comments on commit 85057f4

Please sign in to comment.