@0xobelisk/sui-client 0.5.18 → 0.5.20
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/index.d.ts +15 -0
- package/dist/index.js +340 -233
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +337 -230
- package/dist/index.mjs.map +1 -1
- package/dist/libs/multiSig/client.d.ts +15 -0
- package/dist/libs/multiSig/index.d.ts +1 -0
- package/dist/libs/multiSig/publickey.d.ts +2 -0
- package/dist/libs/suiAccountManager/crypto.d.ts +1 -0
- package/dist/libs/suiAccountManager/index.d.ts +39 -0
- package/dist/libs/suiAccountManager/keypair.d.ts +21 -0
- package/dist/libs/suiAccountManager/util.d.ts +29 -0
- package/dist/libs/suiContractFactory/index.d.ts +20 -0
- package/dist/libs/suiContractFactory/types.d.ts +49 -0
- package/dist/libs/suiInteractor/index.d.ts +1 -0
- package/dist/libs/suiInteractor/suiInteractor.d.ts +50 -0
- package/dist/libs/suiInteractor/util.d.ts +1 -0
- package/dist/libs/suiModel/index.d.ts +2 -0
- package/dist/libs/suiModel/suiOwnedObject.d.ts +24 -0
- package/dist/libs/suiModel/suiSharedObject.d.ts +11 -0
- package/dist/libs/suiTxBuilder/index.d.ts +538 -0
- package/dist/libs/suiTxBuilder/util.d.ts +49 -0
- package/dist/metadata/index.d.ts +3 -0
- package/dist/obelisk.d.ts +140 -0
- package/dist/types/index.d.ts +199 -0
- package/dist/utils/index.d.ts +3 -0
- package/package.json +2 -5
- package/src/libs/multiSig/client.ts +1 -1
- package/src/libs/suiAccountManager/index.ts +4 -5
- package/src/libs/suiInteractor/index.ts +0 -1
- package/src/libs/suiModel/suiOwnedObject.ts +2 -2
- package/src/libs/suiModel/suiSharedObject.ts +2 -2
- package/src/libs/suiTxBuilder/index.ts +43 -49
- package/src/libs/suiTxBuilder/util.ts +65 -129
- package/src/obelisk.ts +329 -139
- package/src/types/index.ts +60 -44
package/src/obelisk.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import keccak256 from 'keccak256';
|
|
2
2
|
import { getFullnodeUrl } from '@mysten/sui/client';
|
|
3
3
|
import { Transaction, TransactionResult } from '@mysten/sui/transactions';
|
|
4
|
-
import
|
|
4
|
+
import { BcsType, SerializedBcs } from '@mysten/bcs';
|
|
5
5
|
import type { TransactionArgument } from '@mysten/sui/transactions';
|
|
6
6
|
import type {
|
|
7
7
|
SuiTransactionBlockResponse,
|
|
8
8
|
DevInspectResults,
|
|
9
9
|
SuiMoveNormalizedModules,
|
|
10
|
+
SuiMoveNormalizedType,
|
|
10
11
|
SuiObjectData,
|
|
11
12
|
} from '@mysten/sui/client';
|
|
12
13
|
import { SuiAccountManager } from './libs/suiAccountManager';
|
|
13
14
|
import { SuiTx } from './libs/suiTxBuilder';
|
|
14
15
|
import { SuiInteractor } from './libs/suiInteractor';
|
|
15
|
-
|
|
16
|
-
import { MapMoudleStruct, NetworkType, ObeliskObjectContent } from './types';
|
|
16
|
+
import { MapObjectStruct, MoveStructType, ObeliskObjectContent } from './types';
|
|
17
17
|
import { SuiContractFactory } from './libs/suiContractFactory';
|
|
18
18
|
import {
|
|
19
19
|
SuiMoveMoudleFuncType,
|
|
@@ -107,7 +107,50 @@ export class Obelisk {
|
|
|
107
107
|
|
|
108
108
|
readonly #query: MapMoudleFuncQuery = {};
|
|
109
109
|
readonly #tx: MapMoudleFuncTx = {};
|
|
110
|
-
readonly #
|
|
110
|
+
readonly #object: MapObjectStruct = {
|
|
111
|
+
address: bcs.bytes(32).transform({
|
|
112
|
+
// To change the input type, you need to provide a type definition for the input
|
|
113
|
+
input: (val: string) => fromHEX(val),
|
|
114
|
+
output: (val) => toHEX(val),
|
|
115
|
+
}),
|
|
116
|
+
u8: bcs.u8(),
|
|
117
|
+
u16: bcs.u16(),
|
|
118
|
+
u32: bcs.u32(),
|
|
119
|
+
u64: bcs.u64(),
|
|
120
|
+
u128: bcs.u128(),
|
|
121
|
+
u256: bcs.u256(),
|
|
122
|
+
bool: bcs.bool(),
|
|
123
|
+
'0x1::ascii::String': bcs.string(),
|
|
124
|
+
'0x1::option::Option<address>': bcs.option(
|
|
125
|
+
bcs.bytes(32).transform({
|
|
126
|
+
// To change the input type, you need to provide a type definition for the input
|
|
127
|
+
input: (val: string) => fromHEX(val),
|
|
128
|
+
output: (val) => toHEX(val),
|
|
129
|
+
})
|
|
130
|
+
),
|
|
131
|
+
'0x1::option::Option<u8>': bcs.option(bcs.u8()),
|
|
132
|
+
'0x1::option::Option<u16>': bcs.option(bcs.u16()),
|
|
133
|
+
'0x1::option::Option<u32>': bcs.option(bcs.u32()),
|
|
134
|
+
'0x1::option::Option<u64>': bcs.option(bcs.u64()),
|
|
135
|
+
'0x1::option::Option<u128>': bcs.option(bcs.u128()),
|
|
136
|
+
'0x1::option::Option<u256>': bcs.option(bcs.u256()),
|
|
137
|
+
'0x1::option::Option<bool>': bcs.option(bcs.bool()),
|
|
138
|
+
'vector<address>': bcs.vector(
|
|
139
|
+
bcs.bytes(32).transform({
|
|
140
|
+
// To change the input type, you need to provide a type definition for the input
|
|
141
|
+
input: (val: string) => fromHEX(val),
|
|
142
|
+
output: (val) => toHEX(val),
|
|
143
|
+
})
|
|
144
|
+
),
|
|
145
|
+
'vector<u8>': bcs.vector(bcs.u8()),
|
|
146
|
+
'vector<u16>': bcs.vector(bcs.u16()),
|
|
147
|
+
'vector<u32>': bcs.vector(bcs.u32()),
|
|
148
|
+
'vector<u64>': bcs.vector(bcs.u64()),
|
|
149
|
+
'vector<u128>': bcs.vector(bcs.u128()),
|
|
150
|
+
'vector<u256>': bcs.vector(bcs.u256()),
|
|
151
|
+
'vector<bool>': bcs.vector(bcs.bool()),
|
|
152
|
+
};
|
|
153
|
+
|
|
111
154
|
/**
|
|
112
155
|
* Support the following ways to init the ObeliskClient:
|
|
113
156
|
* 1. mnemonics
|
|
@@ -137,42 +180,64 @@ export class Obelisk {
|
|
|
137
180
|
this.packageId = packageId;
|
|
138
181
|
if (metadata !== undefined) {
|
|
139
182
|
this.metadata = metadata as SuiMoveNormalizedModules;
|
|
140
|
-
Object.values(metadata as SuiMoveNormalizedModules).forEach(
|
|
141
|
-
(moudlevalue) => {
|
|
142
|
-
const data = moudlevalue as SuiMoveMoudleValueType;
|
|
143
|
-
const moduleName = data.name;
|
|
144
|
-
|
|
145
|
-
Object.entries(data.exposedFunctions).forEach(
|
|
146
|
-
([funcName, funcvalue]) => {
|
|
147
|
-
const meta = funcvalue as SuiMoveMoudleFuncType;
|
|
148
|
-
meta.moduleName = moduleName;
|
|
149
|
-
meta.funcName = funcName;
|
|
150
|
-
// console.log(JSON.stringify(funcvalue));
|
|
151
|
-
if (isUndefined(this.#query[moduleName])) {
|
|
152
|
-
this.#query[moduleName] = {};
|
|
153
|
-
}
|
|
154
|
-
if (isUndefined(this.#query[moduleName][funcName])) {
|
|
155
|
-
this.#query[moduleName][funcName] = createQuery(
|
|
156
|
-
meta,
|
|
157
|
-
(tx, p, typeArguments, isRaw) =>
|
|
158
|
-
this.#read(meta, tx, p, typeArguments, isRaw)
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
183
|
|
|
162
|
-
|
|
163
|
-
|
|
184
|
+
let stillNeedFormat = true;
|
|
185
|
+
while (stillNeedFormat === true) {
|
|
186
|
+
let loopFlag = false;
|
|
187
|
+
Object.values(metadata as SuiMoveNormalizedModules).forEach(
|
|
188
|
+
(moudlevalue) => {
|
|
189
|
+
const data = moudlevalue as SuiMoveMoudleValueType;
|
|
190
|
+
const moduleName = data.name;
|
|
191
|
+
const objMoudleId = `${packageId}::${moduleName}`;
|
|
192
|
+
|
|
193
|
+
Object.entries(data.structs).forEach(([objectName, objectType]) => {
|
|
194
|
+
const objId = `${objMoudleId}::${objectName}`;
|
|
195
|
+
const bcsmeta: MoveStructType = {
|
|
196
|
+
objectName,
|
|
197
|
+
objectType,
|
|
198
|
+
};
|
|
199
|
+
// if (isUndefined(this.#object[objId])) {
|
|
200
|
+
let bcsObj = this.#bcs(bcsmeta);
|
|
201
|
+
if (bcsObj.loopFlag === true) {
|
|
202
|
+
loopFlag = bcsObj.loopFlag;
|
|
164
203
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
204
|
+
this.#object[objId] = bcsObj.bcs;
|
|
205
|
+
// }
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
Object.entries(data.exposedFunctions).forEach(
|
|
209
|
+
([funcName, funcvalue]) => {
|
|
210
|
+
const meta = funcvalue as SuiMoveMoudleFuncType;
|
|
211
|
+
meta.moduleName = moduleName;
|
|
212
|
+
meta.funcName = funcName;
|
|
213
|
+
if (isUndefined(this.#query[moduleName])) {
|
|
214
|
+
this.#query[moduleName] = {};
|
|
215
|
+
}
|
|
216
|
+
if (isUndefined(this.#query[moduleName][funcName])) {
|
|
217
|
+
this.#query[moduleName][funcName] = createQuery(
|
|
218
|
+
meta,
|
|
219
|
+
(tx, p, typeArguments, isRaw) =>
|
|
220
|
+
this.#read(meta, tx, p, typeArguments, isRaw)
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (isUndefined(this.#tx[moduleName])) {
|
|
225
|
+
this.#tx[moduleName] = {};
|
|
226
|
+
}
|
|
227
|
+
if (isUndefined(this.#tx[moduleName][funcName])) {
|
|
228
|
+
this.#tx[moduleName][funcName] = createTx(
|
|
229
|
+
meta,
|
|
230
|
+
(tx, p, typeArguments, isRaw) =>
|
|
231
|
+
this.#exec(meta, tx, p, typeArguments, isRaw)
|
|
232
|
+
);
|
|
233
|
+
}
|
|
171
234
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
stillNeedFormat = loopFlag;
|
|
240
|
+
}
|
|
176
241
|
}
|
|
177
242
|
this.contractFactory = new SuiContractFactory({
|
|
178
243
|
packageId,
|
|
@@ -188,8 +253,8 @@ export class Obelisk {
|
|
|
188
253
|
return this.#tx;
|
|
189
254
|
}
|
|
190
255
|
|
|
191
|
-
public get
|
|
192
|
-
return this.#
|
|
256
|
+
public get object(): MapObjectStruct {
|
|
257
|
+
return this.#object;
|
|
193
258
|
}
|
|
194
259
|
|
|
195
260
|
#exec = async (
|
|
@@ -239,6 +304,227 @@ export class Obelisk {
|
|
|
239
304
|
return await this.inspectTxn(tx);
|
|
240
305
|
};
|
|
241
306
|
|
|
307
|
+
#bcs = (bcsmeta: MoveStructType) => {
|
|
308
|
+
let loopFlag = false;
|
|
309
|
+
const bcsJson: Record<string, BcsType<any, any>> = {};
|
|
310
|
+
Object.entries(bcsmeta.objectType.fields).forEach(([index, type]) => {
|
|
311
|
+
const objName = type.name;
|
|
312
|
+
const objType: SuiMoveNormalizedType = type.type;
|
|
313
|
+
switch (typeof objType) {
|
|
314
|
+
case 'object':
|
|
315
|
+
for (const [key, value] of Object.entries(objType)) {
|
|
316
|
+
switch (key) {
|
|
317
|
+
case 'Struct':
|
|
318
|
+
const structType = value as {
|
|
319
|
+
address: string;
|
|
320
|
+
module: string;
|
|
321
|
+
name: string;
|
|
322
|
+
typeArguments: SuiMoveNormalizedType[];
|
|
323
|
+
};
|
|
324
|
+
if (
|
|
325
|
+
structType.address === '0x1' &&
|
|
326
|
+
structType.module === 'ascii' &&
|
|
327
|
+
structType.name === 'String'
|
|
328
|
+
) {
|
|
329
|
+
bcsJson[objName] = bcs.string();
|
|
330
|
+
return;
|
|
331
|
+
} else if (
|
|
332
|
+
structType.address === '0x2' &&
|
|
333
|
+
structType.module === 'object' &&
|
|
334
|
+
structType.name === 'UID'
|
|
335
|
+
) {
|
|
336
|
+
bcsJson[objName] = bcs.fixedArray(32, bcs.u8()).transform({
|
|
337
|
+
input: (id: string) => fromHEX(id),
|
|
338
|
+
output: (id) => toHEX(Uint8Array.from(id)),
|
|
339
|
+
});
|
|
340
|
+
return;
|
|
341
|
+
} else if (
|
|
342
|
+
structType.address === '0x2' &&
|
|
343
|
+
structType.module === 'object' &&
|
|
344
|
+
structType.name === 'ID'
|
|
345
|
+
) {
|
|
346
|
+
bcsJson[objName] = bcs.fixedArray(32, bcs.u8()).transform({
|
|
347
|
+
input: (id: string) => fromHEX(id),
|
|
348
|
+
output: (id) => toHEX(Uint8Array.from(id)),
|
|
349
|
+
});
|
|
350
|
+
return;
|
|
351
|
+
} else if (
|
|
352
|
+
structType.address === '0x2' &&
|
|
353
|
+
structType.module === 'bag' &&
|
|
354
|
+
structType.name === 'Bag'
|
|
355
|
+
) {
|
|
356
|
+
bcsJson[objName] = bcs.fixedArray(32, bcs.u8()).transform({
|
|
357
|
+
input: (id: string) => fromHEX(id),
|
|
358
|
+
output: (id) => toHEX(Uint8Array.from(id)),
|
|
359
|
+
});
|
|
360
|
+
return;
|
|
361
|
+
} else if (
|
|
362
|
+
structType.address === '0x1' &&
|
|
363
|
+
structType.module === 'option' &&
|
|
364
|
+
structType.name === 'Option'
|
|
365
|
+
) {
|
|
366
|
+
switch (structType.typeArguments[0]) {
|
|
367
|
+
case 'U8':
|
|
368
|
+
bcsJson[objName] = bcs.option(bcs.u8());
|
|
369
|
+
return;
|
|
370
|
+
case 'U16':
|
|
371
|
+
bcsJson[objName] = bcs.option(bcs.u16());
|
|
372
|
+
return;
|
|
373
|
+
case 'U32':
|
|
374
|
+
bcsJson[objName] = bcs.option(bcs.u32());
|
|
375
|
+
return;
|
|
376
|
+
case 'U64':
|
|
377
|
+
bcsJson[objName] = bcs.option(bcs.u64());
|
|
378
|
+
return;
|
|
379
|
+
case 'U128':
|
|
380
|
+
bcsJson[objName] = bcs.option(bcs.u128());
|
|
381
|
+
return;
|
|
382
|
+
case 'U256':
|
|
383
|
+
bcsJson[objName] = bcs.option(bcs.u256());
|
|
384
|
+
return;
|
|
385
|
+
case 'Bool':
|
|
386
|
+
bcsJson[objName] = bcs.option(bcs.bool());
|
|
387
|
+
return;
|
|
388
|
+
case 'Address':
|
|
389
|
+
bcsJson[objName] = bcs.option(
|
|
390
|
+
bcs.bytes(32).transform({
|
|
391
|
+
// To change the input type, you need to provide a type definition for the input
|
|
392
|
+
input: (val: string) => fromHEX(val),
|
|
393
|
+
output: (val) => toHEX(val),
|
|
394
|
+
})
|
|
395
|
+
);
|
|
396
|
+
return;
|
|
397
|
+
default:
|
|
398
|
+
// throw new Error('Unsupported type');
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
if (
|
|
402
|
+
this.object[
|
|
403
|
+
`${structType.address}::${structType.module}::${structType.name}`
|
|
404
|
+
] === undefined
|
|
405
|
+
) {
|
|
406
|
+
loopFlag = true;
|
|
407
|
+
} else {
|
|
408
|
+
bcsJson[objName] =
|
|
409
|
+
this.object[
|
|
410
|
+
`${structType.address}::${structType.module}::${structType.name}`
|
|
411
|
+
];
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return;
|
|
416
|
+
case 'Vector':
|
|
417
|
+
switch (value) {
|
|
418
|
+
case 'U8':
|
|
419
|
+
bcsJson[objName] = bcs.vector(bcs.u8());
|
|
420
|
+
return;
|
|
421
|
+
case 'U16':
|
|
422
|
+
bcsJson[objName] = bcs.vector(bcs.u16());
|
|
423
|
+
return;
|
|
424
|
+
case 'U32':
|
|
425
|
+
bcsJson[objName] = bcs.vector(bcs.u32());
|
|
426
|
+
return;
|
|
427
|
+
case 'U64':
|
|
428
|
+
bcsJson[objName] = bcs.vector(bcs.u64());
|
|
429
|
+
return;
|
|
430
|
+
case 'U128':
|
|
431
|
+
bcsJson[objName] = bcs.vector(bcs.u128());
|
|
432
|
+
return;
|
|
433
|
+
case 'U256':
|
|
434
|
+
bcsJson[objName] = bcs.vector(bcs.u256());
|
|
435
|
+
return;
|
|
436
|
+
case 'Bool':
|
|
437
|
+
bcsJson[objName] = bcs.vector(bcs.bool());
|
|
438
|
+
return;
|
|
439
|
+
case 'Address':
|
|
440
|
+
bcsJson[objName] = bcs.vector(
|
|
441
|
+
bcs.bytes(32).transform({
|
|
442
|
+
// To change the input type, you need to provide a type definition for the input
|
|
443
|
+
input: (val: string) => fromHEX(val),
|
|
444
|
+
output: (val) => toHEX(val),
|
|
445
|
+
})
|
|
446
|
+
);
|
|
447
|
+
return;
|
|
448
|
+
default:
|
|
449
|
+
// throw new Error('Unsupported type');
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
case 'TypeParameter':
|
|
453
|
+
bcsJson[objName] = bcs.u128();
|
|
454
|
+
return;
|
|
455
|
+
// case 'Reference':
|
|
456
|
+
|
|
457
|
+
// case 'MutableReference':
|
|
458
|
+
|
|
459
|
+
default:
|
|
460
|
+
throw new Error('Unsupported type');
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return;
|
|
464
|
+
case 'string':
|
|
465
|
+
switch (objType) {
|
|
466
|
+
case 'U8':
|
|
467
|
+
bcsJson[objName] = bcs.u8();
|
|
468
|
+
return;
|
|
469
|
+
case 'U16':
|
|
470
|
+
bcsJson[objName] = bcs.u16();
|
|
471
|
+
return;
|
|
472
|
+
case 'U32':
|
|
473
|
+
bcsJson[objName] = bcs.u32();
|
|
474
|
+
return;
|
|
475
|
+
case 'U64':
|
|
476
|
+
bcsJson[objName] = bcs.u64();
|
|
477
|
+
return;
|
|
478
|
+
case 'U128':
|
|
479
|
+
bcsJson[objName] = bcs.u128();
|
|
480
|
+
return;
|
|
481
|
+
case 'U256':
|
|
482
|
+
bcsJson[objName] = bcs.u256();
|
|
483
|
+
return;
|
|
484
|
+
case 'Bool':
|
|
485
|
+
bcsJson[objName] = bcs.bool();
|
|
486
|
+
return;
|
|
487
|
+
case 'Address':
|
|
488
|
+
bcsJson[objName] = bcs.bytes(32).transform({
|
|
489
|
+
// To change the input type, you need to provide a type definition for the input
|
|
490
|
+
input: (val: string) => fromHEX(val),
|
|
491
|
+
output: (val) => toHEX(val),
|
|
492
|
+
});
|
|
493
|
+
return;
|
|
494
|
+
default:
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
default:
|
|
498
|
+
throw new Error('Unsupported type');
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
return {
|
|
503
|
+
bcs: bcs.struct(bcsmeta.objectName, bcsJson),
|
|
504
|
+
loopFlag,
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
view(dryResult: DevInspectResults) {
|
|
509
|
+
let returnValues = [];
|
|
510
|
+
|
|
511
|
+
// "success" | "failure";
|
|
512
|
+
if (dryResult.effects.status.status === 'success') {
|
|
513
|
+
const resultList = dryResult.results![0].returnValues!;
|
|
514
|
+
|
|
515
|
+
for (const res of resultList) {
|
|
516
|
+
let baseValue = res[0];
|
|
517
|
+
let baseType = res[1];
|
|
518
|
+
|
|
519
|
+
const value = Uint8Array.from(baseValue);
|
|
520
|
+
returnValues.push(this.object[baseType].parse(value));
|
|
521
|
+
}
|
|
522
|
+
return returnValues;
|
|
523
|
+
} else {
|
|
524
|
+
return undefined;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
242
528
|
/**
|
|
243
529
|
* if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
|
|
244
530
|
* else:
|
|
@@ -549,54 +835,13 @@ export class Obelisk {
|
|
|
549
835
|
params.push(tx.pure.address(entityId));
|
|
550
836
|
}
|
|
551
837
|
|
|
552
|
-
const
|
|
838
|
+
const dryResult = (await this.query[schemaModuleName].get(
|
|
553
839
|
tx,
|
|
554
840
|
params
|
|
555
841
|
)) as DevInspectResults;
|
|
556
|
-
let returnValues = [];
|
|
557
842
|
|
|
558
843
|
// "success" | "failure";
|
|
559
|
-
|
|
560
|
-
const resultList = getResult.results![0].returnValues!;
|
|
561
|
-
|
|
562
|
-
for (const res of resultList) {
|
|
563
|
-
let baseValue = res[0];
|
|
564
|
-
let baseType = res[1];
|
|
565
|
-
|
|
566
|
-
const value = Uint8Array.from(baseValue);
|
|
567
|
-
if (baseType === 'address') {
|
|
568
|
-
const Address = bcs.bytes(32).transform({
|
|
569
|
-
// To change the input type, you need to provide a type definition for the input
|
|
570
|
-
input: (val: string) => fromHEX(val),
|
|
571
|
-
output: (val) => toHEX(val),
|
|
572
|
-
});
|
|
573
|
-
returnValues.push(Address.parse(value));
|
|
574
|
-
} else if (baseType === 'u8') {
|
|
575
|
-
returnValues.push(bcs.u8().parse(value));
|
|
576
|
-
} else if (baseType === 'u16') {
|
|
577
|
-
returnValues.push(bcs.u16().parse(value));
|
|
578
|
-
} else if (baseType === 'u32') {
|
|
579
|
-
returnValues.push(bcs.u32().parse(value));
|
|
580
|
-
} else if (baseType === 'u64') {
|
|
581
|
-
returnValues.push(bcs.u64().parse(value));
|
|
582
|
-
} else if (baseType === 'u128') {
|
|
583
|
-
returnValues.push(bcs.u128().parse(value));
|
|
584
|
-
} else if (baseType === 'u256') {
|
|
585
|
-
returnValues.push(bcs.u256().parse(value));
|
|
586
|
-
} else if (baseType === 'bool') {
|
|
587
|
-
returnValues.push(bcs.bool().parse(value));
|
|
588
|
-
} else if (baseType === '0x1::ascii::String') {
|
|
589
|
-
returnValues.push(bcs.string().parse(value));
|
|
590
|
-
} else if (baseType === 'vector<u8>') {
|
|
591
|
-
returnValues.push(bcs.vector(bcs.u8()).parse(value));
|
|
592
|
-
} else if (baseType === '0x1::option::Option<u8>') {
|
|
593
|
-
returnValues.push(bcs.option(bcs.u8()).parse(value));
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
return returnValues;
|
|
597
|
-
} else {
|
|
598
|
-
return undefined;
|
|
599
|
-
}
|
|
844
|
+
return this.view(dryResult);
|
|
600
845
|
}
|
|
601
846
|
|
|
602
847
|
async containEntity(
|
|
@@ -612,21 +857,12 @@ export class Obelisk {
|
|
|
612
857
|
params.push(tx.pure.address(entityId));
|
|
613
858
|
}
|
|
614
859
|
|
|
615
|
-
const
|
|
860
|
+
const dryResult = (await this.query[schemaModuleName].contains(
|
|
616
861
|
tx,
|
|
617
862
|
params
|
|
618
863
|
)) as DevInspectResults;
|
|
619
864
|
|
|
620
|
-
|
|
621
|
-
if (getResult.effects.status.status === 'success') {
|
|
622
|
-
const res = getResult.results![0].returnValues![0];
|
|
623
|
-
let baseValue = res[0];
|
|
624
|
-
|
|
625
|
-
const value = Uint8Array.from(baseValue);
|
|
626
|
-
return bcs.bool().parse(value);
|
|
627
|
-
} else {
|
|
628
|
-
return undefined;
|
|
629
|
-
}
|
|
865
|
+
return this.view(dryResult) as boolean | undefined;
|
|
630
866
|
}
|
|
631
867
|
|
|
632
868
|
// async getEntities(
|
|
@@ -740,50 +976,4 @@ export class Obelisk {
|
|
|
740
976
|
// const u8Value = Uint8Array.from(value);
|
|
741
977
|
// return bcs.de(type, u8Value);
|
|
742
978
|
// }
|
|
743
|
-
|
|
744
|
-
async autoFormatDryValue(value: DevInspectResults) {
|
|
745
|
-
let returnValues = [];
|
|
746
|
-
|
|
747
|
-
// "success" | "failure";
|
|
748
|
-
if (value.effects.status.status === 'success') {
|
|
749
|
-
const resultList = value.results![0].returnValues!;
|
|
750
|
-
|
|
751
|
-
for (const res of resultList) {
|
|
752
|
-
let baseValue = res[0];
|
|
753
|
-
let baseType = res[1];
|
|
754
|
-
const value = Uint8Array.from(baseValue);
|
|
755
|
-
if (baseType === 'address') {
|
|
756
|
-
const Address = bcs.bytes(32).transform({
|
|
757
|
-
// To change the input type, you need to provide a type definition for the input
|
|
758
|
-
input: (val: string) => fromHEX(val),
|
|
759
|
-
output: (val) => toHEX(val),
|
|
760
|
-
});
|
|
761
|
-
returnValues.push(Address.parse(value));
|
|
762
|
-
} else if (baseType === 'u8') {
|
|
763
|
-
returnValues.push(bcs.u8().parse(value));
|
|
764
|
-
} else if (baseType === 'u16') {
|
|
765
|
-
returnValues.push(bcs.u16().parse(value));
|
|
766
|
-
} else if (baseType === 'u32') {
|
|
767
|
-
returnValues.push(bcs.u32().parse(value));
|
|
768
|
-
} else if (baseType === 'u64') {
|
|
769
|
-
returnValues.push(bcs.u64().parse(value));
|
|
770
|
-
} else if (baseType === 'u128') {
|
|
771
|
-
returnValues.push(bcs.u128().parse(value));
|
|
772
|
-
} else if (baseType === 'u256') {
|
|
773
|
-
returnValues.push(bcs.u256().parse(value));
|
|
774
|
-
} else if (baseType === 'bool') {
|
|
775
|
-
returnValues.push(bcs.bool().parse(value));
|
|
776
|
-
} else if (baseType === '0x1::ascii::String') {
|
|
777
|
-
returnValues.push(bcs.string().parse(value));
|
|
778
|
-
} else if (baseType === 'vector<u8>') {
|
|
779
|
-
returnValues.push(bcs.vector(bcs.u8()).parse(value));
|
|
780
|
-
} else if (baseType === '0x1::option::Option<u8>') {
|
|
781
|
-
returnValues.push(bcs.option(bcs.u8()).parse(value));
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
return returnValues;
|
|
785
|
-
} else {
|
|
786
|
-
return undefined;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
979
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -7,9 +7,10 @@ import type {
|
|
|
7
7
|
TransactionObjectArgument,
|
|
8
8
|
TransactionResult,
|
|
9
9
|
ObjectRef,
|
|
10
|
+
Argument,
|
|
11
|
+
Inputs,
|
|
10
12
|
} from '@mysten/sui/transactions';
|
|
11
13
|
import type {
|
|
12
|
-
SuiObjectRef,
|
|
13
14
|
SuiMoveNormalizedModules,
|
|
14
15
|
DevInspectResults,
|
|
15
16
|
SuiTransactionBlockResponse,
|
|
@@ -108,35 +109,27 @@ export type MapMessageQuery = Record<string, ContractQuery>;
|
|
|
108
109
|
export type MapMoudleFuncTx = Record<string, MapMessageTx>;
|
|
109
110
|
export type MapMoudleFuncQuery = Record<string, MapMessageQuery>;
|
|
110
111
|
|
|
111
|
-
type
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
};
|
|
126
|
-
isPhantom: boolean;
|
|
127
|
-
}[];
|
|
128
|
-
}
|
|
129
|
-
>;
|
|
130
|
-
bcs: BcsType<
|
|
131
|
-
{
|
|
132
|
-
[x: string]: any;
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
[x: string]: any;
|
|
136
|
-
}
|
|
137
|
-
>;
|
|
112
|
+
export type MoveStructValueType = {
|
|
113
|
+
fields: {
|
|
114
|
+
type: SuiMoveNormalizedType;
|
|
115
|
+
name: string;
|
|
116
|
+
}[];
|
|
117
|
+
abilities: {
|
|
118
|
+
abilities: string[];
|
|
119
|
+
};
|
|
120
|
+
typeParameters: {
|
|
121
|
+
constraints: {
|
|
122
|
+
abilities: string[];
|
|
123
|
+
};
|
|
124
|
+
isPhantom: boolean;
|
|
125
|
+
}[];
|
|
138
126
|
};
|
|
139
|
-
export type
|
|
127
|
+
export type MoveStructType = {
|
|
128
|
+
objectType: MoveStructValueType;
|
|
129
|
+
objectName: string;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type MapObjectStruct = Record<string, BcsType<any, any>>;
|
|
140
133
|
|
|
141
134
|
export type MapMoudleFuncTest = Record<string, Record<string, string>>;
|
|
142
135
|
export type MapMoudleFuncQueryTest = Record<string, Record<string, string>>;
|
|
@@ -177,17 +170,26 @@ type TransactionBlockType = InstanceType<typeof Transaction>;
|
|
|
177
170
|
export type PureCallArg = {
|
|
178
171
|
Pure: number[];
|
|
179
172
|
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* An object argument.
|
|
176
|
+
*/
|
|
177
|
+
type ObjectArg =
|
|
178
|
+
| { ImmOrOwnedObject: SuiObjectRef }
|
|
179
|
+
| { SharedObject: SharedObjectRef }
|
|
180
|
+
| { Receiving: SuiObjectRef };
|
|
181
|
+
|
|
180
182
|
export type ObjectCallArg = {
|
|
181
|
-
Object:
|
|
183
|
+
Object: ObjectArg;
|
|
182
184
|
};
|
|
183
185
|
|
|
184
186
|
export type TransactionType = Parameters<TransactionBlockType['add']>;
|
|
185
187
|
|
|
186
188
|
export type TransactionPureArgument = Extract<
|
|
187
|
-
|
|
189
|
+
Argument,
|
|
188
190
|
{
|
|
189
|
-
kind: 'Input';
|
|
190
|
-
type
|
|
191
|
+
$kind: 'Input';
|
|
192
|
+
type?: 'pure';
|
|
191
193
|
}
|
|
192
194
|
>;
|
|
193
195
|
|
|
@@ -205,20 +207,35 @@ export type EntityData = {
|
|
|
205
207
|
key: string;
|
|
206
208
|
};
|
|
207
209
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
type SharedObjectRef = {
|
|
211
|
+
/** Hex code as string representing the object id */
|
|
212
|
+
objectId: string;
|
|
213
|
+
|
|
214
|
+
/** The version the object was shared at */
|
|
215
|
+
initialSharedVersion: number | string;
|
|
216
|
+
|
|
217
|
+
/** Whether reference is mutable */
|
|
218
|
+
mutable: boolean;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
type SuiObjectRef = {
|
|
222
|
+
/** Base64 string representing the object digest */
|
|
223
|
+
objectId: string;
|
|
224
|
+
/** Object version */
|
|
225
|
+
version: number | string;
|
|
226
|
+
/** Hex code as string representing the object id */
|
|
227
|
+
digest: string;
|
|
228
|
+
};
|
|
213
229
|
|
|
214
|
-
export type SuiTxArg =
|
|
230
|
+
export type SuiTxArg = TransactionArgument | SerializedBcs<any>;
|
|
231
|
+
export type SuiAddressArg = Argument | SerializedBcs<any> | string;
|
|
232
|
+
export type SuiAmountsArg = SuiTxArg | number | bigint;
|
|
215
233
|
|
|
216
234
|
export type SuiObjectArg =
|
|
217
|
-
| ObjectRef
|
|
218
235
|
| TransactionObjectArgument
|
|
219
236
|
| string
|
|
220
|
-
| typeof
|
|
221
|
-
|
|
|
237
|
+
| Parameters<typeof Inputs.ObjectRef>[0]
|
|
238
|
+
| Parameters<typeof Inputs.SharedObjectRef>[0]
|
|
222
239
|
| ObjectCallArg;
|
|
223
240
|
|
|
224
241
|
export type SuiVecTxArg =
|
|
@@ -237,8 +254,7 @@ export type SuiBasicTypes =
|
|
|
237
254
|
| 'u32'
|
|
238
255
|
| 'u64'
|
|
239
256
|
| 'u128'
|
|
240
|
-
| 'u256'
|
|
241
|
-
| 'signer';
|
|
257
|
+
| 'u256';
|
|
242
258
|
|
|
243
259
|
export type SuiInputTypes = 'object' | SuiBasicTypes;
|
|
244
260
|
|