@needmoretruth/nmts-cli 0.54.0 → 0.54.1
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/CHANGELOG.md +7 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/client-id.d.ts +1 -1
- package/dist/client-id.js +1 -1
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/shared/lib/wallet/address-history.d.ts +1 -14
- package/dist/shared/lib/wallet/address-history.js +22 -107
- package/dist/shared/lib/wallet/graphql-history.d.ts +25 -0
- package/dist/shared/lib/wallet/graphql-history.js +136 -0
- package/package.json +1 -1
- package/server.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
Each version's entry is what changed for the person or the program using `nmts`. The product's own
|
|
4
4
|
update history, which covers the site and the server too, is at https://nmts.me/updates.
|
|
5
5
|
|
|
6
|
+
## 0.54.1 — 2026-11-09
|
|
7
|
+
|
|
8
|
+
- `nmts wallet activity` and `nmts wallet list` no longer stop with an error when a Sui node refuses
|
|
9
|
+
the history read with a message the tool has not seen before: any refusal or failure that leaves
|
|
10
|
+
history unread now moves the read to Sui GraphQL, which has a second operator (01NODE) when Mysten
|
|
11
|
+
Labs does not answer.
|
|
12
|
+
|
|
6
13
|
## 0.54.0 — 2026-11-08
|
|
7
14
|
|
|
8
15
|
- `put --pay wallet --sui-key-file <file>` pays for the upload from another Sui wallet you hold, read
|
package/README.ko.md
CHANGED
|
@@ -50,7 +50,7 @@ nmts --help
|
|
|
50
50
|
|
|
51
51
|
```sh
|
|
52
52
|
npm install -g github:needmoretruth/nmts-cli # 기본 브랜치
|
|
53
|
-
npm install -g github:needmoretruth/nmts-cli#v0.54.
|
|
53
|
+
npm install -g github:needmoretruth/nmts-cli#v0.54.1 # 버전을 고정할 때
|
|
54
54
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
55
55
|
```
|
|
56
56
|
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ default branch, from a pinned version, or from the tarball attached to the
|
|
|
51
51
|
|
|
52
52
|
```sh
|
|
53
53
|
npm install -g github:needmoretruth/nmts-cli # the default branch
|
|
54
|
-
npm install -g github:needmoretruth/nmts-cli#v0.54.
|
|
54
|
+
npm install -g github:needmoretruth/nmts-cli#v0.54.1 # a pinned version
|
|
55
55
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
56
56
|
```
|
|
57
57
|
|
package/dist/artifact-about.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const CRYPTO_SPEC_URL = "https://github.com/needmoretruth/nmts-re
|
|
|
11
11
|
* is the field's own contract — what the writer says about itself — and a person holding two
|
|
12
12
|
* copies of one account's artefacts can then tell which program made each.
|
|
13
13
|
*/
|
|
14
|
-
export declare const WRITTEN_BY = "nmts-cli 0.54.
|
|
14
|
+
export declare const WRITTEN_BY = "nmts-cli 0.54.1";
|
|
15
15
|
/** Which of the three artefacts a wrapper is. A reader holding several can sort them. */
|
|
16
16
|
export type ArtifactKind = "recovery-list" | "file-list" | "recovery-kit";
|
|
17
17
|
/**
|
package/dist/client-id.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export type ClientKind = "cli" | "mcp" | "sdk";
|
|
|
7
7
|
* points with `"sdk"` and the SDK's own version.
|
|
8
8
|
*/
|
|
9
9
|
export declare function identifyClient(next: ClientKind, nextVersion?: string): void;
|
|
10
|
-
/** `cli/0.54.
|
|
10
|
+
/** `cli/0.54.1`, `mcp/0.54.1`, `sdk/0.17.0`. */
|
|
11
11
|
export declare function clientHeaderValue(): string;
|
package/dist/client-id.js
CHANGED
|
@@ -24,7 +24,7 @@ export function identifyClient(next, nextVersion = VERSION) {
|
|
|
24
24
|
kind = next;
|
|
25
25
|
version = nextVersion;
|
|
26
26
|
}
|
|
27
|
-
/** `cli/0.54.
|
|
27
|
+
/** `cli/0.54.1`, `mcp/0.54.1`, `sdk/0.17.0`. */
|
|
28
28
|
export function clientHeaderValue() {
|
|
29
29
|
return `${kind}/${version}`;
|
|
30
30
|
}
|
package/dist/product.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const BINARY_NAME = "nmts";
|
|
|
9
9
|
* beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
|
|
10
10
|
* command importing the entry point is a cycle waiting to bite.
|
|
11
11
|
*/
|
|
12
|
-
export declare const VERSION = "0.54.
|
|
12
|
+
export declare const VERSION = "0.54.1";
|
|
13
13
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
14
14
|
export declare const HOME_URL = "https://nmts.me";
|
|
15
15
|
/** The source, so a person holding only the built program can find what it was built from. */
|
package/dist/product.js
CHANGED
|
@@ -18,7 +18,7 @@ export const BINARY_NAME = "nmts";
|
|
|
18
18
|
* beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
|
|
19
19
|
* command importing the entry point is a cycle waiting to bite.
|
|
20
20
|
*/
|
|
21
|
-
export const VERSION = "0.54.
|
|
21
|
+
export const VERSION = "0.54.1";
|
|
22
22
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
23
23
|
export const HOME_URL = "https://nmts.me";
|
|
24
24
|
/** The source, so a person holding only the built program can find what it was built from. */
|
|
@@ -13,13 +13,6 @@ export interface AddressHistory {
|
|
|
13
13
|
}
|
|
14
14
|
/** Where history older than the node's window is read: the newest `limit` rows, newest first. */
|
|
15
15
|
export type DeeperHistory = (address: string, limit: number, signal?: AbortSignal) => Promise<HistoryTransaction[]>;
|
|
16
|
-
/**
|
|
17
|
-
* Sui's public GraphQL service per network (Mysten Labs). Measured 2026-10-21: the `affectedAddress`
|
|
18
|
-
* filter answered back to 2023 on both networks, in 0.2–0.9 s, with `access-control-allow-origin: *`.
|
|
19
|
-
* It is the only public operator of it, so it is the second tier and never the only one: a failure
|
|
20
|
-
* here leaves the answer `complete: false`, never "nothing there".
|
|
21
|
-
*/
|
|
22
|
-
export declare const SUI_GRAPHQL_URLS: Readonly<Record<"mainnet" | "testnet", string>>;
|
|
23
16
|
/**
|
|
24
17
|
* How far above a node's lowest checkpoint a read starts, at most. Mainnet seals about four
|
|
25
18
|
* checkpoints a second, so 20,000 is over an hour of pruning before the start falls out of the window
|
|
@@ -53,10 +46,4 @@ export declare function addressTransactions(client: Pick<SuiGrpcClient, "ledgerS
|
|
|
53
46
|
* tell" and "nothing is there" are opposite facts, and only the second may answer `false`.
|
|
54
47
|
*/
|
|
55
48
|
export declare function hasAddressHistory(client: Pick<SuiGrpcClient, "ledgerService">, address: string, signal?: AbortSignal, deeper?: DeeperHistory | null): Promise<boolean>;
|
|
56
|
-
|
|
57
|
-
* The deeper source over Sui's GraphQL service at `url`.
|
|
58
|
-
*
|
|
59
|
-
* ⛔ Anything but a clean answer throws — an error list, a missing page, a row of the wrong shape.
|
|
60
|
-
* The caller turns that into `complete: false`; it never becomes an empty history.
|
|
61
|
-
*/
|
|
62
|
-
export declare function graphqlHistory(url: string, fetchFn?: (input: string, init: RequestInit) => Promise<Response>): DeeperHistory;
|
|
49
|
+
export { graphqlHistory, SUI_GRAPHQL_URLS } from "./graphql-history.ts";
|
|
@@ -37,16 +37,6 @@
|
|
|
37
37
|
// ⚠ It needs the gRPC client: the filter is a raw ledger-service filter, which the SDK's top-level
|
|
38
38
|
// `listTransactions` does not offer (it filters by sender or function only).
|
|
39
39
|
import { GrpcTypes, parseGrpcTransactionResponse } from "@mysten/sui/grpc";
|
|
40
|
-
/**
|
|
41
|
-
* Sui's public GraphQL service per network (Mysten Labs). Measured 2026-10-21: the `affectedAddress`
|
|
42
|
-
* filter answered back to 2023 on both networks, in 0.2–0.9 s, with `access-control-allow-origin: *`.
|
|
43
|
-
* It is the only public operator of it, so it is the second tier and never the only one: a failure
|
|
44
|
-
* here leaves the answer `complete: false`, never "nothing there".
|
|
45
|
-
*/
|
|
46
|
-
export const SUI_GRAPHQL_URLS = {
|
|
47
|
-
mainnet: "https://graphql.mainnet.sui.io/graphql",
|
|
48
|
-
testnet: "https://graphql.testnet.sui.io/graphql",
|
|
49
|
-
};
|
|
50
40
|
/** How many requests one question may take before it answers with what it has. */
|
|
51
41
|
const MAX_REQUESTS = 8;
|
|
52
42
|
/**
|
|
@@ -186,10 +176,17 @@ async function recentTransactions(client, address, limit, signal) {
|
|
|
186
176
|
break;
|
|
187
177
|
}
|
|
188
178
|
catch (e) {
|
|
189
|
-
|
|
179
|
+
// A read the caller called off is called off; it is not a node failing.
|
|
180
|
+
if (signal?.aborted === true)
|
|
190
181
|
throw e;
|
|
191
|
-
// ⛔
|
|
192
|
-
//
|
|
182
|
+
// ⛔ ANY OTHER REFUSAL LEAVES THE NODE'S PART UNREAD, AND THE DEEPER SOURCE IS ASKED (2026-11-09). This
|
|
183
|
+
// used to throw on a refusal whose wording it did not know, so one changed sentence in a
|
|
184
|
+
// node's reply emptied every wallet's activity again (as on 2026-11-05); a node with no connection
|
|
185
|
+
// did the same. What the node could not give is what GraphQL is for. A window no start can
|
|
186
|
+
// hit (Suiscan's testnet replicas disagreed by more than its 54 checkpoints, 2026-11-07)
|
|
187
|
+
// ends the same way.
|
|
188
|
+
if (!learnWindow(client, e))
|
|
189
|
+
return { transactions, fromGenesis: false, failed: e };
|
|
193
190
|
if (attempt >= MAX_WINDOW_RETRIES)
|
|
194
191
|
return { transactions, fromGenesis: false };
|
|
195
192
|
}
|
|
@@ -229,13 +226,21 @@ export async function addressTransactions(client, address, limit, signal, deeper
|
|
|
229
226
|
const recent = await recentTransactions(client, address, limit, signal);
|
|
230
227
|
if (recent.fromGenesis)
|
|
231
228
|
return { transactions: recent.transactions, complete: true };
|
|
232
|
-
|
|
229
|
+
// ⛔ A node that failed and gave nothing, with nobody else to answer, is "could not read", not a
|
|
230
|
+
// partial list: the screen says it failed rather than "older history is missing" over no rows.
|
|
231
|
+
const unread = recent.failed !== undefined && recent.transactions.length === 0;
|
|
232
|
+
if (deeper === null) {
|
|
233
|
+
if (unread)
|
|
234
|
+
throw recent.failed;
|
|
233
235
|
return { transactions: recent.transactions, complete: false };
|
|
236
|
+
}
|
|
234
237
|
try {
|
|
235
238
|
const older = await deeper(address, limit, signal);
|
|
236
239
|
return { transactions: mergeNewestFirst(recent.transactions, older, limit), complete: true };
|
|
237
240
|
}
|
|
238
|
-
catch {
|
|
241
|
+
catch (e) {
|
|
242
|
+
if (unread)
|
|
243
|
+
throw recent.failed ?? e;
|
|
239
244
|
// The node's rows stand; the answer says plainly that it is not the whole history.
|
|
240
245
|
return { transactions: recent.transactions, complete: false };
|
|
241
246
|
}
|
|
@@ -252,95 +257,5 @@ export async function hasAddressHistory(client, address, signal, deeper = null)
|
|
|
252
257
|
throw new Error(`The chain did not finish looking for transactions of ${address}.`);
|
|
253
258
|
return false;
|
|
254
259
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return value;
|
|
258
|
-
}
|
|
259
|
-
if (Array.isArray(value)) {
|
|
260
|
-
const out = [];
|
|
261
|
-
for (const item of value) {
|
|
262
|
-
const json = asJson(item);
|
|
263
|
-
if (json === undefined)
|
|
264
|
-
return undefined;
|
|
265
|
-
out.push(json);
|
|
266
|
-
}
|
|
267
|
-
return out;
|
|
268
|
-
}
|
|
269
|
-
if (typeof value === "object") {
|
|
270
|
-
const out = {};
|
|
271
|
-
for (const [key, item] of Object.entries(value)) {
|
|
272
|
-
const json = asJson(item);
|
|
273
|
-
if (json === undefined)
|
|
274
|
-
return undefined;
|
|
275
|
-
out[key] = json;
|
|
276
|
-
}
|
|
277
|
-
return out;
|
|
278
|
-
}
|
|
279
|
-
return undefined;
|
|
280
|
-
}
|
|
281
|
-
const objectAt = (json) => json !== null && typeof json === "object" && !Array.isArray(json) ? json : undefined;
|
|
282
|
-
const QUERY = `query ($address: SuiAddress!, $last: Int!) {
|
|
283
|
-
transactions(last: $last, filter: { affectedAddress: $address }) {
|
|
284
|
-
nodes { digest transactionJson effects { status timestamp checkpoint { sequenceNumber } balanceChangesJson } }
|
|
285
|
-
}
|
|
286
|
-
}`;
|
|
287
|
-
/** One GraphQL row as the gRPC message the shared parser reads. `undefined` when its shape is off. */
|
|
288
|
-
function executedFromGraphql(node) {
|
|
289
|
-
const effects = objectAt(node["effects"]);
|
|
290
|
-
const digest = node["digest"];
|
|
291
|
-
const transactionJson = objectAt(node["transactionJson"]);
|
|
292
|
-
const timestamp = effects?.["timestamp"];
|
|
293
|
-
const checkpoint = objectAt(effects?.["checkpoint"])?.["sequenceNumber"];
|
|
294
|
-
const changes = effects?.["balanceChangesJson"];
|
|
295
|
-
if (typeof digest !== "string" || transactionJson === undefined || effects === undefined)
|
|
296
|
-
return undefined;
|
|
297
|
-
const ms = typeof timestamp === "string" ? Date.parse(timestamp) : Number.NaN;
|
|
298
|
-
const options = { ignoreUnknownFields: true };
|
|
299
|
-
return GrpcTypes.ExecutedTransaction.create({
|
|
300
|
-
digest,
|
|
301
|
-
transaction: GrpcTypes.Transaction.fromJson(transactionJson, options),
|
|
302
|
-
effects: GrpcTypes.TransactionEffects.create({ status: { success: effects["status"] === "SUCCESS" } }),
|
|
303
|
-
...(Number.isFinite(ms) ? { timestamp: { seconds: BigInt(Math.floor(ms / 1000)), nanos: (ms % 1000) * 1_000_000 } } : {}),
|
|
304
|
-
...(typeof checkpoint === "number" ? { checkpoint: BigInt(checkpoint) } : {}),
|
|
305
|
-
balanceChanges: Array.isArray(changes) ? changes.map((c) => GrpcTypes.BalanceChange.fromJson(c, options)) : [],
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* The deeper source over Sui's GraphQL service at `url`.
|
|
310
|
-
*
|
|
311
|
-
* ⛔ Anything but a clean answer throws — an error list, a missing page, a row of the wrong shape.
|
|
312
|
-
* The caller turns that into `complete: false`; it never becomes an empty history.
|
|
313
|
-
*/
|
|
314
|
-
export function graphqlHistory(url, fetchFn = (input, init) => fetch(input, init)) {
|
|
315
|
-
return async (address, limit, signal) => {
|
|
316
|
-
const res = await fetchFn(url, {
|
|
317
|
-
method: "POST",
|
|
318
|
-
headers: { "content-type": "application/json" },
|
|
319
|
-
body: JSON.stringify({ query: QUERY, variables: { address, last: limit } }),
|
|
320
|
-
...(signal === undefined ? {} : { signal }),
|
|
321
|
-
});
|
|
322
|
-
if (!res.ok)
|
|
323
|
-
throw new Error(`The history service answered HTTP ${res.status}.`);
|
|
324
|
-
const body = await res.json();
|
|
325
|
-
const top = objectAt(asJson(body));
|
|
326
|
-
if (top === undefined || top["errors"] !== undefined) {
|
|
327
|
-
throw new Error("The history service answered with an error.");
|
|
328
|
-
}
|
|
329
|
-
const nodes = objectAt(objectAt(top["data"])?.["transactions"])?.["nodes"];
|
|
330
|
-
if (!Array.isArray(nodes))
|
|
331
|
-
throw new Error("The history service answered without a list.");
|
|
332
|
-
const rows = [];
|
|
333
|
-
// `last: n` arrives oldest-first; the list here is newest-first.
|
|
334
|
-
for (const node of [...nodes].reverse()) {
|
|
335
|
-
const row = objectAt(node);
|
|
336
|
-
const executed = row === undefined ? undefined : executedFromGraphql(row);
|
|
337
|
-
if (executed === undefined)
|
|
338
|
-
throw new Error("The history service answered a row this build cannot read.");
|
|
339
|
-
const parsed = parseGrpcTransactionResponse(executed, { include: { transaction: true, balanceChanges: true } });
|
|
340
|
-
const tx = parsed.Transaction ?? parsed.FailedTransaction;
|
|
341
|
-
if (tx !== undefined)
|
|
342
|
-
rows.push(tx);
|
|
343
|
-
}
|
|
344
|
-
return rows;
|
|
345
|
-
};
|
|
346
|
-
}
|
|
260
|
+
// The deeper source (Sui's GraphQL services) lives in `graphql-history.ts`; both names stay importable here.
|
|
261
|
+
export { graphqlHistory, SUI_GRAPHQL_URLS } from "./graphql-history.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DeeperHistory } from "./address-history.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Sui's public GraphQL services per network, in the order they are asked. Measured 2026-10-21 for
|
|
4
|
+
* Mysten Labs: the `affectedAddress` filter answered back to 2023 on both networks, in 0.2–0.9 s,
|
|
5
|
+
* with `access-control-allow-origin: *`.
|
|
6
|
+
*
|
|
7
|
+
* ⭐ A SECOND OPERATOR ON MAINNET (2026-11-09). Until then Mysten Labs was the only one and a
|
|
8
|
+
* failure there left every wallet's older history unread. 01NODE Funding SRL (Bucharest, Romania,
|
|
9
|
+
* its own network) runs a public mainnet GraphQL at `sui.01.ro`; measured that day from this machine:
|
|
10
|
+
* the same query and the same rows as Mysten's (the treasury's oldest transaction, 2026-08-02),
|
|
11
|
+
* checkpoints back to 2023, `access-control-allow-origin: *`, 1.3 s. Triton One's `rpcpool` answered
|
|
12
|
+
* too; it is not used because its company is not one the Privacy Policy names. Testnet keeps one
|
|
13
|
+
* operator: development has no second public GraphQL and no one's activity depends on it.
|
|
14
|
+
* Still the second tier and never the only one: when every service fails the answer is
|
|
15
|
+
* `complete: false`, never "nothing there".
|
|
16
|
+
*/
|
|
17
|
+
export declare const SUI_GRAPHQL_URLS: Readonly<Record<"mainnet" | "testnet", readonly string[]>>;
|
|
18
|
+
/**
|
|
19
|
+
* The deeper source over Sui's GraphQL services at `urls`, asked in order until one answers cleanly.
|
|
20
|
+
*
|
|
21
|
+
* ⛔ Anything but a clean answer from a service moves to the next — an error list, a missing page, a
|
|
22
|
+
* row of the wrong shape, no connection; when none answers it throws. The caller turns that into
|
|
23
|
+
* `complete: false`; it never becomes an empty history. A call the caller aborted is not retried.
|
|
24
|
+
*/
|
|
25
|
+
export declare function graphqlHistory(urls: string | readonly string[], fetchFn?: (input: string, init: RequestInit) => Promise<Response>): DeeperHistory;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The deeper source of `address-history.ts`: a wallet's history from Sui's public GraphQL services,
|
|
2
|
+
// for what a gRPC node no longer keeps or could not give. ⚠ PUBLISHED — copied byte-for-byte into
|
|
3
|
+
// the `nmts` command-line package; keep comments self-contained English.
|
|
4
|
+
//
|
|
5
|
+
// ⛔ Its rows are read by the SAME parser as the node's: GraphQL's `transactionJson` and
|
|
6
|
+
// `balanceChangesJson` are the gRPC messages written as JSON, so one row means one thing whichever
|
|
7
|
+
// service gave it.
|
|
8
|
+
import { GrpcTypes, parseGrpcTransactionResponse } from "@mysten/sui/grpc";
|
|
9
|
+
/**
|
|
10
|
+
* Sui's public GraphQL services per network, in the order they are asked. Measured 2026-10-21 for
|
|
11
|
+
* Mysten Labs: the `affectedAddress` filter answered back to 2023 on both networks, in 0.2–0.9 s,
|
|
12
|
+
* with `access-control-allow-origin: *`.
|
|
13
|
+
*
|
|
14
|
+
* ⭐ A SECOND OPERATOR ON MAINNET (2026-11-09). Until then Mysten Labs was the only one and a
|
|
15
|
+
* failure there left every wallet's older history unread. 01NODE Funding SRL (Bucharest, Romania,
|
|
16
|
+
* its own network) runs a public mainnet GraphQL at `sui.01.ro`; measured that day from this machine:
|
|
17
|
+
* the same query and the same rows as Mysten's (the treasury's oldest transaction, 2026-08-02),
|
|
18
|
+
* checkpoints back to 2023, `access-control-allow-origin: *`, 1.3 s. Triton One's `rpcpool` answered
|
|
19
|
+
* too; it is not used because its company is not one the Privacy Policy names. Testnet keeps one
|
|
20
|
+
* operator: development has no second public GraphQL and no one's activity depends on it.
|
|
21
|
+
* Still the second tier and never the only one: when every service fails the answer is
|
|
22
|
+
* `complete: false`, never "nothing there".
|
|
23
|
+
*/
|
|
24
|
+
export const SUI_GRAPHQL_URLS = {
|
|
25
|
+
mainnet: ["https://graphql.mainnet.sui.io/graphql", "https://sui.01.ro/graphql"],
|
|
26
|
+
testnet: ["https://graphql.testnet.sui.io/graphql"],
|
|
27
|
+
};
|
|
28
|
+
function asJson(value) {
|
|
29
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const item of value) {
|
|
35
|
+
const json = asJson(item);
|
|
36
|
+
if (json === undefined)
|
|
37
|
+
return undefined;
|
|
38
|
+
out.push(json);
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === "object") {
|
|
43
|
+
const out = {};
|
|
44
|
+
for (const [key, item] of Object.entries(value)) {
|
|
45
|
+
const json = asJson(item);
|
|
46
|
+
if (json === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
out[key] = json;
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const objectAt = (json) => json !== null && typeof json === "object" && !Array.isArray(json) ? json : undefined;
|
|
55
|
+
const QUERY = `query ($address: SuiAddress!, $last: Int!) {
|
|
56
|
+
transactions(last: $last, filter: { affectedAddress: $address }) {
|
|
57
|
+
nodes { digest transactionJson effects { status timestamp checkpoint { sequenceNumber } balanceChangesJson } }
|
|
58
|
+
}
|
|
59
|
+
}`;
|
|
60
|
+
/** One GraphQL row as the gRPC message the shared parser reads. `undefined` when its shape is off. */
|
|
61
|
+
function executedFromGraphql(node) {
|
|
62
|
+
const effects = objectAt(node["effects"]);
|
|
63
|
+
const digest = node["digest"];
|
|
64
|
+
const transactionJson = objectAt(node["transactionJson"]);
|
|
65
|
+
const timestamp = effects?.["timestamp"];
|
|
66
|
+
const checkpoint = objectAt(effects?.["checkpoint"])?.["sequenceNumber"];
|
|
67
|
+
const changes = effects?.["balanceChangesJson"];
|
|
68
|
+
if (typeof digest !== "string" || transactionJson === undefined || effects === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
const ms = typeof timestamp === "string" ? Date.parse(timestamp) : Number.NaN;
|
|
71
|
+
const options = { ignoreUnknownFields: true };
|
|
72
|
+
return GrpcTypes.ExecutedTransaction.create({
|
|
73
|
+
digest,
|
|
74
|
+
transaction: GrpcTypes.Transaction.fromJson(transactionJson, options),
|
|
75
|
+
effects: GrpcTypes.TransactionEffects.create({ status: { success: effects["status"] === "SUCCESS" } }),
|
|
76
|
+
...(Number.isFinite(ms) ? { timestamp: { seconds: BigInt(Math.floor(ms / 1000)), nanos: (ms % 1000) * 1_000_000 } } : {}),
|
|
77
|
+
...(typeof checkpoint === "number" ? { checkpoint: BigInt(checkpoint) } : {}),
|
|
78
|
+
balanceChanges: Array.isArray(changes) ? changes.map((c) => GrpcTypes.BalanceChange.fromJson(c, options)) : [],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The deeper source over Sui's GraphQL services at `urls`, asked in order until one answers cleanly.
|
|
83
|
+
*
|
|
84
|
+
* ⛔ Anything but a clean answer from a service moves to the next — an error list, a missing page, a
|
|
85
|
+
* row of the wrong shape, no connection; when none answers it throws. The caller turns that into
|
|
86
|
+
* `complete: false`; it never becomes an empty history. A call the caller aborted is not retried.
|
|
87
|
+
*/
|
|
88
|
+
export function graphqlHistory(urls, fetchFn = (input, init) => fetch(input, init)) {
|
|
89
|
+
const list = typeof urls === "string" ? [urls] : urls;
|
|
90
|
+
return async (address, limit, signal) => {
|
|
91
|
+
let last = new Error("No history service is configured.");
|
|
92
|
+
for (const url of list) {
|
|
93
|
+
try {
|
|
94
|
+
return await graphqlRows(url, fetchFn, address, limit, signal);
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
if (signal?.aborted === true)
|
|
98
|
+
throw e;
|
|
99
|
+
last = e;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw last;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** One GraphQL service's newest `limit` rows for `address`, newest first; throws on anything unclean. */
|
|
106
|
+
async function graphqlRows(url, fetchFn, address, limit, signal) {
|
|
107
|
+
const res = await fetchFn(url, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: { "content-type": "application/json" },
|
|
110
|
+
body: JSON.stringify({ query: QUERY, variables: { address, last: limit } }),
|
|
111
|
+
...(signal === undefined ? {} : { signal }),
|
|
112
|
+
});
|
|
113
|
+
if (!res.ok)
|
|
114
|
+
throw new Error(`The history service answered HTTP ${res.status}.`);
|
|
115
|
+
const body = await res.json();
|
|
116
|
+
const top = objectAt(asJson(body));
|
|
117
|
+
if (top === undefined || top["errors"] !== undefined) {
|
|
118
|
+
throw new Error("The history service answered with an error.");
|
|
119
|
+
}
|
|
120
|
+
const nodes = objectAt(objectAt(top["data"])?.["transactions"])?.["nodes"];
|
|
121
|
+
if (!Array.isArray(nodes))
|
|
122
|
+
throw new Error("The history service answered without a list.");
|
|
123
|
+
const rows = [];
|
|
124
|
+
// `last: n` arrives oldest-first; the list here is newest-first.
|
|
125
|
+
for (const node of [...nodes].reverse()) {
|
|
126
|
+
const row = objectAt(node);
|
|
127
|
+
const executed = row === undefined ? undefined : executedFromGraphql(row);
|
|
128
|
+
if (executed === undefined)
|
|
129
|
+
throw new Error("The history service answered a row this build cannot read.");
|
|
130
|
+
const parsed = parseGrpcTransactionResponse(executed, { include: { transaction: true, balanceChanges: true } });
|
|
131
|
+
const tx = parsed.Transaction ?? parsed.FailedTransaction;
|
|
132
|
+
if (tx !== undefined)
|
|
133
|
+
rows.push(tx);
|
|
134
|
+
}
|
|
135
|
+
return rows;
|
|
136
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needmoretruth/nmts-cli",
|
|
3
|
-
"version": "0.54.
|
|
3
|
+
"version": "0.54.1",
|
|
4
4
|
"description": "Command-line and MCP access to NMTS (NeedMoreTruthStorage, https://nmts.me): open-source, end-to-end encrypted storage on the Walrus network. No fee to NMTS; you pay the network from your own wallet. For people and for their agents.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
package/server.json
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
"url": "https://github.com/needmoretruth/nmts-cli",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.54.
|
|
9
|
+
"version": "0.54.1",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
14
14
|
"identifier": "@needmoretruth/nmts-cli",
|
|
15
|
-
"version": "0.54.
|
|
15
|
+
"version": "0.54.1",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|