code moved from scripts repo;
dump works
This commit is contained in:
91
rin/wallet/cmd/README.md
Normal file
91
rin/wallet/cmd/README.md
Normal file
@@ -0,0 +1,91 @@
|
||||
# RIN Wallet RPC Scripts
|
||||
|
||||
This directory contains scripts for interacting with the RIN cryptocurrency wallet via RPC.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- `curl` and `jq` must be installed on your system
|
||||
- RIN wallet/node must be running with RPC enabled
|
||||
- RPC credentials must be configured
|
||||
|
||||
## Scripts
|
||||
|
||||
### send_rin.sh
|
||||
Send RIN to another wallet address.
|
||||
|
||||
```bash
|
||||
./send_rin.sh <recipient_address> <amount> [rpc_user] [rpc_password] [rpc_host] [rpc_port]
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
./send_rin.sh rin1qvj0yyt9phvled9kxflju3p687a4s7kareglpk5 100.0
|
||||
```
|
||||
|
||||
### check_balance.sh
|
||||
Check wallet balance.
|
||||
|
||||
```bash
|
||||
./check_balance.sh [account] [rpc_user] [rpc_password] [rpc_host] [rpc_port]
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
./check_balance.sh # Check all accounts
|
||||
./check_balance.sh myaccount # Check specific account
|
||||
```
|
||||
|
||||
### get_transaction.sh
|
||||
Get details of a specific transaction.
|
||||
|
||||
```bash
|
||||
./get_transaction.sh <transaction_id> [rpc_user] [rpc_password] [rpc_host] [rpc_port]
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
./get_transaction.sh a1b2c3d4e5f6...
|
||||
```
|
||||
|
||||
### rpc_call.sh
|
||||
General-purpose RPC call script for any RIN RPC method.
|
||||
|
||||
```bash
|
||||
./rpc_call.sh <method> [param1] [param2] ... [rpc_user] [rpc_password] [rpc_host] [rpc_port]
|
||||
```
|
||||
|
||||
**Examples:**
|
||||
```bash
|
||||
./rpc_call.sh getinfo
|
||||
./rpc_call.sh getnewaddress myaccount
|
||||
./rpc_call.sh listtransactions "*" 10
|
||||
./rpc_call.sh validateaddress rin1qvj0yyt9phvled9kxflju3p687a4s7kareglpk5
|
||||
./rpc_call.sh loadwallet
|
||||
```
|
||||
|
||||
## Default RPC Configuration
|
||||
|
||||
- **Host:** localhost
|
||||
- **Port:** 8332
|
||||
- **User:** rinrpc
|
||||
- **Password:** password
|
||||
|
||||
You can override these defaults by providing them as the last arguments to any script.
|
||||
|
||||
## Common RPC Methods
|
||||
|
||||
- `getbalance [account]` - Get account balance
|
||||
- `getinfo` - Get wallet info
|
||||
- `getnewaddress [account]` - Generate new address
|
||||
- `sendtoaddress <address> <amount>` - Send coins
|
||||
- `listtransactions [account] [count]` - List transactions
|
||||
- `gettransaction <txid>` - Get transaction details
|
||||
- `validateaddress <address>` - Validate address
|
||||
- `getaddressesbyaccount [account]` - Get addresses for account
|
||||
|
||||
## Security Notes
|
||||
|
||||
- These scripts send credentials in plain text (HTTP Basic Auth)
|
||||
- Consider using HTTPS or local connections only
|
||||
- Update default RPC credentials for production use
|
||||
- Store scripts securely and avoid hardcoding sensitive information
|
||||
42
rin/wallet/cmd/check_balance.sh
Normal file
42
rin/wallet/cmd/check_balance.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/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
|
||||
50
rin/wallet/cmd/create_wallet.sh
Normal file
50
rin/wallet/cmd/create_wallet.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to create a new wallet on the RinCoin node
|
||||
# Usage: ./create_wallet.sh <wallet_name> [rpc_user] [rpc_password] [rpc_host] [rpc_port]
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 <wallet_name> [rpc_user] [rpc_password] [rpc_host] [rpc_port]"
|
||||
echo "Example: $0 main"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
WALLET_NAME=$1
|
||||
RPC_USER=${2:-"rinrpc"}
|
||||
RPC_PASSWORD=${3:-"745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"}
|
||||
RPC_HOST=${4:-"localhost"}
|
||||
RPC_PORT=${5:-"9556"}
|
||||
|
||||
# JSON-RPC request to create wallet
|
||||
RPC_REQUEST='{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "createwallet",
|
||||
"method": "createwallet",
|
||||
"params": ["'"$WALLET_NAME"'", false, false, "", false, false, true]
|
||||
}'
|
||||
|
||||
echo "Creating wallet '$WALLET_NAME' 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")
|
||||
|
||||
# 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 result
|
||||
RESULT=$(echo "$RESPONSE" | jq -r '.result' 2>/dev/null)
|
||||
if [ "$RESULT" != "null" ]; then
|
||||
echo "Wallet '$WALLET_NAME' created successfully!"
|
||||
echo "Result: $RESULT"
|
||||
else
|
||||
echo "Unexpected response: $RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
98
rin/wallet/cmd/dump_wallet.sh
Normal file
98
rin/wallet/cmd/dump_wallet.sh
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/bin/bash
|
||||
|
||||
# RinCoin Wallet Backup Script
|
||||
# Dumps all private keys to a secure text file for backup.
|
||||
# WARNING: This file contains sensitive private keys. Store it securely (encrypted, offline).
|
||||
# Do not share or email it. Anyone with this file can spend your coins.
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
# Configuration
|
||||
WALLET="main"
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
# Path as seen by the RIN daemon (relative to its /data directory)
|
||||
DAEMON_BACKUP_FILE="/data/rin_wallet_backup_${TIMESTAMP}.txt"
|
||||
# Actual system path where the file will be created
|
||||
SYSTEM_BACKUP_FILE="/mnt/data/docker_vol/rincoin/rincoin-node/data/rin_wallet_backup_${TIMESTAMP}.txt"
|
||||
|
||||
# RPC Configuration
|
||||
RPC_USER="rinrpc"
|
||||
RPC_PASSWORD="745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"
|
||||
RPC_HOST="localhost"
|
||||
RPC_PORT="9556"
|
||||
|
||||
# No need to create directory - daemon writes to its own /data
|
||||
|
||||
# Check if RIN node is running
|
||||
if ! pgrep -f "rincoind" > /dev/null; then
|
||||
echo "Error: RinCoin daemon is not running. Start it first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure wallet is loaded
|
||||
echo "Checking if wallet '${WALLET}' is loaded..."
|
||||
LIST_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 "$LIST_WALLETS_RESPONSE" | grep -q '"main"'; then
|
||||
echo "Wallet '${WALLET}' not loaded. Attempting to load..."
|
||||
LOAD_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc": "2.0", "id": "loadwallet", "method": "loadwallet", "params": ["'$WALLET'"]}' \
|
||||
"http://$RPC_HOST:$RPC_PORT")
|
||||
|
||||
if echo "$LOAD_RESPONSE" | grep -q '"error"'; then
|
||||
echo "Failed to load wallet. Response: $LOAD_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Dumping wallet to: $DAEMON_BACKUP_FILE"
|
||||
echo "This may take a moment..."
|
||||
|
||||
# Dump wallet using RPC (use daemon's path)
|
||||
DUMP_RESPONSE=$(curl -s -u "$RPC_USER:$RPC_PASSWORD" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc": "2.0", "id": "dumpwallet", "method": "dumpwallet", "params": ["'$DAEMON_BACKUP_FILE'"]}' \
|
||||
"http://$RPC_HOST:$RPC_PORT/wallet/$WALLET")
|
||||
|
||||
# Check for errors in dump response
|
||||
if echo "$DUMP_RESPONSE" | grep -q '"error":null'; then
|
||||
echo "✓ Wallet dump successful"
|
||||
else
|
||||
echo "Error dumping wallet: $DUMP_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify the file was created and has content (check system path)
|
||||
if [[ ! -f "$SYSTEM_BACKUP_FILE" ]]; then
|
||||
echo "Error: Backup file was not created at $SYSTEM_BACKUP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LINE_COUNT=$(wc -l < "$SYSTEM_BACKUP_FILE")
|
||||
if [[ $LINE_COUNT -lt 10 ]]; then
|
||||
echo "Warning: Backup file seems too small (${LINE_COUNT} lines). Check for errors."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copy backup to user's home directory for easy access
|
||||
USER_BACKUP_DIR="${HOME}/rin_wallet_backups"
|
||||
mkdir -p "$USER_BACKUP_DIR"
|
||||
USER_BACKUP_FILE="${USER_BACKUP_DIR}/rin_wallet_backup_${TIMESTAMP}.txt"
|
||||
cp "$SYSTEM_BACKUP_FILE" "$USER_BACKUP_FILE"
|
||||
|
||||
echo "✅ Wallet successfully backed up to: $USER_BACKUP_FILE"
|
||||
echo ""
|
||||
echo "🔐 SECURITY REMINDERS:"
|
||||
echo " - This file contains private keys for ALL addresses in the wallet."
|
||||
echo " - Encrypt it immediately: gpg -c $USER_BACKUP_FILE"
|
||||
echo " - Store on encrypted media (e.g., USB drive in safe)."
|
||||
echo " - Delete the unencrypted file after encryption."
|
||||
echo " - Test restoration on a testnet node before relying on it."
|
||||
echo ""
|
||||
echo "File size: $(du -h "$USER_BACKUP_FILE" | cut -f1)"
|
||||
echo "Lines: $LINE_COUNT"
|
||||
|
||||
49
rin/wallet/cmd/get_transaction.sh
Normal file
49
rin/wallet/cmd/get_transaction.sh
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to get RIN transaction details
|
||||
# Usage: ./get_transaction.sh <txid> [rpc_user] [rpc_password] [rpc_host] [rpc_port]
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 <transaction_id> [rpc_user] [rpc_password] [rpc_host] [rpc_port]"
|
||||
echo "Example: $0 a1b2c3d4... user password localhost 8332"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TXID=$1
|
||||
RPC_USER=${2:-"rinrpc"}
|
||||
RPC_PASSWORD=${3:-"password"}
|
||||
RPC_HOST=${4:-"localhost"}
|
||||
RPC_PORT=${5:-"8332"}
|
||||
|
||||
# JSON-RPC request
|
||||
RPC_REQUEST='{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "gettransaction",
|
||||
"method": "gettransaction",
|
||||
"params": ["'"$TXID"'"]
|
||||
}'
|
||||
|
||||
echo "Getting transaction details for: $TXID"
|
||||
|
||||
# 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")
|
||||
|
||||
# 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
|
||||
|
||||
# Display transaction details
|
||||
RESULT=$(echo "$RESPONSE" | jq -r '.result' 2>/dev/null)
|
||||
if [ "$RESULT" != "null" ]; then
|
||||
echo "Transaction Details:"
|
||||
echo "$RESPONSE" | jq '.result'
|
||||
else
|
||||
echo "Unexpected response: $RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
44
rin/wallet/cmd/list_wallets.sh
Normal file
44
rin/wallet/cmd/list_wallets.sh
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/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")
|
||||
|
||||
# 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 wallet list
|
||||
WALLETS=$(echo "$RESPONSE" | jq -r '.result[]' 2>/dev/null)
|
||||
if [ -n "$WALLETS" ]; then
|
||||
echo "Loaded wallets:"
|
||||
echo "$WALLETS" | while read -r wallet; do
|
||||
echo " - $wallet"
|
||||
done
|
||||
else
|
||||
echo "No wallets are currently loaded."
|
||||
fi
|
||||
|
||||
63
rin/wallet/cmd/restore_wallet.sh
Normal file
63
rin/wallet/cmd/restore_wallet.sh
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
# RinCoin Wallet Restoration Script
|
||||
# Restores a wallet from a dump file on a new RinCoin node.
|
||||
# Prerequisites: New RinCoin node running in Docker, backup file available.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo "Usage: $0 <path_to_backup_file>"
|
||||
echo "Example: $0 ~/rin_wallet_backups/rin_wallet_backup_20230923.txt"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BACKUP_FILE="$1"
|
||||
CONTAINER="rincoin-node"
|
||||
WALLET_NAME="main" # Will be renamed to avoid conflicts
|
||||
NEW_WALLET_NAME="restored_main"
|
||||
|
||||
# Verify backup file exists
|
||||
if [[ ! -f "$BACKUP_FILE" ]]; then
|
||||
echo "Error: Backup file '$BACKUP_FILE' not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if container is running
|
||||
if ! sudo docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
|
||||
echo "Error: ${CONTAINER} container is not running. Start it with 'sudo docker start ${CONTAINER}'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Stopping RinCoin node for safe restoration..."
|
||||
sudo docker stop "$CONTAINER"
|
||||
|
||||
echo "Copying backup file into container..."
|
||||
sudo docker cp "$BACKUP_FILE" "$CONTAINER:/tmp/wallet_backup.txt"
|
||||
|
||||
echo "Starting RinCoin node..."
|
||||
sudo docker start "$CONTAINER"
|
||||
|
||||
# Wait for RPC to be ready
|
||||
echo "Waiting for node to fully start..."
|
||||
sleep 10
|
||||
|
||||
echo "Creating new wallet and importing keys..."
|
||||
# Create a new wallet to avoid conflicts
|
||||
sudo docker exec "$CONTAINER" rincoin-cli -datadir=/data -conf=/data/rincoin.conf createwallet "$NEW_WALLET_NAME"
|
||||
|
||||
# Import the dump file
|
||||
sudo docker exec "$CONTAINER" rincoin-cli -datadir=/data -conf=/data/rincoin.conf -rpcwallet="$NEW_WALLET_NAME" importwallet /tmp/wallet_backup.txt
|
||||
|
||||
# Clean up
|
||||
sudo docker exec "$CONTAINER" rm /tmp/wallet_backup.txt
|
||||
|
||||
echo "✅ Wallet restored successfully!"
|
||||
echo "New wallet name: $NEW_WALLET_NAME"
|
||||
echo ""
|
||||
echo "Verify with:"
|
||||
echo "sudo docker exec $CONTAINER rincoin-cli -datadir=/data -conf=/data/rincoin.conf -rpcwallet=$NEW_WALLET_NAME getbalance"
|
||||
echo ""
|
||||
echo "To use this wallet, update scripts to use -rpcwallet=$NEW_WALLET_NAME"
|
||||
echo "Or rename it back: unloadwallet $NEW_WALLET_NAME && loadwallet $WALLET_NAME"
|
||||
|
||||
87
rin/wallet/cmd/rpc_call.sh
Normal file
87
rin/wallet/cmd/rpc_call.sh
Normal file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
# General script for RIN RPC calls
|
||||
# Usage: ./rpc_call.sh <method> [param1] [param2] ... [rpc_user] [rpc_password] [rpc_host] [rpc_port]
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 <method> [param1] [param2] ... [rpc_user] [rpc_password] [rpc_host] [rpc_port]"
|
||||
echo "Examples:"
|
||||
echo " $0 getinfo"
|
||||
echo " $0 getnewaddress myaccount"
|
||||
echo " $0 listtransactions \"*\" 10"
|
||||
echo " $0 gettransaction txid"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
METHOD=$1
|
||||
shift
|
||||
|
||||
# Parse parameters - last 4 optional args are RPC connection details
|
||||
PARAMS=()
|
||||
RPC_USER="rinrpc"
|
||||
RPC_PASSWORD="password"
|
||||
RPC_HOST="localhost"
|
||||
RPC_PORT="8332"
|
||||
|
||||
# Check if last 4 args are RPC connection details
|
||||
if [ $# -ge 4 ]; then
|
||||
# Assume last 4 are RPC details
|
||||
RPC_PORT="${@: -1}"
|
||||
RPC_HOST="${@: -2}"
|
||||
RPC_PASSWORD="${@: -3}"
|
||||
RPC_USER="${@: -4}"
|
||||
PARAMS=("${@:1:$#-4}")
|
||||
else
|
||||
PARAMS=("$@")
|
||||
fi
|
||||
|
||||
# Build JSON parameters array
|
||||
PARAMS_JSON=""
|
||||
if [ ${#PARAMS[@]} -gt 0 ]; then
|
||||
PARAMS_JSON="["
|
||||
for param in "${PARAMS[@]}"; do
|
||||
# Try to parse as number, otherwise treat as string
|
||||
if [[ $param =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
|
||||
PARAMS_JSON="$PARAMS_JSON$param,"
|
||||
else
|
||||
PARAMS_JSON="$PARAMS_JSON\"$param\","
|
||||
fi
|
||||
done
|
||||
PARAMS_JSON="${PARAMS_JSON%,}]"
|
||||
else
|
||||
PARAMS_JSON="[]"
|
||||
fi
|
||||
|
||||
# JSON-RPC request
|
||||
RPC_REQUEST='{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "'"$METHOD"'",
|
||||
"method": "'"$METHOD"'",
|
||||
"params": '"$PARAMS_JSON"'
|
||||
}'
|
||||
|
||||
echo "Calling RPC method: $METHOD"
|
||||
echo "Parameters: $PARAMS_JSON"
|
||||
|
||||
# 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")
|
||||
|
||||
# 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
|
||||
|
||||
# Display result
|
||||
RESULT=$(echo "$RESPONSE" | jq -r '.result' 2>/dev/null)
|
||||
if [ "$RESULT" != "null" ]; then
|
||||
echo "Result:"
|
||||
echo "$RESPONSE" | jq '.result'
|
||||
else
|
||||
echo "Response:"
|
||||
echo "$RESPONSE"
|
||||
fi
|
||||
55
rin/wallet/cmd/send_rin.sh
Normal file
55
rin/wallet/cmd/send_rin.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ ${1-} == "" ]]; then
|
||||
echo "Usage: $0 <destination_address> [amount]"
|
||||
echo "Amount defaults to 1 RIN if not specified."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ADDRESS="$1"
|
||||
AMOUNT="${2-1}"
|
||||
WALLET="main"
|
||||
CONTAINER="rincoin-node"
|
||||
CLI_CMD=(sudo docker exec "$CONTAINER" rincoin-cli -datadir=/data -conf=/data/rincoin.conf -rpcwallet="$WALLET")
|
||||
|
||||
echo "Checking RinCoin node container..."
|
||||
if ! sudo docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
|
||||
echo "Error: container ${CONTAINER} is not running. Start it with 'sudo docker start ${CONTAINER}'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Ensuring wallet '${WALLET}' is loaded..."
|
||||
if ! "${CLI_CMD[@]//-rpcwallet=$WALLET/}" listwallets | grep -q '"main"'; then
|
||||
echo "Wallet ${WALLET} not loaded, attempting to load..."
|
||||
"${CLI_CMD[@]//-rpcwallet=$WALLET/}" loadwallet "$WALLET" >/dev/null
|
||||
fi
|
||||
|
||||
echo "Checking available balance..."
|
||||
BALANCE_RAW=$("${CLI_CMD[@]}" getbalance)
|
||||
BALANCE=$(printf '%.8f' "$BALANCE_RAW")
|
||||
|
||||
if [[ $(bc <<< "$BALANCE_RAW < $AMOUNT") -eq 1 ]]; then
|
||||
echo "Error: insufficient balance. Available ${BALANCE} RIN, but ${AMOUNT} RIN requested."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Broadcasting transaction..."
|
||||
set +e
|
||||
TX_OUTPUT=$("${CLI_CMD[@]}" sendtoaddress "$ADDRESS" "$AMOUNT" '' '' false true)
|
||||
STATUS=$?
|
||||
set -e
|
||||
|
||||
if [[ $STATUS -ne 0 ]]; then
|
||||
echo "Failed to send transaction."
|
||||
if [[ $STATUS -eq 4 ]]; then
|
||||
echo "Wallet appears to be locked. Unlock it with 'sudo docker exec ${CONTAINER} rincoin-cli -datadir=/data -conf=/data/rincoin.conf -rpcwallet=${WALLET} walletpassphrase <passphrase> 600 true' and rerun."
|
||||
fi
|
||||
exit $STATUS
|
||||
fi
|
||||
|
||||
echo "Transaction broadcast. TXID: ${TX_OUTPUT}"
|
||||
echo "Verify with: sudo docker exec ${CONTAINER} rincoin-cli -datadir=/data -conf=/data/rincoin.conf gettransaction ${TX_OUTPUT}"
|
||||
|
||||
|
||||
12
rin/wallet/cmd/web_wallet.send.sh
Normal file
12
rin/wallet/cmd/web_wallet.send.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR=$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
WEB_WALLET_DIR="${SCRIPT_DIR}/web_wallet"
|
||||
|
||||
bash /mnt/shared/DEV/repos/d-popov.com/scripts/MINE/rin/send_rin.sh "$@"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user