@0xobelisk/client 0.2.8 → 0.2.9
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 +179 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -3
- package/dist/index.mjs.map +1 -1
- package/dist/libs/suiInteractor/suiInteractor.d.ts +2 -1
- package/dist/obelisk.d.ts +68 -0
- package/dist/types/index.d.ts +27 -6
- package/dist/utils/index.d.ts +2 -0
- package/package.json +2 -5
- package/src/libs/suiInteractor/suiInteractor.ts +59 -9
- package/src/obelisk.ts +164 -2
- package/src/types/index.ts +79 -51
- package/src/utils/index.ts +21 -1
- package/src/framework/bcs.ts +0 -6
- package/src/framework/loader.ts +0 -152
- package/src/framework/util.ts +0 -219
package/dist/obelisk.d.ts
CHANGED
|
@@ -2687,5 +2687,73 @@ export declare class Obelisk {
|
|
|
2687
2687
|
parent_object_id?: string | undefined;
|
|
2688
2688
|
} | null | undefined;
|
|
2689
2689
|
}>;
|
|
2690
|
+
getComponentTable(worldId: string, componentName: string): Promise<string>;
|
|
2691
|
+
getEntities(worldId: string, componentName: string, cursor?: string, limit?: number): Promise<{
|
|
2692
|
+
data: import("src/types").EntityData[];
|
|
2693
|
+
nextCursor: string | null;
|
|
2694
|
+
hasNextPage: boolean;
|
|
2695
|
+
}>;
|
|
2696
|
+
getEntity(worldId: string, componentName: string, entityId: string): Promise<{
|
|
2697
|
+
data?: {
|
|
2698
|
+
objectId: string;
|
|
2699
|
+
version: string;
|
|
2700
|
+
digest: string;
|
|
2701
|
+
type?: string | null | undefined;
|
|
2702
|
+
bcs?: {
|
|
2703
|
+
type: string;
|
|
2704
|
+
version: string;
|
|
2705
|
+
hasPublicTransfer: boolean;
|
|
2706
|
+
dataType: "moveObject";
|
|
2707
|
+
bcsBytes: string;
|
|
2708
|
+
} | {
|
|
2709
|
+
id: string;
|
|
2710
|
+
dataType: "package";
|
|
2711
|
+
moduleMap: Record<string, string>;
|
|
2712
|
+
} | null | undefined;
|
|
2713
|
+
owner?: {
|
|
2714
|
+
AddressOwner: string;
|
|
2715
|
+
} | {
|
|
2716
|
+
ObjectOwner: string;
|
|
2717
|
+
} | {
|
|
2718
|
+
Shared: {
|
|
2719
|
+
initial_shared_version: string | null;
|
|
2720
|
+
};
|
|
2721
|
+
} | "Immutable" | null | undefined;
|
|
2722
|
+
storageRebate?: string | null | undefined;
|
|
2723
|
+
previousTransaction?: string | null | undefined;
|
|
2724
|
+
content?: {
|
|
2725
|
+
type: string;
|
|
2726
|
+
fields: Record<string, any>;
|
|
2727
|
+
hasPublicTransfer: boolean;
|
|
2728
|
+
dataType: "moveObject";
|
|
2729
|
+
} | {
|
|
2730
|
+
disassembled: Record<string, unknown>;
|
|
2731
|
+
dataType: "package";
|
|
2732
|
+
} | null | undefined;
|
|
2733
|
+
display?: Record<string, string> | {
|
|
2734
|
+
data?: Record<string, string> | null | undefined;
|
|
2735
|
+
error?: {
|
|
2736
|
+
code: string;
|
|
2737
|
+
version?: string | undefined;
|
|
2738
|
+
digest?: string | undefined;
|
|
2739
|
+
error?: string | undefined;
|
|
2740
|
+
object_id?: string | undefined;
|
|
2741
|
+
parent_object_id?: string | undefined;
|
|
2742
|
+
} | null | undefined;
|
|
2743
|
+
} | null | undefined;
|
|
2744
|
+
} | null | undefined;
|
|
2745
|
+
error?: {
|
|
2746
|
+
code: string;
|
|
2747
|
+
version?: string | undefined;
|
|
2748
|
+
digest?: string | undefined;
|
|
2749
|
+
error?: string | undefined;
|
|
2750
|
+
object_id?: string | undefined;
|
|
2751
|
+
parent_object_id?: string | undefined;
|
|
2752
|
+
} | null | undefined;
|
|
2753
|
+
} | undefined>;
|
|
2690
2754
|
getOwnedObjects(owner: SuiAddress, cursor?: string, limit?: number): Promise<ObeliskObjectData[]>;
|
|
2755
|
+
entity_key_from_object(objectId: string): Promise<string | undefined>;
|
|
2756
|
+
entity_key_from_bytes(bytes: Uint8Array | Buffer | string): Promise<string>;
|
|
2757
|
+
entity_key_from_u256(x: number): Promise<string>;
|
|
2758
|
+
formatData(type: string, value: Buffer | number[] | Uint8Array): Promise<any>;
|
|
2691
2759
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -39,17 +39,17 @@ export type ComponentValueType = {
|
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
export type SuiTxArgument = {
|
|
42
|
-
kind:
|
|
42
|
+
kind: 'Input';
|
|
43
43
|
index: number;
|
|
44
|
-
type?:
|
|
44
|
+
type?: 'object' | 'pure' | undefined;
|
|
45
45
|
value?: any;
|
|
46
46
|
} | {
|
|
47
|
-
kind:
|
|
47
|
+
kind: 'GasCoin';
|
|
48
48
|
} | {
|
|
49
|
-
kind:
|
|
49
|
+
kind: 'Result';
|
|
50
50
|
index: number;
|
|
51
51
|
} | {
|
|
52
|
-
kind:
|
|
52
|
+
kind: 'NestedResult';
|
|
53
53
|
index: number;
|
|
54
54
|
resultIndex: number;
|
|
55
55
|
};
|
|
@@ -57,7 +57,7 @@ export type ComponentContentType = {
|
|
|
57
57
|
type: string;
|
|
58
58
|
fields: ComponentValueType;
|
|
59
59
|
hasPublicTransfer: boolean;
|
|
60
|
-
dataType:
|
|
60
|
+
dataType: 'moveObject';
|
|
61
61
|
};
|
|
62
62
|
export interface MessageMeta {
|
|
63
63
|
readonly meta: SuiMoveMoudleFuncType;
|
|
@@ -101,6 +101,18 @@ export type ObjectData = {
|
|
|
101
101
|
objectDisplay: DisplayFieldsResponse;
|
|
102
102
|
objectFields: ObjectContentFields;
|
|
103
103
|
};
|
|
104
|
+
export type ObjectFieldType = {
|
|
105
|
+
id: {
|
|
106
|
+
id: string;
|
|
107
|
+
};
|
|
108
|
+
name: string;
|
|
109
|
+
value: string;
|
|
110
|
+
};
|
|
111
|
+
export type EntityData = {
|
|
112
|
+
objectId: string;
|
|
113
|
+
index: string;
|
|
114
|
+
key: string;
|
|
115
|
+
};
|
|
104
116
|
export type SuiTxArg = Infer<typeof TransactionArgument> | Infer<typeof ObjectCallArg> | string | number | bigint | boolean;
|
|
105
117
|
export type SuiObjectArg = SharedObjectRef | Infer<typeof SuiObjectRef> | string | Infer<typeof ObjectCallArg> | Infer<typeof TransactionArgument>;
|
|
106
118
|
export type SuiVecTxArg = {
|
|
@@ -112,3 +124,12 @@ export type SuiVecTxArg = {
|
|
|
112
124
|
*/
|
|
113
125
|
export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256';
|
|
114
126
|
export type SuiInputTypes = 'object' | SuiBasicTypes;
|
|
127
|
+
export type SuiReturnValues = {
|
|
128
|
+
returnValues: [number[], string][];
|
|
129
|
+
}[];
|
|
130
|
+
export type DynamicFieldContentType = {
|
|
131
|
+
type: string;
|
|
132
|
+
fields: Record<string, any>;
|
|
133
|
+
hasPublicTransfer: boolean;
|
|
134
|
+
dataType: string;
|
|
135
|
+
};
|
package/dist/utils/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xobelisk/client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Tookit for interacting with move eps framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -46,8 +46,6 @@
|
|
|
46
46
|
"watch": "pnpm run clean & pnpm run watch:types & pnpm run watch:tsup",
|
|
47
47
|
"test": "pnpm test:typecheck && pnpm test:unit",
|
|
48
48
|
"test:typecheck": "tsc -p ./test",
|
|
49
|
-
"test:unit": "vitest run --test-timeout=60000",
|
|
50
|
-
"test:watch": "vitest",
|
|
51
49
|
"format:fix": "prettier --ignore-path 'dist/* docs/*' --write '**/*.{ts,json,md}'",
|
|
52
50
|
"lint:fix": "eslint . --ignore-pattern dist --ext .ts --fix",
|
|
53
51
|
"commit": "commit",
|
|
@@ -90,8 +88,7 @@
|
|
|
90
88
|
"tsconfig-paths": "^4.2.0",
|
|
91
89
|
"tsup": "^7.1.0",
|
|
92
90
|
"typedoc": "^0.24.8",
|
|
93
|
-
"typescript": "^5.0.4"
|
|
94
|
-
"vitest": "^0.32.2"
|
|
91
|
+
"typescript": "^5.0.4"
|
|
95
92
|
},
|
|
96
93
|
"lint-staged": {
|
|
97
94
|
"**/*.ts": [
|
|
@@ -10,11 +10,21 @@ import {
|
|
|
10
10
|
getObjectVersion,
|
|
11
11
|
getSharedObjectInitialVersion,
|
|
12
12
|
DynamicFieldName,
|
|
13
|
-
SuiAddress
|
|
13
|
+
SuiAddress,
|
|
14
14
|
} from '@mysten/sui.js';
|
|
15
15
|
import { requestSuiFromFaucetV0, getFaucetHost } from '@mysten/sui.js/faucet';
|
|
16
|
-
import {
|
|
17
|
-
|
|
16
|
+
import {
|
|
17
|
+
SuiClient,
|
|
18
|
+
getFullnodeUrl,
|
|
19
|
+
GetBalanceParams,
|
|
20
|
+
} from '@mysten/sui.js/client';
|
|
21
|
+
import {
|
|
22
|
+
FaucetNetworkType,
|
|
23
|
+
NetworkType,
|
|
24
|
+
ObjectData,
|
|
25
|
+
ObjectFieldType,
|
|
26
|
+
EntityData,
|
|
27
|
+
} from 'src/types';
|
|
18
28
|
import { SuiOwnedObject, SuiSharedObject } from '../suiModel';
|
|
19
29
|
import { delay } from './util';
|
|
20
30
|
|
|
@@ -78,6 +88,7 @@ export class SuiInteractor {
|
|
|
78
88
|
}
|
|
79
89
|
throw new Error('Failed to send transaction with all fullnodes');
|
|
80
90
|
}
|
|
91
|
+
|
|
81
92
|
async getObjects(ids: string[]) {
|
|
82
93
|
const options = {
|
|
83
94
|
showContent: true,
|
|
@@ -129,11 +140,50 @@ export class SuiInteractor {
|
|
|
129
140
|
return objects[0];
|
|
130
141
|
}
|
|
131
142
|
|
|
143
|
+
async getEntitiesObjects(ids: string[]) {
|
|
144
|
+
const options = {
|
|
145
|
+
showContent: true,
|
|
146
|
+
showType: true,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// const currentProviderIdx = this.providers.indexOf(this.currentProvider);
|
|
150
|
+
// const providers = [
|
|
151
|
+
// ...this.providers.slice(currentProviderIdx, this.providers.length),
|
|
152
|
+
// ...this.providers.slice(0, currentProviderIdx),
|
|
153
|
+
// ]
|
|
154
|
+
|
|
155
|
+
for (const provider of this.providers) {
|
|
156
|
+
try {
|
|
157
|
+
const objects = await provider.multiGetObjects({ ids, options });
|
|
158
|
+
const parsedObjects = objects.map((object) => {
|
|
159
|
+
const objectId = getObjectId(object);
|
|
160
|
+
const objectFields = getObjectFields(object) as ObjectFieldType;
|
|
161
|
+
const index = objectFields.name;
|
|
162
|
+
const key = objectFields.value;
|
|
163
|
+
return {
|
|
164
|
+
objectId,
|
|
165
|
+
index,
|
|
166
|
+
key,
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
return parsedObjects as EntityData[];
|
|
170
|
+
} catch (err) {
|
|
171
|
+
await delay(2000);
|
|
172
|
+
console.warn(
|
|
173
|
+
`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
throw new Error('Failed to get objects with all fullnodes');
|
|
178
|
+
}
|
|
132
179
|
|
|
133
|
-
async getDynamicFieldObject(
|
|
180
|
+
async getDynamicFieldObject(
|
|
181
|
+
parentId: string,
|
|
182
|
+
name: string | DynamicFieldName
|
|
183
|
+
) {
|
|
134
184
|
for (const provider of this.providers) {
|
|
135
185
|
try {
|
|
136
|
-
return provider.getDynamicFieldObject({ parentId, name })
|
|
186
|
+
return provider.getDynamicFieldObject({ parentId, name });
|
|
137
187
|
} catch (err) {
|
|
138
188
|
await delay(2000);
|
|
139
189
|
console.warn(
|
|
@@ -147,7 +197,7 @@ export class SuiInteractor {
|
|
|
147
197
|
async getDynamicFields(parentId: string, cursor?: string, limit?: number) {
|
|
148
198
|
for (const provider of this.providers) {
|
|
149
199
|
try {
|
|
150
|
-
return provider.getDynamicFields({ parentId, cursor, limit })
|
|
200
|
+
return provider.getDynamicFields({ parentId, cursor, limit });
|
|
151
201
|
} catch (err) {
|
|
152
202
|
await delay(2000);
|
|
153
203
|
console.warn(
|
|
@@ -172,12 +222,12 @@ export class SuiInteractor {
|
|
|
172
222
|
throw new Error('Failed to get objects with all fullnodes');
|
|
173
223
|
}
|
|
174
224
|
|
|
175
|
-
|
|
176
225
|
async getNormalizedMoveModulesByPackage(packageId: string) {
|
|
177
226
|
for (const provider of this.providers) {
|
|
178
227
|
try {
|
|
179
|
-
return provider.getNormalizedMoveModulesByPackage({
|
|
180
|
-
|
|
228
|
+
return provider.getNormalizedMoveModulesByPackage({
|
|
229
|
+
package: packageId,
|
|
230
|
+
});
|
|
181
231
|
} catch (err) {
|
|
182
232
|
await delay(2000);
|
|
183
233
|
console.warn(
|
package/src/obelisk.ts
CHANGED
|
@@ -30,9 +30,16 @@ import {
|
|
|
30
30
|
MapMoudleFuncQuery,
|
|
31
31
|
MapMoudleFuncTx,
|
|
32
32
|
FaucetNetworkType,
|
|
33
|
+
SuiReturnValues,
|
|
34
|
+
DynamicFieldContentType,
|
|
33
35
|
} from './types';
|
|
34
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
capitalizeFirstLetter,
|
|
38
|
+
normalizeHexAddress,
|
|
39
|
+
numberToAddressHex,
|
|
40
|
+
} from './utils';
|
|
35
41
|
import keccak256 from 'keccak256';
|
|
42
|
+
import { BCS, getSuiMoveConfig, fromHEX, fromB64, fromB58 } from '@mysten/bcs';
|
|
36
43
|
|
|
37
44
|
export function isUndefined(value?: unknown): value is undefined {
|
|
38
45
|
return value === undefined;
|
|
@@ -467,11 +474,137 @@ export class Obelisk {
|
|
|
467
474
|
const name = {
|
|
468
475
|
type: 'address',
|
|
469
476
|
value: componentIdValue,
|
|
470
|
-
// value: [250,208,186,160,39,171,62,206,98,224,138,41,11,217,63,100,248,104,207,64,78,126,43,109,129,68,64,127,236,113,152,132]
|
|
471
477
|
} as DynamicFieldName;
|
|
472
478
|
return await this.suiInteractor.getDynamicFieldObject(parentId, name);
|
|
473
479
|
}
|
|
474
480
|
|
|
481
|
+
async getComponentTable(worldId: string, componentName: string) {
|
|
482
|
+
let componentMoudleName = `${componentName}_comp`;
|
|
483
|
+
const tx = new TransactionBlock();
|
|
484
|
+
let params = [tx.pure(worldId)] as SuiTxArgument[];
|
|
485
|
+
|
|
486
|
+
const tableResult = (await this.query[componentMoudleName].data(
|
|
487
|
+
tx,
|
|
488
|
+
params
|
|
489
|
+
)) as DevInspectResults;
|
|
490
|
+
const tableId = tableResult.results as SuiReturnValues;
|
|
491
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
492
|
+
|
|
493
|
+
let value = Uint8Array.from(tableId[0].returnValues[0][0]);
|
|
494
|
+
let data = bcs.de('address', value);
|
|
495
|
+
return '0x' + data;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
async getEntities(
|
|
499
|
+
worldId: string,
|
|
500
|
+
componentName: string,
|
|
501
|
+
cursor?: string,
|
|
502
|
+
limit?: number
|
|
503
|
+
) {
|
|
504
|
+
let componentMoudleName = `${componentName}_comp`;
|
|
505
|
+
|
|
506
|
+
const tx = new TransactionBlock();
|
|
507
|
+
let params = [tx.pure(worldId)] as SuiTxArgument[];
|
|
508
|
+
|
|
509
|
+
const tableResult = (await this.query[componentMoudleName].entities(
|
|
510
|
+
tx,
|
|
511
|
+
params
|
|
512
|
+
)) as DevInspectResults;
|
|
513
|
+
const entities = tableResult.results as SuiReturnValues;
|
|
514
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
515
|
+
|
|
516
|
+
let value = Uint8Array.from(entities[0].returnValues[0][0]);
|
|
517
|
+
let tableId = '0x' + bcs.de('address', value);
|
|
518
|
+
let dynamicFields = await this.suiInteractor.getDynamicFields(
|
|
519
|
+
tableId,
|
|
520
|
+
cursor,
|
|
521
|
+
limit
|
|
522
|
+
);
|
|
523
|
+
let objectIds = dynamicFields.data.map((field) => field.objectId);
|
|
524
|
+
let objectDatas = await this.suiInteractor.getEntitiesObjects(objectIds);
|
|
525
|
+
return {
|
|
526
|
+
data: objectDatas,
|
|
527
|
+
nextCursor: dynamicFields.nextCursor,
|
|
528
|
+
hasNextPage: dynamicFields.hasNextPage,
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
async getEntity(worldId: string, componentName: string, entityId: string) {
|
|
533
|
+
let checkWorldId = normalizeHexAddress(worldId);
|
|
534
|
+
if (checkWorldId) {
|
|
535
|
+
worldId = checkWorldId;
|
|
536
|
+
} else {
|
|
537
|
+
return undefined;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
let checkEntityId = normalizeHexAddress(entityId);
|
|
541
|
+
if (checkEntityId) {
|
|
542
|
+
entityId = checkEntityId;
|
|
543
|
+
} else {
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const parentId = await this.getComponentTable(worldId, componentName);
|
|
548
|
+
const name = {
|
|
549
|
+
type: 'address',
|
|
550
|
+
value: entityId,
|
|
551
|
+
} as DynamicFieldName;
|
|
552
|
+
|
|
553
|
+
let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
|
|
554
|
+
parentId,
|
|
555
|
+
name
|
|
556
|
+
);
|
|
557
|
+
return dynamicFieldObject;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// async getEntityData(
|
|
561
|
+
// worldId: string,
|
|
562
|
+
// componentName: string,
|
|
563
|
+
// entityId: string
|
|
564
|
+
// ) {
|
|
565
|
+
// const parentId = await this.getComponentTable(worldId, componentName);
|
|
566
|
+
// const name = {
|
|
567
|
+
// type: 'address',
|
|
568
|
+
// value: entityId,
|
|
569
|
+
// } as DynamicFieldName;
|
|
570
|
+
|
|
571
|
+
// let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
|
|
572
|
+
// parentId,
|
|
573
|
+
// name
|
|
574
|
+
// );
|
|
575
|
+
// let componentMoudleName = `${componentName}_comp`;
|
|
576
|
+
|
|
577
|
+
// const tx = new TransactionBlock();
|
|
578
|
+
// let params = [] as SuiTxArgument[];
|
|
579
|
+
|
|
580
|
+
// const typeResult = (await this.query[componentMoudleName].types(
|
|
581
|
+
// tx,
|
|
582
|
+
// params
|
|
583
|
+
// )) as DevInspectResults;
|
|
584
|
+
// let typeReturn = typeResult.results as SuiReturnValues;
|
|
585
|
+
// console.log(typeReturn[0].returnValues[0][0]);
|
|
586
|
+
|
|
587
|
+
// const typeBCS = new BCS(getSuiMoveConfig());
|
|
588
|
+
// let typeValue = Uint8Array.from(typeReturn[0].returnValues[0][0]);
|
|
589
|
+
|
|
590
|
+
// let typeData = typeBCS.de('vector<vector<u8>>', typeValue);
|
|
591
|
+
// console.log(typeData);
|
|
592
|
+
// const entityType = String.fromCharCode(...typeData[0]);
|
|
593
|
+
|
|
594
|
+
// let dynamicFieldContent = dynamicFieldObject.data!
|
|
595
|
+
// .content as DynamicFieldContentType;
|
|
596
|
+
|
|
597
|
+
// let entityValue = dynamicFieldContent.fields['value'];
|
|
598
|
+
// const bcs = new BCS(getSuiMoveConfig());
|
|
599
|
+
// let value = Uint8Array.from(entityValue);
|
|
600
|
+
// console.log(entityType);
|
|
601
|
+
// console.log(value);
|
|
602
|
+
|
|
603
|
+
// let data = bcs.de(entityType, value);
|
|
604
|
+
// console.log(data);
|
|
605
|
+
// return data;
|
|
606
|
+
// }
|
|
607
|
+
|
|
475
608
|
async getOwnedObjects(owner: SuiAddress, cursor?: string, limit?: number) {
|
|
476
609
|
const ownedObjects = await this.suiInteractor.getOwnedObjects(
|
|
477
610
|
owner,
|
|
@@ -493,4 +626,33 @@ export class Obelisk {
|
|
|
493
626
|
|
|
494
627
|
return ownedObjectsRes;
|
|
495
628
|
}
|
|
629
|
+
|
|
630
|
+
async entity_key_from_object(objectId: string) {
|
|
631
|
+
let checkObjectId = normalizeHexAddress(objectId);
|
|
632
|
+
if (checkObjectId !== null) {
|
|
633
|
+
objectId = checkObjectId;
|
|
634
|
+
return objectId;
|
|
635
|
+
} else {
|
|
636
|
+
return undefined;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
async entity_key_from_bytes(bytes: Uint8Array | Buffer | string) {
|
|
641
|
+
let hashBytes = keccak256(bytes);
|
|
642
|
+
const hashU8Array: number[] = Array.from(hashBytes);
|
|
643
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
644
|
+
let value = Uint8Array.from(hashU8Array);
|
|
645
|
+
let data = bcs.de('address', value);
|
|
646
|
+
return '0x' + data;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
async entity_key_from_u256(x: number) {
|
|
650
|
+
return numberToAddressHex(x);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
async formatData(type: string, value: Buffer | number[] | Uint8Array) {
|
|
654
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
655
|
+
let u8Value = Uint8Array.from(value);
|
|
656
|
+
return bcs.de(type, u8Value);
|
|
657
|
+
}
|
|
496
658
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -9,12 +9,13 @@ import {
|
|
|
9
9
|
TransactionBlock,
|
|
10
10
|
SuiTransactionBlockResponse,
|
|
11
11
|
DevInspectResults,
|
|
12
|
-
SuiMoveNormalizedModules
|
|
12
|
+
SuiMoveNormalizedModules,
|
|
13
13
|
} from '@mysten/sui.js';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
import {
|
|
16
|
+
SuiMoveMoudleValueType,
|
|
17
|
+
SuiMoveMoudleFuncType,
|
|
18
|
+
} from '../libs/suiContractFactory/types';
|
|
18
19
|
|
|
19
20
|
export type ObeliskObjectData = {
|
|
20
21
|
objectId: string;
|
|
@@ -24,73 +25,79 @@ export type ObeliskObjectData = {
|
|
|
24
25
|
objectFields: ObjectContentFields;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
|
|
28
28
|
export type ObeliskParams = {
|
|
29
29
|
mnemonics?: string;
|
|
30
30
|
secretKey?: string;
|
|
31
31
|
fullnodeUrls?: string[];
|
|
32
32
|
faucetUrl?: string;
|
|
33
33
|
networkType?: NetworkType;
|
|
34
|
-
packageId?: string
|
|
35
|
-
metadata?: SuiMoveNormalizedModules
|
|
34
|
+
packageId?: string;
|
|
35
|
+
metadata?: SuiMoveNormalizedModules;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export type ComponentFieldType = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
39
|
+
components: {
|
|
40
|
+
type: string;
|
|
41
|
+
fields: {
|
|
42
|
+
id: {
|
|
43
|
+
id: string;
|
|
44
|
+
};
|
|
45
|
+
size: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
49
|
|
|
50
50
|
export type ComponentValueType = {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
id: {
|
|
52
|
+
id: string;
|
|
53
|
+
};
|
|
54
|
+
name: string;
|
|
55
|
+
value: {
|
|
56
|
+
type: string;
|
|
57
|
+
fields: ComponentFieldType;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type SuiTxArgument =
|
|
62
|
+
| {
|
|
63
|
+
kind: 'Input';
|
|
64
|
+
index: number;
|
|
65
|
+
type?: 'object' | 'pure' | undefined;
|
|
66
|
+
value?: any;
|
|
53
67
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
type: string;
|
|
57
|
-
fields: ComponentFieldType;
|
|
68
|
+
| {
|
|
69
|
+
kind: 'GasCoin';
|
|
58
70
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
kind: "GasCoin";
|
|
69
|
-
} | {
|
|
70
|
-
kind: "Result";
|
|
71
|
-
index: number;
|
|
72
|
-
} | {
|
|
73
|
-
kind: "NestedResult";
|
|
74
|
-
index: number;
|
|
75
|
-
resultIndex: number;
|
|
76
|
-
}
|
|
71
|
+
| {
|
|
72
|
+
kind: 'Result';
|
|
73
|
+
index: number;
|
|
74
|
+
}
|
|
75
|
+
| {
|
|
76
|
+
kind: 'NestedResult';
|
|
77
|
+
index: number;
|
|
78
|
+
resultIndex: number;
|
|
79
|
+
};
|
|
77
80
|
export type ComponentContentType = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
81
|
+
type: string;
|
|
82
|
+
fields: ComponentValueType;
|
|
83
|
+
hasPublicTransfer: boolean;
|
|
84
|
+
dataType: 'moveObject';
|
|
85
|
+
};
|
|
83
86
|
|
|
84
87
|
export interface MessageMeta {
|
|
85
88
|
readonly meta: SuiMoveMoudleFuncType;
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
export interface ContractQuery extends MessageMeta {
|
|
89
|
-
(tx: TransactionBlock, params: SuiTxArgument[], isRaw?: boolean): Promise<
|
|
92
|
+
(tx: TransactionBlock, params: SuiTxArgument[], isRaw?: boolean): Promise<
|
|
93
|
+
DevInspectResults | TransactionBlock
|
|
94
|
+
>;
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
export interface ContractTx extends MessageMeta {
|
|
93
|
-
(tx: TransactionBlock, params: SuiTxArgument[], isRaw?: boolean):
|
|
98
|
+
(tx: TransactionBlock, params: SuiTxArgument[], isRaw?: boolean):
|
|
99
|
+
| SuiTransactionBlockResponse
|
|
100
|
+
| TransactionBlock;
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
export type MapMessageTx = Record<string, ContractTx>;
|
|
@@ -102,8 +109,6 @@ export type MapMoudleFuncQuery = Record<string, MapMessageQuery>;
|
|
|
102
109
|
export type MapMoudleFuncTest = Record<string, Record<string, string>>;
|
|
103
110
|
export type MapMoudleFuncQueryTest = Record<string, Record<string, string>>;
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
112
|
export type AccountMangerParams = {
|
|
108
113
|
mnemonics?: string;
|
|
109
114
|
secretKey?: string;
|
|
@@ -116,7 +121,7 @@ export type DerivePathParams = {
|
|
|
116
121
|
};
|
|
117
122
|
|
|
118
123
|
export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
119
|
-
export type FaucetNetworkType = 'testnet' | 'devnet' | 'localnet'
|
|
124
|
+
export type FaucetNetworkType = 'testnet' | 'devnet' | 'localnet';
|
|
120
125
|
|
|
121
126
|
export type SuiKitParams = {
|
|
122
127
|
mnemonics?: string;
|
|
@@ -136,7 +141,19 @@ export type ObjectData = {
|
|
|
136
141
|
objectFields: ObjectContentFields;
|
|
137
142
|
};
|
|
138
143
|
|
|
144
|
+
export type ObjectFieldType = {
|
|
145
|
+
id: {
|
|
146
|
+
id: string;
|
|
147
|
+
};
|
|
148
|
+
name: string;
|
|
149
|
+
value: string;
|
|
150
|
+
};
|
|
139
151
|
|
|
152
|
+
export type EntityData = {
|
|
153
|
+
objectId: string;
|
|
154
|
+
index: string;
|
|
155
|
+
key: string;
|
|
156
|
+
};
|
|
140
157
|
|
|
141
158
|
export type SuiTxArg =
|
|
142
159
|
| Infer<typeof TransactionArgument>
|
|
@@ -171,3 +188,14 @@ export type SuiBasicTypes =
|
|
|
171
188
|
| 'u256';
|
|
172
189
|
|
|
173
190
|
export type SuiInputTypes = 'object' | SuiBasicTypes;
|
|
191
|
+
|
|
192
|
+
export type SuiReturnValues = {
|
|
193
|
+
returnValues: [number[], string][];
|
|
194
|
+
}[];
|
|
195
|
+
|
|
196
|
+
export type DynamicFieldContentType = {
|
|
197
|
+
type: string;
|
|
198
|
+
fields: Record<string, any>;
|
|
199
|
+
hasPublicTransfer: boolean;
|
|
200
|
+
dataType: string;
|
|
201
|
+
};
|
package/src/utils/index.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
export function capitalizeFirstLetter(input: string): string {
|
|
2
|
-
|
|
2
|
+
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function normalizeHexAddress(input: string): string | null {
|
|
6
|
+
const hexRegex = /^(0x)?[0-9a-fA-F]{64}$/;
|
|
7
|
+
|
|
8
|
+
if (hexRegex.test(input)) {
|
|
9
|
+
if (input.startsWith('0x')) {
|
|
10
|
+
return input;
|
|
11
|
+
} else {
|
|
12
|
+
return '0x' + input;
|
|
13
|
+
}
|
|
14
|
+
} else {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function numberToAddressHex(num: number): string {
|
|
20
|
+
const hex = num.toString(16);
|
|
21
|
+
const paddedHex = '0x' + hex.padStart(64, '0');
|
|
22
|
+
return paddedHex;
|
|
3
23
|
}
|