wip walet restore/list/ debug restore
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
|
||||
# RinCoin Wallet Restoration from Master Seed Script
|
||||
# Restores a wallet from just the master private key (xprv...)
|
||||
# Usage: ./restore_from_seed.sh "xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS"
|
||||
# Usage: ./restore_from_seed.sh "xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS" [wallet_name]
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo "Usage: $0 \"<master_private_key>\""
|
||||
if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then
|
||||
echo "Usage: $0 \"<master_private_key>\" [wallet_name]"
|
||||
echo "Example: $0 \"xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS\""
|
||||
echo "Example: $0 \"xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS\" my_restored_wallet"
|
||||
echo ""
|
||||
echo "To get the master key from your backup file:"
|
||||
echo "grep 'extended private masterkey' ~/rin_wallet_backups/rin_wallet_backup_*.txt"
|
||||
@@ -16,8 +17,12 @@ if [[ $# -ne 1 ]]; then
|
||||
fi
|
||||
|
||||
MASTER_KEY="$1"
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
WALLET_NAME="restored_from_seed_${TIMESTAMP}"
|
||||
if [[ $# -eq 2 ]]; then
|
||||
WALLET_NAME="$2"
|
||||
else
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
WALLET_NAME="restored_from_seed_${TIMESTAMP}"
|
||||
fi
|
||||
|
||||
# RPC Configuration
|
||||
RPC_USER="rinrpc"
|
||||
@@ -37,26 +42,25 @@ if ! pgrep -f "rincoind" > /dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Checking if wallet already exists..."
|
||||
echo "Checking if wallet '$WALLET_NAME' already exists..."
|
||||
|
||||
# First try to load existing wallet
|
||||
LOAD_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc": "2.0", "id": "loadwallet", "method": "loadwallet", "params": ["restored_from_seed"]}' \
|
||||
-d '{"jsonrpc": "2.0", "id": "loadwallet", "method": "loadwallet", "params": ["'$WALLET_NAME'"]}' \
|
||||
"http://$RPC_HOST:$RPC_PORT")
|
||||
|
||||
echo "Load response: $LOAD_RESPONSE"
|
||||
|
||||
if echo "$LOAD_RESPONSE" | grep -q '"error":null'; then
|
||||
echo "✓ Existing wallet 'restored_from_seed' loaded successfully"
|
||||
WALLET_NAME="restored_from_seed"
|
||||
echo "✓ Existing wallet '$WALLET_NAME' loaded successfully"
|
||||
else
|
||||
echo "Creating new wallet for seed restoration..."
|
||||
|
||||
# Create a new wallet
|
||||
# Create a new HD wallet (same format as main wallet)
|
||||
CREATE_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc": "2.0", "id": "createwallet", "method": "createwallet", "params": ["'$WALLET_NAME'", false, true, "", false, false, true]}' \
|
||||
-d '{"jsonrpc": "2.0", "id": "createwallet", "method": "createwallet", "params": ["'$WALLET_NAME'", false, false, "", false, false, true]}' \
|
||||
"http://$RPC_HOST:$RPC_PORT")
|
||||
|
||||
if echo "$CREATE_RESPONSE" | grep -q '"error":null'; then
|
||||
@@ -80,10 +84,10 @@ if echo "$IMPORT_RESPONSE" | grep -q '"error":null'; then
|
||||
else
|
||||
echo "Import response: $IMPORT_RESPONSE"
|
||||
|
||||
# Alternative: Try sethdseed with newkeypool=false (don't replace existing keys)
|
||||
# Alternative: Try sethdseed with newkeypool=true (flush old keys and set new seed)
|
||||
SEED_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc": "2.0", "id": "sethdseed", "method": "sethdseed", "params": [false, "'$MASTER_KEY'"]}' \
|
||||
-d '{"jsonrpc": "2.0", "id": "sethdseed", "method": "sethdseed", "params": [true, "'$MASTER_KEY'"]}' \
|
||||
"http://$RPC_HOST:$RPC_PORT/wallet/$WALLET_NAME")
|
||||
|
||||
if echo "$SEED_RESPONSE" | grep -q '"error":null'; then
|
||||
@@ -95,6 +99,19 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# Rescan the blockchain to find existing transactions
|
||||
echo "Rescanning blockchain to find existing transactions..."
|
||||
RESCAN_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc": "2.0", "id": "rescanblockchain", "method": "rescanblockchain", "params": []}' \
|
||||
"http://$RPC_HOST:$RPC_PORT/wallet/$WALLET_NAME")
|
||||
|
||||
if echo "$RESCAN_RESPONSE" | grep -q '"error":null'; then
|
||||
echo "✓ Blockchain rescan completed"
|
||||
else
|
||||
echo "Warning: Blockchain rescan failed or is still in progress: $RESCAN_RESPONSE"
|
||||
fi
|
||||
|
||||
echo "Generating addresses from seed..."
|
||||
|
||||
# Generate some addresses to populate the wallet
|
||||
@@ -116,11 +133,12 @@ echo "✅ Wallet restored from master key successfully!"
|
||||
echo "Wallet name: $WALLET_NAME"
|
||||
echo ""
|
||||
echo "Important notes:"
|
||||
echo "- The wallet will automatically detect transactions as it syncs"
|
||||
echo "- You may need to rescan the blockchain to find old transactions"
|
||||
echo "- Run: ./rin/wallet/cmd/check_balance.sh to see if funds appear"
|
||||
echo "- The wallet has been restored and blockchain rescan has been initiated"
|
||||
echo "- It may take several minutes for the rescan to complete and funds to appear"
|
||||
echo "- Monitor the node logs for rescan progress"
|
||||
echo "- Run: ./rin/wallet/cmd/check_balance.sh to check current balance"
|
||||
echo ""
|
||||
echo "To rescan blockchain (if needed):"
|
||||
echo "To manually trigger rescan again (if needed):"
|
||||
echo "curl -s -u \"$RPC_USER:$RPC_PASSWORD\" -H \"Content-Type: application/json\" -d '{\"jsonrpc\": \"2.0\", \"id\": \"rescanblockchain\", \"method\": \"rescanblockchain\", \"params\": []}' \"http://$RPC_HOST:$RPC_PORT/wallet/$WALLET_NAME\""
|
||||
echo ""
|
||||
echo "Check balance with:"
|
||||
|
||||
Reference in New Issue
Block a user