rincoin cmds moved to mines repo
This commit is contained in:
@@ -279,6 +279,12 @@ sudo docker exec rincoin-node rincoin-cli -datadir=/data -conf=/data/rincoin.con
|
|||||||
|
|
||||||
### **Wallet Management**
|
### **Wallet Management**
|
||||||
```bash
|
```bash
|
||||||
|
# List all wallets
|
||||||
|
sudo docker exec rincoin-node rincoin-cli -datadir=/data -conf=/data/rincoin.conf listwallets
|
||||||
|
|
||||||
|
# Load wallet
|
||||||
|
sudo docker exec rincoin-node rincoin-cli -datadir=/data -conf=/data/rincoin.conf loadwallet "main"
|
||||||
|
|
||||||
# Get new address
|
# Get new address
|
||||||
sudo docker exec rincoin-node rincoin-cli -datadir=/data -conf=/data/rincoin.conf -rpcwallet=main getnewaddress
|
sudo docker exec rincoin-node rincoin-cli -datadir=/data -conf=/data/rincoin.conf -rpcwallet=main getnewaddress
|
||||||
|
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
#!/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 -euo pipefail
|
|
||||||
|
|
||||||
# Configuration
|
|
||||||
CONTAINER="rincoin-node"
|
|
||||||
WALLET="main"
|
|
||||||
BACKUP_DIR="${HOME}/rin_wallet_backups"
|
|
||||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
|
||||||
BACKUP_FILE="${BACKUP_DIR}/rin_wallet_backup_${TIMESTAMP}.txt"
|
|
||||||
|
|
||||||
# Ensure backup directory exists
|
|
||||||
mkdir -p "$BACKUP_DIR"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Ensure wallet is loaded
|
|
||||||
CLI_CMD=(sudo docker exec "$CONTAINER" rincoin-cli -datadir=/data -conf=/data/rincoin.conf -rpcwallet="$WALLET")
|
|
||||||
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 2>&1 || {
|
|
||||||
echo "Failed to load wallet. Ensure it exists."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Dumping wallet to: $BACKUP_FILE"
|
|
||||||
echo "This may take a moment..."
|
|
||||||
|
|
||||||
# Dump wallet
|
|
||||||
"${CLI_CMD[@]}" dumpwallet "$BACKUP_FILE"
|
|
||||||
|
|
||||||
# Verify the file was created and has content
|
|
||||||
if [[ ! -f "$BACKUP_FILE" ]]; then
|
|
||||||
echo "Error: Backup file was not created."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
LINE_COUNT=$(wc -l < "$BACKUP_FILE")
|
|
||||||
if [[ $LINE_COUNT -lt 10 ]]; then
|
|
||||||
echo "Warning: Backup file seems too small (${LINE_COUNT} lines). Check for errors."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "✅ Wallet successfully backed up to: $BACKUP_FILE"
|
|
||||||
echo ""
|
|
||||||
echo "🔐 SECURITY REMINDERS:"
|
|
||||||
echo " - This file contains private keys for ALL addresses in the wallet."
|
|
||||||
echo " - Encrypt it immediately: gpg -c $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 "$BACKUP_FILE" | cut -f1)"
|
|
||||||
echo "Lines: $LINE_COUNT"
|
|
||||||
|
|
||||||
@@ -1,9 +1 @@
|
|||||||
================================================================================
|
[2025-09-29 20:11:03] 💰 Wallet Balance: 0.00000000 RIN
|
||||||
RinCoin Mining Log
|
|
||||||
================================================================================
|
|
||||||
Started: 2025-09-24 14:21:00
|
|
||||||
Target Address: rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q
|
|
||||||
Stratum: 0.0.0.0:3334
|
|
||||||
RPC: 127.0.0.1:9556
|
|
||||||
================================================================================
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
#!/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"
|
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#!/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}"
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/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 "$@"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
#!/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,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@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()
|
|
||||||
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
SCRIPT_DIR=$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
||||||
CONTAINER="rincoin-node"
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if ! command -v flask >/dev/null 2>&1; then
|
|
||||||
echo "Missing Flask. Install with 'pip install flask python-bitcoinrpc'."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,318 +0,0 @@
|
|||||||
<!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 fetchBalances() {
|
|
||||||
const res = await fetch('/api/balance', { headers: authHeaders() });
|
|
||||||
const 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() {
|
|
||||||
const res = await fetch('/api/transactions', { headers: authHeaders() });
|
|
||||||
const 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() {
|
|
||||||
const res = await fetch('/api/address', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: authHeaders(),
|
|
||||||
body: JSON.stringify({}),
|
|
||||||
});
|
|
||||||
const 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await fetch('/api/send', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: authHeaders(),
|
|
||||||
body: JSON.stringify({ address, amount, subtractFee: true }),
|
|
||||||
});
|
|
||||||
const 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();
|
|
||||||
await refresh();
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user