91 lines
3.0 KiB
Bash
91 lines
3.0 KiB
Bash
#!/bin/bash
|
|
|
|
# RinCoin Wallet Restoration Script
|
|
# Restores a wallet from a dump file on a new RinCoin node.
|
|
# Prerequisites: RinCoin node running, backup file available.
|
|
|
|
set -eo pipefail
|
|
|
|
if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then
|
|
echo "Usage: $0 <path_to_backup_file> [wallet_name]"
|
|
echo "Example: $0 ~/rin_wallet_backups/rin_wallet_backup_20230923.txt"
|
|
echo "Example: $0 ~/rin_wallet_backups/rin_wallet_backup_20230923.txt my_restored_wallet"
|
|
exit 1
|
|
fi
|
|
|
|
BACKUP_FILE="$1"
|
|
NEW_WALLET_NAME="${2:-restored_main}" # Use provided name or default
|
|
|
|
# RPC Configuration
|
|
RPC_USER="rinrpc"
|
|
RPC_PASSWORD="745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"
|
|
RPC_HOST="localhost"
|
|
RPC_PORT="9556"
|
|
|
|
# Verify backup file exists
|
|
if [[ ! -f "$BACKUP_FILE" ]]; then
|
|
echo "Error: Backup file '$BACKUP_FILE' not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if RIN node is running
|
|
if ! pgrep -f "rincoind" > /dev/null; then
|
|
echo "Error: RinCoin daemon is not running. Start it first."
|
|
exit 1
|
|
fi
|
|
|
|
# Copy backup file to daemon's data directory
|
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
|
DAEMON_BACKUP_FILE="/data/restore_backup_${TIMESTAMP}.txt"
|
|
SYSTEM_BACKUP_FILE="/mnt/data/docker_vol/rincoin/rincoin-node/data/restore_backup_${TIMESTAMP}.txt"
|
|
|
|
echo "Copying backup file to daemon directory..."
|
|
cp "$BACKUP_FILE" "$SYSTEM_BACKUP_FILE"
|
|
|
|
echo "Backup file copied to: $DAEMON_BACKUP_FILE"
|
|
|
|
echo "Creating new wallet and importing keys..."
|
|
|
|
# Create a new wallet to avoid conflicts (match original wallet settings)
|
|
CREATE_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"jsonrpc": "2.0", "id": "createwallet", "method": "createwallet", "params": ["'$NEW_WALLET_NAME'", false, true, "", false, false, true]}' \
|
|
"http://$RPC_HOST:$RPC_PORT")
|
|
|
|
if echo "$CREATE_RESPONSE" | grep -q '"error":null'; then
|
|
echo "✓ New wallet '$NEW_WALLET_NAME' created successfully"
|
|
else
|
|
echo "Error creating wallet: $CREATE_RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
# Import the dump file
|
|
echo "Importing wallet from backup file..."
|
|
IMPORT_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"jsonrpc": "2.0", "id": "importwallet", "method": "importwallet", "params": ["'$DAEMON_BACKUP_FILE'"]}' \
|
|
"http://$RPC_HOST:$RPC_PORT/wallet/$NEW_WALLET_NAME")
|
|
|
|
if echo "$IMPORT_RESPONSE" | grep -q '"error":null'; then
|
|
echo "✓ Wallet imported successfully"
|
|
else
|
|
echo "Error importing wallet: $IMPORT_RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
# Clean up
|
|
echo "Cleaning up temporary files..."
|
|
rm -f "$SYSTEM_BACKUP_FILE"
|
|
|
|
echo "✅ Wallet restored successfully!"
|
|
echo "New wallet name: $NEW_WALLET_NAME"
|
|
echo ""
|
|
echo "Verify with:"
|
|
echo "curl -s -u \"$RPC_USER:$RPC_PASSWORD\" -H \"Content-Type: application/json\" -d '{\"jsonrpc\": \"2.0\", \"id\": \"getbalance\", \"method\": \"getbalance\", \"params\": []}' \"http://$RPC_HOST:$RPC_PORT/wallet/$NEW_WALLET_NAME\""
|
|
echo ""
|
|
echo "Or check balance with:"
|
|
echo "./rin/wallet/cmd/check_balance.sh"
|
|
echo ""
|
|
echo "To use this wallet as default, update scripts to use wallet name: $NEW_WALLET_NAME"
|
|
|