diff --git a/functions/api/_shared.mjs b/functions/api/_shared.mjs new file mode 100644 index 0000000..2905c13 --- /dev/null +++ b/functions/api/_shared.mjs @@ -0,0 +1,24 @@ +export const DEFAULT_CHAIN_ID = 13390; +export const DEFAULT_RPC_URL = 'https://rpc.meechain.live'; + +export const DEFAULT_CONTRACTS = { + token: '0x5FbDB2315678afecb367f032d93F642f64180aa3', + nft: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512', + portal: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0', +}; + +export function resolveChainId(env) { + return Number.parseInt(env.CHAIN_ID || String(DEFAULT_CHAIN_ID), 10); +} + +export function resolveRpcUrl(env) { + return env.DRPC_RPC_URL || env.VITE_RPC_URL || DEFAULT_RPC_URL; +} + +export function resolveContracts(env) { + return { + token: env.VITE_TOKEN_CONTRACT_ADDRESS || DEFAULT_CONTRACTS.token, + nft: env.VITE_NFT_CONTRACT_ADDRESS || DEFAULT_CONTRACTS.nft, + portal: env.VITE_STAKING_CONTRACT_ADDRESS || DEFAULT_CONTRACTS.portal, + }; +} diff --git a/functions/api/health.js b/functions/api/health.js index cad338c..9c9a108 100644 --- a/functions/api/health.js +++ b/functions/api/health.js @@ -2,17 +2,26 @@ // ║ Cloudflare Pages Function: /api/health ║ // ╚══════════════════════════════════════════════════════╝ +import { resolveChainId, resolveContracts, resolveRpcUrl } from './_shared.mjs'; import { getMeechainConfig } from './_shared/meechain-config.js'; export async function onRequestGet(ctx) { const { env } = ctx; const config = getMeechainConfig(env); + const contracts = resolveContracts(env); + const data = { status: 'ok', model: 'gpt-5-mini', bot: 'MeeBot AI', web3: false, + chainId: resolveChainId(env), + rpc: resolveRpcUrl(env), + contracts: { + token: contracts.token, + nft: contracts.nft, + staking: contracts.portal, chainId: config.chainId, rpc: config.rpcPrimary, contracts: { diff --git a/functions/api/network.js b/functions/api/network.js index f26b858..c7e310d 100644 --- a/functions/api/network.js +++ b/functions/api/network.js @@ -2,6 +2,7 @@ // ║ Cloudflare Pages Function: /api/network ║ // ╚══════════════════════════════════════════════════════╝ +import { resolveChainId, resolveContracts, resolveRpcUrl } from './_shared.mjs'; function buildRpcGateway(env = {}) { return { primary: { @@ -39,15 +40,16 @@ export async function onRequestGet(ctx) { const { env } = ctx; const config = getMeechainConfig(env); + const chainId = resolveChainId(env); const data = { chainId: `0x${chainId.toString(16)}`, // 0x344e chainName: 'MeeChain Ritual Chain', rpcUrls: [ - env.DRPC_RPC_URL || 'https://rpc.meechain.live', - env.VITE_RPC_URL || 'https://rpc.meechain.live', + resolveRpcUrl(env), ], nativeCurrency: { name: 'MEE Token', symbol: 'MEE', decimals: 18 }, blockExplorerUrls:['http://explorer.meechain.run.place'], + contracts: resolveContracts(env), contracts: { token: env.VITE_TOKEN_CONTRACT_ADDRESS || '0x5FbDB2315678afecb367f032d93F642f64180aa3', nft: env.VITE_NFT_CONTRACT_ADDRESS || '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512', diff --git a/functions/api/web3/status.js b/functions/api/web3/status.js index 98a9429..825646c 100644 --- a/functions/api/web3/status.js +++ b/functions/api/web3/status.js @@ -2,6 +2,14 @@ // ║ Cloudflare Pages Function: /api/web3/status ║ // ╚══════════════════════════════════════════════════════╝ +import { resolveChainId, resolveContracts, resolveRpcUrl } from '../_shared.mjs'; + +export async function onRequestGet(ctx) { + const { env } = ctx; + + const rpcUrl = resolveRpcUrl(env); + const chainId = resolveChainId(env); + const contracts = resolveContracts(env); import { getMeechainConfig } from '../_shared/meechain-config.js'; export async function onRequestGet(ctx) {