Skip to content

Commit

Permalink
clone key value
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cha committed Oct 31, 2024
1 parent 82a3de4 commit d64d156
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,36 @@ func (app *InitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) {
fmt.Println("3. loading all kvs")

err = app.MoveKeeper.VMStore.Walk(ctx, nil, func(key, value []byte) (stop bool, err error) {
kv := KV{
key: bytes.Clone(key),
value: bytes.Clone(value),
}

cursor := movetypes.AddressBytesLength
if len(key) <= cursor {
return true, fmt.Errorf("invalid key length: %d", len(key))
if len(kv.key) <= cursor {
return true, fmt.Errorf("invalid key length: %d", len(kv.key))
}

separator := key[cursor]
separator := kv.key[cursor]

if separator == movetypes.ModuleSeparator {
identifier, err := vmtypes.BcsDeserializeIdentifier(key[cursor+1:])
identifier, err := vmtypes.BcsDeserializeIdentifier(kv.key[cursor+1:])
if err != nil {
return true, err
}

fmt.Println("module", identifier)

checksum := movetypes.ModuleBzToChecksum(value)
checksum := movetypes.ModuleBzToChecksum(kv.value)
fmt.Println("checksum", hex.EncodeToString(checksum[:]))

value = checksum[:]
kv.value = checksum[:]
} else if separator >= movetypes.TableInfoSeparator {
return true, errors.New("unknown prefix")
} else {
rmKeys = append(rmKeys, key)
rmKeys = append(rmKeys, bytes.Clone(kv.key))
}
key[cursor] = key[cursor] + 1
kvs = append(kvs, KV{
key: bytes.Clone(key),
value: bytes.Clone(value),
})
kv.key[cursor] = kv.key[cursor] + 1
return false, nil
})
if err != nil {
Expand Down

0 comments on commit d64d156

Please sign in to comment.