@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xobelisk/client",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Tookit for interacting with move eps framework",
5
5
  "keywords": [
6
6
  "sui",
package/src/obelisk.ts CHANGED
@@ -1,33 +1,32 @@
1
1
  import {
2
- RawSigner,
3
- TransactionBlock,
4
2
  DevInspectResults,
5
- SuiTransactionBlockResponse,
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 { SuiInteractor, getDefaultConnection } from './libs/suiInteractor';
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
- FaucetNetworkType,
30
- SuiReturnValues,
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
- let data = value as SuiMoveMoudleValueType;
135
- let moduleName = data.name;
133
+ const data = value as SuiMoveMoudleValueType;
134
+ const moduleName = data.name;
136
135
  Object.entries(data.exposedFunctions).forEach(([funcName, value]) => {
137
- let meta = value as SuiMoveMoudleFuncType;
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 listComponentNames(worldId: string) {
450
- let worldObject = await this.getObject(worldId);
451
- let newObjectContent = worldObject.objectFields;
452
- return newObjectContent['compnames'];
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(worldId: string, componentName: string, entityId?: string) {
456
- let componentMoudleName = `${componentName}_comp`;
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
- let params = [tx.pure(worldId)] as SuiTxArgument[];
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[componentMoudleName].get(
466
+ const getResult = (await this.query[schemaMoudleName].get(
464
467
  tx,
465
468
  params
466
469
  )) as DevInspectResults;
467
- let returnValue = [];
468
- let resultList = getResult.results![0].returnValues!;
469
- for (let res of resultList) {
470
- const bcs = new BCS(getSuiMoveConfig());
471
- let value = Uint8Array.from(res[0]);
472
- let data = bcs.de(res[1], value);
473
- returnValue.push(data);
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 getEntities(
487
+ async containEntity(
479
488
  worldId: string,
480
- componentName: string,
481
- cursor?: string,
482
- limit?: number
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
- let params = [tx.pure(worldId)] as SuiTxArgument[];
494
+ const params = [tx.pure(worldId)] as SuiTxArgument[];
495
+ if (entityId !== undefined) {
496
+ params.push(tx.pure(entityId));
497
+ }
488
498
 
489
- const tableResult = (await this.query[componentMoudleName].entities(
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
- let value = Uint8Array.from(entities[0].returnValues[0][0]);
497
- let tableId = '0x' + bcs.de('address', value);
498
- let dynamicFields = await this.suiInteractor.getDynamicFields(
499
- tableId,
500
- cursor,
501
- limit
502
- );
503
- let objectIds = dynamicFields.data.map((field) => field.objectId);
504
- let objectDatas = await this.suiInteractor.getEntitiesObjects(objectIds);
505
- return {
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 getEntityData(
515
+ // async getEntities(
541
516
  // worldId: string,
542
- // componentName: string,
543
- // entityId: string
517
+ // schemaName: string,
518
+ // cursor?: string,
519
+ // limit?: number
544
520
  // ) {
545
- // const parentId = await this.getComponentTable(worldId, componentName);
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 typeResult = (await this.query[componentMoudleName].types(
526
+ // const tableResult = (await this.query[schemaonentMoudleName].entities(
561
527
  // tx,
562
528
  // params
563
529
  // )) as DevInspectResults;
564
- // let typeReturn = typeResult.results as SuiReturnValues;
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 data = bcs.de(entityType, value);
584
- // console.log(data);
585
- // return data;
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
- let ownedObjectsRes: ObeliskObjectData[] = [];
555
+ const ownedObjectsRes: ObeliskObjectData[] = [];
595
556
 
596
557
  for (const object of ownedObjects.data) {
597
- let objectDetail = await this.getObject(object.data!.objectId);
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
- let checkObjectId = normalizeHexAddress(objectId);
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
- let hashBytes = keccak256(bytes);
582
+ const hashBytes = keccak256(bytes);
622
583
  const hashU8Array: number[] = Array.from(hashBytes);
623
584
  const bcs = new BCS(getSuiMoveConfig());
624
- let value = Uint8Array.from(hashU8Array);
625
- let data = bcs.de('address', value);
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
- let u8Value = Uint8Array.from(value);
596
+ const u8Value = Uint8Array.from(value);
636
597
  return bcs.de(type, u8Value);
637
598
  }
638
599
  }
@@ -35,8 +35,8 @@ export type ObeliskParams = {
35
35
  metadata?: SuiMoveNormalizedModules;
36
36
  };
37
37
 
38
- export type ComponentFieldType = {
39
- components: {
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 ComponentValueType = {
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: ComponentFieldType;
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 ComponentContentType = {
80
+ export type SchemaContentType = {
81
81
  type: string;
82
- fields: ComponentValueType;
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';