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
2 changes: 2 additions & 0 deletions .claude/rules/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ npm start
```

Supported chain IDs: 1 (Ethereum), 42161 (Arbitrum), 10 (Optimism), 8453 (Base), 56 (BSC), 137 (Polygon), 31337 (Hardhat), 97 (BSC Testnet), 11155111 (Sepolia), 43114 (Avalanche)

Non-EVM networks are selected by slug: `btc`, `tbtc`, `zec`, `tzec`, `sol`, `sol-devnet`, `sol-testnet` (e.g. `OPENSCAN_NETWORKS="1,btc,zec"`).
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ A trustless, open-source blockchain explorer for Bitcoin, Ethereum, and Layer 2
- **Bitcoin Mainnet** (`/btc`) - The main Bitcoin network
- **Bitcoin Testnet4** (`/tbtc`) - Bitcoin test network for development

#### Zcash Networks
- **Zcash Mainnet** (`/zec`) - Privacy-preserving network with transparent and shielded value pools
- **Zcash Testnet** (`/tzec`) - Zcash test network for development

#### EVM Networks
- **Ethereum Mainnet** - The main Ethereum network
- **Sepolia Testnet** - Ethereum test network for development
Expand Down
91 changes: 91 additions & 0 deletions e2e/fixtures/zcash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import type { Page } from "@playwright/test";
import { BLOCK_3483400 } from "../../src/services/adapters/ZcashAdapter/fixtures";
import { mockJsonRpc } from "./rpcMock";

/** The built-in Zcash RPC defaults are Tatum's gateways, so every Zcash request matches this */
export const ZCASH_RPC_PATTERN = /zcash-(mainnet|testnet)(-zebrad)?\.gateway\.tatum\.io/;

export const ZCASH = {
networkSlug: "zec",
tipHeight: BLOCK_3483400.height,
mempoolSize: 9,
} as const;

// Mainnet value pools at block 3,483,461, in zatoshis
const VALUE_POOLS: Array<[string, number]> = [
["transparent", 1_197_461_726_829_416],
["sprout", 2_259_146_261_837],
["sapling", 51_144_292_792_244],
["orchard", 41_719_811_959_765],
["lockbox", 6_319_912_500_000],
["ironwood", 394_349_188_711_218],
];
const CHAIN_SUPPLY_ZAT = 1_693_254_079_054_480;

export interface RecordedRpcCall {
method: string;
params: unknown[];
}

/** Earlier blocks reuse the tip's header with their own height and hash */
function blockSummary(height: number) {
return {
...BLOCK_3483400,
height,
hash: height.toString(16).padStart(64, "0"),
confirmations: ZCASH.tipHeight - height + 1,
tx: [height.toString(16).padStart(64, "f")],
};
}

/**
* Serve a Zcash chain whose tip is mainnet block 3,483,400 and record every Zcash RPC call
* the page makes, including methods that are not mocked.
*/
export async function mockZcashRpc(page: Page): Promise<RecordedRpcCall[]> {
const calls: RecordedRpcCall[] = [];
page.on("request", (request) => {
if (request.method() !== "POST" || !ZCASH_RPC_PATTERN.test(request.url())) return;
try {
const body = JSON.parse(request.postData() ?? "{}");
calls.push({ method: body.method, params: body.params ?? [] });
} catch {
// Not a JSON-RPC body
}
});

await mockJsonRpc(page, ZCASH_RPC_PATTERN, {
getblockcount: { result: ZCASH.tipHeight },
getblockchaininfo: {
result: {
chain: "main",
blocks: ZCASH.tipHeight,
headers: ZCASH.tipHeight,
bestblockhash: BLOCK_3483400.hash,
difficulty: BLOCK_3483400.difficulty,
estimatedheight: ZCASH.tipHeight,
verificationprogress: 1,
chainSupply: {
chainValue: CHAIN_SUPPLY_ZAT / 1e8,
chainValueZat: CHAIN_SUPPLY_ZAT,
monitored: true,
},
valuePools: VALUE_POOLS.map(([id, chainValueZat]) => ({
id,
chainValue: chainValueZat / 1e8,
chainValueZat,
monitored: true,
})),
},
},
getmempoolinfo: { result: { size: ZCASH.mempoolSize, bytes: 4_512, usage: 9_000 } },
getblock: (params) => {
const [hashOrHeight, verbosity] = params as [string, number];
const isTip =
hashOrHeight === String(ZCASH.tipHeight) || hashOrHeight === BLOCK_3483400.hash;
return isTip && verbosity === 2 ? BLOCK_3483400 : blockSummary(Number(hashOrHeight));
},
});

return calls;
}
95 changes: 95 additions & 0 deletions e2e/tests/shared/mocked/zcash-dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { expect, test } from "../../../fixtures/test";
import { mockZcashRpc, ZCASH, ZCASH_RPC_PATTERN } from "../../../fixtures/zcash";

/**
* Hermetic Zcash network dashboard. RPC traffic to the built-in Tatum gateways is served
* from mainnet block 3,483,400, so the page renders without a live node or rate limits.
*/
test.describe("Zcash dashboard", () => {
test("renders chain stats, value pools, latest blocks and transactions", async ({ page }) => {
await mockZcashRpc(page);

await page.goto(`/#/${ZCASH.networkSlug}`);

await expect(page.locator(".network-title-name")).toHaveText("ZCASH MAINNET");

const stats = page.locator(".dashboard-stats-row");
await expect(stats).toContainText("#3,483,400");
await expect(stats).toContainText(`${ZCASH.mempoolSize} txs`);
await expect(stats).toContainText("% shielded");

const pools = page.getByTestId("zcash-value-pools");
for (const name of ["Transparent", "Sprout", "Sapling", "Orchard", "Lockbox", "Ironwood"]) {
await expect(pools).toContainText(name);
}

const blocks = page.getByTestId("zcash-blocks-table");
await expect(blocks).toContainText("#3,483,400");
await expect(blocks).toContainText("#3,483,396");

const transactions = page.getByTestId("zcash-transactions-table");
await expect(transactions).toContainText("Coinbase");
await expect(transactions).toContainText("Fully shielded");
await expect(transactions).toContainText("Shielding");

await expect(page.locator(".network-block-number")).toHaveText("#3,483,400");
});

test("requests blocks by height string and never calls getblockhash", async ({ page }) => {
const calls = await mockZcashRpc(page);

await page.goto(`/#/${ZCASH.networkSlug}`);
await expect(page.getByTestId("zcash-blocks-table")).toContainText("#3,483,396");

const getblockCalls = calls.filter((call) => call.method === "getblock");
expect(getblockCalls.length).toBeGreaterThanOrEqual(5);
for (const call of getblockCalls) {
expect(typeof call.params[0]).toBe("string");
}
expect(calls.map((call) => call.method)).not.toContain("getblockhash");
});

test("shares one getblockchaininfo call between the navbar height and the stats", async ({
page,
}) => {
const calls = await mockZcashRpc(page);

await page.goto(`/#/${ZCASH.networkSlug}`);
await expect(page.getByTestId("zcash-blocks-table")).toContainText("#3,483,396");
await expect(page.locator(".network-block-number")).toHaveText("#3,483,400");

const count = (method: string) => calls.filter((call) => call.method === method).length;
expect(count("getblockchaininfo")).toBe(1);
expect(count("getblockcount")).toBe(0);
// The tip with its transactions, then one summary per earlier block
expect(count("getblock")).toBe(5);
});

test("shows a block that couldn't be loaded instead of leaving a gap", async ({ page }) => {
await mockZcashRpc(page);
const failingHeight = String(ZCASH.tipHeight - 2);
await page.route(ZCASH_RPC_PATTERN, async (route) => {
const body = JSON.parse(route.request().postData() ?? "{}");
if (body.method === "getblock" && body.params?.[0] === failingHeight) {
await route.fulfill({
contentType: "application/json",
body: JSON.stringify({
jsonrpc: "2.0",
id: body.id,
error: { code: -8, message: "Block not found" },
}),
});
return;
}
await route.fallback();
});

await page.goto(`/#/${ZCASH.networkSlug}`);

const blocks = page.getByTestId("zcash-blocks-table");
await expect(blocks).toContainText("#3,483,396");
const unavailable = blocks.getByTestId("zcash-block-unavailable");
await expect(unavailable).toHaveCount(1);
await expect(unavailable).toContainText("#3,483,398");
});
});
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
LazyTokenDetails,
LazyTx,
LazyTxs,
LazyZcashNetwork,
preloadAllRoutes,
} from "./components/LazyComponents";
import { SettingsProvider, useSettings, useTheme } from "./context/SettingsContext";
Expand Down Expand Up @@ -159,6 +160,10 @@ function AppContent() {
<Route path="tbtc/address/:address" element={<LazyBitcoinAddress />} />
<Route path="tbtc/mempool" element={<LazyBitcoinMempool />} />
<Route path="tbtc/mempool/:filter" element={<LazyBitcoinTx />} />
{/* Zcash Mainnet routes (must come before :networkId catch-all) */}
<Route path="zec" element={<LazyZcashNetwork />} />
{/* Zcash Testnet routes */}
<Route path="tzec" element={<LazyZcashNetwork />} />
{/* Solana Mainnet routes (must come before :networkId catch-all) */}
<Route path="sol" element={<LazySolanaNetwork />} />
<Route path="sol/slots" element={<LazySolanaSlots />} />
Expand Down
6 changes: 6 additions & 0 deletions src/components/LazyComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const BitcoinTransactionsPage = lazy(() => import("./pages/bitcoin/BitcoinTransa
const BitcoinAddressPage = lazy(() => import("./pages/bitcoin/BitcoinAddressPage"));
const BitcoinMempoolPage = lazy(() => import("./pages/bitcoin/BitcoinMempoolPage"));

// Lazy load page components - Zcash
const ZcashNetwork = lazy(() => import("./pages/zcash"));

// Lazy load page components - Solana
const SolanaNetwork = lazy(() => import("./pages/solana"));
const SolanaSlotsPage = lazy(() => import("./pages/solana/SolanaSlotsPage"));
Expand Down Expand Up @@ -64,6 +67,7 @@ export const LazyBitcoinTx = withSuspense(BitcoinTransactionPage);
export const LazyBitcoinTxs = withSuspense(BitcoinTransactionsPage);
export const LazyBitcoinAddress = withSuspense(BitcoinAddressPage);
export const LazyBitcoinMempool = withSuspense(BitcoinMempoolPage);
export const LazyZcashNetwork = withSuspense(ZcashNetwork);
export const LazySolanaNetwork = withSuspense(SolanaNetwork);
export const LazySolanaSlots = withSuspense(SolanaSlotsPage);
export const LazySolanaSlot = withSuspense(SolanaSlotPage);
Expand Down Expand Up @@ -109,6 +113,8 @@ export function preloadAllRoutes() {
import("./pages/bitcoin/BitcoinTransactionsPage");
import("./pages/bitcoin/BitcoinAddressPage");
import("./pages/bitcoin/BitcoinMempoolPage");
// Zcash pages
import("./pages/zcash");
// Solana pages
import("./pages/solana");
import("./pages/solana/SolanaSlotsPage");
Expand Down
33 changes: 25 additions & 8 deletions src/components/navbar/NetworkBlockIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { useContext, useEffect, useMemo, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { getRPCUrls } from "../../config/rpcConfig";
import { REFRESH_INTERVAL_MS as ZCASH_REFRESH_INTERVAL_MS } from "../../config/zcashConstants";
import { AppContext, useNetworks } from "../../context/AppContext";
import { RpcClient } from "@openscan/network-connectors";
import { useDataService } from "../../hooks/useDataService";
import { formatGasPrice } from "../../utils/formatUtils";
import { logger } from "../../utils/logger";
import type { NetworkType } from "../../types";
import { resolveNetwork, getNetworkRpcKey } from "../../utils/networkResolver";

// Zcash polls slowly: 75 second blocks served by rate-limited gateways
const POLL_INTERVAL_MS: Record<NetworkType, number> = {
evm: 12_000,
solana: 12_000,
bitcoin: 60_000,
zcash: ZCASH_REFRESH_INTERVAL_MS,
};

interface NetworkBlockIndicatorProps {
className?: string;
}
Expand Down Expand Up @@ -44,17 +54,24 @@ export function NetworkBlockIndicator({ className }: NetworkBlockIndicatorProps)

let isMounted = true;
let intervalId: NodeJS.Timeout | null = null;
const controller = new AbortController();

const fetchData = async () => {
const networkRpcKey = getNetworkRpcKey(network);
try {
if (network.type === "bitcoin" && dataService?.isBitcoin()) {
// Fetch Bitcoin block height
const adapter = dataService.getBitcoinAdapter();
const height = await adapter.getLatestBlockNumber();
// UTXO chains (Bitcoin, Zcash) report a block height and have no gas
const getUtxoHeight = dataService?.isBitcoin()
? () => dataService.getBitcoinAdapter().getLatestBlockNumber()
: dataService?.isZcash()
? () =>
dataService.getZcashAdapter().getLatestBlockNumber({ signal: controller.signal })
: null;

if (getUtxoHeight) {
const height = await getUtxoHeight();
if (isMounted) {
setBlockNumber(height);
setGasPrice(null); // Bitcoin doesn't have gas
setGasPrice(null);
setIsLoading(false);
}
} else if (network.type === "solana" && dataService?.isSolana()) {
Expand Down Expand Up @@ -89,6 +106,7 @@ export function NetworkBlockIndicator({ className }: NetworkBlockIndicatorProps)
}
}
} catch (error) {
if (controller.signal.aborted) return;
logger.error("Failed to fetch block number:", error);
if (isMounted) {
setIsLoading(false);
Expand All @@ -99,12 +117,11 @@ export function NetworkBlockIndicator({ className }: NetworkBlockIndicatorProps)
setIsLoading(true);
fetchData();

// Poll every 12 seconds for EVM, 60 seconds for Bitcoin
const pollInterval = network.type === "bitcoin" ? 60000 : 12000;
intervalId = setInterval(fetchData, pollInterval);
intervalId = setInterval(fetchData, POLL_INTERVAL_MS[network.type]);

return () => {
isMounted = false;
controller.abort();
if (intervalId) {
clearInterval(intervalId);
}
Expand Down
12 changes: 9 additions & 3 deletions src/components/pages/rpcs/useRpcLatencyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ function isHttpRpcUrl(url: string): boolean {
}
}

// Zcash (Zebra) serves the same getblockcount method as Bitcoin Core
function usesBitcoinRpc(networkType: NetworkType): boolean {
return networkType === "bitcoin" || networkType === "zcash";
}

function buildRpcBody(networkType: NetworkType): string {
if (networkType === "bitcoin") {
if (usesBitcoinRpc(networkType)) {
return JSON.stringify({ jsonrpc: "2.0", id: 1, method: "getblockcount", params: [] });
}
return JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_blockNumber", params: [] });
Expand Down Expand Up @@ -78,8 +83,9 @@ export async function testRpcEndpoint(
};
}

const blockNumber =
networkType === "bitcoin" ? String(json.result ?? "") : (json.result ?? null);
const blockNumber = usesBitcoinRpc(networkType)
? String(json.result ?? "")
: (json.result ?? null);

return {
url,
Expand Down
Loading