75 lines
2.4 KiB
Bash
75 lines
2.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Script to find if an address belongs to any loaded wallet
|
|
# Usage: ./find_address.sh <address>
|
|
|
|
if [[ $# -ne 1 ]]; then
|
|
echo "Usage: $0 <address>"
|
|
echo "Example: $0 rin1qvj0yyt9phvled9kxflju3p687a4s7kareglpk5"
|
|
exit 1
|
|
fi
|
|
|
|
ADDRESS="$1"
|
|
|
|
# RPC Configuration
|
|
RPC_USER="rinrpc"
|
|
RPC_PASSWORD="745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"
|
|
RPC_HOST="localhost"
|
|
RPC_PORT="9556"
|
|
|
|
echo "Searching for address: $ADDRESS"
|
|
echo ""
|
|
|
|
# First, get list of all loaded wallets
|
|
WALLETS_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"jsonrpc": "2.0", "id": "listwallets", "method": "listwallets", "params": []}' \
|
|
"http://$RPC_HOST:$RPC_PORT")
|
|
|
|
if echo "$WALLETS_RESPONSE" | grep -q '"error":null'; then
|
|
echo "Loaded wallets found. Checking each wallet..."
|
|
|
|
# Extract wallet names (this is a simple approach, may need refinement)
|
|
WALLET_NAMES=$(echo "$WALLETS_RESPONSE" | grep -o '"[^"]*"' | grep -v '"result"' | grep -v '"error"' | grep -v '"id"' | grep -v '"jsonrpc"' | sed 's/"//g')
|
|
|
|
if [ -z "$WALLET_NAMES" ]; then
|
|
echo "No wallets are currently loaded."
|
|
echo "Load a wallet first with: ./rin/wallet/cmd/load_main_wallet.sh"
|
|
exit 1
|
|
fi
|
|
|
|
FOUND=false
|
|
|
|
for wallet in $WALLET_NAMES; do
|
|
echo "Checking wallet: $wallet"
|
|
|
|
# Check if address belongs to this wallet
|
|
VALIDATE_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"jsonrpc": "2.0", "id": "validateaddress", "method": "validateaddress", "params": ["'$ADDRESS'"]}' \
|
|
"http://$RPC_HOST:$RPC_PORT/wallet/$wallet")
|
|
|
|
if echo "$VALIDATE_RESPONSE" | grep -q '"ismine":true'; then
|
|
echo "✓ FOUND! Address belongs to wallet: $wallet"
|
|
FOUND=true
|
|
|
|
# Get more details
|
|
echo "Address details:"
|
|
echo "$VALIDATE_RESPONSE" | grep -E '"isvalid"|"ismine"|"iswatchonly"|"isscript"|"pubkey"|"hdkeypath"'
|
|
echo ""
|
|
fi
|
|
done
|
|
|
|
if [ "$FOUND" = false ]; then
|
|
echo "❌ Address not found in any loaded wallet."
|
|
echo ""
|
|
echo "The address might be:"
|
|
echo "1. In an unloaded wallet"
|
|
echo "2. Not belonging to this node"
|
|
echo "3. From a different wallet backup"
|
|
fi
|
|
|
|
else
|
|
echo "Error getting wallet list: $WALLETS_RESPONSE"
|
|
fi
|