Repository: rooch-network/rooch
Pull request #3568: Change init function to mannual execute
Author: login: baichuan3
Created: 2025-04-27T10:00:27Z | Merged: 2025-04-28T02:57:05Z

## Summary

Summary about this PR

- Closes #issue


Diff:
diff --git a/frameworks/framework-release/released/22/0x3/package.rpd b/frameworks/framework-release/released/22/0x3/package.rpd
index bc49b4d6cd..58e36d5cd1 100644
Binary files a/frameworks/framework-release/released/22/0x3/package.rpd and b/frameworks/framework-release/released/22/0x3/package.rpd differ
diff --git a/frameworks/framework-release/released/22/stdlib b/frameworks/framework-release/released/22/stdlib
index 9734bbbc1a..5eb9791b77 100644
Binary files a/frameworks/framework-release/released/22/stdlib and b/frameworks/framework-release/released/22/stdlib differ
diff --git a/frameworks/rooch-framework/doc/coin_migration.md b/frameworks/rooch-framework/doc/coin_migration.md
index ffa6c17039..f6788e0c4b 100644
--- a/frameworks/rooch-framework/doc/coin_migration.md
+++ b/frameworks/rooch-framework/doc/coin_migration.md
@@ -13,6 +13,7 @@ It helps migrate coin stores, balances, frozen states, and accept data.
 -  [Resource `MigrationState`](#0x3_coin_migration_MigrationState)
 -  [Resource `MigrationUpdateCap`](#0x3_coin_migration_MigrationUpdateCap)
 -  [Constants](#@Constants_0)
+-  [Function `initialize_entry`](#0x3_coin_migration_initialize_entry)
 -  [Function `dispatch_cap_entry`](#0x3_coin_migration_dispatch_cap_entry)
 -  [Function `ensure_has_cap`](#0x3_coin_migration_ensure_has_cap)
 -  [Function `cap_address`](#0x3_coin_migration_cap_address)
@@ -120,6 +121,18 @@ Nothing to migrate for the account
 
 
 
+<a name="0x3_coin_migration_initialize_entry"></a>
+
+## Function `initialize_entry`
+
+Initialize the migration module, called after framework upgrade
+
+
+<pre><code><b>public</b> entry <b>fun</b> <a href="coin_migration.md#0x3_coin_migration_initialize_entry">initialize_entry</a>(_account: &<a href="">signer</a>)
+</code></pre>
+
+
+
 <a name="0x3_coin_migration_dispatch_cap_entry"></a>
 
 ## Function `dispatch_cap_entry`
diff --git a/frameworks/rooch-framework/sources/coin_migration.move b/frameworks/rooch-framework/sources/coin_migration.move
index 9f37b9de10..dcbfd5c8d7 100644
--- a/frameworks/rooch-framework/sources/coin_migration.move
+++ b/frameworks/rooch-framework/sources/coin_migration.move
@@ -61,8 +61,12 @@ module rooch_framework::coin_migration {
     /// MigrationUpdateCap is the capability for manager operations, such as update migration state.
     struct MigrationUpdateCap has key, store {}
 
-    /// Initialize the migration module, called during genesis or framework upgrade
-    fun init() {
+    /// Initialize the migration module, called after framework upgrade
+    public entry fun initialize_entry(_account: &signer) {
+        initialize()
+    }
+
+    fun initialize() {
         let migration_state_id = object::named_object_id<MigrationState>();
         if(!object::exists_object(migration_state_id)){
             let migration_state = object::new_named_object(MigrationState{
@@ -210,7 +214,7 @@ module rooch_framework::coin_migration {
     //
     #[test_only]
     public fun init_for_test() {
-        init();
+        initialize();
     }
 
     #[test_only]
diff --git a/scripts/migrate_coin_stores.sh b/scripts/migrate_coin_stores.sh
new file mode 100644
index 0000000000..c9d98bc7d1
--- /dev/null
+++ b/scripts/migrate_coin_stores.sh
@@ -0,0 +1,91 @@
+#!/bin/bash
+# Copyright (c) RoochNetwork
+# SPDX-License-Identifier: Apache-2.0
+
+# Check if the input file is provided
+if [ "$#" -ne 1 ]; then
+    echo "Usage: $0 <path_to_coin_stores_file>"
+    echo "Example: $0 ./scripts/coin_stores_testnet.txt"
+    exit 1
+fi
+
+INPUT_FILE="$1"
+
+# Check if the file exists
+if [ ! -f "$INPUT_FILE" ]; then
+    echo "Error: File $INPUT_FILE does not exist."
+    echo "Please provide the full path to the coin stores file."
+    exit 1
+fi
+
+# Counter for tracking progress
+total_records=$(wc -l < "$INPUT_FILE")
+current=0
+success=0
+failed=0
+
+echo "Processing coin store migrations from $INPUT_FILE"
+echo "Total records to process: $total_records"
+echo "-------------------------------------------"
+
+# Process each line of the file
+while IFS=$'\t' read -r id owner object_type || [[ -n "$id" ]]; do
+    # Skip header or empty lines
+    if [[ "$id" =~ ^[[:space:]]*$ || "$id" == "id" ]]; then
+        continue
+    fi
+
+    # Increment counter
+    ((current++))
+
+    # Extract address and coin type
+    address="$owner"
+
+    # Extract the actual coin type from CoinStore<TYPE> format
+    if [[ "$object_type" =~ CoinStore\<(.*)\> ]]; then
+        coin_type="${BASH_REMATCH[1]}"
+    else
+        echo "Warning: Could not parse coin type from $object_type, skipping..."
+        ((failed++))
+        continue
+    fi
+
+    # Remove any potential whitespace
+    address=$(echo "$address" | tr -d ' ')
+    coin_type=$(echo "$coin_type" | tr -d ' ')
+
+#    # Skip migration for address 0x0 (it's often a placeholder/dummy address)
+#    if [[ "$address" == "0x0" ]]; then
+#        echo "[$current/$total_records] Skipping address 0x0..."
+#        continue
+#    fi
+
+    # Log the command
+    echo "[$current/$total_records] Migrating $coin_type for address $address..."
+
+    # Prepare and execute the migration command
+    migration_cmd="rooch move run --function 0x3::coin_migration::migrate_account_entry --type-args $coin_type --args address:$address --sender default"
+    echo "Executing: $migration_cmd"
+
+    # Execute the command and capture output
+    if output=$(eval "$migration_cmd" 2>&1); then
+        echo "  Success"
+        ((success++))
+    else
+        echo "  Failed: $output"
+        ((failed++))
+    fi
+
+    # Add a separator for readability
+    echo "-------------------------------------------"
+
+    # Optional: add a small delay to prevent overwhelming the system
+    sleep 0.1
+done < "$INPUT_FILE"
+
+# Print summary
+echo "-------------------------------------------"
+echo "Migration completed at $(date)"
+echo "Total records processed: $current"
+echo "Successful migrations: $success"
+echo "Failed migrations: $failed"
\ No newline at end of file


Reviews:
user: login: jolestar
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-28T02:21:34Z
user: login: baichuan3
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-28T02:29:12Z
user: login: jolestar
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-28T02:56:55Z

Review comments:
path: scripts/coin_stores/coin_stores_testnet.txt
user: login: jolestar
body: 这个文件似乎没必要提交上来，很容易过期。
created_at: 2025-04-28T02:21:08Z
author_association: CONTRIBUTOR
path: scripts/coin_stores/coin_stores_testnet.txt
user: login: baichuan3
body: 下个 pr 里再移除
created_at: 2025-04-28T02:29:12Z
author_association: CONTRIBUTOR
path: scripts/coin_stores/coin_stores_testnet.txt
user: login: jolestar
body: 我直接在这个 PR 里删除了。避免让主仓库的历史太大。
created_at: 2025-04-28T02:56:55Z
author_association: CONTRIBUTOR

PR comments:
user: login: vercel[bot]
created_at: 2025-04-27T10:00:32Z
body: [vc]: #rt33BluUys9t50sEMZNizDgLYczF/a2HZFihrGXdsZ0=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJyb29jaCIsInJvb3REaXJlY3RvcnkiOiJkb2NzL3dlYnNpdGUiLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vcm9vY2gvcm9vY2gvM0xCRGFNUTVNYmJ5eHZiNEY1cjZwd3hjRGpXUSIsInByZXZpZXdVcmwiOiJyb29jaC1naXQtY29pbm1pZ3JhdGlvbi1yb29jaC52ZXJjZWwuYXBwIiwibmV4dENvbW1pdFN0YXR1cyI6IklHTk9SRUQiLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoiIn19LHsibmFtZSI6InJvb2NoLXBvcnRhbC12Mi4xIiwicm9vdERpcmVjdG9yeSI6ImluZnJhL3Jvb2NoLXBvcnRhbC12MiIsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9yb29jaC9yb29jaC1wb3J0YWwtdjIuMS84RjFCcWdNajc1TkE5a2Y1dGlEQnNOdlI1elhuIiwicHJldmlld1VybCI6InJvb2NoLXBvcnRhbC12MjEtZ2l0LWNvaW5taWdyYXRpb24tcm9vY2gudmVyY2VsLmFwcCIsIm5leHRDb21taXRTdGF0dXMiOiJERVBMT1lFRCIsImxpdmVGZWVkYmFjayI6eyJyZXNvbHZlZCI6MCwidW5yZXNvbHZlZCI6MCwidG90YWwiOjAsImxpbmsiOiJyb29jaC1wb3J0YWwtdjIxLWdpdC1jb2lubWlncmF0aW9uLXJvb2NoLnZlcmNlbC5hcHAifX0seyJuYW1lIjoidGVzdC1wb3J0YWwiLCJyb290RGlyZWN0b3J5IjoiaW5mcmEvcm9vY2gtcG9ydGFsLXYyIiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL3Jvb2NoL3Rlc3QtcG9ydGFsL0dnVEN5dm9Nc0dHaTJIQXpFNkY4V3NyQlZNcEsiLCJwcmV2aWV3VXJsIjoidGVzdC1wb3J0YWwtZ2l0LWNvaW5taWdyYXRpb24tcm9vY2gudmVyY2VsLmFwcCIsIm5leHRDb21taXRTdGF0dXMiOiJERVBMT1lFRCIsImxpdmVGZWVkYmFjayI6eyJyZXNvbHZlZCI6MCwidW5yZXNvbHZlZCI6MCwidG90YWwiOjAsImxpbmsiOiJ0ZXN0LXBvcnRhbC1naXQtY29pbm1pZ3JhdGlvbi1yb29jaC52ZXJjZWwuYXBwIn19XX0=
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **rooch-portal-v2.1** | ✅ Ready ([Inspect](https://vercel.com/rooch/rooch-portal-v2.1/8F1BqgMj75NA9kf5tiDBsNvR5zXn)) | [Visit Preview](https://rooch-portal-v21-git-coinmigration-rooch.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/rooch-portal-v21-git-coinmigration-rooch.vercel.app?via=pr-comment-feedback-link) | Apr 28, 2025 3:00am |
| **test-portal** | ✅ Ready ([Inspect](https://vercel.com/rooch/test-portal/GgTCyvoMsGGi2HAzE6F8WsrBVMpK)) | [Visit Preview](https://test-portal-git-coinmigration-rooch.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/test-portal-git-coinmigration-rooch.vercel.app?via=pr-comment-feedback-link) | Apr 28, 2025 3:00am |

<details><summary>1 Skipped Deployment</summary>

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **rooch** | ⬜️ Ignored ([Inspect](https://vercel.com/rooch/rooch/3LBDaMQ5Mbbyxvb4F5r6pwxcDjWQ)) | [Visit Preview](https://rooch-git-coinmigration-rooch.vercel.app) |  | Apr 28, 2025 3:00am |
</details>




author_association: NONE
user: login: github-actions[bot]
created_at: 2025-04-27T10:00:46Z
body: <h1>Dependency Review</h1>
✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.<h2>Scanned Files</h2>
None

<!-- dependency-review-pr-comment-marker -->
author_association: NONE