Files
mines/rin/wallet/cmd/list_wallets.sh
2025-09-29 23:32:59 +03:00

89 lines
3.2 KiB
Bash

#!/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 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"
fi
done
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