pot_query
Query Proof of Time history from local logs and on-chain subgraph to verify transaction timing and resolve payment disputes.
Instructions
Query Proof of Time history from local log and on-chain subgraph.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| startTime | No | Start time (unix ms). Default: 24h ago | |
| endTime | No | End time (unix ms). Default: now | |
| limit | No | Max entries to return. Default: 100, max: 1000 |
Implementation Reference
- tools.ts:127-185 (handler)The 'potQuery' function implements the 'pot_query' tool, which retrieves proof-of-time anchor logs filtered by time and limit, combining in-memory logs with data from a subgraph.
export async function potQuery(args: { startTime?: number; endTime?: number; limit?: number; }): Promise<unknown> { telemetryIncrement("pot_query"); const limit = Math.min(args.limit ?? 100, 1000); const now = Date.now(); const startTime = args.startTime ?? now - 86400_000; const endTime = args.endTime ?? now; // Filter from in-memory log const filtered = potLog .filter((e) => e.createdAt >= startTime && e.createdAt <= endTime) .slice(-limit); // Best-effort subgraph query let subgraphEntries: unknown[] = []; try { const query = `{ potAnchors( first: ${limit}, orderBy: blockTimestamp, orderDirection: desc, where: { blockTimestamp_gte: "${Math.floor(startTime / 1000)}", blockTimestamp_lte: "${Math.floor(endTime / 1000)}" } ) { id potHash blockTimestamp txHash } }`; const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), 5000); const resp = await fetch(SUBGRAPH_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ query }), signal: controller.signal, }); clearTimeout(timeout); if (resp.ok) { const json = (await resp.json()) as { data?: { potAnchors?: unknown[] } }; subgraphEntries = json.data?.potAnchors ?? []; } } catch { // Subgraph unavailable — local log still returned } return serialize({ local: filtered, subgraph: subgraphEntries, totalLocal: potLog.length, query: { startTime, endTime, limit }, }); }