@needmoretruth/nmts-cli 0.50.1 → 0.52.0
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 +21 -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 +42 -0
- package/dist/shared/lib/wallet/address-history.js +247 -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 +18 -25
- 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
|
@@ -41,10 +41,10 @@ export interface ActivityContext {
|
|
|
41
41
|
/** The network name the explorer link is built for: `"mainnet"` or `"testnet"`. */
|
|
42
42
|
network: string;
|
|
43
43
|
}
|
|
44
|
-
export interface
|
|
45
|
-
package?: string;
|
|
46
|
-
module?: string;
|
|
47
|
-
function?: string;
|
|
44
|
+
export interface ChainMoveCall {
|
|
45
|
+
package?: string | undefined;
|
|
46
|
+
module?: string | undefined;
|
|
47
|
+
function?: string | undefined;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* One command of a programmable transaction.
|
|
@@ -54,59 +54,52 @@ export interface RpcMoveCall {
|
|
|
54
54
|
* ("no properties in common" — weak-type detection). The index signature says "any other field
|
|
55
55
|
* is fine".
|
|
56
56
|
*/
|
|
57
|
-
export interface
|
|
58
|
-
MoveCall?:
|
|
57
|
+
export interface ChainCommand {
|
|
58
|
+
MoveCall?: ChainMoveCall | null | undefined;
|
|
59
59
|
[other: string]: unknown;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
62
|
+
* One transaction input — `{ Object: { SharedObject | ImmOrOwnedObject | Receiving: { objectId } } }`,
|
|
63
|
+
* `{ UnresolvedObject: { objectId } }`, or a pure value that carries no object. Read with checks
|
|
64
|
+
* rather than declared, for the same weak-type reason.
|
|
65
65
|
*/
|
|
66
|
-
export type
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
export interface RpcBalanceChange {
|
|
73
|
-
owner?: unknown;
|
|
74
|
-
coinType?: string;
|
|
75
|
-
amount?: string;
|
|
66
|
+
export type ChainInput = Readonly<Record<string, unknown>>;
|
|
67
|
+
export interface ChainBalanceChange {
|
|
68
|
+
address?: string | undefined;
|
|
69
|
+
coinType?: string | undefined;
|
|
70
|
+
amount?: string | undefined;
|
|
76
71
|
}
|
|
77
|
-
export interface
|
|
78
|
-
digest?: string;
|
|
79
|
-
timestampMs?: string | number | null;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
} | null;
|
|
72
|
+
export interface ChainTransaction {
|
|
73
|
+
digest?: string | undefined;
|
|
74
|
+
timestampMs?: string | number | null | undefined;
|
|
75
|
+
status?: {
|
|
76
|
+
success?: boolean | undefined;
|
|
77
|
+
} | null | undefined;
|
|
78
|
+
balanceChanges?: readonly ChainBalanceChange[] | null | undefined;
|
|
86
79
|
transaction?: {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
* reason as the index signatures: without it other kinds (`ChangeEpoch`) fail the type check. */
|
|
95
|
-
kind?: string;
|
|
96
|
-
inputs?: readonly RpcInput[];
|
|
97
|
-
transactions?: readonly RpcCommandEntry[];
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
} | null;
|
|
80
|
+
sender?: string | null | undefined;
|
|
81
|
+
gasData?: {
|
|
82
|
+
owner?: string | null | undefined;
|
|
83
|
+
} | undefined;
|
|
84
|
+
inputs?: readonly ChainInput[] | undefined;
|
|
85
|
+
commands?: readonly ChainCommand[] | undefined;
|
|
86
|
+
} | null | undefined;
|
|
101
87
|
}
|
|
102
88
|
/**
|
|
103
89
|
* Put an address into one shape before comparing.
|
|
104
90
|
*
|
|
105
91
|
* ⚠ A Sui address can be written zero-padded or not (`0x2` and `0x000…02` are the same one). The
|
|
106
|
-
*
|
|
92
|
+
* chain's form and the one in our configuration can differ, and then THE SAME ADDRESS COMPARES AS
|
|
107
93
|
* DIFFERENT — a gift would fall through to "send". So both are padded to 32 bytes first.
|
|
108
94
|
*/
|
|
109
95
|
export declare function normalizeAddress(raw: string): string;
|
|
96
|
+
/**
|
|
97
|
+
* A coin type with its package address padded — `0x2::sui::SUI` and `0x000…02::sui::SUI` are one type.
|
|
98
|
+
*
|
|
99
|
+
* ⛔ The gRPC and GraphQL nodes write the long form, where JSON-RPC wrote the short one for SUI; a
|
|
100
|
+
* comparison against the short form alone would stop naming SUI anywhere in the list.
|
|
101
|
+
*/
|
|
102
|
+
export declare function normalizeCoinType(raw: string): string;
|
|
110
103
|
/**
|
|
111
104
|
* One transaction → one row for a screen or a terminal.
|
|
112
105
|
*
|
|
@@ -116,7 +109,7 @@ export declare function normalizeAddress(raw: string): string;
|
|
|
116
109
|
* here goes down; donation comes before send because a more specific truth beats a less
|
|
117
110
|
* specific one.
|
|
118
111
|
*/
|
|
119
|
-
export declare function toActivityRow(tx:
|
|
112
|
+
export declare function toActivityRow(tx: ChainTransaction, ctx: ActivityContext): ActivityRow;
|
|
120
113
|
/**
|
|
121
114
|
* Where a person can look the transaction up themselves.
|
|
122
115
|
*
|
|
@@ -128,11 +121,12 @@ export declare function toActivityRow(tx: RpcTransaction, ctx: ActivityContext):
|
|
|
128
121
|
*/
|
|
129
122
|
export declare function explorerTxUrl(digest: string, network: string): string;
|
|
130
123
|
/**
|
|
131
|
-
*
|
|
124
|
+
* Lists of rows folded into one — newest first, each digest once, at most `limit`.
|
|
132
125
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
126
|
+
* ⭐ Since 2026-10-21 the chain is asked ONE question per page ("every transaction that moved this
|
|
127
|
+
* address's state" — the gRPC `affectedAddress` filter), where the retired JSON-RPC could only ask
|
|
128
|
+
* "sent" and "received" separately and this function merged the two. It still takes several lists,
|
|
129
|
+
* because a caller may page, and DUPLICATES ARE STILL REMOVED BY DIGEST.
|
|
136
130
|
* ⚠ Rows with no time go LAST — treating a missing time as 0 would float "1970" to the top.
|
|
137
131
|
*/
|
|
138
132
|
export declare function mergeActivity(groups: readonly (readonly ActivityRow[])[], limit: number): ActivityRow[];
|
|
@@ -33,16 +33,7 @@
|
|
|
33
33
|
// `ActivityContext`, so the same file serves the browser (which reads its build's network) and
|
|
34
34
|
// the command-line tool (which resolves the network at run time) without a fork.
|
|
35
35
|
// ── Small readers ─────────────────────────────────────────────────────────────────────────────
|
|
36
|
-
/** The
|
|
37
|
-
function ownerAddress(owner) {
|
|
38
|
-
if (typeof owner !== "object" || owner === null)
|
|
39
|
-
return null;
|
|
40
|
-
if (!("AddressOwner" in owner))
|
|
41
|
-
return null;
|
|
42
|
-
const value = owner.AddressOwner;
|
|
43
|
-
return typeof value === "string" ? value : null;
|
|
44
|
-
}
|
|
45
|
-
/** The RPC gives the time as a string. Unreadable ⇒ `null`, NEVER an invented number. */
|
|
36
|
+
/** The chain gives the time as a number (or, from some nodes, a string). Unreadable ⇒ `null`, NEVER an invented number. */
|
|
46
37
|
function readTimestamp(raw) {
|
|
47
38
|
if (raw === null || raw === undefined)
|
|
48
39
|
return null;
|
|
@@ -53,7 +44,7 @@ function readTimestamp(raw) {
|
|
|
53
44
|
* Put an address into one shape before comparing.
|
|
54
45
|
*
|
|
55
46
|
* ⚠ A Sui address can be written zero-padded or not (`0x2` and `0x000…02` are the same one). The
|
|
56
|
-
*
|
|
47
|
+
* chain's form and the one in our configuration can differ, and then THE SAME ADDRESS COMPARES AS
|
|
57
48
|
* DIFFERENT — a gift would fall through to "send". So both are padded to 32 bytes first.
|
|
58
49
|
*/
|
|
59
50
|
export function normalizeAddress(raw) {
|
|
@@ -62,24 +53,50 @@ export function normalizeAddress(raw) {
|
|
|
62
53
|
return raw.trim().toLowerCase();
|
|
63
54
|
return `0x${body.padStart(64, "0")}`;
|
|
64
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* A coin type with its package address padded — `0x2::sui::SUI` and `0x000…02::sui::SUI` are one type.
|
|
58
|
+
*
|
|
59
|
+
* ⛔ The gRPC and GraphQL nodes write the long form, where JSON-RPC wrote the short one for SUI; a
|
|
60
|
+
* comparison against the short form alone would stop naming SUI anywhere in the list.
|
|
61
|
+
*/
|
|
62
|
+
export function normalizeCoinType(raw) {
|
|
63
|
+
const [address, ...rest] = raw.split("::");
|
|
64
|
+
return rest.length === 0 || address === undefined ? raw : [normalizeAddress(address), ...rest].join("::");
|
|
65
|
+
}
|
|
65
66
|
/** Every Move call (empty for a pure transfer). */
|
|
66
67
|
function moveCalls(tx) {
|
|
67
|
-
const commands = tx.transaction?.data?.transaction?.transactions ?? [];
|
|
68
68
|
const calls = [];
|
|
69
|
-
for (const command of commands) {
|
|
70
|
-
if (
|
|
71
|
-
continue;
|
|
72
|
-
if (command.MoveCall !== undefined)
|
|
69
|
+
for (const command of tx.transaction?.commands ?? []) {
|
|
70
|
+
if (command.MoveCall !== undefined && command.MoveCall !== null)
|
|
73
71
|
calls.push(command.MoveCall);
|
|
74
72
|
}
|
|
75
73
|
return calls;
|
|
76
74
|
}
|
|
75
|
+
/** `{ objectId }` → the id, anything else → null. */
|
|
76
|
+
function objectIdOf(value) {
|
|
77
|
+
return typeof value === "object" && value !== null && "objectId" in value && typeof value.objectId === "string"
|
|
78
|
+
? value.objectId
|
|
79
|
+
: null;
|
|
80
|
+
}
|
|
81
|
+
/** The `objectId` one level down a tagged value — `{ $kind, SharedObject: { objectId } }` → the id. */
|
|
82
|
+
function idInside(value) {
|
|
83
|
+
if (typeof value !== "object" || value === null)
|
|
84
|
+
return null;
|
|
85
|
+
for (const inner of Object.values(value)) {
|
|
86
|
+
const id = objectIdOf(inner);
|
|
87
|
+
if (id !== null)
|
|
88
|
+
return id;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
77
92
|
/** Every object id among the inputs, zero-padded. */
|
|
78
93
|
function inputObjectIds(tx) {
|
|
79
94
|
const ids = new Set();
|
|
80
|
-
for (const input of tx.transaction?.
|
|
81
|
-
|
|
82
|
-
|
|
95
|
+
for (const input of tx.transaction?.inputs ?? []) {
|
|
96
|
+
// A resolved object input is one level deeper than an unresolved one.
|
|
97
|
+
const id = idInside(input.Object) ?? objectIdOf(input.UnresolvedObject);
|
|
98
|
+
if (id !== null)
|
|
99
|
+
ids.add(normalizeAddress(id));
|
|
83
100
|
}
|
|
84
101
|
return ids;
|
|
85
102
|
}
|
|
@@ -121,26 +138,29 @@ const WALRUS_FUNCTION_KIND = {
|
|
|
121
138
|
export function toActivityRow(tx, ctx) {
|
|
122
139
|
const me = normalizeAddress(ctx.address);
|
|
123
140
|
const digest = typeof tx.digest === "string" ? tx.digest : "";
|
|
124
|
-
const sender = normalizeAddress(tx.transaction?.
|
|
125
|
-
const gasOwnerRaw = tx.transaction?.
|
|
141
|
+
const sender = normalizeAddress(tx.transaction?.sender ?? "");
|
|
142
|
+
const gasOwnerRaw = tx.transaction?.gasData?.owner;
|
|
126
143
|
const gasOwner = typeof gasOwnerRaw === "string" ? normalizeAddress(gasOwnerRaw) : sender;
|
|
127
144
|
const pool = ctx.poolAddress === "" ? null : normalizeAddress(ctx.poolAddress);
|
|
128
145
|
const gasPayer = gasOwner === sender ? "self" : pool !== null && gasOwner === pool ? "pool" : "other";
|
|
129
146
|
const changes = [];
|
|
130
147
|
let donationGain = false;
|
|
148
|
+
const wal = normalizeCoinType(ctx.walCoinType);
|
|
149
|
+
const sui = normalizeCoinType("0x2::sui::SUI");
|
|
131
150
|
for (const change of tx.balanceChanges ?? []) {
|
|
132
|
-
|
|
133
|
-
if (
|
|
151
|
+
// A change whose owner is not an address (an object, a shared balance) has no `address` string.
|
|
152
|
+
if (typeof change.address !== "string")
|
|
134
153
|
continue;
|
|
135
|
-
const normalized = normalizeAddress(
|
|
154
|
+
const normalized = normalizeAddress(change.address);
|
|
136
155
|
const amount = change.amount === undefined ? 0n : amountOf(change.amount);
|
|
137
156
|
// An entry whose figure we cannot read is skipped; the rest of the transaction is still a row.
|
|
138
157
|
if (amount === null)
|
|
139
158
|
continue;
|
|
140
159
|
if (normalized === me) {
|
|
141
160
|
const coinType = change.coinType ?? "";
|
|
161
|
+
const named = normalizeCoinType(coinType);
|
|
142
162
|
changes.push({
|
|
143
|
-
coin:
|
|
163
|
+
coin: named === wal ? "WAL" : named === sui ? "SUI" : null,
|
|
144
164
|
coinType,
|
|
145
165
|
amount,
|
|
146
166
|
});
|
|
@@ -181,7 +201,7 @@ export function toActivityRow(tx, ctx) {
|
|
|
181
201
|
return {
|
|
182
202
|
digest,
|
|
183
203
|
atMs: readTimestamp(tx.timestampMs),
|
|
184
|
-
failed:
|
|
204
|
+
failed: tx.status?.success === false,
|
|
185
205
|
gasPayer,
|
|
186
206
|
kind,
|
|
187
207
|
changes,
|
|
@@ -201,11 +221,12 @@ export function explorerTxUrl(digest, network) {
|
|
|
201
221
|
return `https://suiscan.xyz/${network}/tx/${digest}`;
|
|
202
222
|
}
|
|
203
223
|
/**
|
|
204
|
-
*
|
|
224
|
+
* Lists of rows folded into one — newest first, each digest once, at most `limit`.
|
|
205
225
|
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
226
|
+
* ⭐ Since 2026-10-21 the chain is asked ONE question per page ("every transaction that moved this
|
|
227
|
+
* address's state" — the gRPC `affectedAddress` filter), where the retired JSON-RPC could only ask
|
|
228
|
+
* "sent" and "received" separately and this function merged the two. It still takes several lists,
|
|
229
|
+
* because a caller may page, and DUPLICATES ARE STILL REMOVED BY DIGEST.
|
|
209
230
|
* ⚠ Rows with no time go LAST — treating a missing time as 0 would float "1970" to the top.
|
|
210
231
|
*/
|
|
211
232
|
export function mergeActivity(groups, limit) {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type SuiGrpcClient } from "@mysten/sui/grpc";
|
|
2
|
+
import type { SuiClientTypes } from "@mysten/sui/client";
|
|
3
|
+
/** What one row of history carries: the parsed transaction and every balance it moved. */
|
|
4
|
+
export type HistoryTransaction = SuiClientTypes.Transaction<{
|
|
5
|
+
transaction: true;
|
|
6
|
+
balanceChanges: true;
|
|
7
|
+
}>;
|
|
8
|
+
export interface AddressHistory {
|
|
9
|
+
/** Newest first, at most the `limit` asked for. */
|
|
10
|
+
transactions: HistoryTransaction[];
|
|
11
|
+
/** True when the whole history was looked through — false when some of it could not be read. */
|
|
12
|
+
complete: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Where history older than the node's window is read: the newest `limit` rows, newest first. */
|
|
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
|
+
/**
|
|
24
|
+
* The newest transactions that moved `address`'s state, newest first.
|
|
25
|
+
*
|
|
26
|
+
* @param limit - how many to return at most; 1 is the cheapest "has this address any history".
|
|
27
|
+
* @param deeper - where to read past the node's window; `null` when the caller named its own node and
|
|
28
|
+
* asked for nothing else (the answer is then `complete: false` whenever the window ran out).
|
|
29
|
+
*/
|
|
30
|
+
export declare function addressTransactions(client: Pick<SuiGrpcClient, "ledgerService">, address: string, limit: number, signal?: AbortSignal, deeper?: DeeperHistory | null): Promise<AddressHistory>;
|
|
31
|
+
/**
|
|
32
|
+
* Has `address` ever been in a transaction? Throws when nobody could finish looking — "nobody could
|
|
33
|
+
* tell" and "nothing is there" are opposite facts, and only the second may answer `false`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function hasAddressHistory(client: Pick<SuiGrpcClient, "ledgerService">, address: string, signal?: AbortSignal, deeper?: DeeperHistory | null): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* The deeper source over Sui's GraphQL service at `url`.
|
|
38
|
+
*
|
|
39
|
+
* ⛔ Anything but a clean answer throws — an error list, a missing page, a row of the wrong shape.
|
|
40
|
+
* The caller turns that into `complete: false`; it never becomes an empty history.
|
|
41
|
+
*/
|
|
42
|
+
export declare function graphqlHistory(url: string, fetchFn?: (input: string, init: RequestInit) => Promise<Response>): DeeperHistory;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// The transactions that moved one address — asked of a Sui node over gRPC, and of Sui's GraphQL
|
|
2
|
+
// service for what the node no longer keeps. ⚠ PUBLISHED — copied byte-for-byte into the `nmts`
|
|
3
|
+
// command-line package; keep comments self-contained English.
|
|
4
|
+
//
|
|
5
|
+
// ⛔ WHY ONE QUESTION, WHERE THERE USED TO BE TWO (2026-10-21). The retired JSON-RPC could filter
|
|
6
|
+
// transactions by `FromAddress` or by `ToAddress` and had no OR, so "sent" and "received" were two
|
|
7
|
+
// queries everywhere — the wallet walk, the activity list, both in the browser and in the
|
|
8
|
+
// command-line tool. The gRPC ledger index has the filter that was actually meant:
|
|
9
|
+
// `affectedAddress` — every transaction after which this address owns, lost or changed an object,
|
|
10
|
+
// or whose address balance moved. Sending pays gas from the sender's coin, so a send is in it;
|
|
11
|
+
// receiving gives the address an object, so a receipt is in it.
|
|
12
|
+
//
|
|
13
|
+
// ⛔ A gRPC NODE KEEPS A WINDOW, NOT THE HISTORY (measured 2026-10-21). Each node answers only from
|
|
14
|
+
// the checkpoints it still holds, and says where that ends: a scan with nothing in it stops with
|
|
15
|
+
// `CHECKPOINT_BOUND` at the node's lowest available checkpoint. Mysten Labs' fullnode held about
|
|
16
|
+
// the last three weeks on both networks; Suiscan's held two weeks on mainnet and the last few
|
|
17
|
+
// SECONDS on testnet. So "the node found nothing" means "nothing lately" — a wallet funded in
|
|
18
|
+
// August and idle since read as never used, which is how a funded wallet vanishes from a screen.
|
|
19
|
+
// What the window does not cover is asked of Sui's public GraphQL service, which answered the same
|
|
20
|
+
// filter back to 2023 on both networks; its rows are read by the SAME parser as the node's (its
|
|
21
|
+
// `transactionJson` and `balanceChangesJson` are the gRPC messages written as JSON).
|
|
22
|
+
//
|
|
23
|
+
// ⛔ A SCAN THAT STOPPED SHORT IS NOT "NOTHING THERE". The node also bounds how much of its index one
|
|
24
|
+
// request reads; a request can end with fewer items than asked — even none — and say it stopped
|
|
25
|
+
// because of that bound (`SCAN_LIMIT`). This file follows the cursor for a bounded number of
|
|
26
|
+
// requests. Whatever it could not settle is `complete: false`, so a caller can tell "no history"
|
|
27
|
+
// from "did not finish looking".
|
|
28
|
+
//
|
|
29
|
+
// ⚠ It needs the gRPC client: the filter is a raw ledger-service filter, which the SDK's top-level
|
|
30
|
+
// `listTransactions` does not offer (it filters by sender or function only).
|
|
31
|
+
import { GrpcTypes, parseGrpcTransactionResponse } from "@mysten/sui/grpc";
|
|
32
|
+
/**
|
|
33
|
+
* Sui's public GraphQL service per network (Mysten Labs). Measured 2026-10-21: the `affectedAddress`
|
|
34
|
+
* filter answered back to 2023 on both networks, in 0.2–0.9 s, with `access-control-allow-origin: *`.
|
|
35
|
+
* It is the only public operator of it, so it is the second tier and never the only one: a failure
|
|
36
|
+
* here leaves the answer `complete: false`, never "nothing there".
|
|
37
|
+
*/
|
|
38
|
+
export const SUI_GRAPHQL_URLS = {
|
|
39
|
+
mainnet: "https://graphql.mainnet.sui.io/graphql",
|
|
40
|
+
testnet: "https://graphql.testnet.sui.io/graphql",
|
|
41
|
+
};
|
|
42
|
+
/** How many requests one question may take before it answers with what it has. */
|
|
43
|
+
const MAX_REQUESTS = 8;
|
|
44
|
+
/** The fields the parser reads for `{ transaction, balanceChanges }` (the SDK's own read mask, by name). */
|
|
45
|
+
const READ_MASK = [
|
|
46
|
+
"digest",
|
|
47
|
+
"transaction.digest",
|
|
48
|
+
"signatures",
|
|
49
|
+
"effects.status",
|
|
50
|
+
"timestamp",
|
|
51
|
+
"checkpoint",
|
|
52
|
+
"transaction.sender",
|
|
53
|
+
"transaction.gas_payment",
|
|
54
|
+
"transaction.expiration",
|
|
55
|
+
"transaction.kind",
|
|
56
|
+
"balance_changes",
|
|
57
|
+
];
|
|
58
|
+
async function recentTransactions(client, address, limit, signal) {
|
|
59
|
+
const transactions = [];
|
|
60
|
+
let before;
|
|
61
|
+
for (let request = 0; request < MAX_REQUESTS; request += 1) {
|
|
62
|
+
const call = client.ledgerService.listTransactions({
|
|
63
|
+
readMask: { paths: READ_MASK },
|
|
64
|
+
filter: {
|
|
65
|
+
terms: [
|
|
66
|
+
{
|
|
67
|
+
literals: [
|
|
68
|
+
{ negated: false, predicate: { oneofKind: "affectedAddress", affectedAddress: { address } } },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
options: {
|
|
74
|
+
limit: limit - transactions.length,
|
|
75
|
+
ordering: GrpcTypes.Ordering.DESCENDING,
|
|
76
|
+
...(before === undefined ? {} : { before }),
|
|
77
|
+
},
|
|
78
|
+
}, signal === undefined ? {} : { abort: signal });
|
|
79
|
+
let frontier;
|
|
80
|
+
let reachedCheckpoint;
|
|
81
|
+
let reason;
|
|
82
|
+
for await (const frame of call.responses) {
|
|
83
|
+
if (frame.watermark?.cursor !== undefined)
|
|
84
|
+
frontier = frame.watermark.cursor;
|
|
85
|
+
if (frame.watermark?.checkpoint !== undefined)
|
|
86
|
+
reachedCheckpoint = frame.watermark.checkpoint;
|
|
87
|
+
if (frame.transaction !== undefined && transactions.length < limit) {
|
|
88
|
+
const parsed = parseGrpcTransactionResponse(frame.transaction, {
|
|
89
|
+
include: { transaction: true, balanceChanges: true },
|
|
90
|
+
});
|
|
91
|
+
const tx = parsed.Transaction ?? parsed.FailedTransaction;
|
|
92
|
+
if (tx !== undefined)
|
|
93
|
+
transactions.push(tx);
|
|
94
|
+
}
|
|
95
|
+
if (frame.end !== undefined)
|
|
96
|
+
reason = frame.end.reason;
|
|
97
|
+
}
|
|
98
|
+
if (transactions.length >= limit)
|
|
99
|
+
return { transactions, fromGenesis: true };
|
|
100
|
+
// A scan bound means "there may be more, carry on from here".
|
|
101
|
+
if (reason === GrpcTypes.QueryEndReason.SCAN_LIMIT && frontier !== undefined) {
|
|
102
|
+
before = frontier;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// ⛔ Newest-first, the scan ends at the oldest checkpoint the node still holds. Only when that is
|
|
106
|
+
// the chain's first checkpoint has it seen everything; any other ending is the window's edge.
|
|
107
|
+
return {
|
|
108
|
+
transactions,
|
|
109
|
+
fromGenesis: reason === GrpcTypes.QueryEndReason.CHECKPOINT_BOUND && reachedCheckpoint === 0n,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return { transactions, fromGenesis: false };
|
|
113
|
+
}
|
|
114
|
+
/** Newest first; rows the node gave win over the same rows from the deeper source (they are fresher). */
|
|
115
|
+
function mergeNewestFirst(recent, deeper, limit) {
|
|
116
|
+
const seen = new Set(recent.map((tx) => tx.digest));
|
|
117
|
+
const all = [...recent, ...deeper.filter((tx) => !seen.has(tx.digest))];
|
|
118
|
+
// A row without a time sorts last: it cannot be placed, and it must not push a dated row out.
|
|
119
|
+
const time = (tx) => tx.timestampMs ?? Number.NEGATIVE_INFINITY;
|
|
120
|
+
return all.sort((a, b) => time(b) - time(a)).slice(0, limit);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The newest transactions that moved `address`'s state, newest first.
|
|
124
|
+
*
|
|
125
|
+
* @param limit - how many to return at most; 1 is the cheapest "has this address any history".
|
|
126
|
+
* @param deeper - where to read past the node's window; `null` when the caller named its own node and
|
|
127
|
+
* asked for nothing else (the answer is then `complete: false` whenever the window ran out).
|
|
128
|
+
*/
|
|
129
|
+
export async function addressTransactions(client, address, limit, signal, deeper = null) {
|
|
130
|
+
const recent = await recentTransactions(client, address, limit, signal);
|
|
131
|
+
if (recent.fromGenesis)
|
|
132
|
+
return { transactions: recent.transactions, complete: true };
|
|
133
|
+
if (deeper === null)
|
|
134
|
+
return { transactions: recent.transactions, complete: false };
|
|
135
|
+
try {
|
|
136
|
+
const older = await deeper(address, limit, signal);
|
|
137
|
+
return { transactions: mergeNewestFirst(recent.transactions, older, limit), complete: true };
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// The node's rows stand; the answer says plainly that it is not the whole history.
|
|
141
|
+
return { transactions: recent.transactions, complete: false };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Has `address` ever been in a transaction? Throws when nobody could finish looking — "nobody could
|
|
146
|
+
* tell" and "nothing is there" are opposite facts, and only the second may answer `false`.
|
|
147
|
+
*/
|
|
148
|
+
export async function hasAddressHistory(client, address, signal, deeper = null) {
|
|
149
|
+
const { transactions, complete } = await addressTransactions(client, address, 1, signal, deeper);
|
|
150
|
+
if (transactions.length > 0)
|
|
151
|
+
return true;
|
|
152
|
+
if (!complete)
|
|
153
|
+
throw new Error(`The chain did not finish looking for transactions of ${address}.`);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
function asJson(value) {
|
|
157
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
if (Array.isArray(value)) {
|
|
161
|
+
const out = [];
|
|
162
|
+
for (const item of value) {
|
|
163
|
+
const json = asJson(item);
|
|
164
|
+
if (json === undefined)
|
|
165
|
+
return undefined;
|
|
166
|
+
out.push(json);
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
if (typeof value === "object") {
|
|
171
|
+
const out = {};
|
|
172
|
+
for (const [key, item] of Object.entries(value)) {
|
|
173
|
+
const json = asJson(item);
|
|
174
|
+
if (json === undefined)
|
|
175
|
+
return undefined;
|
|
176
|
+
out[key] = json;
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
const objectAt = (json) => json !== null && typeof json === "object" && !Array.isArray(json) ? json : undefined;
|
|
183
|
+
const QUERY = `query ($address: SuiAddress!, $last: Int!) {
|
|
184
|
+
transactions(last: $last, filter: { affectedAddress: $address }) {
|
|
185
|
+
nodes { digest transactionJson effects { status timestamp checkpoint { sequenceNumber } balanceChangesJson } }
|
|
186
|
+
}
|
|
187
|
+
}`;
|
|
188
|
+
/** One GraphQL row as the gRPC message the shared parser reads. `undefined` when its shape is off. */
|
|
189
|
+
function executedFromGraphql(node) {
|
|
190
|
+
const effects = objectAt(node["effects"]);
|
|
191
|
+
const digest = node["digest"];
|
|
192
|
+
const transactionJson = objectAt(node["transactionJson"]);
|
|
193
|
+
const timestamp = effects?.["timestamp"];
|
|
194
|
+
const checkpoint = objectAt(effects?.["checkpoint"])?.["sequenceNumber"];
|
|
195
|
+
const changes = effects?.["balanceChangesJson"];
|
|
196
|
+
if (typeof digest !== "string" || transactionJson === undefined || effects === undefined)
|
|
197
|
+
return undefined;
|
|
198
|
+
const ms = typeof timestamp === "string" ? Date.parse(timestamp) : Number.NaN;
|
|
199
|
+
const options = { ignoreUnknownFields: true };
|
|
200
|
+
return GrpcTypes.ExecutedTransaction.create({
|
|
201
|
+
digest,
|
|
202
|
+
transaction: GrpcTypes.Transaction.fromJson(transactionJson, options),
|
|
203
|
+
effects: GrpcTypes.TransactionEffects.create({ status: { success: effects["status"] === "SUCCESS" } }),
|
|
204
|
+
...(Number.isFinite(ms) ? { timestamp: { seconds: BigInt(Math.floor(ms / 1000)), nanos: (ms % 1000) * 1_000_000 } } : {}),
|
|
205
|
+
...(typeof checkpoint === "number" ? { checkpoint: BigInt(checkpoint) } : {}),
|
|
206
|
+
balanceChanges: Array.isArray(changes) ? changes.map((c) => GrpcTypes.BalanceChange.fromJson(c, options)) : [],
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The deeper source over Sui's GraphQL service at `url`.
|
|
211
|
+
*
|
|
212
|
+
* ⛔ Anything but a clean answer throws — an error list, a missing page, a row of the wrong shape.
|
|
213
|
+
* The caller turns that into `complete: false`; it never becomes an empty history.
|
|
214
|
+
*/
|
|
215
|
+
export function graphqlHistory(url, fetchFn = (input, init) => fetch(input, init)) {
|
|
216
|
+
return async (address, limit, signal) => {
|
|
217
|
+
const res = await fetchFn(url, {
|
|
218
|
+
method: "POST",
|
|
219
|
+
headers: { "content-type": "application/json" },
|
|
220
|
+
body: JSON.stringify({ query: QUERY, variables: { address, last: limit } }),
|
|
221
|
+
...(signal === undefined ? {} : { signal }),
|
|
222
|
+
});
|
|
223
|
+
if (!res.ok)
|
|
224
|
+
throw new Error(`The history service answered HTTP ${res.status}.`);
|
|
225
|
+
const body = await res.json();
|
|
226
|
+
const top = objectAt(asJson(body));
|
|
227
|
+
if (top === undefined || top["errors"] !== undefined) {
|
|
228
|
+
throw new Error("The history service answered with an error.");
|
|
229
|
+
}
|
|
230
|
+
const nodes = objectAt(objectAt(top["data"])?.["transactions"])?.["nodes"];
|
|
231
|
+
if (!Array.isArray(nodes))
|
|
232
|
+
throw new Error("The history service answered without a list.");
|
|
233
|
+
const rows = [];
|
|
234
|
+
// `last: n` arrives oldest-first; the list here is newest-first.
|
|
235
|
+
for (const node of [...nodes].reverse()) {
|
|
236
|
+
const row = objectAt(node);
|
|
237
|
+
const executed = row === undefined ? undefined : executedFromGraphql(row);
|
|
238
|
+
if (executed === undefined)
|
|
239
|
+
throw new Error("The history service answered a row this build cannot read.");
|
|
240
|
+
const parsed = parseGrpcTransactionResponse(executed, { include: { transaction: true, balanceChanges: true } });
|
|
241
|
+
const tx = parsed.Transaction ?? parsed.FailedTransaction;
|
|
242
|
+
if (tx !== undefined)
|
|
243
|
+
rows.push(tx);
|
|
244
|
+
}
|
|
245
|
+
return rows;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
@@ -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>;
|