@0xobelisk/sui-client 1.1.0 → 1.1.2
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/dist/dubhe.d.ts +21 -4
- package/dist/index.js +111 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -23
- package/dist/index.mjs.map +1 -1
- package/dist/libs/suiIndexerClient/index.d.ts +14 -2
- package/dist/types/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/dubhe.ts +99 -31
- package/src/libs/suiIndexerClient/index.ts +56 -6
- package/src/types/index.ts +4 -0
package/dist/index.mjs
CHANGED
|
@@ -1122,8 +1122,30 @@ var SuiIndexerClient = class {
|
|
|
1122
1122
|
}
|
|
1123
1123
|
async getSchemas(params) {
|
|
1124
1124
|
const query = `
|
|
1125
|
-
query GetSchemas(
|
|
1126
|
-
|
|
1125
|
+
query GetSchemas(
|
|
1126
|
+
$first: Int,
|
|
1127
|
+
$after: String,
|
|
1128
|
+
$name: String,
|
|
1129
|
+
$key1: String,
|
|
1130
|
+
$key2: String,
|
|
1131
|
+
$is_removed: Boolean,
|
|
1132
|
+
$last_update_checkpoint: String,
|
|
1133
|
+
$last_update_digest: String,
|
|
1134
|
+
$value: JSON,
|
|
1135
|
+
$orderBy: [SchemaOrderField!]
|
|
1136
|
+
) {
|
|
1137
|
+
schemas(
|
|
1138
|
+
first: $first,
|
|
1139
|
+
after: $after,
|
|
1140
|
+
name: $name,
|
|
1141
|
+
key1: $key1,
|
|
1142
|
+
key2: $key2,
|
|
1143
|
+
is_removed: $is_removed,
|
|
1144
|
+
last_update_checkpoint: $last_update_checkpoint,
|
|
1145
|
+
last_update_digest: $last_update_digest,
|
|
1146
|
+
value: $value,
|
|
1147
|
+
orderBy: $orderBy
|
|
1148
|
+
) {
|
|
1127
1149
|
edges {
|
|
1128
1150
|
cursor
|
|
1129
1151
|
node {
|
|
@@ -1180,6 +1202,10 @@ var SuiIndexerClient = class {
|
|
|
1180
1202
|
name,
|
|
1181
1203
|
key1,
|
|
1182
1204
|
key2,
|
|
1205
|
+
is_removed = false,
|
|
1206
|
+
last_update_checkpoint,
|
|
1207
|
+
last_update_digest,
|
|
1208
|
+
value,
|
|
1183
1209
|
first,
|
|
1184
1210
|
after,
|
|
1185
1211
|
orderBy
|
|
@@ -1188,15 +1214,19 @@ var SuiIndexerClient = class {
|
|
|
1188
1214
|
name,
|
|
1189
1215
|
key1,
|
|
1190
1216
|
key2,
|
|
1217
|
+
is_removed,
|
|
1218
|
+
last_update_checkpoint,
|
|
1219
|
+
last_update_digest,
|
|
1220
|
+
value,
|
|
1191
1221
|
first,
|
|
1192
1222
|
after,
|
|
1193
1223
|
orderBy
|
|
1194
1224
|
});
|
|
1195
1225
|
const data = schemas.edges.map((edge) => edge.node);
|
|
1196
|
-
const
|
|
1226
|
+
const result = data.map((item) => parseValue(item.value));
|
|
1197
1227
|
return {
|
|
1198
1228
|
data,
|
|
1199
|
-
value,
|
|
1229
|
+
value: result,
|
|
1200
1230
|
pageInfo: schemas.pageInfo,
|
|
1201
1231
|
totalCount: schemas.totalCount
|
|
1202
1232
|
};
|
|
@@ -1204,22 +1234,30 @@ var SuiIndexerClient = class {
|
|
|
1204
1234
|
async getStorageItem({
|
|
1205
1235
|
name,
|
|
1206
1236
|
key1,
|
|
1207
|
-
key2
|
|
1237
|
+
key2,
|
|
1238
|
+
is_removed,
|
|
1239
|
+
last_update_checkpoint,
|
|
1240
|
+
last_update_digest,
|
|
1241
|
+
value
|
|
1208
1242
|
}) {
|
|
1209
1243
|
const schemas = await this.getSchemas({
|
|
1210
1244
|
name,
|
|
1211
1245
|
key1,
|
|
1212
1246
|
key2,
|
|
1247
|
+
is_removed,
|
|
1248
|
+
last_update_checkpoint,
|
|
1249
|
+
last_update_digest,
|
|
1250
|
+
value,
|
|
1213
1251
|
first: 1
|
|
1214
1252
|
});
|
|
1215
1253
|
const data = schemas.edges[0]?.node;
|
|
1216
1254
|
if (!data) {
|
|
1217
1255
|
return void 0;
|
|
1218
1256
|
}
|
|
1219
|
-
const
|
|
1257
|
+
const result = parseValue(data.value);
|
|
1220
1258
|
return {
|
|
1221
1259
|
data,
|
|
1222
|
-
value
|
|
1260
|
+
value: result
|
|
1223
1261
|
};
|
|
1224
1262
|
}
|
|
1225
1263
|
async subscribe(names, handleData) {
|
|
@@ -1413,9 +1451,11 @@ function createTx(meta, fn) {
|
|
|
1413
1451
|
tx,
|
|
1414
1452
|
params,
|
|
1415
1453
|
typeArguments,
|
|
1416
|
-
isRaw
|
|
1454
|
+
isRaw,
|
|
1455
|
+
onSuccess,
|
|
1456
|
+
onError
|
|
1417
1457
|
}) => {
|
|
1418
|
-
return await fn(tx, params, typeArguments, isRaw);
|
|
1458
|
+
return await fn(tx, params, typeArguments, isRaw, onSuccess, onError);
|
|
1419
1459
|
}
|
|
1420
1460
|
);
|
|
1421
1461
|
}
|
|
@@ -1536,7 +1576,7 @@ var Dubhe = class {
|
|
|
1536
1576
|
value: bcs2.u64()
|
|
1537
1577
|
})
|
|
1538
1578
|
});
|
|
1539
|
-
__privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw) => {
|
|
1579
|
+
__privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw, onSuccess, onError) => {
|
|
1540
1580
|
if (isRaw === true) {
|
|
1541
1581
|
return tx.moveCall({
|
|
1542
1582
|
target: `${this.contractFactory.packageId}::${meta.moduleName}::${meta.funcName}`,
|
|
@@ -1549,7 +1589,7 @@ var Dubhe = class {
|
|
|
1549
1589
|
arguments: params,
|
|
1550
1590
|
typeArguments
|
|
1551
1591
|
});
|
|
1552
|
-
return await this.signAndSendTxn(tx);
|
|
1592
|
+
return await this.signAndSendTxn({ tx, onSuccess, onError });
|
|
1553
1593
|
});
|
|
1554
1594
|
__privateAdd(this, _read, async (meta, tx, params, typeArguments, isRaw) => {
|
|
1555
1595
|
if (isRaw === true) {
|
|
@@ -2008,7 +2048,7 @@ var Dubhe = class {
|
|
|
2008
2048
|
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
2009
2049
|
__privateGet(this, _tx)[moduleName][funcName] = createTx(
|
|
2010
2050
|
meta,
|
|
2011
|
-
(tx, p, typeArguments, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw)
|
|
2051
|
+
(tx, p, typeArguments, isRaw, onSuccess, onError) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw, onSuccess, onError)
|
|
2012
2052
|
);
|
|
2013
2053
|
}
|
|
2014
2054
|
}
|
|
@@ -2233,6 +2273,10 @@ var Dubhe = class {
|
|
|
2233
2273
|
name,
|
|
2234
2274
|
key1,
|
|
2235
2275
|
key2,
|
|
2276
|
+
is_removed,
|
|
2277
|
+
last_update_checkpoint,
|
|
2278
|
+
last_update_digest,
|
|
2279
|
+
value,
|
|
2236
2280
|
first,
|
|
2237
2281
|
after,
|
|
2238
2282
|
orderBy
|
|
@@ -2241,6 +2285,10 @@ var Dubhe = class {
|
|
|
2241
2285
|
name,
|
|
2242
2286
|
key1,
|
|
2243
2287
|
key2,
|
|
2288
|
+
is_removed,
|
|
2289
|
+
last_update_checkpoint,
|
|
2290
|
+
last_update_digest,
|
|
2291
|
+
value,
|
|
2244
2292
|
first,
|
|
2245
2293
|
after,
|
|
2246
2294
|
orderBy
|
|
@@ -2250,6 +2298,10 @@ var Dubhe = class {
|
|
|
2250
2298
|
name,
|
|
2251
2299
|
key1,
|
|
2252
2300
|
key2,
|
|
2301
|
+
is_removed,
|
|
2302
|
+
last_update_checkpoint,
|
|
2303
|
+
last_update_digest,
|
|
2304
|
+
value,
|
|
2253
2305
|
first,
|
|
2254
2306
|
after,
|
|
2255
2307
|
orderBy
|
|
@@ -2258,6 +2310,10 @@ var Dubhe = class {
|
|
|
2258
2310
|
name,
|
|
2259
2311
|
key1,
|
|
2260
2312
|
key2,
|
|
2313
|
+
is_removed,
|
|
2314
|
+
last_update_checkpoint,
|
|
2315
|
+
last_update_digest,
|
|
2316
|
+
value,
|
|
2261
2317
|
first,
|
|
2262
2318
|
after,
|
|
2263
2319
|
orderBy
|
|
@@ -2266,12 +2322,20 @@ var Dubhe = class {
|
|
|
2266
2322
|
async getStorageItem({
|
|
2267
2323
|
name,
|
|
2268
2324
|
key1,
|
|
2269
|
-
key2
|
|
2325
|
+
key2,
|
|
2326
|
+
is_removed,
|
|
2327
|
+
last_update_checkpoint,
|
|
2328
|
+
last_update_digest,
|
|
2329
|
+
value
|
|
2270
2330
|
}) {
|
|
2271
2331
|
const response = await this.suiIndexerClient.getStorageItem({
|
|
2272
2332
|
name,
|
|
2273
2333
|
key1,
|
|
2274
|
-
key2
|
|
2334
|
+
key2,
|
|
2335
|
+
is_removed,
|
|
2336
|
+
last_update_checkpoint,
|
|
2337
|
+
last_update_digest,
|
|
2338
|
+
value
|
|
2275
2339
|
});
|
|
2276
2340
|
return response;
|
|
2277
2341
|
}
|
|
@@ -2369,9 +2433,33 @@ var Dubhe = class {
|
|
|
2369
2433
|
const keyPair = this.getSigner(derivePathParams);
|
|
2370
2434
|
return await keyPair.signTransaction(txBytes);
|
|
2371
2435
|
}
|
|
2372
|
-
async signAndSendTxn(
|
|
2373
|
-
|
|
2374
|
-
|
|
2436
|
+
async signAndSendTxn({
|
|
2437
|
+
tx,
|
|
2438
|
+
derivePathParams,
|
|
2439
|
+
onSuccess,
|
|
2440
|
+
onError
|
|
2441
|
+
}) {
|
|
2442
|
+
try {
|
|
2443
|
+
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
2444
|
+
const result = await this.sendTx(bytes, signature);
|
|
2445
|
+
if (result.effects?.status.status === "success") {
|
|
2446
|
+
if (onSuccess) {
|
|
2447
|
+
await onSuccess(result);
|
|
2448
|
+
}
|
|
2449
|
+
} else {
|
|
2450
|
+
if (onError) {
|
|
2451
|
+
await onError(
|
|
2452
|
+
new Error(`Transaction failed: ${result.effects?.status.error}`)
|
|
2453
|
+
);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
return result;
|
|
2457
|
+
} catch (error) {
|
|
2458
|
+
if (onError) {
|
|
2459
|
+
await onError(error);
|
|
2460
|
+
}
|
|
2461
|
+
throw error;
|
|
2462
|
+
}
|
|
2375
2463
|
}
|
|
2376
2464
|
async sendTx(transaction, signature) {
|
|
2377
2465
|
return this.suiInteractor.sendTx(transaction, signature);
|
|
@@ -2388,7 +2476,7 @@ var Dubhe = class {
|
|
|
2388
2476
|
async transferSui(recipient, amount, derivePathParams) {
|
|
2389
2477
|
const tx = new SuiTx();
|
|
2390
2478
|
tx.transferSui(recipient, amount);
|
|
2391
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
2479
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2392
2480
|
}
|
|
2393
2481
|
/**
|
|
2394
2482
|
* Transfer to mutliple recipients
|
|
@@ -2399,7 +2487,7 @@ var Dubhe = class {
|
|
|
2399
2487
|
async transferSuiToMany(recipients, amounts, derivePathParams) {
|
|
2400
2488
|
const tx = new SuiTx();
|
|
2401
2489
|
tx.transferSuiToMany(recipients, amounts);
|
|
2402
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
2490
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2403
2491
|
}
|
|
2404
2492
|
/**
|
|
2405
2493
|
* Transfer the given amounts of coin to multiple recipients
|
|
@@ -2423,7 +2511,7 @@ var Dubhe = class {
|
|
|
2423
2511
|
recipients,
|
|
2424
2512
|
amounts
|
|
2425
2513
|
);
|
|
2426
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
2514
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2427
2515
|
}
|
|
2428
2516
|
async transferCoin(recipient, amount, coinType, derivePathParams) {
|
|
2429
2517
|
return this.transferCoinToMany(
|
|
@@ -2436,7 +2524,7 @@ var Dubhe = class {
|
|
|
2436
2524
|
async transferObjects(objects, recipient, derivePathParams) {
|
|
2437
2525
|
const tx = new SuiTx();
|
|
2438
2526
|
tx.transferObjects(objects, recipient);
|
|
2439
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
2527
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2440
2528
|
}
|
|
2441
2529
|
async moveCall(callParams) {
|
|
2442
2530
|
const {
|
|
@@ -2447,7 +2535,7 @@ var Dubhe = class {
|
|
|
2447
2535
|
} = callParams;
|
|
2448
2536
|
const tx = new SuiTx();
|
|
2449
2537
|
tx.moveCall(target, args, typeArguments);
|
|
2450
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
2538
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2451
2539
|
}
|
|
2452
2540
|
/**
|
|
2453
2541
|
* Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount
|
|
@@ -2474,7 +2562,7 @@ var Dubhe = class {
|
|
|
2474
2562
|
async stakeSui(amount, validatorAddr, derivePathParams) {
|
|
2475
2563
|
const tx = new SuiTx();
|
|
2476
2564
|
tx.stakeSui(amount, validatorAddr);
|
|
2477
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
2565
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2478
2566
|
}
|
|
2479
2567
|
/**
|
|
2480
2568
|
* Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.
|