<?php

$raw_api_url = VEXON_API_URL;
$api_base = preg_match('~^https?://~i', $raw_api_url) ? $raw_api_url : 'https://'.$raw_api_url;
$api_base = rtrim($api_base, '/');
$api_url = htmlspecialchars($api_base, ENT_QUOTES, 'UTF-8');
$pool_url = htmlspecialchars(VEXON_STRATUM_URL, ENT_QUOTES, 'UTF-8');
$stratum_port = getAlgoPort(VEXON_DEFAULT_ALGO);
if (!$stratum_port) $stratum_port = 4499;
$min_payout = floatval(VEXON_PAYMENTS_MINI);
$payout_label = htmlspecialchars(VEXON_PAYOUT_SCHEDULE_LABEL, ENT_QUOTES, 'UTF-8');

echo <<<END
<section class="vexon-page-title">
	<div>
		<p class="vexon-kicker">Developer API</p>
		<h1>Vexon Pool API</h1>
	</div>
	<p>Simple JSON endpoints for pool telemetry, Explorer lookup, wallet status, workers, and VEX reward accounting.</p>
</section>

<section class="vexon-status-strip">
	<div><span>Base URL</span><strong>{$api_url}</strong></div>
	<div><span>Stratum</span><strong>{$pool_url}:{$stratum_port}</strong></div>
	<div><span>Minimum payout</span><strong>{$min_payout} VEX</strong></div>
	<div><span>Payout schedule</span><strong>{$payout_label}</strong></div>
</section>

<section class="vexon-dashboard-grid">
	<div class="vexon-dashboard-main">
		<div class="vexon-telemetry-card">
			<div class="vexon-card-heading">
				<div>
					<span class="vexon-card-kicker">Wallet endpoint</span>
					<h2>Wallet status</h2>
				</div>
				<img src="/vexon/ui/images/vexon-logo.png" alt="Vexon">
			</div>
			<pre class="vexon-code-block">GET {$api_url}/api/wallet?address=VEX_ADDRESS</pre>
			<pre class="vexon-code-block">{
  "currency": "VEX",
  "balance": "0.00000000",
  "unpaid": "0.00000000",
  "paid24h": "0.00000000",
  "minimum_payout": "{$min_payout}",
  "next_payout": "{$payout_label}"
}</pre>
		</div>

		<div class="vexon-telemetry-card">
			<div class="vexon-card-heading">
				<div>
					<span class="vexon-card-kicker">Wallet sync endpoint</span>
					<h2>Node height and address sync</h2>
				</div>
				<img src="/vexon/ui/images/vexon-logo.png" alt="Vexon">
			</div>
			<pre class="vexon-code-block">GET {$api_url}/api/walletsync
GET {$api_url}/api/walletsync?address=VEX_ADDRESS</pre>
			<pre class="vexon-code-block">{
  "ok": true,
  "type": "walletsync",
  "node": {
    "connected": true,
    "blocks": 0,
    "getwork_ready": true
  },
  "wallet_rpc": {
    "configured": true,
    "connected": true,
    "locked": false
  },
  "address": {
    "pool_unpaid": 0,
    "chain_received": 0,
    "tx_index_available": true
  }
}</pre>
		</div>

		<div class="vexon-telemetry-card">
			<div class="vexon-card-heading">
				<div>
					<span class="vexon-card-kicker">Managed wallet endpoint</span>
					<h2>Issue a real VEX address</h2>
				</div>
				<img src="/vexon/ui/images/vexon-logo.png" alt="Vexon">
			</div>
			<pre class="vexon-code-block">POST {$api_url}/api/walletaddress
Content-Type: application/json

{
  "wallet_key": "64_HEX_LOCAL_RECOVERY_KEY"
}</pre>
			<pre class="vexon-code-block">{
  "ok": true,
  "type": "walletaddress",
  "address": "Vs...",
  "managed": true,
  "custody": "server_wallet_rpc",
  "pool_account": {
    "username": "Vs...",
    "coinsymbol": "VEX"
  }
}</pre>
		</div>

		<div class="vexon-telemetry-card">
			<div class="vexon-card-heading">
				<div>
					<span class="vexon-card-kicker">Pool endpoint</span>
					<h2>Pool status</h2>
				</div>
				<img src="/vexon/ui/images/vexon-logo.png" alt="Vexon">
			</div>
			<pre class="vexon-code-block">GET {$api_url}/api/pool</pre>
			<pre class="vexon-code-block">{
  "coin": {
    "name": "Vexon",
    "symbol": "VEX",
    "height": 0,
    "difficulty": 503382015,
    "auto_ready": 1
  },
  "mining": {
    "coin": "VEX",
    "algorithm": "Blake256r14",
    "stratum_port": {$stratum_port},
    "active_workers_15m": 0,
    "accepted_shares_15m": 0,
    "pool_hashrate_hs": 0
  }
}</pre>
		</div>

		<div class="vexon-telemetry-card">
			<div class="vexon-card-heading">
				<div>
					<span class="vexon-card-kicker">Diagnostics endpoint</span>
					<h2>Launch readiness</h2>
				</div>
				<img src="/vexon/ui/images/vexon-logo.png" alt="Vexon">
			</div>
			<pre class="vexon-code-block">GET {$api_url}/api/diagnostics</pre>
			<pre class="vexon-code-block">{
  "ok": true,
  "type": "diagnostics",
  "readiness": {
    "coin_auto_ready": true,
    "node_connected": true,
    "getwork_ready": true,
    "workers_seen_15m": true,
    "accepted_shares_15m": true
  },
  "mining": {
    "pool_hashrate_text": "5.8 Th/s",
    "expected_block_time": "..."
  },
  "warnings": []
}</pre>
		</div>

		<div class="vexon-telemetry-card">
			<div class="vexon-card-heading">
				<div>
					<span class="vexon-card-kicker">Explorer endpoint</span>
					<h2>Blocks and transactions</h2>
				</div>
				<img src="/vexon/ui/images/vexon-logo.png" alt="Vexon">
			</div>
			<pre class="vexon-code-block">GET {$api_url}/api/explorer
GET {$api_url}/api/explorer?q=0
GET {$api_url}/api/explorer?q=BLOCK_HASH_OR_TXID</pre>
			<pre class="vexon-code-block">{
  "ok": true,
  "type": "block",
  "query": "0",
  "data": {
    "height": 0,
    "hash": "..."
  },
  "node": {
    "connected": true,
    "blocks": 0,
    "difficulty": 503382015
  }
}</pre>
		</div>

		<div class="vexon-telemetry-card">
			<div class="vexon-card-heading">
				<div>
					<span class="vexon-card-kicker">Address endpoint</span>
					<h2>Address activity</h2>
				</div>
				<img src="/vexon/ui/images/vexon-logo.png" alt="Vexon">
			</div>
			<pre class="vexon-code-block">GET {$api_url}/api/address?address=VEX_ADDRESS
GET {$api_url}/api/explorer?address=VEX_ADDRESS</pre>
			<pre class="vexon-code-block">{
  "ok": true,
  "type": "address",
  "data": {
    "address": "VEX_ADDRESS",
    "valid": true,
    "pool_account": {
      "balance": 0,
      "paid_total": 0
    },
    "workers": [],
    "shares_24h": {
      "accepted": 0,
      "rejected": 0
    },
    "chain_transactions": []
  }
}</pre>
		</div>

		<div class="vexon-telemetry-card">
			<div class="vexon-card-heading">
				<div>
					<span class="vexon-card-kicker">Broadcast endpoint</span>
					<h2>Signed transaction relay</h2>
				</div>
				<img src="/vexon/ui/images/vexon-logo.png" alt="Vexon">
			</div>
			<pre class="vexon-code-block">POST {$api_url}/api/broadcast
Content-Type: application/json

{
  "rawtx": "SIGNED_RAW_TRANSACTION_HEX"
}</pre>
			<pre class="vexon-code-block">{
  "ok": true,
  "type": "broadcast",
  "txid": "...",
  "bytes": 224,
  "node": {
    "connected": true,
    "blocks": 0
  }
}</pre>
		</div>
	</div>

	<aside class="vexon-side-panel">
		<h2>Integration notes</h2>
		<ul>
			<li>Use a VEX address as the miner username and payout identity.</li>
			<li>Workers can be separated with suffixes such as <code>.D1</code> or <code>.DR5</code>.</li>
			<li>Balances below {$min_payout} VEX remain pending until the next eligible payout window.</li>
			<li>Explorer lookups accept block height, block hash, transaction id, or VEX address.</li>
			<li>The diagnostics endpoint is safe to expose publicly and helps operators confirm node, Stratum, shares, block, and payout readiness without showing secrets.</li>
			<li>Production payouts require the pool wallet service to be online and unlocked.</li>
			<li>The wallet address endpoint creates a real <code>Vs...</code> chain address from the server wallet service and creates the matching pool account for mining.</li>
			<li>The wallet address endpoint receives only a one-way local recovery key. It does not receive the mnemonic or browser wallet password.</li>
			<li>The broadcast endpoint relays already signed transactions only; it never asks for mnemonics, private keys, or wallet passwords.</li>
			<li>Public API responses never expose wallet seeds, private keys, RPC passwords, or database credentials.</li>
		</ul>
	</aside>
</section>
END;
