mirror of
https://github.com/luxfi/explore.git
synced 2026-10-30 16:57:53 +00:00
luxd serves no P-Chain JSON-RPC, so every platform.* read the explorer sent
answered 404 and the validators, chains and heights widgets were empty on Lux
and Zoo. Each read is now GET /v1/chain/P/ops/{validators,blockchains,height},
coded against the node's OpenAPI 3.1 document, through GET
/v1/node/p-chain?op=<op>. The proxy's fixed table allows those three ops and one
NodeID parameter; a POST there answers 405.
ChainEntry.pChain is where the P-Chain that secures a chain is read: Lux reads
its own; Zoo, an L2 carried by Lux's validator set, reads Lux's and never its
own node's; Hanzo, on its own committee until hanzod joins as an L2, has none.
P-Chain UI names whose it is ("Lux primary network validators securing Zoo
Network") and prices stake in LUX. The cross-network validator sum is gone: it
counted Lux's validators again under Zoo.
The top bar shows a link only where its page has content: Chains, Bridge and
DEX on the Lux C-Chain host (their pages now 404 elsewhere), Validators where a
P-Chain secures the chain, Stats where there is a P-Chain panel or a stats
service. A P-Chain at genesis renders height #0 rather than nothing. The chain
page's uptime is no longer multiplied by 100.
Claude-Session: https://claude.ai/code/session_011Ge9UnfkEK37Lapx5nfPQK
374 lines
9.8 KiB
TypeScript
374 lines
9.8 KiB
TypeScript
import type { IncomingMessage } from 'http';
|
|
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
|
|
import type { RollupType } from 'types/client/rollup';
|
|
|
|
import type { Route } from 'nextjs-routes';
|
|
import type { Props } from 'nextjs/getServerSideProps/handlers';
|
|
|
|
import config from 'configs/app';
|
|
import { getPChain, isPrimaryNetworkHost } from 'configs/app/chainRegistry';
|
|
|
|
export type Guard = (chainConfig: typeof config) => <Pathname extends Route['pathname'] = never>(context: GetServerSidePropsContext) =>
|
|
Promise<GetServerSidePropsResult<Props<Pathname>> | undefined>;
|
|
|
|
export const account: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.account.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const verifiedAddresses: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.addressVerification.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const userOps: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.userOps.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const marketplace: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.marketplace.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const marketplaceEssentialDapp: Guard = (chainConfig: typeof config) => async() => {
|
|
const feature = chainConfig.features.marketplace;
|
|
if (!feature.isEnabled || !feature.essentialDapps) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const apiDocs: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.apiDocs.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const csvExport: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.csvExport.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const stats: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.stats.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const suave: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.suave.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const nameServiceEns: Guard = (chainConfig: typeof config) => async() => {
|
|
const feature = chainConfig.features.nameServices;
|
|
if (!feature.isEnabled || !feature.ens.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const nameServiceClusters: Guard = (chainConfig: typeof config) => async() => {
|
|
const feature = chainConfig.features.nameServices;
|
|
if (!feature.isEnabled || !feature.clusters.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const accounts: Guard = (chainConfig: typeof config) => async() => {
|
|
if (chainConfig.UI.views.address.hiddenViews?.top_accounts) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const accountsLabelSearch: Guard = (chainConfig: typeof config) => async(context) => {
|
|
if (!chainConfig.features.addressMetadata.isEnabled || !context.query.tagType) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const validators: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.validators.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const validatorDetails: Guard = (chainConfig: typeof config) => async() => {
|
|
const feature = chainConfig.features.validators;
|
|
if (!feature.isEnabled || feature.chainType !== 'zilliqa') {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const gasTracker: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.gasTracker.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const hotContracts: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.hotContracts.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const advancedFilter: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.advancedFilter.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const dataAvailability: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.dataAvailability.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const dev: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.app.isDev) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const publicTagsSubmit: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.publicTagsSubmission.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const pools: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.pools.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const zetaChainCCTX: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.zetachain.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
// ROLLUPS
|
|
export const rollup: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.rollup.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
const DEPOSITS_ROLLUP_TYPES: Array<RollupType> = [ 'optimistic', 'shibarium', 'zkEvm', 'arbitrum', 'scroll' ];
|
|
export const deposits: Guard = (chainConfig: typeof config) => async() => {
|
|
const rollupFeature = chainConfig.features.rollup;
|
|
const beaconChainFeature = chainConfig.features.beaconChain;
|
|
if (
|
|
(!beaconChainFeature.isEnabled || beaconChainFeature.withdrawalsOnly) &&
|
|
!(rollupFeature.isEnabled && DEPOSITS_ROLLUP_TYPES.includes(rollupFeature.type))) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
const WITHDRAWALS_ROLLUP_TYPES: Array<RollupType> = [ 'optimistic', 'shibarium', 'zkEvm', 'arbitrum', 'scroll' ];
|
|
export const withdrawals: Guard = (chainConfig: typeof config) => async() => {
|
|
const rollupFeature = chainConfig.features.rollup;
|
|
if (
|
|
!chainConfig.features.beaconChain.isEnabled &&
|
|
!(rollupFeature.isEnabled && WITHDRAWALS_ROLLUP_TYPES.includes(rollupFeature.type))
|
|
) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
const BATCH_ROLLUP_TYPES: Array<RollupType> = [ 'zkEvm', 'zkSync', 'arbitrum', 'optimistic', 'scroll' ];
|
|
export const batch: Guard = (chainConfig: typeof config) => async() => {
|
|
const rollupFeature = chainConfig.features.rollup;
|
|
if (!(rollupFeature.isEnabled && BATCH_ROLLUP_TYPES.includes(rollupFeature.type))) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const batchCelestia: Guard = (chainConfig: typeof config) => async() => {
|
|
const rollupFeature = chainConfig.features.rollup;
|
|
if (!(rollupFeature.isEnabled && (rollupFeature.type === 'arbitrum' || rollupFeature.type === 'optimistic'))) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const txnWithdrawals: Guard = (chainConfig: typeof config) => async() => {
|
|
const rollupFeature = chainConfig.features.rollup;
|
|
if (!(rollupFeature.isEnabled && rollupFeature.type === 'arbitrum')) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const outputRoots: Guard = (chainConfig: typeof config) => async() => {
|
|
const rollupFeature = chainConfig.features.rollup;
|
|
if (!(rollupFeature.isEnabled && rollupFeature.outputRootsEnabled)) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const disputeGames: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.faultProofSystem.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const mud: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.mudFramework.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const tac: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.tac.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const celo: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.celo.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const interopMessages: Guard = (chainConfig: typeof config) => async() => {
|
|
const rollupFeature = chainConfig.features.rollup;
|
|
if (!rollupFeature.isEnabled || !rollupFeature.interopEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const crossChainTxs: Guard = (chainConfig: typeof config) => async() => {
|
|
if (!chainConfig.features.crossChainTxs.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const multichain: Guard = () => async() => {
|
|
if (!config.features.multichain.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const notMultichain: Guard = () => async() => {
|
|
if (config.features.multichain.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const megaEth: Guard = () => async() => {
|
|
if (!config.features.megaEth.isEnabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
/** The host a request was addressed to: a proxy's X-Forwarded-Host, else Host. */
|
|
export function requestHost(req: IncomingMessage): string {
|
|
const header = req.headers['x-forwarded-host'] ?? req.headers.host ?? '';
|
|
return String(Array.isArray(header) ? header[0] : header).split(',')[0].trim().replace(/:\d+$/, '');
|
|
}
|
|
|
|
// Pages about the Lux primary network's own chains (DEX, bridge routes, the
|
|
// chain list) exist only on the Lux C-Chain explorer. A brand explorer answers
|
|
// 404 for them rather than rendering another network's chains under its name.
|
|
export const primaryNetwork: Guard = () => async(context: GetServerSidePropsContext) => {
|
|
if (!isPrimaryNetworkHost(requestHost(context.req))) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|
|
|
|
// The validators page answers 404 on a chain no P-Chain secures (Hanzo), rather
|
|
// than render another network's validators as its own.
|
|
export const pChain: Guard = () => async(context: GetServerSidePropsContext) => {
|
|
if (!getPChain(requestHost(context.req))) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
};
|