Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ FAIRCOIN_RPC_PORT=46373
FAIRCOIN_RPC_SCHEME=http

# MongoDB Configuration
# Both Mongoose and the native cache client use the same db name:
# MONGODB_DB_NAME if set, otherwise the path segment of MONGODB_URI.
MONGODB_URI=mongodb://localhost:27017/faircoin-explorer
# MONGODB_DB_NAME=faircoin-explorer

# Vite dev proxy target (optional). Defaults to http://localhost:8080 to match
# the API server PORT below. Set when pointing the SPA at a remote API.
# VITE_API_TARGET=http://localhost:8080

# WebSocket Configuration
WEBSOCKET_ENABLED=true
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Behind a reverse proxy (e.g. nginx/Cloudflare), set `TRUSTED_PROXY_CIDRS` to the
The Express server exposes a read-only JSON API under `/api`:

- `GET /api/blocks`, `/api/block/:hashOrHeight`, `/api/blockcount`
- `GET /api/transactions` (paginated recent txs from mempool + recent blocks)
- `GET /api/transaction/:txid`, `POST /api/tx/broadcast`
- `GET /api/address/:address`, `/api/address/:address/txs?page=&limit=`, `/api/address/:address/utxos` (requires a node with `addressindex` for full data)
- `GET /api/mempool`, `/api/masternodes`, `/api/peers`, `/api/stats`, `/api/network-info`, `/api/mining-info`
Expand Down Expand Up @@ -138,6 +139,7 @@ Only key generation is done in-process (using the audited `@noble/curves` secp25
## Features

- Dashboard with live blocks, mempool, price and network stats
- Global recent transactions feed, charts/analytics, and tools (broadcast, address validator, API docs)
- Block, transaction and address pages (with paginated address history when the node has `addressindex`)
- Masternode list and reward stats, peers, network status
- Universal search (height, hash, txid, address)
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en" class="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>FairCoin Explorer | Real-Time FairCoin Blockchain Analytics</title>
<meta name="description" content="Search the FairCoin blockchain in real time. Track blocks, transactions, addresses, masternodes, fees, mempool activity, supply, price, bridge reserves, peers, and network health from one fast Explorer." />
<meta name="keywords" content="FairCoin Explorer, FairCoin blockchain explorer, FAIR blockchain, FairCoin transactions, FairCoin blocks, FairCoin addresses, FairCoin masternodes, FairCoin mempool, FairCoin fees, FairCoin network status, WFAIR bridge, cryptocurrency analytics" />
Expand All @@ -21,11 +21,11 @@
<meta name="format-detection" content="telephone=no" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="msapplication-config" content="/browserconfig.xml" />
<meta name="msapplication-TileColor" content="#6366f1" />
<meta name="msapplication-TileColor" content="#3d9948" />
<meta name="msapplication-tap-highlight" content="no" />

<meta name="theme-color" content="#0f0f23" media="(prefers-color-scheme: dark)" />
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#23260C" media="(prefers-color-scheme: dark)" />
<meta name="theme-color" content="#3d9948" media="(prefers-color-scheme: light)" />

<link rel="manifest" href="/manifest.json" />
<link rel="icon" type="image/jpeg" href="/images/FairCoin-Logo.jpg" />
Expand Down
2 changes: 1 addition & 1 deletion public/browserconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<msapplication>
<tile>
<square150x150logo src="/icons/icon-192x192.png"/>
<TileColor>#0f0f23</TileColor>
<TileColor>#3d9948</TileColor>
</tile>
</msapplication>
</browserconfig>
89 changes: 69 additions & 20 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import fs from 'fs'
import { fileURLToPath } from 'url'
import { blockCache } from './lib/cache'
import { handleRouteError, parseNetwork, parseLimit, parseOffset, parseBlockOffset, parseAddress, ValidationError } from './lib/http'
import { computeCirculatingSupply, currentBlockReward } from './lib/supply'
import { computeCirculatingSupply, currentBlockReward } from '../shared/supply'
import { logger } from './lib/logger'
import { toPublicNetworkInfo } from './lib/network-info'
import { rpcWithNetwork } from '@fairco.in/rpc-client'
import priceRouter from './routes/price'
Expand All @@ -23,6 +24,7 @@ import broadcastRouter from './routes/broadcast'
import feeEstimateRouter from './routes/fee-estimate'
import githubRouter from './routes/github'
import mcpInfoRouter from './routes/mcp-info'
import transactionsRouter from './routes/transactions'
import { createMcpPostHandler, handleMcpMethodNotAllowed, handleMcpOptions } from './mcp/http'
import packageJson from '../package.json' with { type: 'json' }

Expand Down Expand Up @@ -241,6 +243,9 @@ app.get('/api/transaction/:txid', async (req, res) => {
}
})

// Paginated recent-transaction feed (blocks + optional mempool tip)
app.use('/api/transactions', transactionsRouter)

// Address routes (addressindex RPC + fallback)
app.use('/api/address', addressRouter)

Expand Down Expand Up @@ -308,15 +313,24 @@ app.get('/api/masternodes', async (req, res) => {
const network = parseNetwork(req.query.network)
const limit = parseLimit(req.query.limit)
const offset = parseOffset(req.query.offset)
// Stats-only by default (cheap `masternode count`). Pass `include=list` when
// the caller needs per-node rows — that triggers the heavier `masternodelist`.
const includeList =
typeof req.query.include === 'string' &&
req.query.include.split(',').map((part) => part.trim().toLowerCase()).includes('list')
const COLLATERAL_PER_MASTERNODE = 5000

const [masternodeList, masternodeCount, blockHeight] = await Promise.all([
blockCache.getMasternodeList(network).catch(() => [] as unknown[]),
blockCache.getMasternodeCount(network).catch(() => null),
blockCache.getBlockCount(network).catch(() => 0),
])

interface MasternodeEntry { txid: string; outidx: number; address: string; protocol: number; status: string; activeTime: number; lastSeen: number; lastPaid: number; rank: number }
interface MasternodeEntry {
txid: string
outidx: number
address: string
protocol: number
status: string
activeTime: number
lastSeen: number
lastPaid: number
rank: number
}

// FairCoin v3.0.5 `masternodelist` (default mode) returns an array of objects:
// { rank, txhash, outidx, status, addr, version, lastseen, activetime, lastpaid }.
Expand All @@ -335,23 +349,58 @@ app.get('/api/masternodes', async (req, res) => {
}
}

const masternodes = (Array.isArray(masternodeList) ? masternodeList : []).map(parseMasternodeEntry)
// Real supply schedule (premine + halvings), not a naive height*reward guess.
const [masternodeCount, blockHeight, masternodeList] = await Promise.all([
blockCache.getMasternodeCount(network),
blockCache.getBlockCount(network).catch(() => 0),
includeList
? blockCache.getMasternodeList(network).catch((error: unknown) => {
logger.error('Error fetching masternode list:', error)
return [] as Awaited<ReturnType<typeof blockCache.getMasternodeList>>
})
: Promise.resolve(null),
])

const masternodes = (masternodeList ?? []).map(parseMasternodeEntry)
const totalSupply = computeCirculatingSupply(blockHeight)
const totalCollateral = masternodes.length * COLLATERAL_PER_MASTERNODE
const collateralPercentage = totalSupply > 0 ? (totalCollateral / totalSupply) * 100 : 0

const statusCounts = masternodes.reduce((acc, mn) => { acc[mn.status] = (acc[mn.status] || 0) + 1; return acc }, {} as Record<string, number>)
const statusCounts = masternodes.reduce((acc, mn) => {
acc[mn.status] = (acc[mn.status] || 0) + 1
return acc
}, {} as Record<string, number>)

const enabledCount = masternodeCount?.enabled ?? statusCounts.ENABLED ?? 0
const totalCount = masternodeCount?.total ?? masternodes.length
const totalCount = masternodeCount?.total ?? (includeList ? masternodes.length : 0)
const totalCollateral = totalCount * COLLATERAL_PER_MASTERNODE
const collateralPercentage = totalSupply > 0 ? (totalCollateral / totalSupply) * 100 : 0

const stats = {
total: totalCount, enabled: enabledCount,
preEnabled: statusCounts.PRE_ENABLED || 0, expired: statusCounts.EXPIRED || 0,
newStartRequired: statusCounts.NEW_START_REQUIRED || 0, watchdogExpired: statusCounts.WATCHDOG_EXPIRED || 0,
totalCollateral, collateralPercentage,
averageActiveTime: masternodes.length > 0 ? masternodes.reduce((sum, mn) => sum + mn.activeTime, 0) / masternodes.length : 0,
networkSecurity: { masternodeRewards: MASTERNODE_REWARD_PERCENT, stakingRewards: STAKING_REWARD_PERCENT, budgetRewards: BUDGET_REWARD_PERCENT }
total: totalCount,
enabled: enabledCount,
preEnabled: statusCounts.PRE_ENABLED || 0,
expired: statusCounts.EXPIRED || 0,
newStartRequired: statusCounts.NEW_START_REQUIRED || 0,
watchdogExpired: statusCounts.WATCHDOG_EXPIRED || 0,
totalCollateral,
collateralPercentage,
averageActiveTime:
masternodes.length > 0
? masternodes.reduce((sum, mn) => sum + mn.activeTime, 0) / masternodes.length
: 0,
networkSecurity: {
masternodeRewards: MASTERNODE_REWARD_PERCENT,
stakingRewards: STAKING_REWARD_PERCENT,
budgetRewards: BUDGET_REWARD_PERCENT,
},
}

if (!includeList) {
res.json({
masternodes: [],
stats,
network,
pagination: { total: 0, limit, offset },
})
return
}

// Sort by rank (active masternodes first) so pagination is stable and useful.
Expand Down
Loading
Loading