@0xobelisk/sui-client 0.5.16 → 0.5.18
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.js +360 -205
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -195
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -5
- package/src/index.ts +9 -8
- package/src/libs/multiSig/client.ts +2 -2
- package/src/libs/multiSig/publickey.ts +3 -3
- package/src/libs/suiAccountManager/index.ts +25 -6
- package/src/libs/suiAccountManager/keypair.ts +1 -1
- package/src/libs/suiAccountManager/util.ts +1 -1
- package/src/libs/suiContractFactory/index.ts +1 -1
- package/src/libs/suiContractFactory/types.ts +1 -1
- package/src/libs/suiInteractor/suiInteractor.ts +4 -4
- package/src/libs/suiModel/suiOwnedObject.ts +6 -4
- package/src/libs/suiModel/suiSharedObject.ts +5 -3
- package/src/libs/suiTxBuilder/index.ts +102 -84
- package/src/libs/suiTxBuilder/util.ts +113 -42
- package/src/metadata/index.ts +2 -3
- package/src/obelisk.ts +200 -91
- package/src/types/index.ts +46 -32
- package/dist/index.d.ts +0 -14
- package/dist/libs/multiSig/client.d.ts +0 -15
- package/dist/libs/multiSig/index.d.ts +0 -1
- package/dist/libs/multiSig/publickey.d.ts +0 -2
- package/dist/libs/suiAccountManager/crypto.d.ts +0 -1
- package/dist/libs/suiAccountManager/index.d.ts +0 -35
- package/dist/libs/suiAccountManager/keypair.d.ts +0 -21
- package/dist/libs/suiAccountManager/util.d.ts +0 -29
- package/dist/libs/suiContractFactory/index.d.ts +0 -20
- package/dist/libs/suiContractFactory/types.d.ts +0 -49
- package/dist/libs/suiInteractor/index.d.ts +0 -1
- package/dist/libs/suiInteractor/suiInteractor.d.ts +0 -50
- package/dist/libs/suiInteractor/util.d.ts +0 -1
- package/dist/libs/suiModel/index.d.ts +0 -2
- package/dist/libs/suiModel/suiOwnedObject.d.ts +0 -24
- package/dist/libs/suiModel/suiSharedObject.d.ts +0 -11
- package/dist/libs/suiTxBuilder/index.d.ts +0 -333
- package/dist/libs/suiTxBuilder/util.d.ts +0 -58
- package/dist/metadata/index.d.ts +0 -3
- package/dist/obelisk.d.ts +0 -136
- package/dist/types/index.d.ts +0 -152
- package/dist/utils/index.d.ts +0 -3
package/src/obelisk.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
TransactionResult,
|
|
7
|
-
} from '@mysten/sui.js/transactions';
|
|
8
|
-
import type { SerializedBcs } from '@mysten/bcs';
|
|
9
|
-
import type { TransactionArgument } from '@mysten/sui.js/transactions';
|
|
1
|
+
import keccak256 from 'keccak256';
|
|
2
|
+
import { getFullnodeUrl } from '@mysten/sui/client';
|
|
3
|
+
import { Transaction, TransactionResult } from '@mysten/sui/transactions';
|
|
4
|
+
import type { BcsType, SerializedBcs } from '@mysten/bcs';
|
|
5
|
+
import type { TransactionArgument } from '@mysten/sui/transactions';
|
|
10
6
|
import type {
|
|
11
7
|
SuiTransactionBlockResponse,
|
|
12
8
|
DevInspectResults,
|
|
13
9
|
SuiMoveNormalizedModules,
|
|
14
10
|
SuiObjectData,
|
|
15
|
-
} from '@mysten/sui
|
|
11
|
+
} from '@mysten/sui/client';
|
|
16
12
|
import { SuiAccountManager } from './libs/suiAccountManager';
|
|
17
|
-
import {
|
|
13
|
+
import { SuiTx } from './libs/suiTxBuilder';
|
|
18
14
|
import { SuiInteractor } from './libs/suiInteractor';
|
|
19
15
|
|
|
20
|
-
import { ObeliskObjectContent } from './types';
|
|
16
|
+
import { MapMoudleStruct, NetworkType, ObeliskObjectContent } from './types';
|
|
21
17
|
import { SuiContractFactory } from './libs/suiContractFactory';
|
|
22
18
|
import {
|
|
23
19
|
SuiMoveMoudleFuncType,
|
|
@@ -36,8 +32,8 @@ import {
|
|
|
36
32
|
SuiVecTxArg,
|
|
37
33
|
} from './types';
|
|
38
34
|
import { normalizeHexAddress, numberToAddressHex } from './utils';
|
|
39
|
-
import
|
|
40
|
-
import {
|
|
35
|
+
import { bcs, fromHEX, toHEX } from '@mysten/bcs';
|
|
36
|
+
import { TypeTagSerializer } from '@mysten/sui/bcs';
|
|
41
37
|
|
|
42
38
|
export function isUndefined(value?: unknown): value is undefined {
|
|
43
39
|
return value === undefined;
|
|
@@ -55,7 +51,7 @@ export function withMeta<T extends { meta: SuiMoveMoudleFuncType }>(
|
|
|
55
51
|
function createQuery(
|
|
56
52
|
meta: SuiMoveMoudleFuncType,
|
|
57
53
|
fn: (
|
|
58
|
-
tx:
|
|
54
|
+
tx: Transaction,
|
|
59
55
|
params: (TransactionArgument | SerializedBcs<any>)[],
|
|
60
56
|
typeArguments?: string[],
|
|
61
57
|
isRaw?: boolean
|
|
@@ -64,7 +60,7 @@ function createQuery(
|
|
|
64
60
|
return withMeta(
|
|
65
61
|
meta,
|
|
66
62
|
async (
|
|
67
|
-
tx:
|
|
63
|
+
tx: Transaction,
|
|
68
64
|
params: (TransactionArgument | SerializedBcs<any>)[],
|
|
69
65
|
typeArguments?: string[],
|
|
70
66
|
isRaw?: boolean
|
|
@@ -78,7 +74,7 @@ function createQuery(
|
|
|
78
74
|
function createTx(
|
|
79
75
|
meta: SuiMoveMoudleFuncType,
|
|
80
76
|
fn: (
|
|
81
|
-
tx:
|
|
77
|
+
tx: Transaction,
|
|
82
78
|
params: (TransactionArgument | SerializedBcs<any>)[],
|
|
83
79
|
typeArguments?: string[],
|
|
84
80
|
isRaw?: boolean
|
|
@@ -87,7 +83,7 @@ function createTx(
|
|
|
87
83
|
return withMeta(
|
|
88
84
|
meta,
|
|
89
85
|
async (
|
|
90
|
-
tx:
|
|
86
|
+
tx: Transaction,
|
|
91
87
|
params: (TransactionArgument | SerializedBcs<any>)[],
|
|
92
88
|
typeArguments?: string[],
|
|
93
89
|
isRaw?: boolean
|
|
@@ -111,6 +107,7 @@ export class Obelisk {
|
|
|
111
107
|
|
|
112
108
|
readonly #query: MapMoudleFuncQuery = {};
|
|
113
109
|
readonly #tx: MapMoudleFuncTx = {};
|
|
110
|
+
readonly #struct: MapMoudleStruct = {};
|
|
114
111
|
/**
|
|
115
112
|
* Support the following ways to init the ObeliskClient:
|
|
116
113
|
* 1. mnemonics
|
|
@@ -118,7 +115,7 @@ export class Obelisk {
|
|
|
118
115
|
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
119
116
|
*
|
|
120
117
|
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
121
|
-
* @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
|
|
118
|
+
* @param secretKey, base64 or hex string or bech32, when mnemonics is provided, secretKey will be ignored
|
|
122
119
|
* @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
|
|
123
120
|
* @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
|
|
124
121
|
* @param packageId
|
|
@@ -140,37 +137,42 @@ export class Obelisk {
|
|
|
140
137
|
this.packageId = packageId;
|
|
141
138
|
if (metadata !== undefined) {
|
|
142
139
|
this.metadata = metadata as SuiMoveNormalizedModules;
|
|
143
|
-
Object.values(metadata as SuiMoveNormalizedModules).forEach(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
(
|
|
158
|
-
this.#
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
(tx
|
|
169
|
-
this.#
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
+
|
|
162
|
+
if (isUndefined(this.#tx[moduleName])) {
|
|
163
|
+
this.#tx[moduleName] = {};
|
|
164
|
+
}
|
|
165
|
+
if (isUndefined(this.#tx[moduleName][funcName])) {
|
|
166
|
+
this.#tx[moduleName][funcName] = createTx(
|
|
167
|
+
meta,
|
|
168
|
+
(tx, p, typeArguments, isRaw) =>
|
|
169
|
+
this.#exec(meta, tx, p, typeArguments, isRaw)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
);
|
|
174
176
|
}
|
|
175
177
|
this.contractFactory = new SuiContractFactory({
|
|
176
178
|
packageId,
|
|
@@ -186,9 +188,13 @@ export class Obelisk {
|
|
|
186
188
|
return this.#tx;
|
|
187
189
|
}
|
|
188
190
|
|
|
191
|
+
public get struct(): MapMoudleStruct {
|
|
192
|
+
return this.#struct;
|
|
193
|
+
}
|
|
194
|
+
|
|
189
195
|
#exec = async (
|
|
190
196
|
meta: SuiMoveMoudleFuncType,
|
|
191
|
-
tx:
|
|
197
|
+
tx: Transaction,
|
|
192
198
|
params: (TransactionArgument | SerializedBcs<any>)[],
|
|
193
199
|
typeArguments?: string[],
|
|
194
200
|
isRaw?: boolean
|
|
@@ -211,7 +217,7 @@ export class Obelisk {
|
|
|
211
217
|
|
|
212
218
|
#read = async (
|
|
213
219
|
meta: SuiMoveMoudleFuncType,
|
|
214
|
-
tx:
|
|
220
|
+
tx: Transaction,
|
|
215
221
|
params: (TransactionArgument | SerializedBcs<any>)[],
|
|
216
222
|
typeArguments?: string[],
|
|
217
223
|
isRaw?: boolean
|
|
@@ -229,6 +235,7 @@ export class Obelisk {
|
|
|
229
235
|
arguments: params,
|
|
230
236
|
typeArguments,
|
|
231
237
|
});
|
|
238
|
+
|
|
232
239
|
return await this.inspectTxn(tx);
|
|
233
240
|
};
|
|
234
241
|
|
|
@@ -269,11 +276,27 @@ export class Obelisk {
|
|
|
269
276
|
getMetadata() {
|
|
270
277
|
return this.contractFactory.metadata;
|
|
271
278
|
}
|
|
279
|
+
|
|
280
|
+
getNetwork() {
|
|
281
|
+
return this.suiInteractor.network;
|
|
282
|
+
}
|
|
272
283
|
/**
|
|
273
284
|
* Request some SUI from faucet
|
|
274
285
|
* @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
|
|
275
286
|
*/
|
|
276
|
-
async requestFaucet(
|
|
287
|
+
async requestFaucet(
|
|
288
|
+
address?: string,
|
|
289
|
+
network?: FaucetNetworkType,
|
|
290
|
+
derivePathParams?: DerivePathParams
|
|
291
|
+
) {
|
|
292
|
+
if (address === undefined) {
|
|
293
|
+
address = this.accountManager.getAddress(derivePathParams);
|
|
294
|
+
}
|
|
295
|
+
if (network === undefined) {
|
|
296
|
+
network = this.getNetwork() as
|
|
297
|
+
| FaucetNetworkType
|
|
298
|
+
| 'devnet' as FaucetNetworkType;
|
|
299
|
+
}
|
|
277
300
|
// const addr = this.accountManager.getAddress(derivePathParams);
|
|
278
301
|
return this.suiInteractor.requestFaucet(address, network);
|
|
279
302
|
}
|
|
@@ -308,29 +331,36 @@ export class Obelisk {
|
|
|
308
331
|
}
|
|
309
332
|
|
|
310
333
|
async signTxn(
|
|
311
|
-
tx: Uint8Array |
|
|
334
|
+
tx: Uint8Array | Transaction | SuiTx,
|
|
312
335
|
derivePathParams?: DerivePathParams
|
|
313
336
|
) {
|
|
314
|
-
if (tx instanceof
|
|
337
|
+
if (tx instanceof SuiTx || tx instanceof Transaction) {
|
|
315
338
|
tx.setSender(this.getAddress(derivePathParams));
|
|
316
339
|
}
|
|
317
|
-
const txBlock = tx instanceof
|
|
340
|
+
const txBlock = tx instanceof SuiTx ? tx.tx : tx;
|
|
318
341
|
const txBytes =
|
|
319
|
-
txBlock instanceof
|
|
342
|
+
txBlock instanceof Transaction
|
|
320
343
|
? await txBlock.build({ client: this.client() })
|
|
321
344
|
: txBlock;
|
|
322
345
|
const keyPair = this.getKeypair(derivePathParams);
|
|
323
|
-
return await keyPair.
|
|
346
|
+
return await keyPair.signTransaction(txBytes);
|
|
324
347
|
}
|
|
325
348
|
|
|
326
349
|
async signAndSendTxn(
|
|
327
|
-
tx: Uint8Array |
|
|
350
|
+
tx: Uint8Array | Transaction | SuiTx,
|
|
328
351
|
derivePathParams?: DerivePathParams
|
|
329
352
|
): Promise<SuiTransactionBlockResponse> {
|
|
330
353
|
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
331
354
|
return this.suiInteractor.sendTx(bytes, signature);
|
|
332
355
|
}
|
|
333
356
|
|
|
357
|
+
async sendTxn(
|
|
358
|
+
transactionBlock: Uint8Array | string,
|
|
359
|
+
signature: string | string[]
|
|
360
|
+
): Promise<SuiTransactionBlockResponse> {
|
|
361
|
+
return this.suiInteractor.sendTx(transactionBlock, signature);
|
|
362
|
+
}
|
|
363
|
+
|
|
334
364
|
/**
|
|
335
365
|
* Transfer the given amount of SUI to the recipient
|
|
336
366
|
* @param recipient
|
|
@@ -342,7 +372,7 @@ export class Obelisk {
|
|
|
342
372
|
amount: number,
|
|
343
373
|
derivePathParams?: DerivePathParams
|
|
344
374
|
) {
|
|
345
|
-
const tx = new
|
|
375
|
+
const tx = new SuiTx();
|
|
346
376
|
tx.transferSui(recipient, amount);
|
|
347
377
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
348
378
|
}
|
|
@@ -358,7 +388,7 @@ export class Obelisk {
|
|
|
358
388
|
amounts: number[],
|
|
359
389
|
derivePathParams?: DerivePathParams
|
|
360
390
|
) {
|
|
361
|
-
const tx = new
|
|
391
|
+
const tx = new SuiTx();
|
|
362
392
|
tx.transferSuiToMany(recipients, amounts);
|
|
363
393
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
364
394
|
}
|
|
@@ -376,7 +406,7 @@ export class Obelisk {
|
|
|
376
406
|
coinType: string,
|
|
377
407
|
derivePathParams?: DerivePathParams
|
|
378
408
|
) {
|
|
379
|
-
const tx = new
|
|
409
|
+
const tx = new SuiTx();
|
|
380
410
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
381
411
|
const totalAmount = amounts.reduce((a, b) => a + b, 0);
|
|
382
412
|
const coins = await this.suiInteractor.selectCoins(
|
|
@@ -412,7 +442,7 @@ export class Obelisk {
|
|
|
412
442
|
recipient: string,
|
|
413
443
|
derivePathParams?: DerivePathParams
|
|
414
444
|
) {
|
|
415
|
-
const tx = new
|
|
445
|
+
const tx = new SuiTx();
|
|
416
446
|
tx.transferObjects(objects, recipient);
|
|
417
447
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
418
448
|
}
|
|
@@ -429,7 +459,7 @@ export class Obelisk {
|
|
|
429
459
|
typeArguments = [],
|
|
430
460
|
derivePathParams,
|
|
431
461
|
} = callParams;
|
|
432
|
-
const tx = new
|
|
462
|
+
const tx = new SuiTx();
|
|
433
463
|
tx.moveCall(target, args, typeArguments);
|
|
434
464
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
435
465
|
}
|
|
@@ -467,7 +497,7 @@ export class Obelisk {
|
|
|
467
497
|
validatorAddr: string,
|
|
468
498
|
derivePathParams?: DerivePathParams
|
|
469
499
|
) {
|
|
470
|
-
const tx = new
|
|
500
|
+
const tx = new SuiTx();
|
|
471
501
|
tx.stakeSui(amount, validatorAddr);
|
|
472
502
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
473
503
|
}
|
|
@@ -480,10 +510,10 @@ export class Obelisk {
|
|
|
480
510
|
* @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
|
|
481
511
|
*/
|
|
482
512
|
async inspectTxn(
|
|
483
|
-
tx: Uint8Array |
|
|
513
|
+
tx: Uint8Array | Transaction | SuiTx,
|
|
484
514
|
derivePathParams?: DerivePathParams
|
|
485
515
|
): Promise<DevInspectResults> {
|
|
486
|
-
const txBlock = tx instanceof
|
|
516
|
+
const txBlock = tx instanceof SuiTx ? tx.tx : tx;
|
|
487
517
|
return this.suiInteractor.currentClient.devInspectTransactionBlock({
|
|
488
518
|
transactionBlock: txBlock,
|
|
489
519
|
sender: this.getAddress(derivePathParams),
|
|
@@ -512,30 +542,58 @@ export class Obelisk {
|
|
|
512
542
|
entityId?: string
|
|
513
543
|
): Promise<any[] | undefined> {
|
|
514
544
|
const schemaModuleName = `${schemaName}_schema`;
|
|
515
|
-
const tx = new
|
|
516
|
-
const params = [tx.pure(worldId)] as TransactionArgument[];
|
|
545
|
+
const tx = new Transaction();
|
|
546
|
+
const params = [tx.pure.address(worldId)] as TransactionArgument[];
|
|
517
547
|
|
|
518
548
|
if (entityId !== undefined) {
|
|
519
|
-
params.push(tx.pure(entityId));
|
|
549
|
+
params.push(tx.pure.address(entityId));
|
|
520
550
|
}
|
|
521
551
|
|
|
522
552
|
const getResult = (await this.query[schemaModuleName].get(
|
|
523
553
|
tx,
|
|
524
554
|
params
|
|
525
555
|
)) as DevInspectResults;
|
|
526
|
-
let
|
|
556
|
+
let returnValues = [];
|
|
527
557
|
|
|
528
558
|
// "success" | "failure";
|
|
529
559
|
if (getResult.effects.status.status === 'success') {
|
|
530
560
|
const resultList = getResult.results![0].returnValues!;
|
|
561
|
+
|
|
531
562
|
for (const res of resultList) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
const
|
|
536
|
-
|
|
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
|
+
}
|
|
537
595
|
}
|
|
538
|
-
return
|
|
596
|
+
return returnValues;
|
|
539
597
|
} else {
|
|
540
598
|
return undefined;
|
|
541
599
|
}
|
|
@@ -547,11 +605,11 @@ export class Obelisk {
|
|
|
547
605
|
entityId?: string
|
|
548
606
|
): Promise<boolean | undefined> {
|
|
549
607
|
const schemaModuleName = `${schemaName}_schema`;
|
|
550
|
-
const tx = new
|
|
551
|
-
const params = [tx.pure(worldId)] as TransactionArgument[];
|
|
608
|
+
const tx = new Transaction();
|
|
609
|
+
const params = [tx.pure.address(worldId)] as TransactionArgument[];
|
|
552
610
|
|
|
553
611
|
if (entityId !== undefined) {
|
|
554
|
-
params.push(tx.pure(entityId));
|
|
612
|
+
params.push(tx.pure.address(entityId));
|
|
555
613
|
}
|
|
556
614
|
|
|
557
615
|
const getResult = (await this.query[schemaModuleName].contains(
|
|
@@ -562,9 +620,10 @@ export class Obelisk {
|
|
|
562
620
|
// "success" | "failure";
|
|
563
621
|
if (getResult.effects.status.status === 'success') {
|
|
564
622
|
const res = getResult.results![0].returnValues![0];
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
623
|
+
let baseValue = res[0];
|
|
624
|
+
|
|
625
|
+
const value = Uint8Array.from(baseValue);
|
|
626
|
+
return bcs.bool().parse(value);
|
|
568
627
|
} else {
|
|
569
628
|
return undefined;
|
|
570
629
|
}
|
|
@@ -637,9 +696,13 @@ export class Obelisk {
|
|
|
637
696
|
async entity_key_from_bytes(bytes: Uint8Array | Buffer | string) {
|
|
638
697
|
const hashBytes = keccak256(bytes);
|
|
639
698
|
const hashU8Array: number[] = Array.from(hashBytes);
|
|
640
|
-
const bcs = new BCS(getSuiMoveConfig());
|
|
641
699
|
const value = Uint8Array.from(hashU8Array);
|
|
642
|
-
const
|
|
700
|
+
const Address = bcs.bytes(32).transform({
|
|
701
|
+
// To change the input type, you need to provide a type definition for the input
|
|
702
|
+
input: (val: string) => fromHEX(val),
|
|
703
|
+
output: (val) => toHEX(val),
|
|
704
|
+
});
|
|
705
|
+
const data = Address.parse(value);
|
|
643
706
|
return '0x' + data;
|
|
644
707
|
}
|
|
645
708
|
|
|
@@ -659,9 +722,10 @@ export class Obelisk {
|
|
|
659
722
|
const checkObjectId = normalizeHexAddress(objectId);
|
|
660
723
|
if (checkObjectId !== null) {
|
|
661
724
|
objectId = checkObjectId;
|
|
662
|
-
const bcs = new BCS(getSuiMoveConfig());
|
|
663
725
|
const bytes = Buffer.from(objectId.slice(2), 'hex');
|
|
664
|
-
|
|
726
|
+
|
|
727
|
+
const numberBytes = bcs.u256().serialize(x).toBytes();
|
|
728
|
+
|
|
665
729
|
return this.entity_key_from_bytes(Buffer.concat([bytes, numberBytes]));
|
|
666
730
|
} else {
|
|
667
731
|
return undefined;
|
|
@@ -672,9 +736,54 @@ export class Obelisk {
|
|
|
672
736
|
return numberToAddressHex(x);
|
|
673
737
|
}
|
|
674
738
|
|
|
675
|
-
async formatData(type: string, value: Buffer | number[] | Uint8Array) {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
739
|
+
// async formatData(type: string, value: Buffer | number[] | Uint8Array) {
|
|
740
|
+
// const u8Value = Uint8Array.from(value);
|
|
741
|
+
// return bcs.de(type, u8Value);
|
|
742
|
+
// }
|
|
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
|
+
}
|
|
679
788
|
}
|
|
680
789
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import type { Infer } from 'superstruct';
|
|
2
2
|
import { any, record, string } from 'superstruct';
|
|
3
|
-
import type { SerializedBcs } from '@mysten/bcs';
|
|
4
|
-
import type { TransactionArgument } from '@mysten/sui
|
|
3
|
+
import type { BcsType, SerializedBcs } from '@mysten/bcs';
|
|
4
|
+
import type { TransactionArgument } from '@mysten/sui/transactions';
|
|
5
5
|
import type {
|
|
6
|
-
|
|
6
|
+
Transaction,
|
|
7
7
|
TransactionObjectArgument,
|
|
8
8
|
TransactionResult,
|
|
9
|
-
|
|
9
|
+
ObjectRef,
|
|
10
|
+
} from '@mysten/sui/transactions';
|
|
10
11
|
import type {
|
|
11
12
|
SuiObjectRef,
|
|
12
13
|
SuiMoveNormalizedModules,
|
|
13
14
|
DevInspectResults,
|
|
14
15
|
SuiTransactionBlockResponse,
|
|
15
16
|
DisplayFieldsResponse,
|
|
17
|
+
SuiMoveNormalizedType,
|
|
16
18
|
MoveStruct,
|
|
17
|
-
} from '@mysten/sui
|
|
18
|
-
import
|
|
19
|
-
|
|
19
|
+
} from '@mysten/sui/client';
|
|
20
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
21
|
+
import { bcs as BCS } from '@mysten/bcs';
|
|
20
22
|
|
|
21
23
|
import { SuiMoveMoudleFuncType } from '../libs/suiContractFactory/types';
|
|
22
24
|
|
|
@@ -71,26 +73,6 @@ export type SchemaValueType = {
|
|
|
71
73
|
};
|
|
72
74
|
};
|
|
73
75
|
|
|
74
|
-
// export type SuiTxArgument =
|
|
75
|
-
// | {
|
|
76
|
-
// kind: 'Input';
|
|
77
|
-
// index: number;
|
|
78
|
-
// type?: 'object' | 'pure' | undefined;
|
|
79
|
-
// value?: any;
|
|
80
|
-
// }
|
|
81
|
-
// | {
|
|
82
|
-
// kind: 'GasCoin';
|
|
83
|
-
// }
|
|
84
|
-
// | {
|
|
85
|
-
// kind: 'Result';
|
|
86
|
-
// index: number;
|
|
87
|
-
// }
|
|
88
|
-
// | {
|
|
89
|
-
// kind: 'NestedResult';
|
|
90
|
-
// index: number;
|
|
91
|
-
// resultIndex: number;
|
|
92
|
-
// };
|
|
93
|
-
|
|
94
76
|
export type SchemaContentType = {
|
|
95
77
|
type: string;
|
|
96
78
|
fields: SchemaValueType;
|
|
@@ -104,7 +86,7 @@ export interface MessageMeta {
|
|
|
104
86
|
|
|
105
87
|
export interface ContractQuery extends MessageMeta {
|
|
106
88
|
(
|
|
107
|
-
tx:
|
|
89
|
+
tx: Transaction,
|
|
108
90
|
params: (TransactionArgument | SerializedBcs<any>)[],
|
|
109
91
|
typeArguments?: string[],
|
|
110
92
|
isRaw?: boolean
|
|
@@ -113,7 +95,7 @@ export interface ContractQuery extends MessageMeta {
|
|
|
113
95
|
|
|
114
96
|
export interface ContractTx extends MessageMeta {
|
|
115
97
|
(
|
|
116
|
-
tx:
|
|
98
|
+
tx: Transaction,
|
|
117
99
|
params: (TransactionArgument | SerializedBcs<any>)[],
|
|
118
100
|
typeArguments?: string[],
|
|
119
101
|
isRaw?: boolean
|
|
@@ -126,6 +108,36 @@ export type MapMessageQuery = Record<string, ContractQuery>;
|
|
|
126
108
|
export type MapMoudleFuncTx = Record<string, MapMessageTx>;
|
|
127
109
|
export type MapMoudleFuncQuery = Record<string, MapMessageQuery>;
|
|
128
110
|
|
|
111
|
+
type MoveStructType = {
|
|
112
|
+
struct: Record<
|
|
113
|
+
string,
|
|
114
|
+
{
|
|
115
|
+
fields: {
|
|
116
|
+
type: SuiMoveNormalizedType;
|
|
117
|
+
name: string;
|
|
118
|
+
}[];
|
|
119
|
+
abilities: {
|
|
120
|
+
abilities: string[];
|
|
121
|
+
};
|
|
122
|
+
typeParameters: {
|
|
123
|
+
constraints: {
|
|
124
|
+
abilities: string[];
|
|
125
|
+
};
|
|
126
|
+
isPhantom: boolean;
|
|
127
|
+
}[];
|
|
128
|
+
}
|
|
129
|
+
>;
|
|
130
|
+
bcs: BcsType<
|
|
131
|
+
{
|
|
132
|
+
[x: string]: any;
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
[x: string]: any;
|
|
136
|
+
}
|
|
137
|
+
>;
|
|
138
|
+
};
|
|
139
|
+
export type MapMoudleStruct = Record<string, MoveStructType>;
|
|
140
|
+
|
|
129
141
|
export type MapMoudleFuncTest = Record<string, Record<string, string>>;
|
|
130
142
|
export type MapMoudleFuncQueryTest = Record<string, Record<string, string>>;
|
|
131
143
|
|
|
@@ -160,13 +172,13 @@ export type ObjectData = {
|
|
|
160
172
|
objectDisplay: DisplayFieldsResponse;
|
|
161
173
|
objectFields: ObjectContentFields;
|
|
162
174
|
};
|
|
163
|
-
type TransactionBlockType = InstanceType<typeof
|
|
175
|
+
type TransactionBlockType = InstanceType<typeof Transaction>;
|
|
164
176
|
|
|
165
177
|
export type PureCallArg = {
|
|
166
178
|
Pure: number[];
|
|
167
179
|
};
|
|
168
180
|
export type ObjectCallArg = {
|
|
169
|
-
Object:
|
|
181
|
+
Object: typeof bcs.CallArg.$inferType;
|
|
170
182
|
};
|
|
171
183
|
|
|
172
184
|
export type TransactionType = Parameters<TransactionBlockType['add']>;
|
|
@@ -202,9 +214,10 @@ export type SuiAddressArg =
|
|
|
202
214
|
export type SuiTxArg = SuiAddressArg | number | bigint | boolean;
|
|
203
215
|
|
|
204
216
|
export type SuiObjectArg =
|
|
217
|
+
| ObjectRef
|
|
205
218
|
| TransactionObjectArgument
|
|
206
219
|
| string
|
|
207
|
-
| SharedObjectRef
|
|
220
|
+
| typeof bcs.SharedObjectRef.$inferType
|
|
208
221
|
| SuiObjectRef
|
|
209
222
|
| ObjectCallArg;
|
|
210
223
|
|
|
@@ -212,6 +225,7 @@ export type SuiVecTxArg =
|
|
|
212
225
|
| { value: SuiTxArg[]; vecType: SuiInputTypes }
|
|
213
226
|
| SuiTxArg[];
|
|
214
227
|
|
|
228
|
+
export type DryTxReturnValues = Array<[Uint8Array, string]>;
|
|
215
229
|
/**
|
|
216
230
|
* These are the basics types that can be used in the SUI
|
|
217
231
|
*/
|
package/dist/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * from '@mysten/sui.js/client';
|
|
2
|
-
export * from '@mysten/sui.js/utils';
|
|
3
|
-
export * from '@mysten/sui.js/transactions';
|
|
4
|
-
export * from '@mysten/sui.js/keypairs/ed25519';
|
|
5
|
-
export * from '@mysten/sui.js/keypairs/secp256k1';
|
|
6
|
-
export * from '@mysten/sui.js/keypairs/secp256r1';
|
|
7
|
-
export { BCS, getSuiMoveConfig } from '@mysten/bcs';
|
|
8
|
-
export { Obelisk } from './obelisk';
|
|
9
|
-
export { SuiAccountManager } from './libs/suiAccountManager';
|
|
10
|
-
export { SuiTxBlock } from './libs/suiTxBuilder';
|
|
11
|
-
export { MultiSigClient } from './libs/multiSig';
|
|
12
|
-
export { SuiContractFactory } from './libs/suiContractFactory';
|
|
13
|
-
export { loadMetadata } from './metadata';
|
|
14
|
-
export type * from './types';
|