refactoring
This commit is contained in:
Binary file not shown.
@@ -6,16 +6,23 @@ Provides web dashboard for pool statistics and miner management
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
import threading
|
||||
import time
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
class PoolWebInterface:
|
||||
def __init__(self, pool_db, host='0.0.0.0', port=8080):
|
||||
def __init__(self, pool_db, host='0.0.0.0', port=8080, rpc_host='127.0.0.1', rpc_port=9556,
|
||||
rpc_user='rinrpc', rpc_password='745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90'):
|
||||
self.pool_db = pool_db
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.rpc_host = rpc_host
|
||||
self.rpc_port = rpc_port
|
||||
self.rpc_user = rpc_user
|
||||
self.rpc_password = rpc_password
|
||||
self.chart_time_window = 3600 # 1 hour default, adjustable
|
||||
|
||||
def set_chart_time_window(self, seconds):
|
||||
@@ -39,6 +46,37 @@ class PoolWebInterface:
|
||||
else:
|
||||
return "0.00 H/s"
|
||||
|
||||
def get_pool_balance(self):
|
||||
"""Get pool wallet balance via RPC"""
|
||||
try:
|
||||
url = f"http://{self.rpc_host}:{self.rpc_port}/"
|
||||
headers = {'content-type': 'text/plain'}
|
||||
auth = HTTPBasicAuth(self.rpc_user, self.rpc_password)
|
||||
|
||||
payload = {
|
||||
"jsonrpc": "1.0",
|
||||
"id": "pool_balance",
|
||||
"method": "getbalance",
|
||||
"params": []
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers, auth=auth, timeout=10)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
if 'error' in result and result['error'] is not None:
|
||||
print(f"RPC Error getting balance: {result['error']}")
|
||||
return 0.0
|
||||
balance = result.get('result', 0)
|
||||
return float(balance) / 100000000 # Convert from satoshis to RIN
|
||||
else:
|
||||
print(f"HTTP Error getting balance: {response.status_code}")
|
||||
return 0.0
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error getting pool balance: {e}")
|
||||
return 0.0
|
||||
|
||||
def get_pool_stats(self):
|
||||
"""Get current pool statistics"""
|
||||
try:
|
||||
@@ -150,6 +188,9 @@ class PoolWebInterface:
|
||||
''')
|
||||
all_miners = cursor.fetchall()
|
||||
|
||||
# Get pool balance
|
||||
pool_balance = self.get_pool_balance()
|
||||
|
||||
return {
|
||||
'total_miners': total_miners,
|
||||
'active_miners': active_miners,
|
||||
@@ -161,6 +202,7 @@ class PoolWebInterface:
|
||||
'all_miners': all_miners,
|
||||
'miner_hashrates': miner_hashrates,
|
||||
'historical_data': historical_data,
|
||||
'pool_balance': pool_balance,
|
||||
'debug': {
|
||||
'recent_difficulty': recent_difficulty,
|
||||
'recent_share_count': recent_share_count,
|
||||
@@ -224,12 +266,17 @@ class PoolWebInterface:
|
||||
<div class="stat-value">{stats.get('total_blocks', 0)}</div>
|
||||
<div class="stat-label">Blocks Found</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">{stats.get('pool_balance', 0):.2f}</div>
|
||||
<div class="stat-label">Pool Balance (RIN)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>📊 Pool Statistics</h2>
|
||||
<p><strong>24h Shares:</strong> {stats.get('total_shares_24h', 0):,}</p>
|
||||
<p><strong>Pool Fee:</strong> 1%</p>
|
||||
<p><strong>Pool Balance:</strong> {stats.get('pool_balance', 0):.8f} RIN</p>
|
||||
<p><strong>Connection String:</strong> <code>stratum+tcp://YOUR_IP:3333</code></p>
|
||||
|
||||
<!-- Debug info -->
|
||||
@@ -452,9 +499,10 @@ class PoolWebHandler(BaseHTTPRequestHandler):
|
||||
# Suppress access logs
|
||||
pass
|
||||
|
||||
def start_web_interface(pool_db, host='0.0.0.0', port=8083):
|
||||
def start_web_interface(pool_db, host='0.0.0.0', port=8083, rpc_host='127.0.0.1', rpc_port=9556,
|
||||
rpc_user='rinrpc', rpc_password='745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90'):
|
||||
"""Start the web interface server"""
|
||||
interface = PoolWebInterface(pool_db, host, port)
|
||||
interface = PoolWebInterface(pool_db, host, port, rpc_host, rpc_port, rpc_user, rpc_password)
|
||||
|
||||
class Handler(PoolWebHandler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@@ -542,7 +542,11 @@ class RinCoinMiningPool(RinCoinStratumBase):
|
||||
stats_thread.start()
|
||||
|
||||
# Start web interface in background
|
||||
web_thread = threading.Thread(target=start_web_interface, args=(self.db, '0.0.0.0', 8083), daemon=True)
|
||||
web_thread = threading.Thread(target=start_web_interface,
|
||||
args=(self.db, '0.0.0.0', 8083,
|
||||
self.rpc_host, self.rpc_port,
|
||||
self.rpc_user, self.rpc_password),
|
||||
daemon=True)
|
||||
web_thread.start()
|
||||
|
||||
print(f"🌐 Web dashboard started on http://0.0.0.0:8083")
|
||||
|
Reference in New Issue
Block a user