#!/bin/bash # Script to list all loaded wallets on the RinCoin node # Usage: ./list_wallets.sh [rpc_user] [rpc_password] [rpc_host] [rpc_port] RPC_USER=${1:-"rinrpc"} RPC_PASSWORD=${2:-"745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"} RPC_HOST=${3:-"localhost"} RPC_PORT=${4:-"9556"} # JSON-RPC request to list wallets RPC_REQUEST='{ "jsonrpc": "2.0", "id": "listwallets", "method": "listwallets", "params": [] }' echo "Listing loaded wallets on RinCoin node..." # Make the RPC call RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \ -H "Content-Type: application/json" \ -d "$RPC_REQUEST" \ "http://$RPC_HOST:$RPC_PORT") # Show raw response for debugging echo "Raw response: $RESPONSE" echo "" # Check for errors (without jq) if echo "$RESPONSE" | grep -q '"error":null'; then echo "No errors in response" # Extract wallet names from the result array # Look for pattern: "result":["wallet1","wallet2"] WALLET_SECTION=$(echo "$RESPONSE" | grep -o '"result":\[[^]]*\]') if [ -n "$WALLET_SECTION" ]; then # Extract wallet names between quotes WALLETS=$(echo "$WALLET_SECTION" | grep -o '"[^"]*"' | grep -v '"result"' | sed 's/"//g') if [ -n "$WALLETS" ]; then echo "Loaded wallets:" echo "$WALLETS" | while read -r wallet; do echo " - $wallet" # Get wallet info WALLET_INFO=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \ -H "Content-Type: application/json" \ -d '{"jsonrpc": "2.0", "id": "getwalletinfo", "method": "getwalletinfo", "params": []}' \ "http://$RPC_HOST:$RPC_PORT/wallet/$wallet") if echo "$WALLET_INFO" | grep -q '"error":null'; then # Extract balance BALANCE=$(echo "$WALLET_INFO" | grep -o '"balance":[0-9.]*' | cut -d: -f2) # Extract address count ADDRESS_COUNT=$(echo "$WALLET_INFO" | grep -o '"txcount":[0-9]*' | cut -d: -f2) echo " Balance: ${BALANCE:-0} RIN" echo " Transactions: ${ADDRESS_COUNT:-0}" # 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 else echo " (Could not retrieve addresses - wallet may be empty)" fi fi echo "" done else echo "No wallets are currently loaded." fi else echo "No wallet result found in response." fi else echo "Error in response: $RESPONSE" fi