wip walet restore/list/ debug restore

This commit is contained in:
Dobromir Popov
2025-09-29 23:54:32 +03:00
parent 0d34b69fb4
commit fca9d8a8a3
8 changed files with 284 additions and 35 deletions

31
compare_wallets.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
echo "=== Comparing main vs my-wall wallets ==="
echo ""
echo "Main wallet info:"
curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "getwalletinfo", "method": "getwalletinfo", "params": []}' \
"http://localhost:9556/wallet/main" | grep -E '"format"|"keypoololdest"|"hdseedid"|"hdmasterkeyid"|"private_keys_enabled"|"descriptors"' | head -10
echo ""
echo "My-wall wallet info:"
curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "getwalletinfo", "method": "getwalletinfo", "params": []}' \
"http://localhost:9556/wallet/my-wall" | grep -E '"format"|"keypoololdest"|"hdseedid"|"hdmasterkeyid"|"private_keys_enabled"|"descriptors"' | head -10
echo ""
echo "Checking if mining address exists in main wallet:"
curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "validateaddress", "method": "validateaddress", "params": ["rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q"]}' \
"http://localhost:9556/wallet/main" | grep -E '"ismine"|"address"'
echo ""
echo "Checking if mining address exists in my-wall wallet:"
curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "validateaddress", "method": "validateaddress", "params": ["rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q"]}' \
"http://localhost:9556/wallet/my-wall" | grep -E '"ismine"|"address"'

22
debug_addresses.sh Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
echo "Testing address retrieval..."
# Test listreceivedbyaddress
echo "Testing listreceivedbyaddress..."
RESPONSE=$(curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "listreceivedbyaddress", "method": "listreceivedbyaddress", "params": [0, true, true]}' \
"http://localhost:9556/wallet/my-wall")
echo "Response: $RESPONSE"
echo ""
# Test getaddressesbylabel
echo "Testing getaddressesbylabel..."
RESPONSE2=$(curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "getaddressesbylabel", "method": "getaddressesbylabel", "params": [""]}' \
"http://localhost:9556/wallet/my-wall")
echo "Response: $RESPONSE2"

39
debug_wallet_addresses.sh Normal file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
echo "=== Debugging wallet addresses ==="
echo ""
echo "Testing main wallet addresses..."
MAIN_RESPONSE=$(curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "listreceivedbyaddress", "method": "listreceivedbyaddress", "params": [0, true, true]}' \
"http://localhost:9556/wallet/main")
echo "Main wallet raw response:"
echo "$MAIN_RESPONSE"
echo ""
echo "Main wallet parsed addresses:"
echo "$MAIN_RESPONSE" | grep -o '"address":"[^"]*"' | cut -d'"' -f4 | head -10
echo ""
echo "Testing my-wall wallet addresses..."
MYWALL_RESPONSE=$(curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "listreceivedbyaddress", "method": "listreceivedbyaddress", "params": [0, true, true]}' \
"http://localhost:9556/wallet/my-wall")
echo "My-wall wallet raw response:"
echo "$MYWALL_RESPONSE"
echo ""
echo "My-wall wallet parsed addresses:"
echo "$MYWALL_RESPONSE" | grep -o '"address":"[^"]*"' | cut -d'"' -f4 | head -10
echo ""
echo "Checking specific mining address in main wallet..."
MINING_CHECK=$(curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "validateaddress", "method": "validateaddress", "params": ["rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q"]}' \
"http://localhost:9556/wallet/main")
echo "Mining address validation:"
echo "$MINING_CHECK"

View File

@@ -60,7 +60,62 @@ General-purpose RPC call script for any RIN RPC method.
./rpc_call.sh getnewaddress myaccount ./rpc_call.sh getnewaddress myaccount
./rpc_call.sh listtransactions "*" 10 ./rpc_call.sh listtransactions "*" 10
./rpc_call.sh validateaddress rin1qvj0yyt9phvled9kxflju3p687a4s7kareglpk5 ./rpc_call.sh validateaddress rin1qvj0yyt9phvled9kxflju3p687a4s7kareglpk5
./rpc_call.sh loadwallet ./rpc_call.sh loadwallet
```
### list_wallets.sh
List all loaded wallets with balance, transaction count, and used addresses.
```bash
./list_wallets.sh
```
### load_wallet.sh
Load a specific wallet by name.
```bash
./load_wallet.sh main
./load_wallet.sh my-wall
```
### set_web_wallet.sh
Set which wallet the web interface should use.
```bash
./set_web_wallet.sh main
```
### find_address.sh
Check if an address belongs to any loaded wallet.
```bash
./find_address.sh rin1qvj0yyt9phvled9kxflju3p687a4s7kareglpk5
```
### dump_wallet.sh
Create a secure backup of all private keys in a wallet.
```bash
./dump_wallet.sh
```
### restore_wallet.sh
Restore a wallet from a backup dump file.
```bash
./restore_wallet.sh ~/rin_wallet_backups/rin_wallet_backup_20230923.txt
./restore_wallet.sh ~/rin_wallet_backups/rin_wallet_backup_20230923.txt my_restored_wallet
```
### restore_from_seed.sh
Restore a wallet from just the master private key.
```bash
# Auto-generate wallet name
./restore_from_seed.sh "xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS"
# Specify custom wallet name
./restore_from_seed.sh "xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS" my_restored_wallet
``` ```
## Default RPC Configuration ## Default RPC Configuration

View File

@@ -60,19 +60,29 @@ if echo "$RESPONSE" | grep -q '"error":null'; then
echo " Balance: ${BALANCE:-0} RIN" echo " Balance: ${BALANCE:-0} RIN"
echo " Transactions: ${ADDRESS_COUNT:-0}" echo " Transactions: ${ADDRESS_COUNT:-0}"
# Get a few addresses # Get used addresses
echo " Sample addresses:" echo " Used addresses:"
for i in {1..3}; do ADDRESSES_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
ADDR_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \ -H "Content-Type: application/json" \
-H "Content-Type: application/json" \ -d '{"jsonrpc": "2.0", "id": "listreceivedbyaddress", "method": "listreceivedbyaddress", "params": [0, true, true]}' \
-d '{"jsonrpc": "2.0", "id": "getnewaddress", "method": "getnewaddress", "params": []}' \ "http://$RPC_HOST:$RPC_PORT/wallet/$wallet")
"http://$RPC_HOST:$RPC_PORT/wallet/$wallet")
if echo "$ADDRESSES_RESPONSE" | grep -q '"error":null'; then
if echo "$ADDR_RESPONSE" | grep -q '"error":null'; then # Extract addresses from the response
ADDR=$(echo "$ADDR_RESPONSE" | grep -o '"result":"[^"]*"' | cut -d'"' -f4) ADDRESSES=$(echo "$ADDRESSES_RESPONSE" | grep -o '"address":"[^"]*"' | cut -d'"' -f4 | head -5)
echo " $ADDR"
if [ -n "$ADDRESSES" ]; then
echo "$ADDRESSES" | while read -r addr; do
if [ -n "$addr" ]; then
echo " $addr"
fi
done
else
echo " (No used addresses found)"
fi fi
done else
echo " (Could not retrieve addresses - wallet may be empty)"
fi
fi fi
echo "" echo ""
done done

View File

@@ -2,13 +2,14 @@
# RinCoin Wallet Restoration from Master Seed Script # RinCoin Wallet Restoration from Master Seed Script
# Restores a wallet from just the master private key (xprv...) # 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 set -eo pipefail
if [[ $# -ne 1 ]]; then if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then
echo "Usage: $0 \"<master_private_key>\"" echo "Usage: $0 \"<master_private_key>\" [wallet_name]"
echo "Example: $0 \"xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS\"" echo "Example: $0 \"xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS\""
echo "Example: $0 \"xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS\" my_restored_wallet"
echo "" echo ""
echo "To get the master key from your backup file:" echo "To get the master key from your backup file:"
echo "grep 'extended private masterkey' ~/rin_wallet_backups/rin_wallet_backup_*.txt" echo "grep 'extended private masterkey' ~/rin_wallet_backups/rin_wallet_backup_*.txt"
@@ -16,8 +17,12 @@ if [[ $# -ne 1 ]]; then
fi fi
MASTER_KEY="$1" MASTER_KEY="$1"
TIMESTAMP=$(date +%Y%m%d_%H%M%S) if [[ $# -eq 2 ]]; then
WALLET_NAME="restored_from_seed_${TIMESTAMP}" WALLET_NAME="$2"
else
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
WALLET_NAME="restored_from_seed_${TIMESTAMP}"
fi
# RPC Configuration # RPC Configuration
RPC_USER="rinrpc" RPC_USER="rinrpc"
@@ -37,26 +42,25 @@ if ! pgrep -f "rincoind" > /dev/null; then
exit 1 exit 1
fi fi
echo "Checking if wallet already exists..." echo "Checking if wallet '$WALLET_NAME' already exists..."
# First try to load existing wallet # First try to load existing wallet
LOAD_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \ LOAD_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
-H "Content-Type: application/json" \ -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") "http://$RPC_HOST:$RPC_PORT")
echo "Load response: $LOAD_RESPONSE" echo "Load response: $LOAD_RESPONSE"
if echo "$LOAD_RESPONSE" | grep -q '"error":null'; then if echo "$LOAD_RESPONSE" | grep -q '"error":null'; then
echo "✓ Existing wallet 'restored_from_seed' loaded successfully" echo "✓ Existing wallet '$WALLET_NAME' loaded successfully"
WALLET_NAME="restored_from_seed"
else else
echo "Creating new wallet for seed restoration..." 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" \ CREATE_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
-H "Content-Type: application/json" \ -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") "http://$RPC_HOST:$RPC_PORT")
if echo "$CREATE_RESPONSE" | grep -q '"error":null'; then if echo "$CREATE_RESPONSE" | grep -q '"error":null'; then
@@ -80,10 +84,10 @@ if echo "$IMPORT_RESPONSE" | grep -q '"error":null'; then
else else
echo "Import response: $IMPORT_RESPONSE" 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" \ SEED_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
-H "Content-Type: application/json" \ -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") "http://$RPC_HOST:$RPC_PORT/wallet/$WALLET_NAME")
if echo "$SEED_RESPONSE" | grep -q '"error":null'; then if echo "$SEED_RESPONSE" | grep -q '"error":null'; then
@@ -95,6 +99,19 @@ else
fi fi
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..." echo "Generating addresses from seed..."
# Generate some addresses to populate the wallet # Generate some addresses to populate the wallet
@@ -116,11 +133,12 @@ echo "✅ Wallet restored from master key successfully!"
echo "Wallet name: $WALLET_NAME" echo "Wallet name: $WALLET_NAME"
echo "" echo ""
echo "Important notes:" echo "Important notes:"
echo "- The wallet will automatically detect transactions as it syncs" echo "- The wallet has been restored and blockchain rescan has been initiated"
echo "- You may need to rescan the blockchain to find old transactions" echo "- It may take several minutes for the rescan to complete and funds to appear"
echo "- Run: ./rin/wallet/cmd/check_balance.sh to see if funds appear" echo "- Monitor the node logs for rescan progress"
echo "- Run: ./rin/wallet/cmd/check_balance.sh to check current balance"
echo "" 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 "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 ""
echo "Check balance with:" echo "Check balance with:"

View File

@@ -46,11 +46,11 @@ echo "Backup file copied to: $DAEMON_BACKUP_FILE"
echo "Creating new wallet and importing keys..." echo "Creating new wallet and importing keys..."
# Create a new wallet to avoid conflicts # Create a new wallet to avoid conflicts (match original wallet settings)
CREATE_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \ CREATE_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "createwallet", "method": "createwallet", "params": ["'$NEW_WALLET_NAME'", false, false, "", false, false, true]}' \ -d '{"jsonrpc": "2.0", "id": "createwallet", "method": "createwallet", "params": ["'$NEW_WALLET_NAME'", false, true, "", false, false, true]}' \
"http://$RPC_HOST:$RPC_PORT") "http://$RPC_HOST:$RPC_PORT")
if echo "$CREATE_RESPONSE" | grep -q '"error":null'; then if echo "$CREATE_RESPONSE" | grep -q '"error":null'; then
echo "✓ New wallet '$NEW_WALLET_NAME' created successfully" echo "✓ New wallet '$NEW_WALLET_NAME' created successfully"

74
test_master_key.sh Normal file
View File

@@ -0,0 +1,74 @@
#!/bin/bash
# Test if the master key format is valid
MASTER_KEY="xprv9s21ZrQH143K3bjynHVk6hBTZLmV9wjqWScL3UyENBYK6RaFo75zu5jnWQtBi932zKbD7c2WARWLJNjBbE3Td2Cc44ym3dmp343qKKFXwxS"
echo "Testing master key format..."
echo "Key: $MASTER_KEY"
echo ""
# Check basic format
if [[ "$MASTER_KEY" =~ ^xprv[a-zA-Z0-9]+ ]]; then
echo "✓ Basic format is correct (starts with xprv)"
else
echo "✗ Invalid format"
exit 1
fi
# Check length (should be 111 characters for xprv)
LENGTH=${#MASTER_KEY}
echo "Key length: $LENGTH characters"
if [[ $LENGTH -eq 111 ]]; then
echo "✓ Length is correct for extended private key"
else
echo "⚠ Length is $LENGTH, expected 111 for xprv"
fi
echo ""
echo "Testing with a temporary wallet..."
TEMP_WALLET="test_key_wallet_$(date +%s)"
# Create temp wallet
CREATE_RESPONSE=$(curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "createwallet", "method": "createwallet", "params": ["'$TEMP_WALLET'", false, false, "", false, false, true]}' \
"http://localhost:9556")
if echo "$CREATE_RESPONSE" | grep -q '"error":null'; then
echo "✓ Temp wallet created"
# Try to set HD seed
SEED_RESPONSE=$(curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "sethdseed", "method": "sethdseed", "params": [true, "'$MASTER_KEY'"]}' \
"http://localhost:9556/wallet/$TEMP_WALLET")
echo "Seed response: $SEED_RESPONSE"
if echo "$SEED_RESPONSE" | grep -q '"error":null'; then
echo "✓ Master key accepted by sethdseed"
# Generate an address to see if it works
ADDR_RESPONSE=$(curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "getnewaddress", "method": "getnewaddress", "params": []}' \
"http://localhost:9556/wallet/$TEMP_WALLET")
if echo "$ADDR_RESPONSE" | grep -q '"error":null'; then
echo "✓ Address generation works"
else
echo "✗ Address generation failed"
fi
else
echo "✗ Master key rejected by sethdseed"
fi
# Clean up
curl -s -u "rinrpc:745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "unloadwallet", "method": "unloadwallet", "params": ["'$TEMP_WALLET'"]}' \
"http://localhost:9556" > /dev/null
else
echo "✗ Could not create temp wallet"
fi