flop-guild 0.2.7 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/cli.js +23 -1
- package/dist/config.js +1 -1
- package/dist/server.js +17 -9
- package/dist/shell.js +62 -11
- package/dist/testnet.js +356 -0
- package/package.json +3 -2
- package/site/theme.js +29 -0
- package/skill.md +7 -7
package/README.md
CHANGED
|
@@ -50,8 +50,10 @@ refuses to run on a mismatch. Only devnet is filled in.
|
|
|
50
50
|
them and a read-only MCP endpoint at `/mcp` with the tools `get_guide`, `network_status`,
|
|
51
51
|
`join_guild` and `autopilot_install`. It never signs, holds keys or stores request data.
|
|
52
52
|
|
|
53
|
-
The public hostname is one setting, `PUBLIC_HOST
|
|
54
|
-
and the tunnel config all read it.
|
|
53
|
+
The public hostname is one setting, `PUBLIC_HOST` (default `flopguild.xyz`). The site, skill.md,
|
|
54
|
+
llms.txt, the MCP server and the tunnel config all read it.
|
|
55
|
+
|
|
56
|
+
Release: put `SHIP_SSH_KEY` and `SHIP_SSH_TARGET` in `deploy/ship.env` (git-ignored), bump the version, then run `./ship.sh`. It builds, publishes to npm (add `NPM_OTP=<code>` if npm asks for a one-time password), waits for the registry, updates and restarts the server, and prints the site's status line.
|
|
55
57
|
|
|
56
58
|
Deploy on a VPS with Docker:
|
|
57
59
|
|
package/dist/cli.js
CHANGED
|
@@ -27,6 +27,10 @@ Setup (idempotent; never overwrites keys or files)
|
|
|
27
27
|
setup [name] [--network devnet|testnet] [--dry-run] [--presets stocks,privacy,memes]
|
|
28
28
|
[--budget 0.2] [--cap 0.01] [--flow wallet|did] [--until claim] [--no-announce]
|
|
29
29
|
|
|
30
|
+
Testnet (read-only; never changes networks.json)
|
|
31
|
+
testnet-status [--check] [--verify] print the testnet candidate the watcher saved; --check fetches Flop's pages now;
|
|
32
|
+
--verify asks the candidate RPC for block 0 and compares it with the candidate genesis
|
|
33
|
+
|
|
30
34
|
Miners (read-only, no key)
|
|
31
35
|
miners [--limit 10] [--pages 10] rank miners by settled sessions and settlement rate
|
|
32
36
|
|
|
@@ -39,7 +43,7 @@ Secrets live in ~/.flop-guild (or FLOP_GUILD_HOME), mode 600, and are never prin
|
|
|
39
43
|
function parse(argv) {
|
|
40
44
|
const pos = [];
|
|
41
45
|
const opt = {};
|
|
42
|
-
const flags = new Set(["json", "yes", "help", "dry-run", "no-announce"]);
|
|
46
|
+
const flags = new Set(["json", "yes", "help", "dry-run", "no-announce", "check", "verify"]);
|
|
43
47
|
for (let i = 0; i < argv.length; i++) {
|
|
44
48
|
const a = argv[i];
|
|
45
49
|
if (a.startsWith("--")) {
|
|
@@ -191,6 +195,24 @@ async function main() {
|
|
|
191
195
|
});
|
|
192
196
|
break;
|
|
193
197
|
}
|
|
198
|
+
case "testnet-status": {
|
|
199
|
+
const t = await import("./testnet.js");
|
|
200
|
+
if (get("check") === "true")
|
|
201
|
+
await t.checkOnce({ log: () => { } });
|
|
202
|
+
const { existsSync, readFileSync } = await import("node:fs");
|
|
203
|
+
const st = t.status();
|
|
204
|
+
const cand = existsSync(t.candidatePath()) ? readFileSync(t.candidatePath(), "utf8").trim() : "no candidate saved yet (the watcher runs inside the site server; or use --check)";
|
|
205
|
+
out = `testnet published: ${st.published}\nlast checked: ${st.lastChecked ?? "never"}\nlast changed: ${st.lastChanged ?? "never"}${st.lastError ? `\nlast error: ${st.lastError}` : ""}\ncandidate (${t.candidatePath()}):\n${cand}`;
|
|
206
|
+
if (get("verify") === "true") {
|
|
207
|
+
const v = await t.verifyCandidate();
|
|
208
|
+
out += v.error
|
|
209
|
+
? `\nverify: NOT VERIFIED: ${v.error}`
|
|
210
|
+
: `\nverify: ${v.match ? "MATCH" : "MISMATCH"}\n rpc: ${v.rpc}\n candidate: ${v.expected}\n rpc says: ${v.actual}`;
|
|
211
|
+
if (!v.match)
|
|
212
|
+
process.exitCode = 1;
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
194
216
|
case "miners": {
|
|
195
217
|
const { miners } = await import("./miners.js");
|
|
196
218
|
out = await miners(network, num("limit") ?? 10, num("pages") ?? 10);
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The one place the public hostname is defined. Everything else reads PUBLIC_HOST from here.
|
|
2
|
-
const DEFAULT_PUBLIC_HOST = "flopguild.
|
|
2
|
+
const DEFAULT_PUBLIC_HOST = "flopguild.xyz";
|
|
3
3
|
export function publicHost() {
|
|
4
4
|
const h = (process.env.PUBLIC_HOST || DEFAULT_PUBLIC_HOST).trim().toLowerCase();
|
|
5
5
|
if (!/^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*(:\d{1,5})?$/.test(h)) {
|
package/dist/server.js
CHANGED
|
@@ -7,7 +7,7 @@ import { dirname, join } from "node:path";
|
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { GUILD_ROOM, publicHost, render } from "./config.js";
|
|
9
9
|
import { networksPath } from "./net.js";
|
|
10
|
-
import { esc, ICONS, page } from "./shell.js";
|
|
10
|
+
import { DISCLAIMER, esc, ICONS, page } from "./shell.js";
|
|
11
11
|
import { expand, GUIDES, guidesHtml, mdToHtml, ROLES, roleMd, rolesHtml, rolesMd } from "./content.js";
|
|
12
12
|
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
13
13
|
const SITE = join(ROOT, "site");
|
|
@@ -193,7 +193,7 @@ async function handleRpc(req) {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
// ---------- /start (browser-only did:key starter) ----------
|
|
196
|
-
const START_FOOTER =
|
|
196
|
+
const START_FOOTER = DISCLAIMER;
|
|
197
197
|
// The page may load only its own scripts and may connect only to technocore.chat.
|
|
198
198
|
const START_CSP = [
|
|
199
199
|
"default-src 'none'",
|
|
@@ -220,7 +220,7 @@ const HOME_STYLE = `
|
|
|
220
220
|
.stat-top{display:flex;align-items:center;gap:.6rem}.stat-label{font-size:.82rem;color:var(--muted);flex:1;min-width:0}
|
|
221
221
|
.live{display:inline-flex;align-items:center;gap:.3rem;font:600 .6rem/1 var(--mono);letter-spacing:.08em;color:var(--dim);white-space:nowrap}
|
|
222
222
|
.live::before{content:"";width:.42rem;height:.42rem;border-radius:50%;background:var(--dim)}
|
|
223
|
-
.live.on{color:var(--accent)}.live.on::before{background:var(--accent);box-shadow:0 0 0 3px
|
|
223
|
+
.live.on{color:var(--accent)}.live.on::before{background:var(--accent);box-shadow:0 0 0 3px var(--glow)}
|
|
224
224
|
.stat-value{font:700 1.45rem/1.15 var(--display);letter-spacing:-.02em;overflow-wrap:anywhere}.stat-value.text{font-size:1.02rem;line-height:1.35}
|
|
225
225
|
.stat-sub{font-size:.8rem;color:var(--muted)}
|
|
226
226
|
.roles{display:flex;gap:.8rem;overflow-x:auto;scroll-snap-type:x mandatory;padding:.15rem .15rem .5rem;margin:0 -.15rem .6rem;scrollbar-width:thin}
|
|
@@ -238,11 +238,11 @@ const HOME_STYLE = `
|
|
|
238
238
|
.timeline::before{content:"";position:absolute;left:.95rem;top:.6rem;bottom:.6rem;width:1px;background:var(--line-2)}
|
|
239
239
|
.step{counter-increment:step;position:relative;padding-left:2.9rem;margin-bottom:.8rem}
|
|
240
240
|
.step::before{content:counter(step);position:absolute;left:0;top:.85rem;width:1.95rem;height:1.95rem;border-radius:50%;background:var(--bg);border:1px solid var(--line-2);display:grid;place-items:center;font:700 .8rem/1 var(--display);color:var(--muted)}
|
|
241
|
-
.step.done::before{content:"\\2713";background:var(--accent-deep);border-color:var(--accent);color
|
|
241
|
+
.step.done::before{content:"\\2713";background:var(--accent-deep);border-color:var(--accent);color:var(--done-fg)}
|
|
242
242
|
.step-card{margin:0;padding:.85rem 1rem}.step-card>:last-child{margin-bottom:0}.step-card p{margin:.5rem 0 0}
|
|
243
243
|
.step-head{display:flex;align-items:flex-start;gap:.7rem}.step-head h3{margin:0;font:600 .95rem/1.4 "Inter",system-ui,sans-serif}
|
|
244
244
|
.step.done .step-head h3{color:var(--muted)}
|
|
245
|
-
.step-done{appearance:none;-webkit-appearance:none;flex:none;width:1.15rem;height:1.15rem;margin:.12rem 0 0;border:1.5px solid var(--line-2);border-radius:4px;background
|
|
245
|
+
.step-done{appearance:none;-webkit-appearance:none;flex:none;width:1.15rem;height:1.15rem;margin:.12rem 0 0;border:1.5px solid var(--line-2);border-radius:4px;background:var(--input-bg);cursor:pointer;display:grid;place-items:center}
|
|
246
246
|
.step-done:checked{background:var(--accent);border-color:var(--accent)}
|
|
247
247
|
.step-done:checked::after{content:"";width:.3rem;height:.55rem;border:solid var(--on-accent);border-width:0 2px 2px 0;transform:translateY(-1px) rotate(45deg)}
|
|
248
248
|
.notes{margin-top:.2rem}
|
|
@@ -257,6 +257,7 @@ const STATIC_JS = {
|
|
|
257
257
|
"/vendor/noble-ed25519-3.2.0.js": { file: "vendor/noble-ed25519-3.2.0.js", type: "text/javascript; charset=utf-8" },
|
|
258
258
|
"/vendor/noble-ed25519-LICENSE.txt": { file: "vendor/noble-ed25519-LICENSE.txt", type: "text/plain; charset=utf-8" },
|
|
259
259
|
"/copy.js": { file: "copy.js", type: "text/javascript; charset=utf-8" },
|
|
260
|
+
"/theme.js": { file: "theme.js", type: "text/javascript; charset=utf-8" },
|
|
260
261
|
"/tabs.js": { file: "tabs.js", type: "text/javascript; charset=utf-8" },
|
|
261
262
|
"/logo.svg": { file: "logo.svg", type: "image/svg+xml" },
|
|
262
263
|
"/favicon.svg": { file: "favicon.svg", type: "image/svg+xml" },
|
|
@@ -299,10 +300,12 @@ async function homeStats() {
|
|
|
299
300
|
const faucet = Number.isFinite(cap) && cap > 0
|
|
300
301
|
? stat(ICONS.faucet, "Faucet daily limit", `${cap.toLocaleString("en-US")} FLOP`, `whole faucet per day${Number.isFinite(grant) && grant > 0 ? `, ${grant} FLOP per address${Number.isFinite(hours) && hours > 0 ? ` every ${hours} h` : ""}` : ""} ${devnet}`, "on", "LIVE")
|
|
301
302
|
: stat(ICONS.faucet, "Faucet daily limit", DASH, `faucet did not answer ${devnet}`, "off", "NO DATA");
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
void nets;
|
|
304
|
+
const tn = (await import("./testnet.js")).status();
|
|
305
|
+
const when = (iso) => (iso ? `${iso.slice(0, 16).replace("T", " ")} UTC` : "");
|
|
306
|
+
const testnet = tn.published
|
|
307
|
+
? stat(ICONS.clock, "Testnet status", "Endpoints published, not yet enabled in the kit", `seen on Flop's testnet page since ${when(tn.lastChanged)}`, "on", "LIVE", true)
|
|
308
|
+
: stat(ICONS.clock, "Testnet status", "Waiting for Flop endpoints", tn.lastChecked ? `Flop's testnet page checked ${when(tn.lastChecked)}; not yet published: ${tn.missing.join(", ")}` : "first check of Flop's testnet page pending", "off", "WATCHING", true);
|
|
306
309
|
return `<div class="stats">${miners}${validators}${faucet}${testnet}</div>`;
|
|
307
310
|
}
|
|
308
311
|
// ---------- HTTP ----------
|
|
@@ -369,6 +372,7 @@ async function mcp(req, res) {
|
|
|
369
372
|
}
|
|
370
373
|
export function startServer(port, host = "0.0.0.0") {
|
|
371
374
|
publicHost(); // fail fast on a bad PUBLIC_HOST
|
|
375
|
+
void import("./testnet.js").then((t) => t.startWatcher());
|
|
372
376
|
const server = createServer(async (req, res) => {
|
|
373
377
|
try {
|
|
374
378
|
const path = new URL(req.url ?? "/", "http://x").pathname.replace(/\/+$/, "") || "/";
|
|
@@ -376,6 +380,10 @@ export function startServer(port, host = "0.0.0.0") {
|
|
|
376
380
|
return await mcp(req, res);
|
|
377
381
|
if (req.method !== "GET" && req.method !== "HEAD")
|
|
378
382
|
return send(res, 405, "text/plain", "method not allowed\n", { allow: "GET, HEAD" });
|
|
383
|
+
if (path === "/api/status") {
|
|
384
|
+
const { status } = await import("./testnet.js");
|
|
385
|
+
return send(res, 200, "application/json", JSON.stringify(status(), null, 2), { "cache-control": "no-store" });
|
|
386
|
+
}
|
|
379
387
|
if (path === "/healthz")
|
|
380
388
|
return send(res, 200, "text/plain", "ok\n", { "cache-control": "no-store" });
|
|
381
389
|
if (path === "/start") {
|
package/dist/shell.js
CHANGED
|
@@ -49,9 +49,18 @@ const FONT_CSS = `
|
|
|
49
49
|
@font-face{font-family:"Inter";font-style:normal;font-weight:400;font-display:swap;src:url(/fonts/inter-latin-400-normal.woff2) format("woff2")}
|
|
50
50
|
@font-face{font-family:"Inter";font-style:normal;font-weight:600;font-display:swap;src:url(/fonts/inter-latin-600-normal.woff2) format("woff2")}
|
|
51
51
|
@font-face{font-family:"Space Mono";font-style:normal;font-weight:700;font-display:swap;src:url(/fonts/space-mono-latin-700-normal.woff2) format("woff2")}`;
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
/** Dark is the base; light overrides it. No-JS visitors follow prefers-color-scheme; theme.js sets data-theme. */
|
|
53
|
+
const DARK = `color-scheme:dark;--bg:#0a1020;--panel:#0f1729;--card:#121c31;--card-2:#17223a;--line:#1f2b44;--line-2:#2a3856;
|
|
54
54
|
--fg:#e6ebf4;--muted:#8d99b0;--dim:#64708a;--accent:#8cc5b1;--accent-deep:#2f5d50;--on-accent:#08130f;--warn:#e0b25c;--bad:#ef8a80;
|
|
55
|
+
--warn-line:#4a3d22;--warn-bg:#1d1a12;--tag-bg:#2f5d50;--tag-fg:#d8efe6;--term-bg:#070c18;--term-fg:#dfe6f2;--term-prompt:#8cc5b1;--input-bg:#0b1222;--glow:rgba(140,197,177,.15);--done-fg:#e6f6ef;`;
|
|
56
|
+
const LIGHT = `color-scheme:light;--bg:#f5f7fa;--panel:#ffffff;--card:#ffffff;--card-2:#f0f3f7;--line:#e1e6ed;--line-2:#cfd7e2;
|
|
57
|
+
--fg:#111a2c;--muted:#525e72;--dim:#7a8597;--accent:#2f5d50;--accent-deep:#2f5d50;--on-accent:#ffffff;--warn:#8a5a00;--bad:#b3261e;
|
|
58
|
+
--warn-line:#e7cf9c;--warn-bg:#fdf6e6;--tag-bg:#dcefe7;--tag-fg:#1f4a3e;--term-bg:#0f1729;--term-fg:#e6ebf4;--term-prompt:#8cc5b1;--input-bg:#ffffff;--glow:rgba(47,93,80,.15);--done-fg:#ffffff;`;
|
|
59
|
+
const THEME_CSS = `
|
|
60
|
+
:root[data-theme=light]{${LIGHT}}
|
|
61
|
+
@media (prefers-color-scheme: light){:root:not([data-theme]){${LIGHT}}}`;
|
|
62
|
+
export const SHELL_CSS = `${FONT_CSS}
|
|
63
|
+
:root{${DARK}
|
|
55
64
|
--display:"Space Mono",ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;--mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace}
|
|
56
65
|
*,*::before,*::after{box-sizing:border-box}
|
|
57
66
|
html{-webkit-text-size-adjust:100%}
|
|
@@ -68,7 +77,7 @@ code{font-family:var(--mono);font-size:.86em;background:var(--card-2);border:1px
|
|
|
68
77
|
.topbar .wrap{display:flex;align-items:center;gap:.5rem 1.2rem;flex-wrap:wrap;min-height:3.6rem;padding-top:.5rem;padding-bottom:.5rem}
|
|
69
78
|
.brand{display:inline-flex;align-items:center;gap:.55rem;color:var(--fg)}.brand:hover{text-decoration:none}
|
|
70
79
|
.brand img{display:block;border-radius:6px}.wm{font-size:1.15rem;letter-spacing:-.03em}.wm b{font-weight:600}.wm span{font-weight:400}
|
|
71
|
-
.pill{display:inline-flex;align-items:center;gap:.35rem;font:600 .68rem/1 var(--mono);letter-spacing:.08em;color:var(--warn);border:1px solid
|
|
80
|
+
.pill{display:inline-flex;align-items:center;gap:.35rem;font:600 .68rem/1 var(--mono);letter-spacing:.08em;color:var(--warn);border:1px solid var(--warn-line);background:var(--warn-bg);border-radius:99px;padding:.3rem .55rem}
|
|
72
81
|
.pill::before{content:"";width:.4rem;height:.4rem;border-radius:50%;background:currentColor}
|
|
73
82
|
.nav{display:flex;gap:.2rem 1.1rem;flex-wrap:wrap;font-size:.9rem;margin-left:auto}.nav a{color:var(--muted)}.nav a:hover{color:var(--fg);text-decoration:none}
|
|
74
83
|
.btn{display:inline-block;font:600 .88rem/1 "Inter",system-ui,sans-serif;background:var(--accent);color:var(--on-accent);border:1px solid var(--accent);border-radius:8px;padding:.6rem .9rem;cursor:pointer;white-space:nowrap}
|
|
@@ -85,33 +94,75 @@ main.wrap{padding-top:1.8rem;padding-bottom:3rem}
|
|
|
85
94
|
.tile{display:inline-grid;place-items:center;width:2rem;height:2rem;border-radius:8px;background:var(--card-2);border:1px solid var(--line-2);color:var(--accent);flex:none}
|
|
86
95
|
.tile svg{width:1.05rem;height:1.05rem}
|
|
87
96
|
.tag,.prov{display:inline-block;font:600 .62rem/1.5 var(--mono);letter-spacing:.06em;padding:0 .4rem;border-radius:4px;vertical-align:.12em;text-transform:uppercase;white-space:nowrap}
|
|
88
|
-
.tag{background:var(--
|
|
97
|
+
.tag{background:var(--tag-bg);color:var(--tag-fg)}.prov{border:1px solid var(--warn-line);color:var(--warn)}
|
|
89
98
|
table{border-collapse:collapse;width:100%}th,td{text-align:left;vertical-align:top;padding:.45rem .5rem .45rem 0;border-bottom:1px solid var(--line)}
|
|
90
99
|
tr:last-child>th,tr:last-child>td{border-bottom:0}
|
|
91
100
|
/* terminal code blocks */
|
|
92
|
-
.term{border:1px solid var(--line-2);border-radius:10px;overflow:hidden;margin:.6rem 0 1rem;background
|
|
101
|
+
.term{border:1px solid var(--line-2);border-radius:10px;overflow:hidden;margin:.6rem 0 1rem;background:var(--term-bg);min-width:0}
|
|
93
102
|
.term-bar{display:flex;align-items:center;justify-content:space-between;gap:.6rem;padding:.35rem .4rem .35rem .75rem;background:var(--card-2);border-bottom:1px solid var(--line-2)}
|
|
94
103
|
.runin{font-size:.75rem;color:var(--muted);line-height:1.35;min-width:0}
|
|
95
|
-
.term pre{margin:0;padding:.75rem .9rem;overflow-x:auto;font:13px/1.65 var(--mono);color
|
|
104
|
+
.term pre{margin:0;padding:.75rem .9rem;overflow-x:auto;font:13px/1.65 var(--mono);color:var(--term-fg)}
|
|
96
105
|
.term pre code{background:none;border:0;padding:0;font-size:inherit;overflow-wrap:normal;white-space:pre}
|
|
97
|
-
.term pre.cmd .ln::before{content:"$ ";color:var(--
|
|
106
|
+
.term pre.cmd .ln::before{content:"$ ";color:var(--term-prompt);user-select:none}
|
|
98
107
|
button.copy{font:600 .72rem/1 "Inter",system-ui,sans-serif;color:var(--fg);background:transparent;border:1px solid var(--line-2);border-radius:6px;padding:.35rem .6rem;cursor:pointer;flex:none}
|
|
99
108
|
button.copy:hover{border-color:var(--accent);color:var(--accent)}
|
|
100
109
|
/* forms */
|
|
101
|
-
input[type=text],input[type=password],input[type=number]{font:inherit;color:var(--fg);background
|
|
110
|
+
input[type=text],input[type=password],input[type=number]{font:inherit;color:var(--fg);background:var(--input-bg);border:1px solid var(--line-2);border-radius:8px;padding:.5rem .6rem;margin-top:.3rem;width:100%;min-width:0}
|
|
102
111
|
input:focus{outline:none;border-color:var(--accent)}
|
|
103
112
|
label{display:flex;flex-direction:column;font-size:.85rem;color:var(--muted)}label.inline{flex-direction:row;gap:.5rem;align-items:center}
|
|
104
113
|
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(13rem,1fr));gap:.8rem 1rem}
|
|
105
114
|
main button:not(.copy):not([role=tab]){font:600 .88rem/1 "Inter",system-ui,sans-serif;background:var(--accent);color:var(--on-accent);border:1px solid var(--accent);border-radius:8px;padding:.6rem .9rem;cursor:pointer}
|
|
106
115
|
.msg{color:var(--muted)}.msg.bad{color:var(--bad)}
|
|
107
116
|
/* footer */
|
|
108
|
-
.foot{border-top:1px solid var(--line);color:var(--
|
|
109
|
-
|
|
117
|
+
.foot{position:relative;overflow:hidden;border-top:1px solid var(--line);background:var(--panel);color:var(--muted);font-size:.86rem;margin-top:2rem}
|
|
118
|
+
.foot-log{position:absolute;inset:-30% -10%;transform:rotate(-9deg);font:600 .8rem/2.1 var(--mono);color:var(--fg);opacity:.045;white-space:pre;pointer-events:none;user-select:none;columns:3 16rem;column-gap:3rem}
|
|
119
|
+
.foot>.wrap{position:relative}
|
|
120
|
+
.foot-main{display:grid;gap:2rem;grid-template-columns:minmax(0,1fr);padding-top:2.4rem;padding-bottom:1.6rem}
|
|
121
|
+
@media (min-width:960px){.foot-main{grid-template-columns:minmax(0,15rem) minmax(0,1fr)}}
|
|
122
|
+
.foot-brand p{margin:.7rem 0 0;max-width:16rem}
|
|
123
|
+
.foot-cols{display:grid;gap:1.6rem 1.2rem;grid-template-columns:repeat(4,minmax(0,1fr))}
|
|
124
|
+
@media (max-width:760px){.foot-cols{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
|
125
|
+
@media (max-width:400px){.foot-cols{grid-template-columns:minmax(0,1fr)}}
|
|
126
|
+
.foot-label{font:700 .66rem/1 var(--mono);letter-spacing:.12em;text-transform:uppercase;color:var(--dim);margin:0 0 .85rem}
|
|
127
|
+
.foot-col ul{list-style:none;margin:0;padding:0}.foot-col li{margin:0 0 .5rem;overflow-wrap:anywhere}
|
|
128
|
+
.foot-col a{color:var(--muted)}.foot-col a:hover{color:var(--fg);text-decoration:none}.foot-col code{font-size:.78rem}
|
|
129
|
+
.foot-bottom{display:flex;align-items:center;justify-content:space-between;gap:1rem;border-top:1px solid var(--line);padding-top:1rem;padding-bottom:1.4rem;color:var(--dim);font-size:.8rem}
|
|
130
|
+
.foot-bottom p{margin:0}.foot-bottom a{color:var(--dim);text-decoration:underline}
|
|
131
|
+
.theme-toggle{flex:none;display:inline-grid;place-items:center;width:2.1rem;height:2.1rem;border-radius:8px;border:1px solid var(--line-2);background:var(--card);color:var(--fg);cursor:pointer;padding:0}
|
|
132
|
+
.theme-toggle:hover{border-color:var(--accent);color:var(--accent)}.theme-toggle svg{width:1rem;height:1rem}
|
|
133
|
+
.theme-toggle .sun{display:none}:root[data-theme=dark] .theme-toggle .sun{display:block}:root[data-theme=dark] .theme-toggle .moon{display:none}
|
|
134
|
+
${THEME_CSS}`;
|
|
135
|
+
const NAV = `<nav class="nav" aria-label="Main"><a href="/start">Create DID</a><a href="/miner">Miner calculator</a><a href="${GUILD_ROOM_URL}">Guild room</a></nav>`;
|
|
136
|
+
export const DISCLAIMER = "Unofficial community kit, not affiliated with Flop Labs. No airdrop promises.";
|
|
137
|
+
/** Real setup step text for the footer backdrop: no numbers, no hashes. */
|
|
138
|
+
const LOG_LINES = ["created did:key", "created encrypted wallet", "genesis ok on devnet", "faucet accepted", "enrolled via the wallet flow", "wrote tasks.json", "wrote agent.json", "posted to d-flopguild"];
|
|
139
|
+
const FOOT_LOG = Array.from({ length: 9 }, (_, i) => LOG_LINES.slice(i % LOG_LINES.length).concat(LOG_LINES.slice(0, i % LOG_LINES.length)).map((l) => `setup ${l}`).join("\n")).join("\n");
|
|
140
|
+
const SUN = '<svg class="sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M4.6 4.6l1.4 1.4M18 18l1.4 1.4M2.5 12h2M19.5 12h2M4.6 19.4L6 18M18 6l1.4-1.4"/></svg>';
|
|
141
|
+
const MOON = '<svg class="moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z"/></svg>';
|
|
142
|
+
function footer(note) {
|
|
143
|
+
const col = (label, items) => `<div class="foot-col"><p class="foot-label">${label}</p><ul>${items.map((i) => `<li>${i}</li>`).join("")}</ul></div>`;
|
|
144
|
+
return `<footer class="foot">
|
|
145
|
+
<div class="foot-log" aria-hidden="true">${FOOT_LOG}</div>
|
|
146
|
+
<div class="wrap foot-main">
|
|
147
|
+
<div class="foot-brand"><a class="brand" href="/" aria-label="flopguild home"><img src="/logo.svg" alt="" width="26" height="26"><span class="wm"><span>flop</span><b>guild</b></span></a>
|
|
148
|
+
<p>Community kit for the Flop network</p></div>
|
|
149
|
+
<nav class="foot-cols" aria-label="Footer">
|
|
150
|
+
${col("Product", ['<a href="/#agent">Start your agent</a>', '<a href="/start">Create DID</a>', '<a href="/miner">Miner calculator</a>'])}
|
|
151
|
+
${col("Learn", ['<a href="/#agent">Agent</a>', '<a href="/#miner">Miner</a>', '<a href="/#validator">Validator</a>', '<a href="/guides/claude-vps">Claude + VPS guide</a>', '<a href="/guides/manual-pc">Own PC guide</a>'])}
|
|
152
|
+
${col("For agents", ['<a href="/skill.md">skill.md</a>', '<a href="/llms.txt">llms.txt</a>', 'MCP: <code>/mcp</code>', '<a href="/guides/agent-quickstart">Agent quick start</a>'])}
|
|
153
|
+
${col("Project", [`<a href="${GUILD_ROOM_URL}">Guild room ${GUILD_ROOM}</a>`, '<a href="https://www.npmjs.com/package/flop-guild">flop-guild on npm</a>', '<a href="https://docs.flop.network/">Flop docs</a>'])}
|
|
154
|
+
</nav>
|
|
155
|
+
</div>
|
|
156
|
+
<div class="wrap foot-bottom"><p>${esc(note)} via flop-guild</p>
|
|
157
|
+
<button type="button" class="theme-toggle" aria-label="Switch between light and dark theme" title="Light or dark theme">${SUN}${MOON}</button></div>
|
|
158
|
+
</footer>`;
|
|
159
|
+
}
|
|
110
160
|
export function page(title, body, o = {}) {
|
|
111
161
|
body = decorateCode(o.cards ? cardify(body) : body);
|
|
112
162
|
const copy = body.includes("copyable") ? '<script defer src="/copy.js"></script>' : "";
|
|
113
163
|
return `<!doctype html>
|
|
114
164
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
165
|
+
<script src="/theme.js"></script>
|
|
115
166
|
<title>${esc(title)}</title>
|
|
116
167
|
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
117
168
|
<link rel="preload" href="/fonts/space-mono-latin-700-normal.woff2" as="font" type="font/woff2" crossorigin>
|
|
@@ -127,7 +178,7 @@ ${NAV}
|
|
|
127
178
|
<main class="wrap">
|
|
128
179
|
${body}
|
|
129
180
|
</main>
|
|
130
|
-
|
|
181
|
+
${footer(o.footerNote ?? DISCLAIMER)}
|
|
131
182
|
</body></html>`;
|
|
132
183
|
}
|
|
133
184
|
/** Small line icons for tiles. stroke = currentColor. */
|
package/dist/testnet.js
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
// Testnet watcher. Reads Flop's official pages, extracts the testnet endpoints and keeps them as a
|
|
2
|
+
// candidate for a human to review. It never writes networks.json and never points the kit at them.
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { homeDir } from "./identity.js";
|
|
6
|
+
import { networksPath } from "./net.js";
|
|
7
|
+
export const SOURCES = {
|
|
8
|
+
docs: "https://docs.flop.network/networks/testnet",
|
|
9
|
+
releases: "https://flop.network/releases.json",
|
|
10
|
+
};
|
|
11
|
+
export const INTERVAL_MS = 5 * 60 * 1000;
|
|
12
|
+
export const FIELDS = ["rpc", "gateway", "faucet", "genesis", "chainId"];
|
|
13
|
+
// ---------- validation ----------
|
|
14
|
+
const isHttps = (u) => !!u && /^https:\/\/[a-z0-9.-]+(:\d+)?(\/\S*)?$/i.test(u);
|
|
15
|
+
const isRpc = (u) => !!u && /^(wss|https):\/\/[a-z0-9.-]+(:\d+)?(\/\S*)?$/i.test(u);
|
|
16
|
+
const VALID = {
|
|
17
|
+
rpc: isRpc, // the kit talks to the chain over WebSocket; an https RPC is accepted too
|
|
18
|
+
gateway: isHttps,
|
|
19
|
+
faucet: isHttps,
|
|
20
|
+
genesis: (v) => !!v && /^0x[0-9a-f]{64}$/i.test(v),
|
|
21
|
+
chainId: (v) => !!v && /^[a-z0-9][a-z0-9_-]{2,63}$/i.test(v),
|
|
22
|
+
};
|
|
23
|
+
export function missingFields(c) {
|
|
24
|
+
return FIELDS.filter((f) => !VALID[f](c[f]));
|
|
25
|
+
}
|
|
26
|
+
// ---------- extraction ----------
|
|
27
|
+
/** Hosts the kit already uses for devnet. A testnet field may not reuse one of them from prose. */
|
|
28
|
+
function devnetHosts() {
|
|
29
|
+
try {
|
|
30
|
+
const d = JSON.parse(readFileSync(networksPath(), "utf8")).devnet ?? {};
|
|
31
|
+
return new Set(Object.values(d).filter((v) => typeof v === "string" && /^[a-z]+:\/\//.test(v)).map((v) => new URL(v).host));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return new Set();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** HTML to plain text, keeping link targets as "text (url)". */
|
|
38
|
+
export function pageText(html) {
|
|
39
|
+
return html
|
|
40
|
+
.replace(/<script[\s\S]*?<\/script>|<style[\s\S]*?<\/style>/gi, " ")
|
|
41
|
+
.replace(/<a\b[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/gi, (_m, href, t) => `${t} (${href})`)
|
|
42
|
+
.replace(/<[^>]+>/g, " ")
|
|
43
|
+
.replace(/&/g, "&")
|
|
44
|
+
.replace(/</g, "<")
|
|
45
|
+
.replace(/>/g, ">")
|
|
46
|
+
.replace(/"/g, '"')
|
|
47
|
+
.replace(/'|'/g, "'")
|
|
48
|
+
.replace(/\s+/g, " ")
|
|
49
|
+
.trim();
|
|
50
|
+
}
|
|
51
|
+
const KEYWORDS = {
|
|
52
|
+
rpc: /\bRPC\b/,
|
|
53
|
+
gateway: /\bgateway\b/i,
|
|
54
|
+
faucet: /\bfaucet\b/i,
|
|
55
|
+
};
|
|
56
|
+
/** Hosts that are never endpoints: package registries, code hosting, block explorers. */
|
|
57
|
+
const NOT_ENDPOINT = /(^|\.)(npmjs\.org|npmjs\.com|github\.com|githubusercontent\.com)$|scan\b|explorer/i;
|
|
58
|
+
const NEAR = 60; // max characters between the keyword and the URL, with no other URL in between
|
|
59
|
+
/**
|
|
60
|
+
* From the docs page: a URL counts for a field only when it is close to a word naming the field,
|
|
61
|
+
* in a sentence that does not mention devnet, and its host is neither a devnet host of the kit nor
|
|
62
|
+
* a registry, code host or explorer. For the RPC a wss:// URL wins over https://.
|
|
63
|
+
*/
|
|
64
|
+
export function fromDocs(html, devHosts = devnetHosts()) {
|
|
65
|
+
const text = pageText(html);
|
|
66
|
+
const c = {};
|
|
67
|
+
const sentences = text.split(/(?<=[.?!])\s+(?=[A-Z])/);
|
|
68
|
+
for (const field of ["rpc", "gateway", "faucet"]) {
|
|
69
|
+
const found = [];
|
|
70
|
+
for (const s of sentences) {
|
|
71
|
+
if (/devnet/i.test(s))
|
|
72
|
+
continue;
|
|
73
|
+
const urls = [...s.matchAll(/\b(?:https|wss):\/\/[^\s()<>"',]+/g)].map((m) => ({ u: m[0].replace(/[.;:]+$/, ""), at: m.index, end: m.index + m[0].length }));
|
|
74
|
+
const keys = [...s.matchAll(new RegExp(KEYWORDS[field].source, KEYWORDS[field].flags.includes("i") ? "gi" : "g"))].map((m) => ({ at: m.index, end: m.index + m[0].length }));
|
|
75
|
+
for (const x of urls) {
|
|
76
|
+
let host;
|
|
77
|
+
try {
|
|
78
|
+
host = new URL(x.u).host;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (devHosts.has(host) || NOT_ENDPOINT.test(host))
|
|
84
|
+
continue;
|
|
85
|
+
if (!(field === "rpc" ? isRpc(x.u) : isHttps(x.u)))
|
|
86
|
+
continue;
|
|
87
|
+
const near = keys.some((k) => {
|
|
88
|
+
const [from, to] = k.at >= x.end ? [x.end, k.at] : [k.end, x.at];
|
|
89
|
+
if (to - from > NEAR || to < from)
|
|
90
|
+
return false;
|
|
91
|
+
return !urls.some((o) => o !== x && o.at >= from && o.end <= to);
|
|
92
|
+
});
|
|
93
|
+
if (near)
|
|
94
|
+
found.push(x.u);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const pick = field === "rpc" ? (found.find((u) => u.startsWith("wss:")) ?? found[0]) : found[0];
|
|
98
|
+
if (pick)
|
|
99
|
+
c[field] = pick;
|
|
100
|
+
}
|
|
101
|
+
const g = text.match(/genesis[^.]{0,80}?\b(0x[0-9a-fA-F]{64})\b/i);
|
|
102
|
+
if (g)
|
|
103
|
+
c.genesis = g[1].toLowerCase();
|
|
104
|
+
const id = text.match(/chain ID (?:is|:)\s*`?([A-Za-z0-9][A-Za-z0-9_-]{2,63})/i);
|
|
105
|
+
if (id)
|
|
106
|
+
c.chainId = id[1];
|
|
107
|
+
return c;
|
|
108
|
+
}
|
|
109
|
+
/** From releases.json: any object that names itself testnet (or sits under a "testnet" key) and carries endpoint fields. */
|
|
110
|
+
export function fromReleases(json) {
|
|
111
|
+
const c = {};
|
|
112
|
+
const pick = (o) => {
|
|
113
|
+
const get = (...keys) => keys.map((k) => o[k]).find((v) => typeof v === "string");
|
|
114
|
+
c.rpc ??= get("rpc", "rpcUrl", "rpc_url", "ws", "wss");
|
|
115
|
+
c.gateway ??= get("gateway", "gatewayUrl", "gateway_url", "api");
|
|
116
|
+
c.faucet ??= get("faucet", "faucetUrl", "faucet_url");
|
|
117
|
+
c.genesis ??= get("genesis", "genesisHash", "genesis_hash")?.toLowerCase();
|
|
118
|
+
c.chainId ??= get("chainId", "chain_id", "chainID");
|
|
119
|
+
};
|
|
120
|
+
const walk = (v, underTestnet, depth) => {
|
|
121
|
+
if (!v || typeof v !== "object" || depth > 8)
|
|
122
|
+
return;
|
|
123
|
+
if (Array.isArray(v))
|
|
124
|
+
return v.forEach((x) => walk(x, underTestnet, depth + 1));
|
|
125
|
+
const o = v;
|
|
126
|
+
const named = [o.network, o.name, o.id].some((x) => typeof x === "string" && x.toLowerCase() === "testnet");
|
|
127
|
+
if (underTestnet || named)
|
|
128
|
+
pick(o);
|
|
129
|
+
for (const [k, x] of Object.entries(o))
|
|
130
|
+
walk(x, underTestnet || named || k.toLowerCase() === "testnet", depth + 1);
|
|
131
|
+
};
|
|
132
|
+
walk(json, false, 0);
|
|
133
|
+
for (const f of FIELDS)
|
|
134
|
+
if (c[f] === undefined)
|
|
135
|
+
delete c[f];
|
|
136
|
+
return c;
|
|
137
|
+
}
|
|
138
|
+
/** Merge both sources: releases.json (structured) wins over prose for any field it has. */
|
|
139
|
+
export function extract(docsHtml, releasesJson, devHosts = devnetHosts()) {
|
|
140
|
+
const d = docsHtml ? fromDocs(docsHtml, devHosts) : {};
|
|
141
|
+
const r = releasesJson ? fromReleases(releasesJson) : {};
|
|
142
|
+
const candidate = {};
|
|
143
|
+
const sources = {};
|
|
144
|
+
for (const f of FIELDS) {
|
|
145
|
+
if (VALID[f](r[f]))
|
|
146
|
+
(candidate[f] = r[f]), (sources[f] = SOURCES.releases);
|
|
147
|
+
else if (VALID[f](d[f]))
|
|
148
|
+
(candidate[f] = d[f]), (sources[f] = SOURCES.docs);
|
|
149
|
+
}
|
|
150
|
+
const missing = missingFields(candidate);
|
|
151
|
+
return { candidate, sources, missing, published: missing.length === 0 };
|
|
152
|
+
}
|
|
153
|
+
// ---------- state ----------
|
|
154
|
+
export const statePath = () => join(homeDir(), "testnet-watch.json");
|
|
155
|
+
export const candidatePath = () => join(homeDir(), "testnet-candidate.json");
|
|
156
|
+
export function loadState() {
|
|
157
|
+
try {
|
|
158
|
+
return JSON.parse(readFileSync(statePath(), "utf8"));
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return { published: false, candidate: {}, missing: [...FIELDS], sources: {} };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function writeJson(path, v) {
|
|
165
|
+
mkdirSync(homeDir(), { recursive: true, mode: 0o700 });
|
|
166
|
+
writeFileSync(path + ".tmp", JSON.stringify(v, null, 2) + "\n", { mode: 0o600 });
|
|
167
|
+
renameSync(path + ".tmp", path);
|
|
168
|
+
}
|
|
169
|
+
const fingerprint = (s) => JSON.stringify([s.published, FIELDS.map((f) => s.candidate[f] ?? null)]);
|
|
170
|
+
let warnedNoTelegram = false;
|
|
171
|
+
/** Telegram via FLOP_TG_TOKEN and FLOP_TG_CHAT. Unset: log once and skip. The token is never logged. */
|
|
172
|
+
export async function notify(text, log, fetcher = fetch) {
|
|
173
|
+
const token = process.env.FLOP_TG_TOKEN;
|
|
174
|
+
const chat = process.env.FLOP_TG_CHAT;
|
|
175
|
+
if (!token || !chat) {
|
|
176
|
+
if (!warnedNoTelegram)
|
|
177
|
+
log("testnet watcher: FLOP_TG_TOKEN or FLOP_TG_CHAT not set, Telegram messages skipped");
|
|
178
|
+
warnedNoTelegram = true;
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const f = fetcher;
|
|
183
|
+
const r = await f(`https://api.telegram.org/bot${token}/sendMessage`, {
|
|
184
|
+
method: "POST",
|
|
185
|
+
headers: { "content-type": "application/json" },
|
|
186
|
+
body: JSON.stringify({ chat_id: chat, text, disable_web_page_preview: true }),
|
|
187
|
+
signal: AbortSignal.timeout(15_000),
|
|
188
|
+
});
|
|
189
|
+
if (!r.ok)
|
|
190
|
+
log(`testnet watcher: Telegram answered HTTP ${r.status}`);
|
|
191
|
+
return r.ok;
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
log(`testnet watcher: Telegram failed: ${e.name}`); // never the URL: it holds the token
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function message(s, first) {
|
|
199
|
+
const lines = FIELDS.map((f) => `${f}: ${s.candidate[f] ?? "missing"}`);
|
|
200
|
+
const head = first
|
|
201
|
+
? "flop-guild: Flop testnet endpoints are published. Not enabled in the kit; review testnet-candidate.json."
|
|
202
|
+
: `flop-guild: testnet candidate changed (${s.published ? "published" : "no longer complete"}). Not enabled in the kit.`;
|
|
203
|
+
return [head, ...lines, `source: ${SOURCES.docs}`].join("\n");
|
|
204
|
+
}
|
|
205
|
+
/** One check. Fetch errors keep the last state and record the error. */
|
|
206
|
+
export async function checkOnce(o = {}) {
|
|
207
|
+
const fetcher = o.fetcher ?? ((u) => fetch(u, { headers: { "user-agent": "flop-guild-testnet-watch" }, signal: AbortSignal.timeout(20_000) }));
|
|
208
|
+
const now = (o.now ?? (() => new Date()))().toISOString();
|
|
209
|
+
const log = o.log ?? ((s) => process.stderr.write(s + "\n"));
|
|
210
|
+
const prev = loadState();
|
|
211
|
+
const get = async (u) => {
|
|
212
|
+
const r = await fetcher(u);
|
|
213
|
+
if (!r.ok)
|
|
214
|
+
throw new Error(`${u}: HTTP ${r.status}`);
|
|
215
|
+
return r.text();
|
|
216
|
+
};
|
|
217
|
+
const [docs, rel] = await Promise.allSettled([get(SOURCES.docs), get(SOURCES.releases)]);
|
|
218
|
+
if (docs.status === "rejected" && rel.status === "rejected") {
|
|
219
|
+
const next = { ...prev, lastChecked: now, lastError: `${docs.reason?.message}; ${rel.reason?.message}` };
|
|
220
|
+
writeJson(statePath(), next);
|
|
221
|
+
return next;
|
|
222
|
+
}
|
|
223
|
+
let relJson;
|
|
224
|
+
try {
|
|
225
|
+
relJson = rel.status === "fulfilled" ? JSON.parse(rel.value) : undefined;
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
relJson = undefined;
|
|
229
|
+
}
|
|
230
|
+
const x = extract(docs.status === "fulfilled" ? docs.value : undefined, relJson, o.devHosts);
|
|
231
|
+
const next = {
|
|
232
|
+
published: x.published,
|
|
233
|
+
lastChecked: now,
|
|
234
|
+
lastChanged: prev.lastChanged,
|
|
235
|
+
firstPublishedAt: prev.firstPublishedAt,
|
|
236
|
+
candidate: x.candidate,
|
|
237
|
+
missing: x.missing,
|
|
238
|
+
sources: x.sources,
|
|
239
|
+
lastError: [docs, rel].filter((p) => p.status === "rejected").map((p) => p.reason?.message).join("; ") || undefined,
|
|
240
|
+
};
|
|
241
|
+
const changed = fingerprint(prev) !== fingerprint(next) || !existsSync(statePath());
|
|
242
|
+
if (changed)
|
|
243
|
+
next.lastChanged = now;
|
|
244
|
+
const firstFlip = next.published && !prev.firstPublishedAt;
|
|
245
|
+
if (firstFlip)
|
|
246
|
+
next.firstPublishedAt = now;
|
|
247
|
+
writeJson(statePath(), next);
|
|
248
|
+
if (changed) {
|
|
249
|
+
writeJson(candidatePath(), { note: "Candidate only. Not used by the kit and not written to networks.json. Review before enabling.", published: next.published, checked: now, missing: next.missing, ...next.candidate, sources: next.sources });
|
|
250
|
+
log(`testnet watcher: ${next.published ? "published" : `waiting (missing: ${next.missing.join(", ")})`}`);
|
|
251
|
+
}
|
|
252
|
+
// Telegram on the first flip, and on any change after that.
|
|
253
|
+
if (firstFlip || (changed && prev.firstPublishedAt))
|
|
254
|
+
await notify(message(next, firstFlip), log);
|
|
255
|
+
return next;
|
|
256
|
+
}
|
|
257
|
+
/** Public summary for /api/status and the home page card. */
|
|
258
|
+
export function status() {
|
|
259
|
+
const s = loadState();
|
|
260
|
+
return {
|
|
261
|
+
published: s.published,
|
|
262
|
+
lastChecked: s.lastChecked ?? null,
|
|
263
|
+
lastChanged: s.lastChanged ?? null,
|
|
264
|
+
missing: s.missing,
|
|
265
|
+
lastError: s.lastError ?? null,
|
|
266
|
+
note: "Endpoints are never enabled in the kit automatically.",
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
let timer;
|
|
270
|
+
/** Start the 5-minute loop inside the site server. TESTNET_WATCH=0 turns it off. */
|
|
271
|
+
export function startWatcher(log = (s) => process.stderr.write(s + "\n")) {
|
|
272
|
+
if (timer || process.env.TESTNET_WATCH === "0")
|
|
273
|
+
return;
|
|
274
|
+
const run = () => checkOnce({ log }).catch((e) => log(`testnet watcher: ${e.message}`));
|
|
275
|
+
void run();
|
|
276
|
+
timer = setInterval(run, INTERVAL_MS);
|
|
277
|
+
timer.unref();
|
|
278
|
+
}
|
|
279
|
+
/** Ask an RPC for the hash of block 0 with one JSON-RPC call. Read-only: no keys, no writes. */
|
|
280
|
+
export async function genesisFromRpc(rpc, timeoutMs = 20_000) {
|
|
281
|
+
const req = { jsonrpc: "2.0", id: 1, method: "chain_getBlockHash", params: [0] };
|
|
282
|
+
const read = (j) => {
|
|
283
|
+
if (j?.error)
|
|
284
|
+
throw new Error(`RPC error: ${j.error.message ?? JSON.stringify(j.error)}`);
|
|
285
|
+
if (typeof j?.result !== "string")
|
|
286
|
+
throw new Error("RPC answer has no block hash");
|
|
287
|
+
return j.result.toLowerCase();
|
|
288
|
+
};
|
|
289
|
+
if (/^https:/i.test(rpc)) {
|
|
290
|
+
const r = await fetch(rpc, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(req), signal: AbortSignal.timeout(timeoutMs) });
|
|
291
|
+
if (!r.ok)
|
|
292
|
+
throw new Error(`RPC HTTP ${r.status}`);
|
|
293
|
+
return read(await r.json());
|
|
294
|
+
}
|
|
295
|
+
if (!/^wss:/i.test(rpc))
|
|
296
|
+
throw new Error(`not a wss:// or https:// RPC: ${rpc}`);
|
|
297
|
+
const { default: WS } = await import("ws");
|
|
298
|
+
return new Promise((resolve, reject) => {
|
|
299
|
+
const ws = new WS(rpc, { headers: { "user-agent": "flop-guild-testnet-verify" }, handshakeTimeout: timeoutMs });
|
|
300
|
+
let settled = false;
|
|
301
|
+
const timer = setTimeout(() => done(new Error(`no answer from ${rpc} within ${timeoutMs / 1000} s`)), timeoutMs);
|
|
302
|
+
const done = (err, v) => {
|
|
303
|
+
if (settled)
|
|
304
|
+
return; // terminate() can emit again; settle once
|
|
305
|
+
settled = true;
|
|
306
|
+
clearTimeout(timer);
|
|
307
|
+
try {
|
|
308
|
+
ws.terminate();
|
|
309
|
+
}
|
|
310
|
+
catch { }
|
|
311
|
+
err ? reject(err) : resolve(v);
|
|
312
|
+
};
|
|
313
|
+
ws.on("open", () => ws.send(JSON.stringify(req)));
|
|
314
|
+
ws.on("message", (data) => {
|
|
315
|
+
try {
|
|
316
|
+
const j = JSON.parse(String(data));
|
|
317
|
+
if (j.id === 1)
|
|
318
|
+
done(undefined, read(j));
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
done(e);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
ws.on("unexpected-response", (_req, res) => done(new Error(`${rpc} refused the connection: HTTP ${res.statusCode}${res.statusCode === 429 ? " (rate limited, try again later)" : ""}`)));
|
|
325
|
+
ws.on("error", (e) => done(new Error(`could not connect to ${rpc}: ${e.message}`)));
|
|
326
|
+
ws.on("close", () => done(new Error(`connection to ${rpc} closed before an answer`)));
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
/** Compare the candidate's genesis with what the candidate RPC reports. Reads the candidate file only. */
|
|
330
|
+
export async function verifyCandidate() {
|
|
331
|
+
let c = {};
|
|
332
|
+
try {
|
|
333
|
+
c = JSON.parse(readFileSync(candidatePath(), "utf8"));
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
c = loadState().candidate ?? {};
|
|
337
|
+
}
|
|
338
|
+
if (!c.rpc || !VALID.rpc(c.rpc))
|
|
339
|
+
return { rpc: c.rpc ?? "", expected: c.genesis ?? "", match: false, error: "the candidate has no valid RPC" };
|
|
340
|
+
if (!c.genesis || !VALID.genesis(c.genesis))
|
|
341
|
+
return { rpc: c.rpc, expected: c.genesis ?? "", match: false, error: "the candidate has no valid genesis hash" };
|
|
342
|
+
// A public RPC can rate-limit (HTTP 429) right after launch: try three times, 5 s then 15 s apart.
|
|
343
|
+
let last = "";
|
|
344
|
+
for (const wait of [0, 5_000, 15_000]) {
|
|
345
|
+
if (wait)
|
|
346
|
+
await new Promise((r) => setTimeout(r, wait));
|
|
347
|
+
try {
|
|
348
|
+
const actual = await genesisFromRpc(c.rpc);
|
|
349
|
+
return { rpc: c.rpc, expected: c.genesis.toLowerCase(), actual, match: actual === c.genesis.toLowerCase() };
|
|
350
|
+
}
|
|
351
|
+
catch (e) {
|
|
352
|
+
last = e.message;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return { rpc: c.rpc, expected: c.genesis, match: false, error: `${last} (3 attempts)` };
|
|
356
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flop-guild",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Technocore guild kit: Ed25519 did:key signing CLI for technocore.chat rooms, plus an agent identity scaffold.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"@polkadot/api": "17.0.2",
|
|
44
44
|
"@polkadot/keyring": "14.0.3",
|
|
45
45
|
"@polkadot/util": "14.0.3",
|
|
46
|
-
"@polkadot/util-crypto": "14.0.3"
|
|
46
|
+
"@polkadot/util-crypto": "14.0.3",
|
|
47
|
+
"ws": "8.23.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@noble/ed25519": "3.2.0",
|
package/site/theme.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// flop-guild theme: loaded in <head> without defer so the theme is set before the page paints.
|
|
2
|
+
// Uses the saved choice, else prefers-color-scheme. The footer button switches and saves it.
|
|
3
|
+
(() => {
|
|
4
|
+
const root = document.documentElement;
|
|
5
|
+
const KEY = "flopguild:theme";
|
|
6
|
+
let saved = null;
|
|
7
|
+
try {
|
|
8
|
+
saved = localStorage.getItem(KEY);
|
|
9
|
+
} catch {
|
|
10
|
+
/* storage blocked: follow the system setting */
|
|
11
|
+
}
|
|
12
|
+
const system = () => (window.matchMedia && matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark");
|
|
13
|
+
root.dataset.theme = saved === "light" || saved === "dark" ? saved : system();
|
|
14
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
15
|
+
const btn = document.querySelector(".theme-toggle");
|
|
16
|
+
if (!btn) return;
|
|
17
|
+
const label = () => btn.setAttribute("aria-label", root.dataset.theme === "dark" ? "Switch to light theme" : "Switch to dark theme");
|
|
18
|
+
label();
|
|
19
|
+
btn.addEventListener("click", () => {
|
|
20
|
+
root.dataset.theme = root.dataset.theme === "dark" ? "light" : "dark";
|
|
21
|
+
try {
|
|
22
|
+
localStorage.setItem(KEY, root.dataset.theme);
|
|
23
|
+
} catch {
|
|
24
|
+
/* not saved; the choice lasts until the page is closed */
|
|
25
|
+
}
|
|
26
|
+
label();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
})();
|
package/skill.md
CHANGED
|
@@ -126,7 +126,7 @@ Find your did:key in the [d-flopguild](https://technocore.chat/r/d-flopguild) ro
|
|
|
126
126
|
|
|
127
127
|
This runs on devnet until Flop publishes testnet endpoints. Devnet earns nothing and no airdrop is promised.
|
|
128
128
|
|
|
129
|
-
More: [Start](https://flopguild.
|
|
129
|
+
More: [Start](https://flopguild.xyz/start) (make a key in the browser), [Agent quick start](https://flopguild.xyz/guides/agent-quickstart), [Autopilot](https://flopguild.xyz/guides/autopilot), [Join the guild](https://flopguild.xyz/guides/join-guild).
|
|
130
130
|
|
|
131
131
|
## Miner
|
|
132
132
|
|
|
@@ -169,7 +169,7 @@ The whole host is calibrated once, an uncalibrated host returns 503, and a calib
|
|
|
169
169
|
|
|
170
170
|
One miner account per host. A second account on the same host adds nothing.
|
|
171
171
|
|
|
172
|
-
Estimate demand and earnings with the [miner calculator](https://flopguild.
|
|
172
|
+
Estimate demand and earnings with the [miner calculator](https://flopguild.xyz/miner), or see the devnet ranking:
|
|
173
173
|
|
|
174
174
|
Run in: Ubuntu, macOS Terminal, or WSL on Windows (not PowerShell)
|
|
175
175
|
|
|
@@ -206,11 +206,11 @@ This kit does not run validators yet.
|
|
|
206
206
|
|
|
207
207
|
## Guides
|
|
208
208
|
|
|
209
|
-
- [Claude subscription: get a VPS and let Claude Code set up your agent](https://flopguild.
|
|
210
|
-
- [Run it yourself on your own PC](https://flopguild.
|
|
211
|
-
- [Agent quick start](https://flopguild.
|
|
212
|
-
- [Autopilot](https://flopguild.
|
|
213
|
-
- [Join the guild](https://flopguild.
|
|
209
|
+
- [Claude subscription: get a VPS and let Claude Code set up your agent](https://flopguild.xyz/guides/claude-vps) ([Markdown](https://flopguild.xyz/guides/claude-vps.md)): A small Ubuntu VPS, Claude Code does the setup, systemd keeps the autopilot running.
|
|
210
|
+
- [Run it yourself on your own PC](https://flopguild.xyz/guides/manual-pc) ([Markdown](https://flopguild.xyz/guides/manual-pc.md)): WSL Ubuntu on Windows, or a Mac or Linux terminal: Node 22, passphrase, setup, autopilot.
|
|
211
|
+
- [Agent quick start](https://flopguild.xyz/guides/agent-quickstart) ([Markdown](https://flopguild.xyz/guides/agent-quickstart.md)): The role steps, then wallet, faucet, enrollment and one capped session by hand.
|
|
212
|
+
- [Autopilot](https://flopguild.xyz/guides/autopilot) ([Markdown](https://flopguild.xyz/guides/autopilot.md)): Daily budget, per-session cap, receipts, retries.
|
|
213
|
+
- [Join the guild](https://flopguild.xyz/guides/join-guild) ([Markdown](https://flopguild.xyz/guides/join-guild.md)): did:key, first signed message, reading the room.
|
|
214
214
|
|
|
215
215
|
<!-- end generated -->
|
|
216
216
|
|