@needmoretruth/nmts-cli 0.50.1 → 0.52.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 +28 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/api.js +3 -0
- package/dist/artifact-about.d.ts +1 -1
- package/dist/client-id.d.ts +11 -0
- package/dist/client-id.js +30 -0
- package/dist/commands/mcp.js +3 -0
- package/dist/commands/wallet-activity.d.ts +10 -6
- package/dist/commands/wallet-activity.js +17 -6
- package/dist/env-vars.d.ts +1 -1
- package/dist/env-vars.js +1 -1
- package/dist/extend-chain.d.ts +4 -6
- package/dist/extend-chain.js +25 -26
- package/dist/net-retry.js +14 -0
- package/dist/portable.d.ts +2 -0
- package/dist/portable.js +2 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/reach.d.ts +1 -1
- package/dist/shared/lib/storage-control/chain.d.ts +30 -29
- package/dist/shared/lib/storage-control/chain.js +14 -20
- package/dist/shared/lib/wallet/activity.d.ts +42 -48
- package/dist/shared/lib/wallet/activity.js +51 -30
- package/dist/shared/lib/wallet/address-history.d.ts +54 -0
- package/dist/shared/lib/wallet/address-history.js +313 -0
- package/dist/shared/lib/wallet/chain-calls.d.ts +44 -0
- package/dist/shared/lib/wallet/chain-calls.js +59 -0
- package/dist/storage-control-chain.js +5 -4
- package/dist/sui-execute.d.ts +54 -0
- package/dist/sui-execute.js +43 -0
- package/dist/sui-rpc.d.ts +16 -9
- package/dist/sui-rpc.js +53 -19
- package/dist/upload-wallet-chain.d.ts +3 -3
- package/dist/upload-wallet-chain.js +14 -22
- package/dist/wallet-activity-chain.d.ts +2 -2
- package/dist/wallet-activity-chain.js +12 -27
- package/dist/wallet-chain.js +19 -13
- package/dist/wallet-list-chain.d.ts +1 -1
- package/dist/wallet-list-chain.js +13 -14
- package/dist/wallet-send-chain.js +4 -3
- package/dist/wallet-sign-external.d.ts +19 -26
- package/dist/wallet-sign-external.js +13 -18
- package/dist/wallet-sign.js +19 -69
- package/dist/wallet-storage-chain.js +2 -3
- package/dist/wallet-swap-chain.d.ts +3 -6
- package/dist/wallet-swap-chain.js +16 -16
- package/dist/wallet-swap-quote.js +16 -17
- package/dist/walrus-write.js +6 -16
- package/dist/walrus.d.ts +13 -13
- package/dist/walrus.js +15 -15
- package/package.json +7 -4
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +11 -11
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +11 -11
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
|
|
2
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
3
|
+
/** What a devInspect gave: one list of BCS return values per command, or the chain's refusal. */
|
|
4
|
+
export interface Inspection {
|
|
5
|
+
/** The chain's own words when the calls aborted; `null` when they ran. */
|
|
6
|
+
error: string | null;
|
|
7
|
+
results: {
|
|
8
|
+
returnValues: Uint8Array[];
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Run `transaction` without signing, checks off, and return what each command returned.
|
|
13
|
+
*
|
|
14
|
+
* `sender` is set only when the transaction has none — a devInspect needs one, and nothing is spent:
|
|
15
|
+
* with checks off and no gas payment the node simulates with a mocked gas coin.
|
|
16
|
+
*
|
|
17
|
+
* ⛔ A refusal the node REPORTS (the Move call aborted) comes back as `error`; a request the node
|
|
18
|
+
* could not run at all (no such object, malformed call) throws, as the old call's RPC errors did.
|
|
19
|
+
*/
|
|
20
|
+
export declare function inspect(client: ClientWithCoreApi, transaction: Transaction, sender: string): Promise<Inspection>;
|
|
21
|
+
/** What a dry run of built bytes says: whether it would succeed, and what it would burn in gas. */
|
|
22
|
+
export interface DryRun {
|
|
23
|
+
status: SuiClientTypes.ExecutionStatus;
|
|
24
|
+
gasUsed: SuiClientTypes.GasCostSummary;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Simulate built transaction bytes exactly as they would be submitted (checks on, gas as built).
|
|
28
|
+
*
|
|
29
|
+
* Nothing is signed, nothing is broadcast. Throws when the node returns no effects, because a dry run
|
|
30
|
+
* without a gas figure is not an answer any caller can use.
|
|
31
|
+
*/
|
|
32
|
+
export declare function dryRun(client: ClientWithCoreApi, bytes: Uint8Array): Promise<DryRun>;
|
|
33
|
+
/** A u64 return value: exactly eight little-endian bytes, or a refusal to guess. */
|
|
34
|
+
export declare function u64FromLe(bytes: Uint8Array | undefined): bigint;
|
|
35
|
+
/**
|
|
36
|
+
* An object's Move fields as JSON, or `null` when the node rendered none. An object that does not
|
|
37
|
+
* exist (deleted, wrapped, or on another network) THROWS — the core API's `getObject` refuses rather
|
|
38
|
+
* than answering empty, and a caller that must tell "gone" from "unreadable" catches it.
|
|
39
|
+
*
|
|
40
|
+
* ⚠ The JSON form is the node's rendering of the struct; the SDK warns that its exact field shapes
|
|
41
|
+
* may differ between transports. Callers here read top-level primitive fields (a package id, a
|
|
42
|
+
* number) only, which every transport renders the same way.
|
|
43
|
+
*/
|
|
44
|
+
export declare function objectFields(client: ClientWithCoreApi, objectId: string): Promise<Record<string, unknown> | null>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run `transaction` without signing, checks off, and return what each command returned.
|
|
3
|
+
*
|
|
4
|
+
* `sender` is set only when the transaction has none — a devInspect needs one, and nothing is spent:
|
|
5
|
+
* with checks off and no gas payment the node simulates with a mocked gas coin.
|
|
6
|
+
*
|
|
7
|
+
* ⛔ A refusal the node REPORTS (the Move call aborted) comes back as `error`; a request the node
|
|
8
|
+
* could not run at all (no such object, malformed call) throws, as the old call's RPC errors did.
|
|
9
|
+
*/
|
|
10
|
+
export async function inspect(client, transaction, sender) {
|
|
11
|
+
transaction.setSenderIfNotSet(sender);
|
|
12
|
+
const res = await client.core.simulateTransaction({
|
|
13
|
+
transaction,
|
|
14
|
+
checksEnabled: false,
|
|
15
|
+
include: { commandResults: true },
|
|
16
|
+
});
|
|
17
|
+
if (res.$kind === "FailedTransaction") {
|
|
18
|
+
return { error: res.FailedTransaction.status.error?.message ?? "the calls did not run", results: [] };
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
error: null,
|
|
22
|
+
results: (res.commandResults ?? []).map((r) => ({ returnValues: r.returnValues.map((v) => v.bcs) })),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Simulate built transaction bytes exactly as they would be submitted (checks on, gas as built).
|
|
27
|
+
*
|
|
28
|
+
* Nothing is signed, nothing is broadcast. Throws when the node returns no effects, because a dry run
|
|
29
|
+
* without a gas figure is not an answer any caller can use.
|
|
30
|
+
*/
|
|
31
|
+
export async function dryRun(client, bytes) {
|
|
32
|
+
const res = await client.core.simulateTransaction({ transaction: bytes, include: { effects: true } });
|
|
33
|
+
const tx = res.Transaction ?? res.FailedTransaction;
|
|
34
|
+
const effects = tx?.effects;
|
|
35
|
+
if (tx === undefined || effects === undefined || effects === null) {
|
|
36
|
+
throw new Error("The dry run came back without effects.");
|
|
37
|
+
}
|
|
38
|
+
return { status: tx.status, gasUsed: effects.gasUsed };
|
|
39
|
+
}
|
|
40
|
+
/** A u64 return value: exactly eight little-endian bytes, or a refusal to guess. */
|
|
41
|
+
export function u64FromLe(bytes) {
|
|
42
|
+
if (bytes === undefined || bytes.length !== 8) {
|
|
43
|
+
throw new Error("The chain answered a number in an unexpected shape.");
|
|
44
|
+
}
|
|
45
|
+
return bytes.reduceRight((acc, byte) => (acc << 8n) | BigInt(byte), 0n);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* An object's Move fields as JSON, or `null` when the node rendered none. An object that does not
|
|
49
|
+
* exist (deleted, wrapped, or on another network) THROWS — the core API's `getObject` refuses rather
|
|
50
|
+
* than answering empty, and a caller that must tell "gone" from "unreadable" catches it.
|
|
51
|
+
*
|
|
52
|
+
* ⚠ The JSON form is the node's rendering of the struct; the SDK warns that its exact field shapes
|
|
53
|
+
* may differ between transports. Callers here read top-level primitive fields (a package id, a
|
|
54
|
+
* number) only, which every transport renders the same way.
|
|
55
|
+
*/
|
|
56
|
+
export async function objectFields(client, objectId) {
|
|
57
|
+
const { object } = await client.core.getObject({ objectId, include: { json: true } });
|
|
58
|
+
return object.json ?? null;
|
|
59
|
+
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { Transaction } from "@mysten/sui/transactions";
|
|
17
17
|
import { walrusClient, netGasFee } from "./extend-chain.js";
|
|
18
18
|
import { splitStorageToFit } from "./shared/lib/storage-control/reuse.js";
|
|
19
|
+
import { dryRun } from "./shared/lib/wallet/chain-calls.js";
|
|
19
20
|
/** The transaction one shape is, for `sender`. */
|
|
20
21
|
export function storageOpTransaction(shape, input) {
|
|
21
22
|
const tx = new Transaction();
|
|
@@ -59,11 +60,11 @@ export function storageOpsReads(network) {
|
|
|
59
60
|
try {
|
|
60
61
|
const walrusPackageId = await this.walrusPackageId();
|
|
61
62
|
const bytes = await storageOpTransaction(shape, { walrusPackageId, sender }).build({ client });
|
|
62
|
-
const {
|
|
63
|
-
if (
|
|
64
|
-
return { feeMist: null, refusal:
|
|
63
|
+
const { status, gasUsed } = await dryRun(client, bytes);
|
|
64
|
+
if (!status.success) {
|
|
65
|
+
return { feeMist: null, refusal: status.error?.message || "the chain gave no reason" };
|
|
65
66
|
}
|
|
66
|
-
return { feeMist: netGasFee(
|
|
67
|
+
return { feeMist: netGasFee(gasUsed), refusal: null };
|
|
67
68
|
}
|
|
68
69
|
catch (error) {
|
|
69
70
|
// ⚠ A refusal at ASSEMBLY (a wrong argument, an object that is not this wallet's) is an
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ClientWithCoreApi } from "@mysten/sui/client";
|
|
2
|
+
import type { Signer } from "@mysten/sui/cryptography";
|
|
3
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
4
|
+
/** What every execution asks the node to include: the effects (status, objects) and the objects' types. */
|
|
5
|
+
export declare const EXECUTE_INCLUDE: {
|
|
6
|
+
readonly effects: true;
|
|
7
|
+
readonly objectTypes: true;
|
|
8
|
+
};
|
|
9
|
+
/** The parts of one transaction in the node's answer this tool reads. The SDK's shape fits it. */
|
|
10
|
+
export interface AnsweredTransaction {
|
|
11
|
+
digest: string;
|
|
12
|
+
status: {
|
|
13
|
+
success: boolean;
|
|
14
|
+
error?: {
|
|
15
|
+
message: string;
|
|
16
|
+
} | null;
|
|
17
|
+
};
|
|
18
|
+
effects?: {
|
|
19
|
+
changedObjects: readonly {
|
|
20
|
+
objectId: string;
|
|
21
|
+
idOperation: string;
|
|
22
|
+
}[];
|
|
23
|
+
} | null;
|
|
24
|
+
objectTypes?: Readonly<Record<string, string>> | null;
|
|
25
|
+
}
|
|
26
|
+
/** The node's answer: the transaction under the name that says how it ended. */
|
|
27
|
+
export interface ChainAnswer {
|
|
28
|
+
Transaction?: AnsweredTransaction;
|
|
29
|
+
FailedTransaction?: AnsweredTransaction;
|
|
30
|
+
}
|
|
31
|
+
export interface Executed {
|
|
32
|
+
digest: string;
|
|
33
|
+
/** The chain's reason when the transaction executed and FAILED; `null` when it went through. */
|
|
34
|
+
refused: string | null;
|
|
35
|
+
/** Every object it created, with its Move type when the node named one. */
|
|
36
|
+
created: readonly {
|
|
37
|
+
objectId: string;
|
|
38
|
+
type: string | null;
|
|
39
|
+
}[];
|
|
40
|
+
}
|
|
41
|
+
/** Read one answer. Throws when it carries no transaction at all — that is not an answer to judge. */
|
|
42
|
+
export declare function readAnswer(answer: ChainAnswer): Executed;
|
|
43
|
+
/**
|
|
44
|
+
* Sign `transaction` with `signer`, execute it once, and read the answer.
|
|
45
|
+
*
|
|
46
|
+
* ⛔ THE WAIT AFTER A SUCCESS is for what happens NEXT — the server told the digest, `nmts wallet`
|
|
47
|
+
* run, the browser's activity list opened — because a node that has not indexed the transaction
|
|
48
|
+
* yet answers those as if nothing happened. A wait that times out changes nothing about what was
|
|
49
|
+
* signed, so it is not an error of the transaction.
|
|
50
|
+
*
|
|
51
|
+
* ⚠ A THROW HERE IS NOT PROOF THAT NOTHING HAPPENED: a timeout or a dropped connection after the
|
|
52
|
+
* bytes went out says nothing about whether the transaction executed.
|
|
53
|
+
*/
|
|
54
|
+
export declare function signAndRun(client: ClientWithCoreApi, transaction: Transaction, signer: Signer): Promise<Executed>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// What the chain says about one executed transaction — read ONE way for every signer in this tool.
|
|
2
|
+
//
|
|
3
|
+
// ⛔ WHY ONE READER (2026-10-21). Sui retired JSON-RPC, whose execute answer carried the status as a
|
|
4
|
+
// word (`effects.status.status === "failure"`) and the created objects as `objectChanges`. The gRPC
|
|
5
|
+
// answer carries `status.success` and `effects.changedObjects` plus a separate `objectTypes` map.
|
|
6
|
+
// Six signers in `wallet-sign.ts` and two in `wallet-sign-external.ts` each read the old shape by
|
|
7
|
+
// hand; one translation here is what keeps "executed and FAILED" from being misread in one of them.
|
|
8
|
+
//
|
|
9
|
+
// ⛔ A DIGEST IS NOT A SUCCESS. A transaction that executed and failed still has a digest, and its
|
|
10
|
+
// gas is gone. `refused` is the chain's reason in that case and `null` only when it went through.
|
|
11
|
+
/** What every execution asks the node to include: the effects (status, objects) and the objects' types. */
|
|
12
|
+
export const EXECUTE_INCLUDE = { effects: true, objectTypes: true };
|
|
13
|
+
/** Read one answer. Throws when it carries no transaction at all — that is not an answer to judge. */
|
|
14
|
+
export function readAnswer(answer) {
|
|
15
|
+
const tx = answer.Transaction ?? answer.FailedTransaction;
|
|
16
|
+
if (tx === undefined)
|
|
17
|
+
throw new Error("The chain answered without the transaction it was asked about.");
|
|
18
|
+
const reason = tx.status.error?.message;
|
|
19
|
+
const refused = tx.status.success ? null : reason !== undefined && reason !== "" ? reason : "no reason was given";
|
|
20
|
+
const created = (tx.effects?.changedObjects ?? [])
|
|
21
|
+
.filter((change) => change.idOperation === "Created")
|
|
22
|
+
.map((change) => ({ objectId: change.objectId, type: tx.objectTypes?.[change.objectId] ?? null }));
|
|
23
|
+
return { digest: tx.digest, refused, created };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sign `transaction` with `signer`, execute it once, and read the answer.
|
|
27
|
+
*
|
|
28
|
+
* ⛔ THE WAIT AFTER A SUCCESS is for what happens NEXT — the server told the digest, `nmts wallet`
|
|
29
|
+
* run, the browser's activity list opened — because a node that has not indexed the transaction
|
|
30
|
+
* yet answers those as if nothing happened. A wait that times out changes nothing about what was
|
|
31
|
+
* signed, so it is not an error of the transaction.
|
|
32
|
+
*
|
|
33
|
+
* ⚠ A THROW HERE IS NOT PROOF THAT NOTHING HAPPENED: a timeout or a dropped connection after the
|
|
34
|
+
* bytes went out says nothing about whether the transaction executed.
|
|
35
|
+
*/
|
|
36
|
+
export async function signAndRun(client, transaction, signer) {
|
|
37
|
+
const answer = await client.core.signAndExecuteTransaction({ transaction, signer, include: EXECUTE_INCLUDE });
|
|
38
|
+
const executed = readAnswer(answer);
|
|
39
|
+
if (executed.refused === null) {
|
|
40
|
+
await client.core.waitForTransaction({ digest: executed.digest }).catch(() => undefined);
|
|
41
|
+
}
|
|
42
|
+
return executed;
|
|
43
|
+
}
|
package/dist/sui-rpc.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
2
|
+
import { type DeeperHistory } from "./shared/lib/wallet/address-history.ts";
|
|
2
3
|
/**
|
|
3
|
-
* A Sui
|
|
4
|
+
* A Sui client for `network` that asks the network's hosts in order.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
* the testnet one was measured dead — `rpc-testnet.suiscan.xyz` completes the TCP handshake in
|
|
7
|
-
* 31 ms and then sends nothing for twelve seconds, three times running. It had been that way for
|
|
8
|
-
* eleven days, so every command that needed the shard count on testnet had simply stopped.
|
|
9
|
-
*
|
|
10
|
-
* ⚠ One transport per client on purpose: the host that answered becomes the one asked first, and
|
|
6
|
+
* ⚠ One failover per client on purpose: the host that answered becomes the one asked first, and
|
|
11
7
|
* sharing that state across clients would let one command's bad luck redirect every other. The
|
|
12
8
|
* flip side is that a recovered first host is not noticed until the process restarts — that is
|
|
13
9
|
* the price of not probing a node nobody asked us to talk to.
|
|
10
|
+
*
|
|
11
|
+
* `format: "binary"` — protobuf bytes as they are; every host in the tables answers binary
|
|
12
|
+
* (measured 2026-10-21), and the default text form base64s every message.
|
|
13
|
+
*/
|
|
14
|
+
export declare function suiClient(network: "testnet" | "mainnet"): SuiGrpcClient;
|
|
15
|
+
/**
|
|
16
|
+
* Where a wallet's history OLDER than a gRPC node's few-week window is read — Sui's GraphQL service
|
|
17
|
+
* (`shared/lib/wallet/address-history.ts` holds why and the measurements) — or `null` when this run
|
|
18
|
+
* named its own Sui node: somebody who names a node is saying *that one*, and quietly asking a public
|
|
19
|
+
* service as well would send their addresses somewhere they did not choose. The history answer then
|
|
20
|
+
* says it is partial instead.
|
|
14
21
|
*/
|
|
15
|
-
export declare function
|
|
22
|
+
export declare function deeperHistory(network: "testnet" | "mainnet"): DeeperHistory | null;
|
package/dist/sui-rpc.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// The chain
|
|
1
|
+
// The chain client: which Sui node a command talks to, over what, and what happens when it does not
|
|
2
|
+
// answer.
|
|
2
3
|
//
|
|
3
4
|
// ⛔ WHY THIS IS ITS OWN FILE AND NOT PART OF walrus.ts. `walrus.ts` holds the host tables, and it
|
|
4
5
|
// is loaded by EVERY invocation including `nmts --help`. Importing the Sui SDK there pulled 150
|
|
@@ -6,32 +7,35 @@
|
|
|
6
7
|
// and failed the build, which is exactly what that gate is for. The SDK is imported here, and
|
|
7
8
|
// only the commands that actually reach the chain import this.
|
|
8
9
|
//
|
|
10
|
+
// ⛔ gRPC-WEB, SINCE 2026-10-21. Sui removed JSON-RPC from its node software in October 2026, and every
|
|
11
|
+
// host this tool used to ask answered only JSON-RPC. The SDK's `SuiGrpcClient` speaks gRPC-web over
|
|
12
|
+
// `fetch`, so the failover below wraps the same `fetch` it always did — the path
|
|
13
|
+
// (`/sui.rpc.v2.<Service>/<Method>`) is kept and only the host changes.
|
|
14
|
+
//
|
|
9
15
|
// ⛔ NOT A RETRIER. Each host is asked once. Anything other than "no answer" — any 4xx that is not
|
|
10
|
-
// 429 — is an answer, and asking a different node the
|
|
11
|
-
|
|
16
|
+
// 429, and every gRPC status the node sends back — is an answer, and asking a different node the
|
|
17
|
+
// same question gets the same one.
|
|
18
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
12
19
|
import { reachFetch } from "./reach.js";
|
|
13
|
-
import {
|
|
20
|
+
import { graphqlHistory, SUI_GRAPHQL_URLS } from "./shared/lib/wallet/address-history.js";
|
|
21
|
+
import { SUI_RPC_HOSTS, suiRpcHosts } from "./walrus.js";
|
|
14
22
|
/** HTTP statuses that mean "no answer came", the only ones worth asking a second node about. */
|
|
15
23
|
function worthAnotherHost(status) {
|
|
16
24
|
return status >= 500 || status === 429;
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
|
-
* A
|
|
27
|
+
* A `fetch` that asks the network's hosts in order.
|
|
20
28
|
*
|
|
21
|
-
* ⭐ 2026-09-01. There used to be one host per network, and on that morning
|
|
22
|
-
*
|
|
23
|
-
* 31 ms and then sends nothing for twelve seconds, three times running. It had been that way for
|
|
24
|
-
* eleven days, so every command that needed the shard count on testnet had simply stopped.
|
|
29
|
+
* ⭐ 2026-09-01. There used to be one host per network, and on that morning the testnet one was
|
|
30
|
+
* measured dead for eleven days — every command that needed the chain on testnet had simply stopped.
|
|
25
31
|
*
|
|
26
|
-
* ⚠
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* the price of not probing a node nobody asked us to talk to.
|
|
32
|
+
* ⚠ THE LAST HOST'S 5xx/429 IS THROWN, with its number in the sentence (2026-10-21). The gRPC-web
|
|
33
|
+
* transport turns a returned 500 or 502 into a bare `UNKNOWN`, and then "the server failed" and
|
|
34
|
+
* "the node said no" look the same to whoever decides whether to wait and ask again.
|
|
30
35
|
*/
|
|
31
|
-
|
|
32
|
-
const hosts = suiRpcHosts(network);
|
|
36
|
+
function failoverFetch(hosts) {
|
|
33
37
|
let preferred = 0;
|
|
34
|
-
|
|
38
|
+
return async (input, init) => {
|
|
35
39
|
const asked = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
|
|
36
40
|
let lastError = null;
|
|
37
41
|
for (let step = 0; step < hosts.length; step += 1) {
|
|
@@ -41,8 +45,8 @@ export function suiRpcTransport(network) {
|
|
|
41
45
|
continue;
|
|
42
46
|
try {
|
|
43
47
|
const res = await reachFetch(new URL(asked.pathname + asked.search, host), init);
|
|
44
|
-
if (worthAnotherHost(res.status)
|
|
45
|
-
lastError = new Error(`${host}
|
|
48
|
+
if (worthAnotherHost(res.status)) {
|
|
49
|
+
lastError = new Error(`${host} → HTTP ${res.status}`);
|
|
46
50
|
continue;
|
|
47
51
|
}
|
|
48
52
|
preferred = index;
|
|
@@ -56,5 +60,35 @@ export function suiRpcTransport(network) {
|
|
|
56
60
|
? lastError
|
|
57
61
|
: new Error(`no Sui node answered (${hosts.length} tried)`);
|
|
58
62
|
};
|
|
59
|
-
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A Sui client for `network` that asks the network's hosts in order.
|
|
66
|
+
*
|
|
67
|
+
* ⚠ One failover per client on purpose: the host that answered becomes the one asked first, and
|
|
68
|
+
* sharing that state across clients would let one command's bad luck redirect every other. The
|
|
69
|
+
* flip side is that a recovered first host is not noticed until the process restarts — that is
|
|
70
|
+
* the price of not probing a node nobody asked us to talk to.
|
|
71
|
+
*
|
|
72
|
+
* `format: "binary"` — protobuf bytes as they are; every host in the tables answers binary
|
|
73
|
+
* (measured 2026-10-21), and the default text form base64s every message.
|
|
74
|
+
*/
|
|
75
|
+
export function suiClient(network) {
|
|
76
|
+
const hosts = suiRpcHosts(network);
|
|
77
|
+
return new SuiGrpcClient({
|
|
78
|
+
network,
|
|
79
|
+
baseUrl: hosts[0] ?? "",
|
|
80
|
+
format: "binary",
|
|
81
|
+
fetch: failoverFetch(hosts),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Where a wallet's history OLDER than a gRPC node's few-week window is read — Sui's GraphQL service
|
|
86
|
+
* (`shared/lib/wallet/address-history.ts` holds why and the measurements) — or `null` when this run
|
|
87
|
+
* named its own Sui node: somebody who names a node is saying *that one*, and quietly asking a public
|
|
88
|
+
* service as well would send their addresses somewhere they did not choose. The history answer then
|
|
89
|
+
* says it is partial instead.
|
|
90
|
+
*/
|
|
91
|
+
export function deeperHistory(network) {
|
|
92
|
+
const named = suiRpcHosts(network).join(" ") !== (SUI_RPC_HOSTS[network] ?? []).join(" ");
|
|
93
|
+
return named ? null : graphqlHistory(SUI_GRAPHQL_URLS[network], (input, init) => reachFetch(input, init));
|
|
60
94
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
2
1
|
import { Transaction } from "@mysten/sui/transactions";
|
|
3
2
|
import type { Network } from "./network.ts";
|
|
3
|
+
import type { Executed } from "./sui-execute.ts";
|
|
4
4
|
import type { RegisterShape, WalletUploadReads } from "./upload-wallet-plan.ts";
|
|
5
5
|
import type { Certificate } from "./upload-wire.ts";
|
|
6
6
|
/**
|
|
@@ -18,7 +18,7 @@ export declare function packageConfig(network: Network): {
|
|
|
18
18
|
};
|
|
19
19
|
declare function build(network: Network, relayUrl: string): import("@mysten/sui/client").ClientWithExtensions<{
|
|
20
20
|
walrus: import("@mysten/walrus").WalrusClient;
|
|
21
|
-
},
|
|
21
|
+
}, import("@mysten/sui/grpc").SuiGrpcClient>;
|
|
22
22
|
export type PayingClient = ReturnType<typeof build>;
|
|
23
23
|
/** A Walrus client bound to ONE relay, able to pay that relay's tip. */
|
|
24
24
|
export declare function payingClient(network: Network, relayUrl: string): PayingClient;
|
|
@@ -48,7 +48,7 @@ export declare function certifyTransaction(client: PayingClient, input: {
|
|
|
48
48
|
* ⛔ THE OBJECT IS FOUND BY ITS TYPE, not by position: the transaction also creates the leftover
|
|
49
49
|
* resource on a cut, and on a purchase the storage object is created and consumed inside it.
|
|
50
50
|
*/
|
|
51
|
-
export declare function createdBlob(client: PayingClient,
|
|
51
|
+
export declare function createdBlob(client: PayingClient, created: Executed["created"]): Promise<{
|
|
52
52
|
blobObjectId: string;
|
|
53
53
|
endEpoch: number;
|
|
54
54
|
}>;
|
|
@@ -14,11 +14,9 @@
|
|
|
14
14
|
// ⛔ THE ENCODED SIZE IS THE CHAIN'S ARITHMETIC, NOT A COPY. Registration checks
|
|
15
15
|
// `encoded_size <= storage_size` with `walrus::encoding::encoded_blob_length`, and the SDK keeps
|
|
16
16
|
// its own copy unexported. Cutting a held resource to fit needs that exact number, so it is
|
|
17
|
-
// asked of the chain itself, in a
|
|
17
|
+
// asked of the chain itself, in a simulation that costs nothing — a copy kept here would be
|
|
18
18
|
// wrong the day the protocol changed it, and the way that surfaces is a refused registration
|
|
19
19
|
// after the split was signed.
|
|
20
|
-
import { bcs } from "@mysten/sui/bcs";
|
|
21
|
-
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
22
20
|
import { Transaction } from "@mysten/sui/transactions";
|
|
23
21
|
import { blobIdFromInt, blobIdToInt, MAINNET_WALRUS_PACKAGE_CONFIG, TESTNET_WALRUS_PACKAGE_CONFIG, walrus, } from "@mysten/walrus";
|
|
24
22
|
import { fromBase64Url } from "./bytes.js";
|
|
@@ -27,9 +25,10 @@ import { extendReads, netGasFee, readBlobLease } from "./extend-chain.js";
|
|
|
27
25
|
import { reachFetch } from "./reach.js";
|
|
28
26
|
import { readOwnedStorage, readStorageType } from "./shared/lib/storage-control/chain.js";
|
|
29
27
|
import { registerIntoStorage, splitStorageToFit } from "./shared/lib/storage-control/reuse.js";
|
|
28
|
+
import { dryRun, inspect, u64FromLe } from "./shared/lib/wallet/chain-calls.js";
|
|
30
29
|
import { storageNodesThrough } from "./walrus.js";
|
|
31
30
|
import { freshWalrus } from "./walrus-fresh.js";
|
|
32
|
-
import {
|
|
31
|
+
import { suiClient } from "./sui-rpc.js";
|
|
33
32
|
import { readBalances, walCoinType } from "./wallet.js";
|
|
34
33
|
import { chainReader } from "./wallet-chain.js";
|
|
35
34
|
/**
|
|
@@ -49,7 +48,7 @@ export function packageConfig(network) {
|
|
|
49
48
|
return network === "mainnet" ? MAINNET_WALRUS_PACKAGE_CONFIG : TESTNET_WALRUS_PACKAGE_CONFIG;
|
|
50
49
|
}
|
|
51
50
|
function build(network, relayUrl) {
|
|
52
|
-
return
|
|
51
|
+
return suiClient(network).$extend(walrus({
|
|
53
52
|
...storageNodesThrough(),
|
|
54
53
|
uploadRelay: { host: relayUrl, sendTip: { max: RELAY_TIP_CEILING_MIST[network] }, fetch: reachFetch },
|
|
55
54
|
}));
|
|
@@ -132,16 +131,9 @@ export function certifyTransaction(client, input) {
|
|
|
132
131
|
* ⛔ THE OBJECT IS FOUND BY ITS TYPE, not by position: the transaction also creates the leftover
|
|
133
132
|
* resource on a cut, and on a purchase the storage object is created and consumed inside it.
|
|
134
133
|
*/
|
|
135
|
-
export async function createdBlob(client,
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
change !== null &&
|
|
139
|
-
Reflect.get(change, "type") === "created" &&
|
|
140
|
-
typeof Reflect.get(change, "objectType") === "string" &&
|
|
141
|
-
String(Reflect.get(change, "objectType")).endsWith("::blob::Blob"))
|
|
142
|
-
: undefined;
|
|
143
|
-
const id = created === undefined ? undefined : Reflect.get(created, "objectId");
|
|
144
|
-
if (typeof id !== "string") {
|
|
134
|
+
export async function createdBlob(client, created) {
|
|
135
|
+
const id = created.find((object) => object.type?.endsWith("::blob::Blob") === true)?.objectId;
|
|
136
|
+
if (id === undefined) {
|
|
145
137
|
throw new NmtsError("The registration executed but the chain did not list the blob object it created.", {
|
|
146
138
|
exitCode: 1,
|
|
147
139
|
nextStep: "The storage is bought. Running the same command again does not pay again: it reads the record and continues.",
|
|
@@ -161,15 +153,15 @@ export async function encodedLength(client, sender, sealedLen) {
|
|
|
161
153
|
// 1 = RS2, the encoding every registration in this tool names (`reuse.ts`).
|
|
162
154
|
arguments: [tx.pure.u64(sealedLen), tx.pure.u8(1), tx.pure.u16(state.committee.n_shards)],
|
|
163
155
|
});
|
|
164
|
-
const result = await client
|
|
165
|
-
const value = result.results
|
|
166
|
-
if (value === undefined) {
|
|
156
|
+
const result = await inspect(client, tx, sender);
|
|
157
|
+
const value = result.error === null ? result.results[0]?.returnValues[0] : undefined;
|
|
158
|
+
if (value === undefined || value.length !== 8) {
|
|
167
159
|
throw new NmtsError("The chain did not say how large this part is once encoded.", {
|
|
168
160
|
exitCode: 1,
|
|
169
161
|
nextStep: "Nothing was signed. A held resource cannot be cut to fit without that number; buy new storage instead, or try again.",
|
|
170
162
|
});
|
|
171
163
|
}
|
|
172
|
-
return Number(
|
|
164
|
+
return Number(u64FromLe(value));
|
|
173
165
|
}
|
|
174
166
|
/** A part shaped like a real one, for measuring the fee of a registration before anything is sealed. */
|
|
175
167
|
function placeholderPart(sealedLen) {
|
|
@@ -203,10 +195,10 @@ export function walletUploadReads(network, relayUrl) {
|
|
|
203
195
|
try {
|
|
204
196
|
const tx = await registerTransaction(client, network, { sender, epochs, storage, part: placeholderPart(sealedLen) });
|
|
205
197
|
const bytes = await tx.build({ client });
|
|
206
|
-
const {
|
|
207
|
-
if (
|
|
198
|
+
const { status, gasUsed } = await dryRun(client, bytes);
|
|
199
|
+
if (!status.success)
|
|
208
200
|
return null;
|
|
209
|
-
return netGasFee(
|
|
201
|
+
return netGasFee(gasUsed);
|
|
210
202
|
}
|
|
211
203
|
catch {
|
|
212
204
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ActivityFetch } from "./commands/wallet-activity.ts";
|
|
2
2
|
import type { Network } from "./network.ts";
|
|
3
|
-
/** How long the
|
|
3
|
+
/** How long the question gets. A read that stalls is a read that failed. */
|
|
4
4
|
export declare const ACTIVITY_TIMEOUT_MS = 20000;
|
|
5
5
|
export declare function queryActivity(network: Network, address: string): Promise<ActivityFetch>;
|
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
// The live read behind `nmts wallet activity`: the chain's
|
|
1
|
+
// The live read behind `nmts wallet activity`: the chain's list for one address.
|
|
2
2
|
//
|
|
3
|
-
// ⛔ READ ONLY. The same
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
3
|
+
// ⛔ READ ONLY. The same gRPC client `wallet-chain.ts` reads balances with, and the browser's own
|
|
4
|
+
// question (`shared/lib/wallet/address-history.ts`); nothing here builds or signs a transaction.
|
|
5
|
+
// Imported lazily, only when no seam was supplied.
|
|
6
|
+
import { FETCH } from "./commands/wallet-activity.js";
|
|
7
|
+
import { addressTransactions } from "./shared/lib/wallet/address-history.js";
|
|
8
|
+
import { deeperHistory, suiClient } from "./sui-rpc.js";
|
|
9
|
+
/** How long the question gets. A read that stalls is a read that failed. */
|
|
9
10
|
export const ACTIVITY_TIMEOUT_MS = 20_000;
|
|
10
11
|
export async function queryActivity(network, address) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
client.queryTransactionBlocks({
|
|
16
|
-
filter: { FromAddress: address },
|
|
17
|
-
options,
|
|
18
|
-
limit: FETCH_PER_DIRECTION,
|
|
19
|
-
order: "descending",
|
|
20
|
-
signal,
|
|
21
|
-
}),
|
|
22
|
-
client.queryTransactionBlocks({
|
|
23
|
-
filter: { ToAddress: address },
|
|
24
|
-
options,
|
|
25
|
-
limit: FETCH_PER_DIRECTION,
|
|
26
|
-
order: "descending",
|
|
27
|
-
signal,
|
|
28
|
-
}),
|
|
29
|
-
]);
|
|
30
|
-
return { sent: sent.data, received: received.data };
|
|
12
|
+
const { transactions, complete } = await addressTransactions(suiClient(network), address, FETCH, AbortSignal.timeout(ACTIVITY_TIMEOUT_MS),
|
|
13
|
+
// Past the node's few-week window, the older rows come from Sui's GraphQL service.
|
|
14
|
+
deeperHistory(network));
|
|
15
|
+
return { transactions, complete };
|
|
31
16
|
}
|
package/dist/wallet-chain.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
// address holds, and whether a coin type exists. A balance is public data — anybody can ask the
|
|
11
11
|
// same question about the same address — so nothing about this run leaves that was not already
|
|
12
12
|
// published by the chain itself.
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { RpcError } from "@mysten/sui/grpc";
|
|
14
|
+
import { suiClient } from "./sui-rpc.js";
|
|
15
15
|
/**
|
|
16
16
|
* How long one balance question gets.
|
|
17
17
|
*
|
|
@@ -31,25 +31,31 @@ export const BALANCE_TIMEOUT_MS = 20_000;
|
|
|
31
31
|
export function chainReader(network, address) {
|
|
32
32
|
// The network name reaches the SDK as well as the URL, which is what keeps a mirror pointed at
|
|
33
33
|
// the wrong chain from being discovered later, as an answer that quietly made no sense.
|
|
34
|
-
const client =
|
|
34
|
+
const client = suiClient(network);
|
|
35
35
|
return {
|
|
36
36
|
async totalOf(coinType) {
|
|
37
|
-
const {
|
|
37
|
+
const { balance } = await client.core.getBalance({
|
|
38
38
|
owner: address,
|
|
39
39
|
coinType,
|
|
40
40
|
signal: AbortSignal.timeout(BALANCE_TIMEOUT_MS),
|
|
41
41
|
});
|
|
42
|
-
return baseUnitsOf(
|
|
42
|
+
return baseUnitsOf(balance.balance);
|
|
43
43
|
},
|
|
44
44
|
async knowsCoinType(coinType) {
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
// ⛔ ASKED RAW, NOT THROUGH `client.core.getCoinMetadata`: that helper answers `null` for ANY
|
|
46
|
+
// failure, a timeout included, and then "the node did not answer" would print as "this
|
|
47
|
+
// chain does not know the coin". The node's own answer for a type that does not exist is the
|
|
48
|
+
// status NOT_FOUND (measured on both networks' four hosts, 2026-10-21); every other failure
|
|
49
|
+
// is thrown, which the caller reports as "could not be confirmed".
|
|
50
|
+
try {
|
|
51
|
+
const { response } = await client.stateService.getCoinInfo({ coinType }, { abort: AbortSignal.timeout(BALANCE_TIMEOUT_MS) });
|
|
52
|
+
return response.metadata !== undefined;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof RpcError && error.code === "NOT_FOUND")
|
|
56
|
+
return false;
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
53
59
|
},
|
|
54
60
|
};
|
|
55
61
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Network } from "./network.ts";
|
|
2
|
-
/** How long the
|
|
2
|
+
/** How long the question gets. A read that stalls is a read that failed. */
|
|
3
3
|
export declare const HISTORY_TIMEOUT_MS = 20000;
|
|
4
4
|
export declare function hasHistory(network: Network, address: string): Promise<boolean>;
|