@mysten/sui 1.31.0 → 1.33.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 +18 -0
- package/dist/cjs/client/client.d.ts +13 -12
- package/dist/cjs/client/client.js +189 -48
- package/dist/cjs/client/client.js.map +3 -3
- package/dist/cjs/experimental/cache.d.ts +1 -0
- package/dist/cjs/experimental/cache.js +9 -0
- package/dist/cjs/experimental/cache.js.map +2 -2
- package/dist/cjs/experimental/client.d.ts +2 -1
- package/dist/cjs/experimental/client.js +2 -1
- package/dist/cjs/experimental/client.js.map +2 -2
- package/dist/cjs/experimental/core.d.ts +6 -0
- package/dist/cjs/experimental/core.js +11 -3
- package/dist/cjs/experimental/core.js.map +2 -2
- package/dist/cjs/experimental/index.d.ts +2 -2
- package/dist/cjs/experimental/index.js.map +2 -2
- package/dist/cjs/experimental/mvr.d.ts +42 -0
- package/dist/cjs/experimental/mvr.js +355 -0
- package/dist/cjs/experimental/mvr.js.map +7 -0
- package/dist/cjs/experimental/transports/graphql.d.ts +4 -1
- package/dist/cjs/experimental/transports/graphql.js +17 -8
- package/dist/cjs/experimental/transports/graphql.js.map +2 -2
- package/dist/cjs/experimental/transports/jsonRPC.d.ts +5 -2
- package/dist/cjs/experimental/transports/jsonRPC.js +25 -17
- package/dist/cjs/experimental/transports/jsonRPC.js.map +3 -3
- package/dist/cjs/experimental/transports/utils.js +2 -2
- package/dist/cjs/experimental/transports/utils.js.map +2 -2
- package/dist/cjs/experimental/types.d.ts +43 -1
- package/dist/cjs/experimental/types.js.map +1 -1
- package/dist/cjs/graphql/client.d.ts +2 -1
- package/dist/cjs/graphql/client.js +6 -2
- package/dist/cjs/graphql/client.js.map +2 -2
- package/dist/cjs/transactions/index.d.ts +4 -1
- package/dist/cjs/transactions/index.js +2 -2
- package/dist/cjs/transactions/index.js.map +3 -3
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.d.ts +4 -3
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +38 -90
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
- package/dist/cjs/transactions/resolve.js +6 -3
- package/dist/cjs/transactions/resolve.js.map +2 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/client/client.d.ts +13 -12
- package/dist/esm/client/client.js +188 -47
- package/dist/esm/client/client.js.map +2 -2
- package/dist/esm/experimental/cache.d.ts +1 -0
- package/dist/esm/experimental/cache.js +9 -0
- package/dist/esm/experimental/cache.js.map +2 -2
- package/dist/esm/experimental/client.d.ts +2 -1
- package/dist/esm/experimental/client.js +2 -1
- package/dist/esm/experimental/client.js.map +2 -2
- package/dist/esm/experimental/core.d.ts +6 -0
- package/dist/esm/experimental/core.js +11 -3
- package/dist/esm/experimental/core.js.map +2 -2
- package/dist/esm/experimental/index.d.ts +2 -2
- package/dist/esm/experimental/index.js.map +2 -2
- package/dist/esm/experimental/mvr.d.ts +42 -0
- package/dist/esm/experimental/mvr.js +340 -0
- package/dist/esm/experimental/mvr.js.map +7 -0
- package/dist/esm/experimental/transports/graphql.d.ts +4 -1
- package/dist/esm/experimental/transports/graphql.js +17 -8
- package/dist/esm/experimental/transports/graphql.js.map +2 -2
- package/dist/esm/experimental/transports/jsonRPC.d.ts +5 -2
- package/dist/esm/experimental/transports/jsonRPC.js +22 -14
- package/dist/esm/experimental/transports/jsonRPC.js.map +3 -3
- package/dist/esm/experimental/transports/utils.js +1 -1
- package/dist/esm/experimental/transports/utils.js.map +1 -1
- package/dist/esm/experimental/types.d.ts +43 -1
- package/dist/esm/graphql/client.d.ts +2 -1
- package/dist/esm/graphql/client.js +6 -2
- package/dist/esm/graphql/client.js.map +2 -2
- package/dist/esm/transactions/index.d.ts +4 -1
- package/dist/esm/transactions/index.js.map +2 -2
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.d.ts +4 -3
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +37 -95
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
- package/dist/esm/transactions/resolve.js +6 -3
- package/dist/esm/transactions/resolve.js.map +2 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/client/client.ts +239 -60
- package/src/experimental/cache.ts +14 -0
- package/src/experimental/client.ts +3 -1
- package/src/experimental/core.ts +20 -1
- package/src/experimental/index.ts +2 -1
- package/src/experimental/mvr.ts +477 -0
- package/src/experimental/transports/graphql.ts +22 -10
- package/src/experimental/transports/jsonRPC.ts +21 -11
- package/src/experimental/transports/utils.ts +1 -1
- package/src/experimental/types.ts +59 -1
- package/src/graphql/client.ts +7 -1
- package/src/transactions/index.ts +5 -1
- package/src/transactions/plugins/NamedPackagesPlugin.ts +46 -120
- package/src/transactions/resolve.ts +6 -3
- package/src/version.ts +1 -1
- package/dist/cjs/transactions/plugins/utils.d.ts +0 -31
- package/dist/cjs/transactions/plugins/utils.js +0 -144
- package/dist/cjs/transactions/plugins/utils.js.map +0 -7
- package/dist/esm/transactions/plugins/utils.d.ts +0 -31
- package/dist/esm/transactions/plugins/utils.js +0 -124
- package/dist/esm/transactions/plugins/utils.js.map +0 -7
- package/src/transactions/plugins/utils.ts +0 -215
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
4
4
|
"description": "Sui TypeScript API(Work in Progress)",
|
|
5
5
|
"homepage": "https://sdk.mystenlabs.com",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.33.0",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
@@ -147,8 +147,8 @@
|
|
|
147
147
|
"graphql": "^16.11.0",
|
|
148
148
|
"poseidon-lite": "^0.2.0",
|
|
149
149
|
"valibot": "^0.36.0",
|
|
150
|
-
"@mysten/bcs": "1.6.
|
|
151
|
-
"@mysten/utils": "0.0
|
|
150
|
+
"@mysten/bcs": "1.6.3",
|
|
151
|
+
"@mysten/utils": "0.1.0"
|
|
152
152
|
},
|
|
153
153
|
"scripts": {
|
|
154
154
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
package/src/client/client.ts
CHANGED
|
@@ -9,8 +9,8 @@ import type {
|
|
|
9
9
|
Experimental_SuiClientTypes,
|
|
10
10
|
SelfRegisteringClientExtension,
|
|
11
11
|
} from '../experimental/types.js';
|
|
12
|
-
import type { Transaction } from '../transactions/
|
|
13
|
-
import { isTransaction } from '../transactions/
|
|
12
|
+
import type { Transaction } from '../transactions/Transaction.js';
|
|
13
|
+
import { isTransaction } from '../transactions/Transaction.js';
|
|
14
14
|
import {
|
|
15
15
|
isValidSuiAddress,
|
|
16
16
|
isValidSuiObjectId,
|
|
@@ -101,6 +101,8 @@ import type {
|
|
|
101
101
|
VerifyZkLoginSignatureParams,
|
|
102
102
|
ZkLoginVerifyResult,
|
|
103
103
|
} from './types/index.js';
|
|
104
|
+
import { isValidNamedPackage } from '../utils/move-registry.js';
|
|
105
|
+
import { hasMvrName } from '../experimental/mvr.js';
|
|
104
106
|
|
|
105
107
|
export interface PaginationArguments<Cursor> {
|
|
106
108
|
/** Optional paging cursor */
|
|
@@ -119,6 +121,7 @@ export interface OrderArguments {
|
|
|
119
121
|
*/
|
|
120
122
|
export type SuiClientOptions = NetworkOrTransport & {
|
|
121
123
|
network?: Experimental_SuiClientTypes.Network;
|
|
124
|
+
mvr?: Experimental_SuiClientTypes.MvrOptions;
|
|
122
125
|
};
|
|
123
126
|
|
|
124
127
|
type NetworkOrTransport =
|
|
@@ -140,7 +143,7 @@ export function isSuiClient(client: unknown): client is SuiClient {
|
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
export class SuiClient extends Experimental_BaseClient implements SelfRegisteringClientExtension {
|
|
143
|
-
core: JSONRpcTransport
|
|
146
|
+
core: JSONRpcTransport;
|
|
144
147
|
jsonRpc = this;
|
|
145
148
|
protected transport: SuiTransport;
|
|
146
149
|
|
|
@@ -156,6 +159,10 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
156
159
|
constructor(options: SuiClientOptions) {
|
|
157
160
|
super({ network: options.network ?? 'unknown' });
|
|
158
161
|
this.transport = options.transport ?? new SuiHTTPTransport({ url: options.url });
|
|
162
|
+
this.core = new JSONRpcTransport({
|
|
163
|
+
jsonRpcClient: this,
|
|
164
|
+
mvr: options.mvr,
|
|
165
|
+
});
|
|
159
166
|
}
|
|
160
167
|
|
|
161
168
|
async getRpcApiVersion({ signal }: { signal?: AbortSignal } = {}): Promise<string | undefined> {
|
|
@@ -171,15 +178,29 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
171
178
|
/**
|
|
172
179
|
* Get all Coin<`coin_type`> objects owned by an address.
|
|
173
180
|
*/
|
|
174
|
-
async getCoins(
|
|
175
|
-
|
|
181
|
+
async getCoins({
|
|
182
|
+
coinType,
|
|
183
|
+
owner,
|
|
184
|
+
cursor,
|
|
185
|
+
limit,
|
|
186
|
+
signal,
|
|
187
|
+
}: GetCoinsParams): Promise<PaginatedCoins> {
|
|
188
|
+
if (!owner || !isValidSuiAddress(normalizeSuiAddress(owner))) {
|
|
176
189
|
throw new Error('Invalid Sui address');
|
|
177
190
|
}
|
|
178
191
|
|
|
192
|
+
if (coinType && hasMvrName(coinType)) {
|
|
193
|
+
coinType = (
|
|
194
|
+
await this.core.mvr.resolveType({
|
|
195
|
+
type: coinType,
|
|
196
|
+
})
|
|
197
|
+
).type;
|
|
198
|
+
}
|
|
199
|
+
|
|
179
200
|
return await this.transport.request({
|
|
180
201
|
method: 'suix_getCoins',
|
|
181
|
-
params: [
|
|
182
|
-
signal:
|
|
202
|
+
params: [owner, coinType, cursor, limit],
|
|
203
|
+
signal: signal,
|
|
183
204
|
});
|
|
184
205
|
}
|
|
185
206
|
|
|
@@ -201,14 +222,23 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
201
222
|
/**
|
|
202
223
|
* Get the total coin balance for one coin type, owned by the address owner.
|
|
203
224
|
*/
|
|
204
|
-
async getBalance(
|
|
205
|
-
if (!
|
|
225
|
+
async getBalance({ owner, coinType, signal }: GetBalanceParams): Promise<CoinBalance> {
|
|
226
|
+
if (!owner || !isValidSuiAddress(normalizeSuiAddress(owner))) {
|
|
206
227
|
throw new Error('Invalid Sui address');
|
|
207
228
|
}
|
|
229
|
+
|
|
230
|
+
if (coinType && hasMvrName(coinType)) {
|
|
231
|
+
coinType = (
|
|
232
|
+
await this.core.mvr.resolveType({
|
|
233
|
+
type: coinType,
|
|
234
|
+
})
|
|
235
|
+
).type;
|
|
236
|
+
}
|
|
237
|
+
|
|
208
238
|
return await this.transport.request({
|
|
209
239
|
method: 'suix_getBalance',
|
|
210
|
-
params: [
|
|
211
|
-
signal:
|
|
240
|
+
params: [owner, coinType],
|
|
241
|
+
signal: signal,
|
|
212
242
|
});
|
|
213
243
|
}
|
|
214
244
|
|
|
@@ -229,22 +259,38 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
229
259
|
/**
|
|
230
260
|
* Fetch CoinMetadata for a given coin type
|
|
231
261
|
*/
|
|
232
|
-
async getCoinMetadata(
|
|
262
|
+
async getCoinMetadata({ coinType, signal }: GetCoinMetadataParams): Promise<CoinMetadata | null> {
|
|
263
|
+
if (coinType && hasMvrName(coinType)) {
|
|
264
|
+
coinType = (
|
|
265
|
+
await this.core.mvr.resolveType({
|
|
266
|
+
type: coinType,
|
|
267
|
+
})
|
|
268
|
+
).type;
|
|
269
|
+
}
|
|
270
|
+
|
|
233
271
|
return await this.transport.request({
|
|
234
272
|
method: 'suix_getCoinMetadata',
|
|
235
|
-
params: [
|
|
236
|
-
signal:
|
|
273
|
+
params: [coinType],
|
|
274
|
+
signal: signal,
|
|
237
275
|
});
|
|
238
276
|
}
|
|
239
277
|
|
|
240
278
|
/**
|
|
241
279
|
* Fetch total supply for a coin
|
|
242
280
|
*/
|
|
243
|
-
async getTotalSupply(
|
|
281
|
+
async getTotalSupply({ coinType, signal }: GetTotalSupplyParams): Promise<CoinSupply> {
|
|
282
|
+
if (coinType && hasMvrName(coinType)) {
|
|
283
|
+
coinType = (
|
|
284
|
+
await this.core.mvr.resolveType({
|
|
285
|
+
type: coinType,
|
|
286
|
+
})
|
|
287
|
+
).type;
|
|
288
|
+
}
|
|
289
|
+
|
|
244
290
|
return await this.transport.request({
|
|
245
291
|
method: 'suix_getTotalSupply',
|
|
246
|
-
params: [
|
|
247
|
-
signal:
|
|
292
|
+
params: [coinType],
|
|
293
|
+
signal: signal,
|
|
248
294
|
});
|
|
249
295
|
}
|
|
250
296
|
|
|
@@ -264,13 +310,24 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
264
310
|
/**
|
|
265
311
|
* Get Move function argument types like read, write and full access
|
|
266
312
|
*/
|
|
267
|
-
async getMoveFunctionArgTypes(
|
|
268
|
-
|
|
269
|
-
|
|
313
|
+
async getMoveFunctionArgTypes({
|
|
314
|
+
package: pkg,
|
|
315
|
+
module,
|
|
316
|
+
function: fn,
|
|
317
|
+
signal,
|
|
318
|
+
}: GetMoveFunctionArgTypesParams): Promise<SuiMoveFunctionArgType[]> {
|
|
319
|
+
if (pkg && isValidNamedPackage(pkg)) {
|
|
320
|
+
pkg = (
|
|
321
|
+
await this.core.mvr.resolvePackage({
|
|
322
|
+
package: pkg,
|
|
323
|
+
})
|
|
324
|
+
).package;
|
|
325
|
+
}
|
|
326
|
+
|
|
270
327
|
return await this.transport.request({
|
|
271
328
|
method: 'sui_getMoveFunctionArgTypes',
|
|
272
|
-
params: [
|
|
273
|
-
signal:
|
|
329
|
+
params: [pkg, module, fn],
|
|
330
|
+
signal: signal,
|
|
274
331
|
});
|
|
275
332
|
}
|
|
276
333
|
|
|
@@ -278,52 +335,93 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
278
335
|
* Get a map from module name to
|
|
279
336
|
* structured representations of Move modules
|
|
280
337
|
*/
|
|
281
|
-
async getNormalizedMoveModulesByPackage(
|
|
282
|
-
|
|
283
|
-
|
|
338
|
+
async getNormalizedMoveModulesByPackage({
|
|
339
|
+
package: pkg,
|
|
340
|
+
signal,
|
|
341
|
+
}: GetNormalizedMoveModulesByPackageParams): Promise<SuiMoveNormalizedModules> {
|
|
342
|
+
if (pkg && isValidNamedPackage(pkg)) {
|
|
343
|
+
pkg = (
|
|
344
|
+
await this.core.mvr.resolvePackage({
|
|
345
|
+
package: pkg,
|
|
346
|
+
})
|
|
347
|
+
).package;
|
|
348
|
+
}
|
|
349
|
+
|
|
284
350
|
return await this.transport.request({
|
|
285
351
|
method: 'sui_getNormalizedMoveModulesByPackage',
|
|
286
|
-
params: [
|
|
287
|
-
signal:
|
|
352
|
+
params: [pkg],
|
|
353
|
+
signal: signal,
|
|
288
354
|
});
|
|
289
355
|
}
|
|
290
356
|
|
|
291
357
|
/**
|
|
292
358
|
* Get a structured representation of Move module
|
|
293
359
|
*/
|
|
294
|
-
async getNormalizedMoveModule(
|
|
295
|
-
|
|
296
|
-
|
|
360
|
+
async getNormalizedMoveModule({
|
|
361
|
+
package: pkg,
|
|
362
|
+
module,
|
|
363
|
+
signal,
|
|
364
|
+
}: GetNormalizedMoveModuleParams): Promise<SuiMoveNormalizedModule> {
|
|
365
|
+
if (pkg && isValidNamedPackage(pkg)) {
|
|
366
|
+
pkg = (
|
|
367
|
+
await this.core.mvr.resolvePackage({
|
|
368
|
+
package: pkg,
|
|
369
|
+
})
|
|
370
|
+
).package;
|
|
371
|
+
}
|
|
372
|
+
|
|
297
373
|
return await this.transport.request({
|
|
298
374
|
method: 'sui_getNormalizedMoveModule',
|
|
299
|
-
params: [
|
|
300
|
-
signal:
|
|
375
|
+
params: [pkg, module],
|
|
376
|
+
signal: signal,
|
|
301
377
|
});
|
|
302
378
|
}
|
|
303
379
|
|
|
304
380
|
/**
|
|
305
381
|
* Get a structured representation of Move function
|
|
306
382
|
*/
|
|
307
|
-
async getNormalizedMoveFunction(
|
|
308
|
-
|
|
309
|
-
|
|
383
|
+
async getNormalizedMoveFunction({
|
|
384
|
+
package: pkg,
|
|
385
|
+
module,
|
|
386
|
+
function: fn,
|
|
387
|
+
signal,
|
|
388
|
+
}: GetNormalizedMoveFunctionParams): Promise<SuiMoveNormalizedFunction> {
|
|
389
|
+
if (pkg && isValidNamedPackage(pkg)) {
|
|
390
|
+
pkg = (
|
|
391
|
+
await this.core.mvr.resolvePackage({
|
|
392
|
+
package: pkg,
|
|
393
|
+
})
|
|
394
|
+
).package;
|
|
395
|
+
}
|
|
396
|
+
|
|
310
397
|
return await this.transport.request({
|
|
311
398
|
method: 'sui_getNormalizedMoveFunction',
|
|
312
|
-
params: [
|
|
313
|
-
signal:
|
|
399
|
+
params: [pkg, module, fn],
|
|
400
|
+
signal: signal,
|
|
314
401
|
});
|
|
315
402
|
}
|
|
316
403
|
|
|
317
404
|
/**
|
|
318
405
|
* Get a structured representation of Move struct
|
|
319
406
|
*/
|
|
320
|
-
async getNormalizedMoveStruct(
|
|
321
|
-
|
|
322
|
-
|
|
407
|
+
async getNormalizedMoveStruct({
|
|
408
|
+
package: pkg,
|
|
409
|
+
module,
|
|
410
|
+
struct,
|
|
411
|
+
signal,
|
|
412
|
+
}: GetNormalizedMoveStructParams): Promise<SuiMoveNormalizedStruct> {
|
|
413
|
+
if (pkg && isValidNamedPackage(pkg)) {
|
|
414
|
+
pkg = (
|
|
415
|
+
await this.core.mvr.resolvePackage({
|
|
416
|
+
package: pkg,
|
|
417
|
+
})
|
|
418
|
+
).package;
|
|
419
|
+
}
|
|
420
|
+
|
|
323
421
|
return await this.transport.request({
|
|
324
422
|
method: 'sui_getNormalizedMoveStruct',
|
|
325
|
-
params: [
|
|
326
|
-
signal:
|
|
423
|
+
params: [pkg, module, struct],
|
|
424
|
+
signal: signal,
|
|
327
425
|
});
|
|
328
426
|
}
|
|
329
427
|
|
|
@@ -335,12 +433,35 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
335
433
|
throw new Error('Invalid Sui address');
|
|
336
434
|
}
|
|
337
435
|
|
|
436
|
+
const filter = input.filter
|
|
437
|
+
? {
|
|
438
|
+
...input.filter,
|
|
439
|
+
}
|
|
440
|
+
: undefined;
|
|
441
|
+
|
|
442
|
+
if (filter && 'MoveModule' in filter && isValidNamedPackage(filter.MoveModule.package)) {
|
|
443
|
+
filter.MoveModule = {
|
|
444
|
+
module: filter.MoveModule.module,
|
|
445
|
+
package: (
|
|
446
|
+
await this.core.mvr.resolvePackage({
|
|
447
|
+
package: filter.MoveModule.package,
|
|
448
|
+
})
|
|
449
|
+
).package,
|
|
450
|
+
};
|
|
451
|
+
} else if (filter && 'StructType' in filter && hasMvrName(filter.StructType)) {
|
|
452
|
+
filter.StructType = (
|
|
453
|
+
await this.core.mvr.resolveType({
|
|
454
|
+
type: filter.StructType,
|
|
455
|
+
})
|
|
456
|
+
).type;
|
|
457
|
+
}
|
|
458
|
+
|
|
338
459
|
return await this.transport.request({
|
|
339
460
|
method: 'suix_getOwnedObjects',
|
|
340
461
|
params: [
|
|
341
462
|
input.owner,
|
|
342
463
|
{
|
|
343
|
-
filter
|
|
464
|
+
filter,
|
|
344
465
|
options: input.options,
|
|
345
466
|
} as SuiObjectResponseQuery,
|
|
346
467
|
input.cursor,
|
|
@@ -396,21 +517,39 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
396
517
|
/**
|
|
397
518
|
* Get transaction blocks for a given query criteria
|
|
398
519
|
*/
|
|
399
|
-
async queryTransactionBlocks(
|
|
400
|
-
|
|
401
|
-
|
|
520
|
+
async queryTransactionBlocks({
|
|
521
|
+
filter,
|
|
522
|
+
options,
|
|
523
|
+
cursor,
|
|
524
|
+
limit,
|
|
525
|
+
order,
|
|
526
|
+
signal,
|
|
527
|
+
}: QueryTransactionBlocksParams): Promise<PaginatedTransactionResponse> {
|
|
528
|
+
if (filter && 'MoveFunction' in filter && isValidNamedPackage(filter.MoveFunction.package)) {
|
|
529
|
+
filter = {
|
|
530
|
+
...filter,
|
|
531
|
+
MoveFunction: {
|
|
532
|
+
package: (
|
|
533
|
+
await this.core.mvr.resolvePackage({
|
|
534
|
+
package: filter.MoveFunction.package,
|
|
535
|
+
})
|
|
536
|
+
).package,
|
|
537
|
+
},
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
402
541
|
return await this.transport.request({
|
|
403
542
|
method: 'suix_queryTransactionBlocks',
|
|
404
543
|
params: [
|
|
405
544
|
{
|
|
406
|
-
filter
|
|
407
|
-
options
|
|
545
|
+
filter,
|
|
546
|
+
options,
|
|
408
547
|
} as SuiTransactionBlockResponseQuery,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
(
|
|
548
|
+
cursor,
|
|
549
|
+
limit,
|
|
550
|
+
(order || 'descending') === 'descending',
|
|
412
551
|
],
|
|
413
|
-
signal
|
|
552
|
+
signal,
|
|
414
553
|
});
|
|
415
554
|
}
|
|
416
555
|
|
|
@@ -578,16 +717,56 @@ export class SuiClient extends Experimental_BaseClient implements SelfRegisterin
|
|
|
578
717
|
/**
|
|
579
718
|
* Get events for a given query criteria
|
|
580
719
|
*/
|
|
581
|
-
async queryEvents(
|
|
720
|
+
async queryEvents({
|
|
721
|
+
query,
|
|
722
|
+
cursor,
|
|
723
|
+
limit,
|
|
724
|
+
order,
|
|
725
|
+
signal,
|
|
726
|
+
}: QueryEventsParams): Promise<PaginatedEvents> {
|
|
727
|
+
if (query && 'MoveEventType' in query && hasMvrName(query.MoveEventType)) {
|
|
728
|
+
query = {
|
|
729
|
+
...query,
|
|
730
|
+
MoveEventType: (
|
|
731
|
+
await this.core.mvr.resolveType({
|
|
732
|
+
type: query.MoveEventType,
|
|
733
|
+
})
|
|
734
|
+
).type,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
if (query && 'MoveEventModule' in query && isValidNamedPackage(query.MoveEventModule.package)) {
|
|
739
|
+
query = {
|
|
740
|
+
...query,
|
|
741
|
+
MoveEventModule: {
|
|
742
|
+
module: query.MoveEventModule.module,
|
|
743
|
+
package: (
|
|
744
|
+
await this.core.mvr.resolvePackage({
|
|
745
|
+
package: query.MoveEventModule.package,
|
|
746
|
+
})
|
|
747
|
+
).package,
|
|
748
|
+
},
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if ('MoveModule' in query && isValidNamedPackage(query.MoveModule.package)) {
|
|
753
|
+
query = {
|
|
754
|
+
...query,
|
|
755
|
+
MoveModule: {
|
|
756
|
+
module: query.MoveModule.module,
|
|
757
|
+
package: (
|
|
758
|
+
await this.core.mvr.resolvePackage({
|
|
759
|
+
package: query.MoveModule.package,
|
|
760
|
+
})
|
|
761
|
+
).package,
|
|
762
|
+
},
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
|
|
582
766
|
return await this.transport.request({
|
|
583
767
|
method: 'suix_queryEvents',
|
|
584
|
-
params: [
|
|
585
|
-
|
|
586
|
-
input.cursor,
|
|
587
|
-
input.limit,
|
|
588
|
-
(input.order || 'descending') === 'descending',
|
|
589
|
-
],
|
|
590
|
-
signal: input.signal,
|
|
768
|
+
params: [query, cursor, limit, (order || 'descending') === 'descending'],
|
|
769
|
+
signal,
|
|
591
770
|
});
|
|
592
771
|
}
|
|
593
772
|
|
|
@@ -41,6 +41,20 @@ export class ClientCache {
|
|
|
41
41
|
return result as T;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
readSync<T>(key: [string, ...string[]], load: () => T): T {
|
|
45
|
+
const cacheKey = [this.#prefix, ...key].join(':');
|
|
46
|
+
|
|
47
|
+
if (this.#cache.has(cacheKey)) {
|
|
48
|
+
return this.#cache.get(cacheKey) as T;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const result = load();
|
|
52
|
+
|
|
53
|
+
this.#cache.set(cacheKey, result);
|
|
54
|
+
|
|
55
|
+
return result as T;
|
|
56
|
+
}
|
|
57
|
+
|
|
44
58
|
clear(prefix?: string[]) {
|
|
45
59
|
const prefixKey = [...this.#prefix, ...(prefix ?? [])].join(':');
|
|
46
60
|
if (!prefixKey) {
|
|
@@ -14,9 +14,11 @@ import type {
|
|
|
14
14
|
export abstract class Experimental_BaseClient {
|
|
15
15
|
network: Experimental_SuiClientTypes.Network;
|
|
16
16
|
cache = new ClientCache();
|
|
17
|
+
base: Experimental_BaseClient;
|
|
17
18
|
|
|
18
|
-
constructor({ network }: Experimental_SuiClientTypes.SuiClientOptions) {
|
|
19
|
+
constructor({ network, base }: Experimental_SuiClientTypes.SuiClientOptions) {
|
|
19
20
|
this.network = network;
|
|
21
|
+
this.base = base ?? this;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
abstract core: Experimental_CoreClient;
|
package/src/experimental/core.ts
CHANGED
|
@@ -7,16 +7,34 @@ import { deriveDynamicFieldID } from '../utils/dynamic-fields.js';
|
|
|
7
7
|
import { normalizeStructTag, parseStructTag, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';
|
|
8
8
|
import { Experimental_BaseClient } from './client.js';
|
|
9
9
|
import type { ClientWithExtensions, Experimental_SuiClientTypes } from './types.js';
|
|
10
|
+
import { MvrClient } from './mvr.js';
|
|
10
11
|
|
|
11
12
|
export type ClientWithCoreApi = ClientWithExtensions<{
|
|
12
13
|
core: Experimental_CoreClient;
|
|
13
14
|
}>;
|
|
14
15
|
|
|
16
|
+
export interface Experimental_CoreClientOptions
|
|
17
|
+
extends Experimental_SuiClientTypes.SuiClientOptions {
|
|
18
|
+
base: Experimental_BaseClient;
|
|
19
|
+
mvr?: Experimental_SuiClientTypes.MvrOptions;
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
export abstract class Experimental_CoreClient
|
|
16
23
|
extends Experimental_BaseClient
|
|
17
24
|
implements Experimental_SuiClientTypes.TransportMethods
|
|
18
25
|
{
|
|
19
26
|
core = this;
|
|
27
|
+
mvr: Experimental_SuiClientTypes.MvrMethods;
|
|
28
|
+
|
|
29
|
+
constructor(options: Experimental_CoreClientOptions) {
|
|
30
|
+
super(options);
|
|
31
|
+
this.mvr = new MvrClient({
|
|
32
|
+
cache: this.base.cache.scope('core'),
|
|
33
|
+
url: options.mvr?.url,
|
|
34
|
+
pageSize: options.mvr?.pageSize,
|
|
35
|
+
overrides: options.mvr?.overrides,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
20
38
|
|
|
21
39
|
abstract getObjects(
|
|
22
40
|
options: Experimental_SuiClientTypes.GetObjectsOptions,
|
|
@@ -93,6 +111,7 @@ export abstract class Experimental_CoreClient
|
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
const fieldType = parseStructTag(fieldObject.type);
|
|
114
|
+
const content = await fieldObject.content;
|
|
96
115
|
|
|
97
116
|
return {
|
|
98
117
|
dynamicField: {
|
|
@@ -112,7 +131,7 @@ export abstract class Experimental_CoreClient
|
|
|
112
131
|
typeof fieldType.typeParams[1] === 'string'
|
|
113
132
|
? fieldType.typeParams[1]
|
|
114
133
|
: normalizeStructTag(fieldType.typeParams[1]),
|
|
115
|
-
bcs:
|
|
134
|
+
bcs: content.slice(SUI_ADDRESS_LENGTH + options.name.bcs.length),
|
|
116
135
|
},
|
|
117
136
|
},
|
|
118
137
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { Experimental_BaseClient } from './client.js';
|
|
5
|
-
import type { ClientWithCoreApi } from './core.js';
|
|
5
|
+
import type { ClientWithCoreApi, Experimental_CoreClientOptions } from './core.js';
|
|
6
6
|
import { Experimental_CoreClient } from './core.js';
|
|
7
7
|
import type {
|
|
8
8
|
ClientWithExtensions,
|
|
@@ -14,6 +14,7 @@ export { parseTransactionBcs, parseTransactionEffectsBcs } from './transports/ut
|
|
|
14
14
|
export {
|
|
15
15
|
Experimental_BaseClient,
|
|
16
16
|
Experimental_CoreClient,
|
|
17
|
+
type Experimental_CoreClientOptions,
|
|
17
18
|
type ClientWithExtensions,
|
|
18
19
|
type Experimental_SuiClientTypes,
|
|
19
20
|
type SuiClientRegistration,
|