code moved from scripts repo;

dump works
This commit is contained in:
Dobromir Popov
2025-09-29 22:23:38 +03:00
parent f92dc9a4b4
commit dc8f69c5c3
33 changed files with 4541 additions and 0 deletions

91
rin/wallet/cmd/README.md Normal file
View 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

View 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

View 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

View 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"

View 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

View 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

View 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"

View 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

View 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}"

View 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 "$@"

View File

@@ -0,0 +1,2 @@
Flask==2.3.3
python-bitcoinrpc==1.0

151
rin/wallet/web/server.py Normal file
View File

@@ -0,0 +1,151 @@
#!/usr/bin/env python3
from __future__ import annotations
import json
import os
import secrets
from functools import wraps
from flask import Flask, jsonify, request, send_from_directory
try:
from bitcoinrpc.authproxy import AuthServiceProxy
except ImportError: # pragma: no cover
raise SystemExit("Missing python-bitcoinrpc. Install with: pip install python-bitcoinrpc")
RIN_RPC_HOST = os.environ.get("RIN_RPC_HOST", "127.0.0.1")
RIN_RPC_PORT = int(os.environ.get("RIN_RPC_PORT", "9556"))
RIN_RPC_USER = os.environ.get("RIN_RPC_USER", "rinrpc")
RIN_RPC_PASSWORD = os.environ.get("RIN_RPC_PASSWORD", "745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90")
RIN_WALLET_NAME = os.environ.get("RIN_WALLET_NAME", "main")
API_TOKEN = os.environ.get("RIN_WEB_WALLET_TOKEN")
if not API_TOKEN:
API_TOKEN = secrets.token_urlsafe(32)
print("[web-wallet] No RIN_WEB_WALLET_TOKEN provided. Generated one for this session.")
print(f"[web-wallet] API token: {API_TOKEN}")
def create_rpc_client() -> AuthServiceProxy:
url = f"http://{RIN_RPC_USER}:{RIN_RPC_PASSWORD}@{RIN_RPC_HOST}:{RIN_RPC_PORT}/wallet/{RIN_WALLET_NAME}"
return AuthServiceProxy(url, timeout=15)
def require_token(view_func):
@wraps(view_func)
def wrapper(*args, **kwargs):
header = request.headers.get("Authorization", "")
if not header.startswith("Bearer "):
return jsonify({"error": "missing_token"}), 401
token = header.split(" ", 1)[1]
if token != API_TOKEN:
return jsonify({"error": "invalid_token"}), 403
return view_func(*args, **kwargs)
return wrapper
app = Flask(__name__, static_folder="static", static_url_path="")
def rpc_call(method: str, *params):
try:
rpc = create_rpc_client()
return rpc.__getattr__(method)(*params)
except Exception as exc: # noqa: BLE001
raise RuntimeError(str(exc)) from exc
@app.route("/api/session", methods=["GET"])
def session_info():
return jsonify({
"wallet": RIN_WALLET_NAME,
"host": RIN_RPC_HOST,
"token": API_TOKEN,
})
@app.route("/api/address", methods=["POST"])
@require_token
def create_address():
data = request.get_json(silent=True) or {}
label = data.get("label", "")
try:
address = rpc_call("getnewaddress", label)
return jsonify({"address": address})
except RuntimeError as exc:
return jsonify({"error": str(exc)}), 500
@app.route("/api/balance", methods=["GET"])
@require_token
def get_balance():
try:
info = rpc_call("getwalletinfo")
confirmed = info.get("balance", 0)
unconfirmed = info.get("unconfirmed_balance", 0)
immature = info.get("immature_balance", 0)
total = confirmed + unconfirmed + immature
return jsonify({
"confirmed": confirmed,
"unconfirmed": unconfirmed,
"immature": immature,
"total": total,
})
except RuntimeError as exc:
return jsonify({"error": str(exc)}), 500
@app.route("/api/send", methods=["POST"])
@require_token
def send():
payload = request.get_json(force=True)
address = payload.get("address")
amount = payload.get("amount")
subtract_fee = bool(payload.get("subtractFee", True))
if not address or not isinstance(amount, (int, float)):
return jsonify({"error": "invalid_request"}), 400
if amount <= 0:
return jsonify({"error": "amount_must_be_positive"}), 400
try:
txid = rpc_call("sendtoaddress", address, float(amount), "", "", subtract_fee)
return jsonify({"txid": txid})
except RuntimeError as exc:
status = 400 if "Invalid RinCoin address" in str(exc) else 500
return jsonify({"error": str(exc)}), status
@app.route("/api/transactions", methods=["GET"])
@require_token
def list_transactions():
count = int(request.args.get("count", 10))
try:
txs = rpc_call("listtransactions", "*", count, 0, True)
return jsonify({"transactions": txs})
except RuntimeError as exc:
return jsonify({"error": str(exc)}), 500
@app.route("/")
def root():
return send_from_directory(app.static_folder, "index.html")
@app.route("/<path:path>")
def static_proxy(path):
return send_from_directory(app.static_folder, path)
def main():
port = int(os.environ.get("RIN_WEB_WALLET_PORT", "8787"))
app.run(host="127.0.0.1", port=port, debug=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,46 @@
#!/bin/bash
set -euo pipefail
SCRIPT_DIR=$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)
CONTAINER="rincoin-node2"
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
# Check prerequisites
if ! command -v python3 >/dev/null 2>&1; then
echo "Error: python3 is required but not installed."
exit 1
fi
if ! python3 -c "import venv" 2>/dev/null; then
echo "Error: python3-venv is required. Install with 'sudo apt install python3-venv' (Ubuntu/Debian) or equivalent."
exit 1
fi
# Setup virtual environment
VENV_DIR="${SCRIPT_DIR}/venv"
if [ ! -d "$VENV_DIR" ]; then
echo "Creating virtual environment..."
python3 -m venv "$VENV_DIR"
fi
# Activate virtual environment
echo "Activating virtual environment..."
source "$VENV_DIR/bin/activate"
# Install/update dependencies
echo "Installing/updating dependencies..."
pip install --quiet -r "${SCRIPT_DIR}/requirements.txt"
echo "Starting RinCoin web wallet on http://127.0.0.1:8787"
export FLASK_APP="${SCRIPT_DIR}/server.py"
export FLASK_ENV=production
export PYTHONPATH="${SCRIPT_DIR}"
flask run --host 127.0.0.1 --port 8787
# Note: To clean up the virtual environment, run: rm -rf "${SCRIPT_DIR}/venv"

View File

@@ -0,0 +1,370 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>RinCoin Web Wallet</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background: #0b1a28;
color: #f5f8fc;
display: flex;
min-height: 100vh;
}
.sidebar {
width: 260px;
background: #122c43;
padding: 24px;
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 24px;
}
.content {
flex: 1;
padding: 32px;
box-sizing: border-box;
}
h1 {
margin: 0 0 16px;
font-size: 24px;
}
h2 {
margin-top: 32px;
margin-bottom: 16px;
font-size: 18px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
padding-bottom: 8px;
}
label {
display: block;
margin-bottom: 8px;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 0.08em;
color: rgba(255, 255, 255, 0.7);
}
input {
width: 100%;
padding: 10px 12px;
border-radius: 6px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(9, 19, 30, 0.8);
color: #fff;
margin-bottom: 16px;
box-sizing: border-box;
}
button {
background: #29b6f6;
border: none;
padding: 12px 16px;
border-radius: 6px;
color: #04121f;
font-weight: 600;
cursor: pointer;
transition: background 0.2s ease;
}
button:hover {
background: #4fc3f7;
}
.card {
background: rgba(9, 19, 30, 0.8);
padding: 24px;
border-radius: 12px;
margin-bottom: 24px;
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}
.balance {
font-size: 36px;
font-weight: 600;
}
.muted {
color: rgba(255, 255, 255, 0.6);
font-size: 14px;
}
.transaction-list {
margin: 0;
padding: 0;
list-style: none;
}
.transaction-list li {
padding: 14px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.address-box {
word-break: break-all;
background: rgba(41, 182, 246, 0.15);
border-radius: 6px;
padding: 12px;
margin: 12px 0;
}
.status {
border-radius: 6px;
margin-top: 16px;
padding: 12px 14px;
}
.status.success {
background: rgba(76, 175, 80, 0.2);
color: #c8e6c9;
}
.status.error {
background: rgba(244, 67, 54, 0.2);
color: #ffcdd2;
}
.token-display {
background: rgba(9, 19, 30, 0.8);
padding: 12px;
border-radius: 6px;
font-size: 13px;
word-break: break-all;
}
.sidebar h2 {
margin-top: 0;
}
.sidebar button {
width: 100%;
}
@media (max-width: 900px) {
body {
flex-direction: column;
}
.sidebar {
width: 100%;
flex-direction: row;
gap: 16px;
flex-wrap: wrap;
}
.sidebar section {
flex: 1 1 200px;
}
.content {
padding: 24px;
}
}
</style>
</head>
<body>
<aside class="sidebar">
<section>
<h2>Session</h2>
<div class="token-display" id="tokenDisplay">Loading…</div>
</section>
<section>
<button id="refreshButton">Refresh Data</button>
</section>
<section>
<button id="generateButton">Generate Address</button>
</section>
</aside>
<main class="content">
<h1>RinCoin Wallet</h1>
<div class="card">
<div class="muted">Confirmed Balance</div>
<div class="balance" id="confirmedBalance"></div>
<div class="muted" id="totalBalance">Total: —</div>
</div>
<div class="card">
<h2>Send RinCoin</h2>
<label for="sendAddress">Recipient Address</label>
<input id="sendAddress" type="text" placeholder="rin1..." />
<label for="sendAmount">Amount (RIN)</label>
<input id="sendAmount" type="number" step="0.00000001" min="0" />
<button id="sendButton">Send</button>
<div id="sendStatus" class="status" style="display:none;"></div>
</div>
<div class="card" id="generatedAddressCard" style="display:none;">
<h2>New Address</h2>
<div class="address-box" id="generatedAddress"></div>
</div>
<div class="card">
<h2>Recent Activity</h2>
<ul class="transaction-list" id="txList"></ul>
</div>
</main>
<script>
const tokenDisplay = document.getElementById('tokenDisplay');
const confirmedBalance = document.getElementById('confirmedBalance');
const totalBalance = document.getElementById('totalBalance');
const txList = document.getElementById('txList');
const sendStatus = document.getElementById('sendStatus');
const generatedAddressCard = document.getElementById('generatedAddressCard');
const generatedAddress = document.getElementById('generatedAddress');
let apiToken = localStorage.getItem('rinWebWalletToken');
async function fetchSession() {
const res = await fetch('/api/session');
const data = await res.json();
if (!apiToken) {
apiToken = data.token;
localStorage.setItem('rinWebWalletToken', apiToken);
}
tokenDisplay.textContent = `Wallet: ${data.wallet}`;
}
function authHeaders() {
return { Authorization: `Bearer ${apiToken}`, 'Content-Type': 'application/json' };
}
async function refreshToken() {
const res = await fetch('/api/session');
const data = await res.json();
apiToken = data.token;
localStorage.setItem('rinWebWalletToken', apiToken);
tokenDisplay.textContent = `Wallet: ${data.wallet}`;
}
async function fetchBalances() {
let res = await fetch('/api/balance', { headers: authHeaders() });
let data = await res.json();
// If token is invalid, refresh and retry
if (data.error === 'invalid_token') {
await refreshToken();
res = await fetch('/api/balance', { headers: authHeaders() });
data = await res.json();
}
if (data.error) {
confirmedBalance.textContent = 'Error';
totalBalance.textContent = data.error;
return;
}
confirmedBalance.textContent = `${Number(data.confirmed).toFixed(8)} RIN`;
totalBalance.textContent = `Total: ${Number(data.total).toFixed(8)} RIN`;
}
function renderTx(tx) {
const li = document.createElement('li');
const amount = Number(tx.amount).toFixed(8);
const type = tx.category === 'send' ? 'Sent' : 'Received';
li.innerHTML = `
<div><strong>${type}</strong> ${amount} RIN</div>
<div class="muted">${tx.time ? new Date(tx.time * 1000).toLocaleString() : ''}</div>
<div class="muted">${tx.txid}</div>
`;
return li;
}
async function fetchTransactions() {
let res = await fetch('/api/transactions', { headers: authHeaders() });
let data = await res.json();
// If token is invalid, refresh and retry
if (data.error === 'invalid_token') {
await refreshToken();
res = await fetch('/api/transactions', { headers: authHeaders() });
data = await res.json();
}
txList.innerHTML = '';
if (data.error) {
txList.innerHTML = `<li class="muted">${data.error}</li>`;
return;
}
if (!data.transactions.length) {
txList.innerHTML = '<li class="muted">No transactions yet.</li>';
return;
}
data.transactions.forEach((tx) => txList.appendChild(renderTx(tx)));
}
async function generateAddress() {
let res = await fetch('/api/address', {
method: 'POST',
headers: authHeaders(),
body: JSON.stringify({}),
});
let data = await res.json();
// If token is invalid, refresh and retry
if (data.error === 'invalid_token') {
await refreshToken();
res = await fetch('/api/address', {
method: 'POST',
headers: authHeaders(),
body: JSON.stringify({}),
});
data = await res.json();
}
if (data.error) {
generatedAddressCard.style.display = 'block';
generatedAddress.textContent = `Error: ${data.error}`;
return;
}
generatedAddressCard.style.display = 'block';
generatedAddress.textContent = data.address;
}
async function sendCoins() {
const address = document.getElementById('sendAddress').value.trim();
const amount = Number(document.getElementById('sendAmount').value);
if (!address || !amount) {
sendStatus.textContent = 'Destination and amount are required.';
sendStatus.className = 'status error';
sendStatus.style.display = 'block';
return;
}
let res = await fetch('/api/send', {
method: 'POST',
headers: authHeaders(),
body: JSON.stringify({ address, amount, subtractFee: true }),
});
let data = await res.json();
// If token is invalid, refresh and retry
if (data.error === 'invalid_token') {
await refreshToken();
res = await fetch('/api/send', {
method: 'POST',
headers: authHeaders(),
body: JSON.stringify({ address, amount, subtractFee: true }),
});
data = await res.json();
}
if (data.error) {
sendStatus.textContent = data.error;
sendStatus.className = 'status error';
sendStatus.style.display = 'block';
return;
}
sendStatus.textContent = `Transaction broadcast. TXID: ${data.txid}`;
sendStatus.className = 'status success';
sendStatus.style.display = 'block';
await refresh();
}
async function refresh() {
await Promise.all([fetchBalances(), fetchTransactions()]);
}
document.getElementById('refreshButton').addEventListener('click', refresh);
document.getElementById('generateButton').addEventListener('click', generateAddress);
document.getElementById('sendButton').addEventListener('click', sendCoins);
(async () => {
await fetchSession();
// Ensure we have a token before making authenticated requests
if (apiToken) {
await refresh();
} else {
console.error('No API token available');
}
})();
</script>
</body>
</html>