@0xobelisk/sui-cli 1.2.0-pre.21 → 1.2.0-pre.24
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/dubhe.js +46 -46
- package/dist/dubhe.js.map +1 -1
- package/package.json +4 -3
- package/src/commands/build.ts +2 -1
- package/src/commands/call.ts +83 -83
- package/src/commands/convertJson.ts +49 -0
- package/src/commands/doctor.ts +348 -0
- package/src/commands/index.ts +10 -7
- package/src/commands/loadMetadata.ts +50 -0
- package/src/commands/localnode.ts +19 -5
- package/src/commands/publish.ts +3 -1
- package/src/commands/query.ts +101 -101
- package/src/commands/schemagen.ts +4 -1
- package/src/commands/upgrade.ts +38 -38
- package/src/dubhe.ts +7 -7
- package/src/utils/callHandler.ts +118 -118
- package/src/utils/index.ts +2 -2
- package/src/utils/metadataHandler.ts +16 -0
- package/src/utils/publishHandler.ts +82 -266
- package/src/utils/queryStorage.ts +141 -141
- package/src/utils/startNode.ts +113 -16
- package/src/utils/storeConfig.ts +5 -11
- package/src/utils/upgradeHandler.ts +250 -250
- package/src/utils/utils.ts +161 -21
package/src/utils/utils.ts
CHANGED
|
@@ -6,18 +6,19 @@ import { FsIibError } from './errors';
|
|
|
6
6
|
import * as fs from 'fs';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import { spawn } from 'child_process';
|
|
9
|
-
import { Dubhe, NetworkType, SuiMoveNormalizedModules } from '@0xobelisk/sui-client';
|
|
9
|
+
import { Dubhe, NetworkType, SuiMoveNormalizedModules, loadMetadata } from '@0xobelisk/sui-client';
|
|
10
10
|
import { DubheCliError } from './errors';
|
|
11
11
|
import packageJson from '../../package.json';
|
|
12
|
+
import { Component, MoveType, EmptyComponent, DubheConfig } from '@0xobelisk/sui-common';
|
|
12
13
|
|
|
13
14
|
export type DeploymentJsonType = {
|
|
14
15
|
projectName: string;
|
|
15
16
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
16
17
|
packageId: string;
|
|
17
|
-
|
|
18
|
+
dappHub: string;
|
|
18
19
|
upgradeCap: string;
|
|
19
20
|
version: number;
|
|
20
|
-
|
|
21
|
+
components: Record<string, Component | MoveType | EmptyComponent>;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
export function validatePrivateKey(privateKey: string): false | string {
|
|
@@ -76,43 +77,43 @@ export async function getDeploymentJson(
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
export async function
|
|
80
|
+
export async function getDeploymentDappHub(projectPath: string, network: string): Promise<string> {
|
|
80
81
|
try {
|
|
81
82
|
const data = await fsAsync.readFile(
|
|
82
83
|
`${projectPath}/.history/sui_${network}/latest.json`,
|
|
83
84
|
'utf8'
|
|
84
85
|
);
|
|
85
86
|
const deployment = JSON.parse(data) as DeploymentJsonType;
|
|
86
|
-
return deployment.
|
|
87
|
+
return deployment.dappHub;
|
|
87
88
|
} catch (error) {
|
|
88
89
|
return '';
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
export async function
|
|
93
|
+
export async function getDubheDappHub(network: string) {
|
|
93
94
|
const path = process.cwd();
|
|
94
95
|
const contractPath = `${path}/src/dubhe`;
|
|
95
96
|
|
|
96
97
|
switch (network) {
|
|
97
98
|
case 'mainnet':
|
|
98
|
-
return await
|
|
99
|
+
return await getDeploymentDappHub(contractPath, 'mainnet');
|
|
99
100
|
case 'testnet':
|
|
100
|
-
return await
|
|
101
|
+
return await getDeploymentDappHub(contractPath, 'testnet');
|
|
101
102
|
case 'devnet':
|
|
102
|
-
return await
|
|
103
|
+
return await getDeploymentDappHub(contractPath, 'devnet');
|
|
103
104
|
case 'localnet':
|
|
104
|
-
return await
|
|
105
|
+
return await getDeploymentDappHub(contractPath, 'localnet');
|
|
105
106
|
default:
|
|
106
107
|
throw new Error(`Invalid network: ${network}`);
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
export async function
|
|
111
|
+
export async function getOnchainComponents(
|
|
111
112
|
projectPath: string,
|
|
112
113
|
network: string
|
|
113
|
-
): Promise<Record<string,
|
|
114
|
+
): Promise<Record<string, Component | MoveType | EmptyComponent>> {
|
|
114
115
|
const deployment = await getDeploymentJson(projectPath, network);
|
|
115
|
-
return deployment.
|
|
116
|
+
return deployment.components;
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
export async function getVersion(projectPath: string, network: string): Promise<number> {
|
|
@@ -133,9 +134,9 @@ export async function getOldPackageId(projectPath: string, network: string): Pro
|
|
|
133
134
|
return deployment.packageId;
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
export async function
|
|
137
|
+
export async function getDappHub(projectPath: string, network: string): Promise<string> {
|
|
137
138
|
const deployment = await getDeploymentJson(projectPath, network);
|
|
138
|
-
return deployment.
|
|
139
|
+
return deployment.dappHub;
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
export async function getUpgradeCap(projectPath: string, network: string): Promise<string> {
|
|
@@ -143,34 +144,62 @@ export async function getUpgradeCap(projectPath: string, network: string): Promi
|
|
|
143
144
|
return deployment.upgradeCap;
|
|
144
145
|
}
|
|
145
146
|
|
|
146
|
-
export function saveContractData(
|
|
147
|
+
export async function saveContractData(
|
|
147
148
|
projectName: string,
|
|
148
149
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
149
150
|
packageId: string,
|
|
150
|
-
|
|
151
|
+
dappHub: string,
|
|
151
152
|
upgradeCap: string,
|
|
152
153
|
version: number,
|
|
153
|
-
|
|
154
|
+
components: Record<string, Component | MoveType | EmptyComponent>
|
|
154
155
|
) {
|
|
155
156
|
const DeploymentData: DeploymentJsonType = {
|
|
156
157
|
projectName,
|
|
157
158
|
network,
|
|
158
159
|
packageId,
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
dappHub,
|
|
161
|
+
components,
|
|
161
162
|
upgradeCap,
|
|
162
163
|
version
|
|
163
164
|
};
|
|
164
165
|
|
|
165
166
|
const path = process.cwd();
|
|
166
167
|
const storeDeploymentData = JSON.stringify(DeploymentData, null, 2);
|
|
167
|
-
writeOutput(
|
|
168
|
+
await writeOutput(
|
|
168
169
|
storeDeploymentData,
|
|
169
170
|
`${path}/src/${projectName}/.history/sui_${network}/latest.json`,
|
|
170
171
|
'Update deploy log'
|
|
171
172
|
);
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
export async function saveMetadata(
|
|
176
|
+
projectName: string,
|
|
177
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
178
|
+
packageId: string
|
|
179
|
+
) {
|
|
180
|
+
const path = process.cwd();
|
|
181
|
+
|
|
182
|
+
// Save metadata files
|
|
183
|
+
try {
|
|
184
|
+
const metadata = await loadMetadata(network, packageId);
|
|
185
|
+
if (metadata) {
|
|
186
|
+
const metadataJson = JSON.stringify(metadata, null, 2);
|
|
187
|
+
|
|
188
|
+
// Save packageId-specific metadata file
|
|
189
|
+
await writeOutput(
|
|
190
|
+
metadataJson,
|
|
191
|
+
`${path}/src/${projectName}/.history/sui_${network}/${packageId}.json`,
|
|
192
|
+
'Save package metadata'
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// Save latest metadata.json
|
|
196
|
+
await writeOutput(metadataJson, `${path}/metadata.json`, 'Save latest metadata');
|
|
197
|
+
}
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.warn(chalk.yellow(`Warning: Failed to save metadata: ${error}`));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
174
203
|
export async function writeOutput(
|
|
175
204
|
output: string,
|
|
176
205
|
fullOutputPath: string,
|
|
@@ -387,3 +416,114 @@ export function initializeDubhe({
|
|
|
387
416
|
metadata
|
|
388
417
|
});
|
|
389
418
|
}
|
|
419
|
+
|
|
420
|
+
export function generateConfigJson(config: DubheConfig): string {
|
|
421
|
+
const components = Object.entries(config.components).map(([name, component]) => {
|
|
422
|
+
if (typeof component === 'string') {
|
|
423
|
+
return {
|
|
424
|
+
[name]: {
|
|
425
|
+
fields: [
|
|
426
|
+
{ entity_id: 'address' },
|
|
427
|
+
{ value: component }
|
|
428
|
+
],
|
|
429
|
+
keys: ['entity_id']
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (Object.keys(component as object).length === 0) {
|
|
435
|
+
return {
|
|
436
|
+
[name]: {
|
|
437
|
+
fields: [
|
|
438
|
+
{ entity_id: 'address' }
|
|
439
|
+
],
|
|
440
|
+
keys: ['entity_id']
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const fields = (component as any).fields || {};
|
|
446
|
+
const keys = (component as any).keys || ['entity_id'];
|
|
447
|
+
|
|
448
|
+
// ensure entity_id field exists
|
|
449
|
+
if (!fields.entity_id && keys.includes('entity_id')) {
|
|
450
|
+
fields.entity_id = 'address';
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return {
|
|
454
|
+
[name]: {
|
|
455
|
+
fields: Object.entries(fields).map(([fieldName, fieldType]) => ({
|
|
456
|
+
[fieldName]: fieldType
|
|
457
|
+
})),
|
|
458
|
+
keys: keys
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
const resources = Object.entries(config.resources).map(([name, resource]) => {
|
|
464
|
+
if (typeof resource === 'string') {
|
|
465
|
+
return {
|
|
466
|
+
[name]: {
|
|
467
|
+
fields: [
|
|
468
|
+
{ value: resource }
|
|
469
|
+
],
|
|
470
|
+
keys: []
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (Object.keys(resource as object).length === 0) {
|
|
476
|
+
return {
|
|
477
|
+
[name]: {
|
|
478
|
+
fields: [],
|
|
479
|
+
keys: []
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const fields = (resource as any).fields || {};
|
|
485
|
+
const keys = (resource as any).keys || [];
|
|
486
|
+
|
|
487
|
+
return {
|
|
488
|
+
[name]: {
|
|
489
|
+
fields: Object.entries(fields).map(([fieldName, fieldType]) => ({
|
|
490
|
+
[fieldName]: fieldType
|
|
491
|
+
})),
|
|
492
|
+
keys: keys
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// handle enums
|
|
498
|
+
const enums = Object.entries(config.enums || {}).map(([name, enumFields]) => {
|
|
499
|
+
// Sort enum values by first letter
|
|
500
|
+
let sortedFields = enumFields.sort((a, b) => a.localeCompare(b)).map((value, index) => ({
|
|
501
|
+
[index]: value
|
|
502
|
+
}));
|
|
503
|
+
|
|
504
|
+
return {
|
|
505
|
+
[name]: {
|
|
506
|
+
fields: sortedFields
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
return JSON.stringify({
|
|
512
|
+
components,
|
|
513
|
+
resources,
|
|
514
|
+
enums
|
|
515
|
+
}, null, 2);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Updates the dubhe address in Move.toml file
|
|
520
|
+
* @param path - Directory path containing Move.toml file
|
|
521
|
+
* @param packageAddress - New dubhe package address to set
|
|
522
|
+
*/
|
|
523
|
+
export function updateMoveTomlAddress(path: string, packageAddress: string) {
|
|
524
|
+
const moveTomlPath = `${path}/Move.toml`;
|
|
525
|
+
const moveTomlContent = fs.readFileSync(moveTomlPath, 'utf-8');
|
|
526
|
+
// Use regex to match any dubhe address, not just "0x0"
|
|
527
|
+
const updatedContent = moveTomlContent.replace(/dubhe\s*=\s*"[^"]*"/, `dubhe = "${packageAddress}"`);
|
|
528
|
+
fs.writeFileSync(moveTomlPath, updatedContent, 'utf-8');
|
|
529
|
+
}
|