43 lines
1.1 KiB
Bash
43 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
# Script to check RIN wallet balance
|
|
# Usage: ./check_balance.sh [account] [rpc_user] [rpc_password] [rpc_host] [rpc_port]
|
|
|
|
ACCOUNT=${1:-"*"} # Default to all accounts
|
|
RPC_USER=${2:-"rinrpc"}
|
|
RPC_PASSWORD=${3:-"745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"}
|
|
RPC_HOST=${4:-"localhost"}
|
|
RPC_PORT=${5:-"9556"}
|
|
|
|
# JSON-RPC request for getbalance
|
|
RPC_REQUEST='{
|
|
"jsonrpc": "2.0",
|
|
"id": "getbalance",
|
|
"method": "getbalance",
|
|
"params": ["'"$ACCOUNT"'"]
|
|
}'
|
|
|
|
echo "Checking RIN wallet balance..."
|
|
|
|
# Make the RPC call to wallet-specific endpoint
|
|
RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$RPC_REQUEST" \
|
|
"http://$RPC_HOST:$RPC_PORT/wallet/main")
|
|
|
|
# Check for errors
|
|
ERROR=$(echo "$RESPONSE" | jq -r '.error' 2>/dev/null)
|
|
if [ "$ERROR" != "null" ] && [ -n "$ERROR" ]; then
|
|
echo "Error: $(echo "$ERROR" | jq -r '.message')"
|
|
exit 1
|
|
fi
|
|
|
|
# Get balance
|
|
BALANCE=$(echo "$RESPONSE" | jq -r '.result' 2>/dev/null)
|
|
if [ "$BALANCE" != "null" ] && [ -n "$BALANCE" ]; then
|
|
echo "Wallet balance: $BALANCE RIN"
|
|
else
|
|
echo "Unexpected response: $RESPONSE"
|
|
exit 1
|
|
fi
|