@0xobelisk/sui-cli 1.2.0-pre.22 → 1.2.0-pre.25
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
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import { loadMetadata } from '@0xobelisk/sui-client';
|
|
2
|
-
import { DubheCliError } from './errors';
|
|
3
|
-
import { getOldPackageId, getSchemaId, initializeDubhe } from './utils';
|
|
4
|
-
import { DubheConfig } from '@0xobelisk/sui-common';
|
|
5
|
-
import * as fs from 'fs';
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
|
|
8
|
-
function validateParams(storageType: string, params: any[]): boolean {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function getExpectedParamsCount(storageType: string): number {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function queryStorage({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
export async function loadMetadataFromFile(metadataFilePath: string) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
1
|
+
// import { loadMetadata } from '@0xobelisk/sui-client';
|
|
2
|
+
// import { DubheCliError } from './errors';
|
|
3
|
+
// import { getOldPackageId, getSchemaId, initializeDubhe } from './utils';
|
|
4
|
+
// import { DubheConfig } from '@0xobelisk/sui-common';
|
|
5
|
+
// import * as fs from 'fs';
|
|
6
|
+
// import * as path from 'path';
|
|
7
|
+
|
|
8
|
+
// function validateParams(storageType: string, params: any[]): boolean {
|
|
9
|
+
// const formatStorageType = storageType.split('<')[0].trim();
|
|
10
|
+
// switch (formatStorageType) {
|
|
11
|
+
// case 'StorageValue':
|
|
12
|
+
// return params.length === 0;
|
|
13
|
+
// case 'StorageMap':
|
|
14
|
+
// return params.length === 1;
|
|
15
|
+
// case 'StorageDoubleMap':
|
|
16
|
+
// return params.length === 2;
|
|
17
|
+
// default:
|
|
18
|
+
// return false;
|
|
19
|
+
// }
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
// function getExpectedParamsCount(storageType: string): number {
|
|
23
|
+
// const formatStorageType = storageType.split('<')[0].trim();
|
|
24
|
+
// switch (formatStorageType) {
|
|
25
|
+
// case 'StorageValue':
|
|
26
|
+
// return 0;
|
|
27
|
+
// case 'StorageMap':
|
|
28
|
+
// return 1;
|
|
29
|
+
// case 'StorageDoubleMap':
|
|
30
|
+
// return 2;
|
|
31
|
+
// default:
|
|
32
|
+
// return 0;
|
|
33
|
+
// }
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// export async function queryStorage({
|
|
37
|
+
// dubheConfig,
|
|
38
|
+
// schema,
|
|
39
|
+
// params,
|
|
40
|
+
// network,
|
|
41
|
+
// objectId,
|
|
42
|
+
// packageId,
|
|
43
|
+
// metadataFilePath
|
|
44
|
+
// }: {
|
|
45
|
+
// dubheConfig: DubheConfig;
|
|
46
|
+
// schema: string;
|
|
47
|
+
// params?: any[];
|
|
48
|
+
// network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
49
|
+
// objectId?: string;
|
|
50
|
+
// packageId?: string;
|
|
51
|
+
// metadataFilePath?: string;
|
|
52
|
+
// }) {
|
|
53
|
+
// const path = process.cwd();
|
|
54
|
+
// const projectPath = `${path}/src/${dubheConfig.name}`;
|
|
55
|
+
|
|
56
|
+
// packageId = packageId || (await getOldPackageId(projectPath, network));
|
|
57
|
+
|
|
58
|
+
// objectId = objectId || (await getSchemaId(projectPath, network));
|
|
59
|
+
|
|
60
|
+
// let metadata;
|
|
61
|
+
// if (metadataFilePath) {
|
|
62
|
+
// metadata = await loadMetadataFromFile(metadataFilePath);
|
|
63
|
+
// } else {
|
|
64
|
+
// metadata = await loadMetadata(network, packageId);
|
|
65
|
+
// }
|
|
66
|
+
// if (!metadata) {
|
|
67
|
+
// throw new DubheCliError(
|
|
68
|
+
// `Metadata file not found. Please provide a metadata file path or set the packageId.`
|
|
69
|
+
// );
|
|
70
|
+
// }
|
|
71
|
+
|
|
72
|
+
// if (!dubheConfig.schemas[schema]) {
|
|
73
|
+
// throw new DubheCliError(
|
|
74
|
+
// `Schema "${schema}" not found in dubhe config. Available schemas: ${Object.keys(
|
|
75
|
+
// dubheConfig.schemas
|
|
76
|
+
// ).join(', ')}`
|
|
77
|
+
// );
|
|
78
|
+
// }
|
|
79
|
+
|
|
80
|
+
// const storageType = dubheConfig.schemas[schema];
|
|
81
|
+
|
|
82
|
+
// const processedParams = params || [];
|
|
83
|
+
// if (!validateParams(storageType, processedParams)) {
|
|
84
|
+
// throw new Error(
|
|
85
|
+
// `Invalid params count for ${storageType}. ` +
|
|
86
|
+
// `Expected: ${getExpectedParamsCount(storageType)}, ` +
|
|
87
|
+
// `Got: ${processedParams.length}`
|
|
88
|
+
// );
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
// const dubhe = initializeDubhe({
|
|
92
|
+
// network,
|
|
93
|
+
// packageId,
|
|
94
|
+
// metadata
|
|
95
|
+
// });
|
|
96
|
+
// const result = await dubhe.parseState({
|
|
97
|
+
// schema,
|
|
98
|
+
// objectId,
|
|
99
|
+
// storageType,
|
|
100
|
+
// params: processedParams
|
|
101
|
+
// });
|
|
102
|
+
|
|
103
|
+
// console.log(result);
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
// /**
|
|
107
|
+
// * Load metadata from a JSON file and construct the metadata structure
|
|
108
|
+
// * @param metadataFilePath Path to the metadata JSON file
|
|
109
|
+
// * @param network Network type
|
|
110
|
+
// * @param packageId Package ID
|
|
111
|
+
// * @returns Constructed metadata object
|
|
112
|
+
// */
|
|
113
|
+
// export async function loadMetadataFromFile(metadataFilePath: string) {
|
|
114
|
+
// // Verify file extension is .json
|
|
115
|
+
// if (path.extname(metadataFilePath) !== '.json') {
|
|
116
|
+
// throw new Error('Metadata file must be in JSON format');
|
|
117
|
+
// }
|
|
118
|
+
|
|
119
|
+
// try {
|
|
120
|
+
// // Read JSON file content
|
|
121
|
+
// const rawData = fs.readFileSync(metadataFilePath, 'utf8');
|
|
122
|
+
// const jsonData = JSON.parse(rawData);
|
|
123
|
+
|
|
124
|
+
// // Validate JSON structure
|
|
125
|
+
// if (!jsonData || typeof jsonData !== 'object') {
|
|
126
|
+
// throw new Error('Invalid JSON format');
|
|
127
|
+
// }
|
|
128
|
+
|
|
129
|
+
// // Construct metadata structure
|
|
130
|
+
// const metadata = {
|
|
131
|
+
// ...jsonData
|
|
132
|
+
// };
|
|
133
|
+
|
|
134
|
+
// return metadata;
|
|
135
|
+
// } catch (error) {
|
|
136
|
+
// if (error instanceof Error) {
|
|
137
|
+
// throw new Error(`Failed to read metadata file: ${error.message}`);
|
|
138
|
+
// }
|
|
139
|
+
// throw error;
|
|
140
|
+
// }
|
|
141
|
+
// }
|
package/src/utils/startNode.ts
CHANGED
|
@@ -3,18 +3,104 @@ import chalk from 'chalk';
|
|
|
3
3
|
import { printDubhe } from './printDubhe';
|
|
4
4
|
import { delay, DubheCliError, validatePrivateKey } from '../utils';
|
|
5
5
|
import { Dubhe } from '@0xobelisk/sui-client';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
|
|
8
|
+
export function stopLocalNode(): void {
|
|
9
|
+
console.log(chalk.yellow('🔔 Stopping existing Local Node...'));
|
|
10
|
+
|
|
11
|
+
let processStopped = false;
|
|
12
|
+
|
|
13
|
+
if (process.platform === 'win32') {
|
|
14
|
+
// Windows: Kill all sui.exe processes
|
|
15
|
+
try {
|
|
16
|
+
execSync('taskkill /F /IM sui.exe', { stdio: 'ignore' });
|
|
17
|
+
processStopped = true;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
// Process not found
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
// Unix-like systems: Try multiple patterns to find sui processes
|
|
23
|
+
const patterns = [
|
|
24
|
+
'sui start', // Exact match
|
|
25
|
+
'sui.*start', // Pattern with any flags
|
|
26
|
+
'^sui', // Any sui command
|
|
27
|
+
'sui.*--with-faucet' // Match our specific startup pattern
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
for (const pattern of patterns) {
|
|
31
|
+
try {
|
|
32
|
+
const result = execSync(`pgrep -f "${pattern}"`, { stdio: 'pipe' }).toString().trim();
|
|
33
|
+
if (result) {
|
|
34
|
+
const pids = result.split('\n').filter((pid) => pid);
|
|
35
|
+
console.log(chalk.cyan(` ├─ Found ${pids.length} process(es) matching "${pattern}"`));
|
|
36
|
+
|
|
37
|
+
pids.forEach((pid) => {
|
|
38
|
+
try {
|
|
39
|
+
// First try graceful termination
|
|
40
|
+
execSync(`kill -TERM ${pid}`, { stdio: 'ignore' });
|
|
41
|
+
console.log(chalk.cyan(` ├─ Sent SIGTERM to process ${pid}`));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
// If graceful termination fails, force kill
|
|
44
|
+
try {
|
|
45
|
+
execSync(`kill -KILL ${pid}`, { stdio: 'ignore' });
|
|
46
|
+
console.log(chalk.cyan(` ├─ Force killed process ${pid}`));
|
|
47
|
+
} catch (killError) {
|
|
48
|
+
console.log(chalk.gray(` ├─ Process ${pid} already terminated`));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
processStopped = true;
|
|
53
|
+
break; // Stop after first successful pattern match
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
// This pattern didn't match any processes, continue to next pattern
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (processStopped) {
|
|
63
|
+
console.log(chalk.green(' └─ Local Node stopped successfully'));
|
|
64
|
+
} else {
|
|
65
|
+
console.log(chalk.gray(' └─ No running Local Node found'));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function removeDirectory(dirPath: string): void {
|
|
70
|
+
try {
|
|
71
|
+
if (fs.existsSync(dirPath)) {
|
|
72
|
+
console.log(chalk.yellow(`🗑️ Removing directory: ${dirPath}`));
|
|
73
|
+
fs.rmSync(dirPath, { recursive: true, force: true });
|
|
74
|
+
console.log(chalk.green(' └─ Directory removed successfully'));
|
|
75
|
+
} else {
|
|
76
|
+
console.log(chalk.gray(` └─ Directory ${dirPath} does not exist`));
|
|
77
|
+
}
|
|
78
|
+
} catch (error: any) {
|
|
79
|
+
console.error(chalk.red(` └─ Error removing directory: ${error.message}`));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
6
82
|
|
|
7
83
|
function isSuiStartRunning(): boolean {
|
|
8
84
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
85
|
+
if (process.platform === 'win32') {
|
|
86
|
+
const result = execSync(`tasklist /FI "IMAGENAME eq sui.exe" /FO CSV /NH`).toString().trim();
|
|
87
|
+
return result.toLowerCase().includes('sui.exe');
|
|
88
|
+
} else {
|
|
89
|
+
// Try multiple patterns to detect running sui processes
|
|
90
|
+
const patterns = ['sui start', 'sui.*start', '^sui', 'sui.*--with-faucet'];
|
|
91
|
+
|
|
92
|
+
for (const pattern of patterns) {
|
|
93
|
+
try {
|
|
94
|
+
const result = execSync(`pgrep -f "${pattern}"`, { stdio: 'pipe' }).toString().trim();
|
|
95
|
+
if (result && result.length > 0) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
18
104
|
} catch (error) {
|
|
19
105
|
return false;
|
|
20
106
|
}
|
|
@@ -78,8 +164,15 @@ function handleProcessSignals(suiProcess: ReturnType<typeof spawn> | null) {
|
|
|
78
164
|
process.on('SIGTERM', cleanup);
|
|
79
165
|
}
|
|
80
166
|
|
|
81
|
-
export async function startLocalNode() {
|
|
82
|
-
if (
|
|
167
|
+
export async function startLocalNode(data_dir: string, force?: boolean) {
|
|
168
|
+
if (force) {
|
|
169
|
+
console.log(chalk.cyan('\n🔄 Force mode enabled'));
|
|
170
|
+
stopLocalNode();
|
|
171
|
+
console.log(chalk.yellow(' ├─ Waiting for processes to terminate...'));
|
|
172
|
+
await delay(3000); // Wait longer for process to fully stop
|
|
173
|
+
removeDirectory(data_dir);
|
|
174
|
+
console.log('');
|
|
175
|
+
} else if (isSuiStartRunning()) {
|
|
83
176
|
console.log(chalk.yellow('\n⚠️ Warning: Local Node Already Running'));
|
|
84
177
|
console.log(chalk.yellow(' ├─ Cannot start a new instance'));
|
|
85
178
|
console.log(chalk.yellow(' └─ Please stop the existing process first'));
|
|
@@ -90,10 +183,14 @@ export async function startLocalNode() {
|
|
|
90
183
|
console.log('🚀 Starting Local Node...');
|
|
91
184
|
let suiProcess: ReturnType<typeof spawn> | null = null;
|
|
92
185
|
try {
|
|
93
|
-
suiProcess = spawn(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
186
|
+
suiProcess = spawn(
|
|
187
|
+
'sui',
|
|
188
|
+
['start', '--with-faucet', '--force-regenesis', '--data-ingestion-dir', data_dir],
|
|
189
|
+
{
|
|
190
|
+
env: { ...process.env, RUST_LOG: 'off,sui_node=info' },
|
|
191
|
+
stdio: 'ignore'
|
|
192
|
+
}
|
|
193
|
+
);
|
|
97
194
|
|
|
98
195
|
suiProcess.on('error', (error) => {
|
|
99
196
|
console.error(chalk.red('\n❌ Failed to Start Local Node'));
|
|
@@ -131,4 +228,4 @@ export async function startLocalNode() {
|
|
|
131
228
|
}
|
|
132
229
|
process.exit(1);
|
|
133
230
|
}
|
|
134
|
-
}
|
|
231
|
+
}
|
package/src/utils/storeConfig.ts
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from 'fs';
|
|
2
2
|
import { dirname } from 'path';
|
|
3
3
|
import { DubheConfig } from '@0xobelisk/sui-common';
|
|
4
|
-
import { getDeploymentJson,
|
|
4
|
+
import { getDeploymentJson, getDubheDappHub } from './utils';
|
|
5
5
|
|
|
6
|
-
async function storeConfig(
|
|
7
|
-
network
|
|
8
|
-
packageId: string,
|
|
9
|
-
schemaId: string,
|
|
10
|
-
outputPath: string
|
|
11
|
-
) {
|
|
12
|
-
const dubheSchemaId = await getDubheSchemaId(network);
|
|
6
|
+
async function storeConfig(network: string, packageId: string, outputPath: string) {
|
|
7
|
+
const dubheDappHub = await getDubheDappHub(network);
|
|
13
8
|
let code = `type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
14
9
|
|
|
15
10
|
export const NETWORK: NetworkType = '${network}';
|
|
16
11
|
export const PACKAGE_ID = '${packageId}';
|
|
17
|
-
export const
|
|
18
|
-
export const DUBHE_SCHEMA_ID = '${dubheSchemaId}';
|
|
12
|
+
export const DUBHE_SCHEMA_ID = '${dubheDappHub}';
|
|
19
13
|
`;
|
|
20
14
|
|
|
21
15
|
writeOutput(code, outputPath, 'storeConfig');
|
|
@@ -42,5 +36,5 @@ export async function storeConfigHandler(
|
|
|
42
36
|
const path = process.cwd();
|
|
43
37
|
const contractPath = `${path}/src/${dubheConfig.name}`;
|
|
44
38
|
const deployment = await getDeploymentJson(contractPath, network);
|
|
45
|
-
await storeConfig(deployment.network, deployment.packageId,
|
|
39
|
+
await storeConfig(deployment.network, deployment.packageId, outputPath);
|
|
46
40
|
}
|