diff --git a/compare_wallets.sh b/compare_wallets.sh new file mode 100644 index 0000000..9bf4846 --- /dev/null +++ b/compare_wallets.sh @@ -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"' diff --git a/debug_addresses.sh b/debug_addresses.sh new file mode 100644 index 0000000..6731a60 --- /dev/null +++ b/debug_addresses.sh @@ -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" diff --git a/debug_wallet_addresses.sh b/debug_wallet_addresses.sh new file mode 100644 index 0000000..d7c4edd --- /dev/null +++ b/debug_wallet_addresses.sh @@ -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" diff --git a/rin/wallet/cmd/README.md b/rin/wallet/cmd/README.md index 496796b..b8e217a 100644 --- a/rin/wallet/cmd/README.md +++ b/rin/wallet/cmd/README.md @@ -60,7 +60,62 @@ General-purpose RPC call script for any RIN RPC method. ./rpc_call.sh getnewaddress myaccount ./rpc_call.sh listtransactions "*" 10 ./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 diff --git a/rin/wallet/cmd/list_wallets.sh b/rin/wallet/cmd/list_wallets.sh index 6c48b5d..99c5a74 100644 --- a/rin/wallet/cmd/list_wallets.sh +++ b/rin/wallet/cmd/list_wallets.sh @@ -60,19 +60,29 @@ if echo "$RESPONSE" | grep -q '"error":null'; then echo " Balance: ${BALANCE:-0} RIN" echo " Transactions: ${ADDRESS_COUNT:-0}" - # Get a few addresses - echo " Sample addresses:" - for i in {1..3}; do - ADDR_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \ - -H "Content-Type: application/json" \ - -d '{"jsonrpc": "2.0", "id": "getnewaddress", "method": "getnewaddress", "params": []}' \ - "http://$RPC_HOST:$RPC_PORT/wallet/$wallet") - - if echo "$ADDR_RESPONSE" | grep -q '"error":null'; then - ADDR=$(echo "$ADDR_RESPONSE" | grep -o '"result":"[^"]*"' | cut -d'"' -f4) - echo " $ADDR" + # Get used addresses + echo " Used addresses:" + ADDRESSES_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \ + -H "Content-Type: application/json" \ + -d '{"jsonrpc": "2.0", "id": "listreceivedbyaddress", "method": "listreceivedbyaddress", "params": [0, true, true]}' \ + "http://$RPC_HOST:$RPC_PORT/wallet/$wallet") + + if echo "$ADDRESSES_RESPONSE" | grep -q '"error":null'; then + # Extract addresses from the response + ADDRESSES=$(echo "$ADDRESSES_RESPONSE" | grep -o '"address":"[^"]*"' | cut -d'"' -f4 | head -5) + + 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 - done + else + echo " (Could not retrieve addresses - wallet may be empty)" + fi fi echo "" done diff --git a/rin/wallet/cmd/restore_from_seed.sh b/rin/wallet/cmd/restore_from_seed.sh index 9a89f49..5f096a9 100644 --- a/rin/wallet/cmd/restore_from_seed.sh +++ b/rin/wallet/cmd/restore_from_seed.sh @@ -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 \"\"" +if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then + echo "Usage: $0 \"\" [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:" diff --git a/rin/wallet/cmd/restore_wallet.sh b/rin/wallet/cmd/restore_wallet.sh index 815de78..8f33417 100644 --- a/rin/wallet/cmd/restore_wallet.sh +++ b/rin/wallet/cmd/restore_wallet.sh @@ -46,11 +46,11 @@ echo "Backup file copied to: $DAEMON_BACKUP_FILE" echo "Creating new wallet and importing keys..." -# Create a new wallet to avoid conflicts -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, false, "", false, false, true]}' \ - "http://$RPC_HOST:$RPC_PORT") + # 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" diff --git a/test_master_key.sh b/test_master_key.sh new file mode 100644 index 0000000..0b2f602 --- /dev/null +++ b/test_master_key.sh @@ -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