@0xobelisk/client 0.3.1 → 0.3.3
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/package.json +1 -1
- package/src/obelisk.ts +90 -129
- package/src/types/index.ts +6 -6
- package/dist/index.d.ts +0 -9
- package/dist/index.js +0 -1315
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -1297
- package/dist/index.mjs.map +0 -1
- package/dist/libs/suiAccountManager/index.d.ts +0 -35
- package/dist/libs/suiAccountManager/keypair.d.ts +0 -21
- package/dist/libs/suiInteractor/defaultConfig.d.ts +0 -10
- package/dist/libs/suiInteractor/index.d.ts +0 -2
- package/dist/libs/suiInteractor/suiInteractor.d.ts +0 -205
- package/dist/libs/suiTxBuilder/index.d.ts +0 -544
- package/dist/libs/suiTxBuilder/util.d.ts +0 -76
- package/dist/metadata/index.d.ts +0 -34
- package/dist/obelisk.d.ts +0 -2570
- package/dist/types/index.d.ts +0 -141
package/package.json
CHANGED
package/src/obelisk.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
|
-
RawSigner,
|
|
3
|
-
TransactionBlock,
|
|
4
2
|
DevInspectResults,
|
|
5
|
-
|
|
6
|
-
SuiMoveNormalizedModules,
|
|
3
|
+
RawSigner,
|
|
7
4
|
SuiAddress,
|
|
5
|
+
SuiMoveNormalizedModules,
|
|
6
|
+
SuiTransactionBlockResponse,
|
|
7
|
+
TransactionBlock,
|
|
8
8
|
} from '@mysten/sui.js';
|
|
9
9
|
import { SuiAccountManager } from './libs/suiAccountManager';
|
|
10
10
|
import { SuiTxBlock } from './libs/suiTxBuilder';
|
|
11
|
-
import {
|
|
11
|
+
import { getDefaultConnection, SuiInteractor } from './libs/suiInteractor';
|
|
12
12
|
|
|
13
13
|
import { ObeliskObjectData } from 'src/types';
|
|
14
14
|
import { SuiContractFactory } from './libs/suiContractFactory';
|
|
15
15
|
import {
|
|
16
|
-
SuiMoveMoudleValueType,
|
|
17
16
|
SuiMoveMoudleFuncType,
|
|
17
|
+
SuiMoveMoudleValueType,
|
|
18
18
|
} from './libs/suiContractFactory/types';
|
|
19
19
|
import {
|
|
20
|
-
ObeliskParams,
|
|
21
|
-
DerivePathParams,
|
|
22
|
-
SuiTxArg,
|
|
23
|
-
SuiVecTxArg,
|
|
24
|
-
SuiTxArgument,
|
|
25
20
|
ContractQuery,
|
|
26
21
|
ContractTx,
|
|
22
|
+
DerivePathParams,
|
|
23
|
+
FaucetNetworkType,
|
|
27
24
|
MapMoudleFuncQuery,
|
|
28
25
|
MapMoudleFuncTx,
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
ObeliskParams,
|
|
27
|
+
SuiTxArg,
|
|
28
|
+
SuiTxArgument,
|
|
29
|
+
SuiVecTxArg,
|
|
31
30
|
} from './types';
|
|
32
31
|
import { normalizeHexAddress, numberToAddressHex } from './utils';
|
|
33
32
|
import keccak256 from 'keccak256';
|
|
@@ -131,10 +130,10 @@ export class Obelisk {
|
|
|
131
130
|
if (metadata !== undefined) {
|
|
132
131
|
this.metadata = metadata as SuiMoveNormalizedModules;
|
|
133
132
|
Object.values(metadata as SuiMoveNormalizedModules).forEach((value) => {
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
const data = value as SuiMoveMoudleValueType;
|
|
134
|
+
const moduleName = data.name;
|
|
136
135
|
Object.entries(data.exposedFunctions).forEach(([funcName, value]) => {
|
|
137
|
-
|
|
136
|
+
const meta = value as SuiMoveMoudleFuncType;
|
|
138
137
|
meta.moudleName = moduleName;
|
|
139
138
|
meta.funcName = funcName;
|
|
140
139
|
|
|
@@ -446,143 +445,105 @@ export class Obelisk {
|
|
|
446
445
|
return this.suiInteractor.getObject(worldObjectId);
|
|
447
446
|
}
|
|
448
447
|
|
|
449
|
-
async
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return newObjectContent['
|
|
448
|
+
async listSchemaNames(worldId: string) {
|
|
449
|
+
const worldObject = await this.getObject(worldId);
|
|
450
|
+
const newObjectContent = worldObject.objectFields;
|
|
451
|
+
return newObjectContent['schemaNames'];
|
|
453
452
|
}
|
|
454
453
|
|
|
455
|
-
async getEntity(
|
|
456
|
-
|
|
454
|
+
async getEntity(
|
|
455
|
+
worldId: string,
|
|
456
|
+
schemaName: string,
|
|
457
|
+
entityId?: string
|
|
458
|
+
): Promise<any[] | undefined> {
|
|
459
|
+
const schemaMoudleName = `${schemaName}_schema`;
|
|
457
460
|
const tx = new TransactionBlock();
|
|
458
|
-
|
|
461
|
+
const params = [tx.pure(worldId)] as SuiTxArgument[];
|
|
459
462
|
if (entityId !== undefined) {
|
|
460
463
|
params.push(tx.pure(entityId));
|
|
461
464
|
}
|
|
462
465
|
|
|
463
|
-
const getResult = (await this.query[
|
|
466
|
+
const getResult = (await this.query[schemaMoudleName].get(
|
|
464
467
|
tx,
|
|
465
468
|
params
|
|
466
469
|
)) as DevInspectResults;
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
470
|
+
const returnValue = [];
|
|
471
|
+
|
|
472
|
+
// "success" | "failure";
|
|
473
|
+
if (getResult.effects.status.status === 'success') {
|
|
474
|
+
const resultList = getResult.results![0].returnValues!;
|
|
475
|
+
for (const res of resultList) {
|
|
476
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
477
|
+
const value = Uint8Array.from(res[0]);
|
|
478
|
+
const data = bcs.de(res[1], value);
|
|
479
|
+
returnValue.push(data);
|
|
480
|
+
}
|
|
481
|
+
return returnValue;
|
|
482
|
+
} else {
|
|
483
|
+
return undefined;
|
|
474
484
|
}
|
|
475
|
-
return returnValue;
|
|
476
485
|
}
|
|
477
486
|
|
|
478
|
-
async
|
|
487
|
+
async containEntity(
|
|
479
488
|
worldId: string,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
let componentMoudleName = `${componentName}_comp`;
|
|
485
|
-
|
|
489
|
+
schemaName: string,
|
|
490
|
+
entityId?: string
|
|
491
|
+
): Promise<boolean | undefined> {
|
|
492
|
+
const schemaMoudleName = `${schemaName}_schema`;
|
|
486
493
|
const tx = new TransactionBlock();
|
|
487
|
-
|
|
494
|
+
const params = [tx.pure(worldId)] as SuiTxArgument[];
|
|
495
|
+
if (entityId !== undefined) {
|
|
496
|
+
params.push(tx.pure(entityId));
|
|
497
|
+
}
|
|
488
498
|
|
|
489
|
-
const
|
|
499
|
+
const getResult = (await this.query[schemaMoudleName].contains(
|
|
490
500
|
tx,
|
|
491
501
|
params
|
|
492
502
|
)) as DevInspectResults;
|
|
493
|
-
const entities = tableResult.results as SuiReturnValues;
|
|
494
|
-
const bcs = new BCS(getSuiMoveConfig());
|
|
495
503
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
data: objectDatas,
|
|
507
|
-
nextCursor: dynamicFields.nextCursor,
|
|
508
|
-
hasNextPage: dynamicFields.hasNextPage,
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// async getEntity(worldId: string, componentName: string, entityId: string) {
|
|
513
|
-
// let checkWorldId = normalizeHexAddress(worldId);
|
|
514
|
-
// if (checkWorldId) {
|
|
515
|
-
// worldId = checkWorldId;
|
|
516
|
-
// } else {
|
|
517
|
-
// return undefined;
|
|
518
|
-
// }
|
|
519
|
-
|
|
520
|
-
// let checkEntityId = normalizeHexAddress(entityId);
|
|
521
|
-
// if (checkEntityId) {
|
|
522
|
-
// entityId = checkEntityId;
|
|
523
|
-
// } else {
|
|
524
|
-
// return undefined;
|
|
525
|
-
// }
|
|
526
|
-
|
|
527
|
-
// const parentId = await this.getComponentTable(worldId, componentName);
|
|
528
|
-
// const name = {
|
|
529
|
-
// type: 'address',
|
|
530
|
-
// value: entityId,
|
|
531
|
-
// } as DynamicFieldName;
|
|
532
|
-
|
|
533
|
-
// let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
|
|
534
|
-
// parentId,
|
|
535
|
-
// name
|
|
536
|
-
// );
|
|
537
|
-
// return dynamicFieldObject;
|
|
538
|
-
// }
|
|
504
|
+
// "success" | "failure";
|
|
505
|
+
if (getResult.effects.status.status === 'success') {
|
|
506
|
+
const res = getResult.results![0].returnValues![0];
|
|
507
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
508
|
+
const value = Uint8Array.from(res[0]);
|
|
509
|
+
return bcs.de(res[1], value);
|
|
510
|
+
} else {
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
539
514
|
|
|
540
|
-
// async
|
|
515
|
+
// async getEntities(
|
|
541
516
|
// worldId: string,
|
|
542
|
-
//
|
|
543
|
-
//
|
|
517
|
+
// schemaName: string,
|
|
518
|
+
// cursor?: string,
|
|
519
|
+
// limit?: number
|
|
544
520
|
// ) {
|
|
545
|
-
//
|
|
546
|
-
// const name = {
|
|
547
|
-
// type: 'address',
|
|
548
|
-
// value: entityId,
|
|
549
|
-
// } as DynamicFieldName;
|
|
550
|
-
|
|
551
|
-
// let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
|
|
552
|
-
// parentId,
|
|
553
|
-
// name
|
|
554
|
-
// );
|
|
555
|
-
// let componentMoudleName = `${componentName}_comp`;
|
|
521
|
+
// let schemaMoudleName = `${schemaName}_schema`;
|
|
556
522
|
|
|
557
523
|
// const tx = new TransactionBlock();
|
|
558
|
-
// let params = [] as SuiTxArgument[];
|
|
524
|
+
// let params = [tx.pure(worldId)] as SuiTxArgument[];
|
|
559
525
|
|
|
560
|
-
// const
|
|
526
|
+
// const tableResult = (await this.query[schemaonentMoudleName].entities(
|
|
561
527
|
// tx,
|
|
562
528
|
// params
|
|
563
529
|
// )) as DevInspectResults;
|
|
564
|
-
//
|
|
565
|
-
// console.log(typeReturn[0].returnValues[0][0]);
|
|
566
|
-
|
|
567
|
-
// const typeBCS = new BCS(getSuiMoveConfig());
|
|
568
|
-
// let typeValue = Uint8Array.from(typeReturn[0].returnValues[0][0]);
|
|
569
|
-
|
|
570
|
-
// let typeData = typeBCS.de('vector<vector<u8>>', typeValue);
|
|
571
|
-
// console.log(typeData);
|
|
572
|
-
// const entityType = String.fromCharCode(...typeData[0]);
|
|
573
|
-
|
|
574
|
-
// let dynamicFieldContent = dynamicFieldObject.data!
|
|
575
|
-
// .content as DynamicFieldContentType;
|
|
576
|
-
|
|
577
|
-
// let entityValue = dynamicFieldContent.fields['value'];
|
|
530
|
+
// const entities = tableResult.results as SuiReturnValues;
|
|
578
531
|
// const bcs = new BCS(getSuiMoveConfig());
|
|
579
|
-
// let value = Uint8Array.from(entityValue);
|
|
580
|
-
// console.log(entityType);
|
|
581
|
-
// console.log(value);
|
|
582
532
|
|
|
583
|
-
// let
|
|
584
|
-
//
|
|
585
|
-
//
|
|
533
|
+
// let value = Uint8Array.from(entities[0].returnValues[0][0]);
|
|
534
|
+
// let tableId = '0x' + bcs.de('address', value);
|
|
535
|
+
// let dynamicFields = await this.suiInteractor.getDynamicFields(
|
|
536
|
+
// tableId,
|
|
537
|
+
// cursor,
|
|
538
|
+
// limit
|
|
539
|
+
// );
|
|
540
|
+
// let objectIds = dynamicFields.data.map((field) => field.objectId);
|
|
541
|
+
// let objectDatas = await this.suiInteractor.getEntitiesObjects(objectIds);
|
|
542
|
+
// return {
|
|
543
|
+
// data: objectDatas,
|
|
544
|
+
// nextCursor: dynamicFields.nextCursor,
|
|
545
|
+
// hasNextPage: dynamicFields.hasNextPage,
|
|
546
|
+
// };
|
|
586
547
|
// }
|
|
587
548
|
|
|
588
549
|
async getOwnedObjects(owner: SuiAddress, cursor?: string, limit?: number) {
|
|
@@ -591,10 +552,10 @@ export class Obelisk {
|
|
|
591
552
|
cursor,
|
|
592
553
|
limit
|
|
593
554
|
);
|
|
594
|
-
|
|
555
|
+
const ownedObjectsRes: ObeliskObjectData[] = [];
|
|
595
556
|
|
|
596
557
|
for (const object of ownedObjects.data) {
|
|
597
|
-
|
|
558
|
+
const objectDetail = await this.getObject(object.data!.objectId);
|
|
598
559
|
|
|
599
560
|
if (
|
|
600
561
|
objectDetail.objectType.split('::')[0] ===
|
|
@@ -608,7 +569,7 @@ export class Obelisk {
|
|
|
608
569
|
}
|
|
609
570
|
|
|
610
571
|
async entity_key_from_object(objectId: string) {
|
|
611
|
-
|
|
572
|
+
const checkObjectId = normalizeHexAddress(objectId);
|
|
612
573
|
if (checkObjectId !== null) {
|
|
613
574
|
objectId = checkObjectId;
|
|
614
575
|
return objectId;
|
|
@@ -618,11 +579,11 @@ export class Obelisk {
|
|
|
618
579
|
}
|
|
619
580
|
|
|
620
581
|
async entity_key_from_bytes(bytes: Uint8Array | Buffer | string) {
|
|
621
|
-
|
|
582
|
+
const hashBytes = keccak256(bytes);
|
|
622
583
|
const hashU8Array: number[] = Array.from(hashBytes);
|
|
623
584
|
const bcs = new BCS(getSuiMoveConfig());
|
|
624
|
-
|
|
625
|
-
|
|
585
|
+
const value = Uint8Array.from(hashU8Array);
|
|
586
|
+
const data = bcs.de('address', value);
|
|
626
587
|
return '0x' + data;
|
|
627
588
|
}
|
|
628
589
|
|
|
@@ -632,7 +593,7 @@ export class Obelisk {
|
|
|
632
593
|
|
|
633
594
|
async formatData(type: string, value: Buffer | number[] | Uint8Array) {
|
|
634
595
|
const bcs = new BCS(getSuiMoveConfig());
|
|
635
|
-
|
|
596
|
+
const u8Value = Uint8Array.from(value);
|
|
636
597
|
return bcs.de(type, u8Value);
|
|
637
598
|
}
|
|
638
599
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -35,8 +35,8 @@ export type ObeliskParams = {
|
|
|
35
35
|
metadata?: SuiMoveNormalizedModules;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export type
|
|
39
|
-
|
|
38
|
+
export type SchemaFieldType = {
|
|
39
|
+
schemas: {
|
|
40
40
|
type: string;
|
|
41
41
|
fields: {
|
|
42
42
|
id: {
|
|
@@ -47,14 +47,14 @@ export type ComponentFieldType = {
|
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
export type
|
|
50
|
+
export type SchemaValueType = {
|
|
51
51
|
id: {
|
|
52
52
|
id: string;
|
|
53
53
|
};
|
|
54
54
|
name: string;
|
|
55
55
|
value: {
|
|
56
56
|
type: string;
|
|
57
|
-
fields:
|
|
57
|
+
fields: SchemaFieldType;
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
60
|
|
|
@@ -77,9 +77,9 @@ export type SuiTxArgument =
|
|
|
77
77
|
index: number;
|
|
78
78
|
resultIndex: number;
|
|
79
79
|
};
|
|
80
|
-
export type
|
|
80
|
+
export type SchemaContentType = {
|
|
81
81
|
type: string;
|
|
82
|
-
fields:
|
|
82
|
+
fields: SchemaValueType;
|
|
83
83
|
hasPublicTransfer: boolean;
|
|
84
84
|
dataType: 'moveObject';
|
|
85
85
|
};
|
package/dist/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from '@mysten/sui.js';
|
|
2
|
-
export { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
3
|
-
export * from '@mysten/bcs';
|
|
4
|
-
export { Obelisk } from './obelisk';
|
|
5
|
-
export { SuiAccountManager } from './libs/suiAccountManager';
|
|
6
|
-
export { SuiTxBlock } from './libs/suiTxBuilder';
|
|
7
|
-
export { SuiContractFactory } from './libs/suiContractFactory';
|
|
8
|
-
export { getMetadata } from './metadata';
|
|
9
|
-
export type * from './types';
|