getMessage() . "\n"); } // --- Fetch All Users --- $users = $db->getAllUsers(); if (empty($users)) { die("ā„¹ļø No users found in the database. Nothing to do.\n"); } $totalUsers = count($users); echo "āœ… Found {$totalUsers} users to update.\n\n"; // --- Migration Loop --- $successCount = 0; foreach ($users as $index => $user) { $userId = $user['id']; $oldAddress = $user['salvium_subaddress']; echo "Updating user #{$userId} (" . ($index + 1) . "/{$totalUsers})... "; // 1. Generate new address $newAddress = $wallet->getNewSubaddress(); if (!$newAddress || !str_starts_with($newAddress, 'SC1')) { echo "āŒ FAILED: Could not generate a valid new address from the wallet RPC.\n"; continue; // Skip to the next user } // 2. Update the database if ($db->updateUserSubaddress($userId, $newAddress)) { echo "āœ… SUCCESS: New address assigned.\n"; // Optional: uncomment the line below for detailed logging // echo " - Old: {$oldAddress}\n - New: {$newAddress}\n"; $successCount++; } else { echo "āŒ FAILED: Database update failed for user #{$userId}.\n"; } } // --- Final Report --- echo "\n============================================\n"; echo "šŸŽ‰ Migration Complete!\n"; echo "Successfully updated: {$successCount} / {$totalUsers} users.\n"; echo "============================================\n"; ?>