@0xobelisk/sui-cli 1.1.5 → 1.1.6

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.
@@ -3,103 +3,96 @@ import { execSync } from 'child_process';
3
3
  import chalk from 'chalk';
4
4
  import { DubheCliError } from './errors';
5
5
  import {
6
- saveContractData,
7
- validatePrivateKey,
8
- updateDubheDependency,
9
- switchEnv,
10
- delay,
6
+ saveContractData,
7
+ validatePrivateKey,
8
+ updateDubheDependency,
9
+ switchEnv,
10
+ delay
11
11
  } from './utils';
12
12
  import { DubheConfig } from '@0xobelisk/sui-common';
13
13
  import * as fs from 'fs';
14
14
  import * as path from 'path';
15
15
 
16
16
  async function removeEnvContent(
17
- filePath: string,
18
- networkType: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
17
+ filePath: string,
18
+ networkType: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
19
19
  ): Promise<void> {
20
- if (!fs.existsSync(filePath)) {
21
- return;
22
- }
23
- const content = fs.readFileSync(filePath, 'utf-8');
24
- const regex = new RegExp(
25
- `\\[env\\.${networkType}\\][\\s\\S]*?(?=\\[|$)`,
26
- 'g'
27
- );
28
- const updatedContent = content.replace(regex, '');
29
- fs.writeFileSync(filePath, updatedContent, 'utf-8');
20
+ if (!fs.existsSync(filePath)) {
21
+ return;
22
+ }
23
+ const content = fs.readFileSync(filePath, 'utf-8');
24
+ const regex = new RegExp(`\\[env\\.${networkType}\\][\\s\\S]*?(?=\\[|$)`, 'g');
25
+ const updatedContent = content.replace(regex, '');
26
+ fs.writeFileSync(filePath, updatedContent, 'utf-8');
30
27
  }
31
28
 
32
29
  interface EnvConfig {
33
- chainId: string;
34
- originalPublishedId: string;
35
- latestPublishedId: string;
36
- publishedVersion: number;
30
+ chainId: string;
31
+ originalPublishedId: string;
32
+ latestPublishedId: string;
33
+ publishedVersion: number;
37
34
  }
38
35
 
39
36
  function updateEnvFile(
40
- filePath: string,
41
- networkType: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
42
- operation: 'publish' | 'upgrade',
43
- chainId: string,
44
- publishedId: string
37
+ filePath: string,
38
+ networkType: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
39
+ operation: 'publish' | 'upgrade',
40
+ chainId: string,
41
+ publishedId: string
45
42
  ): void {
46
- const envFilePath = path.resolve(filePath);
47
- const envContent = fs.readFileSync(envFilePath, 'utf-8');
48
- const envLines = envContent.split('\n');
49
-
50
- const networkSectionIndex = envLines.findIndex(
51
- line => line.trim() === `[env.${networkType}]`
52
- );
53
- const config: EnvConfig = {
54
- chainId: chainId,
55
- originalPublishedId: '',
56
- latestPublishedId: '',
57
- publishedVersion: 0,
58
- };
59
-
60
- if (networkSectionIndex === -1) {
61
- // If network section is not found, add a new section
62
- if (operation === 'publish') {
63
- config.originalPublishedId = publishedId;
64
- config.latestPublishedId = publishedId;
65
- config.publishedVersion = 1;
66
- } else {
67
- throw new Error(
68
- `Network type [env.${networkType}] not found in the file and cannot upgrade.`
69
- );
70
- }
71
- } else {
72
- for (let i = networkSectionIndex + 1; i < envLines.length; i++) {
73
- const line = envLines[i].trim();
74
- if (line.startsWith('[')) break; // End of the current network section
75
-
76
- const [key, value] = line
77
- .split('=')
78
- .map(part => part.trim().replace(/"/g, ''));
79
- switch (key) {
80
- case 'original-published-id':
81
- config.originalPublishedId = value;
82
- break;
83
- case 'latest-published-id':
84
- config.latestPublishedId = value;
85
- break;
86
- case 'published-version':
87
- config.publishedVersion = parseInt(value, 10);
88
- break;
89
- }
90
- }
91
-
92
- if (operation === 'publish') {
93
- config.originalPublishedId = publishedId;
94
- config.latestPublishedId = publishedId;
95
- config.publishedVersion = 1;
96
- } else if (operation === 'upgrade') {
97
- config.latestPublishedId = publishedId;
98
- config.publishedVersion += 1;
99
- }
100
- }
101
-
102
- const updatedSection = `
43
+ const envFilePath = path.resolve(filePath);
44
+ const envContent = fs.readFileSync(envFilePath, 'utf-8');
45
+ const envLines = envContent.split('\n');
46
+
47
+ const networkSectionIndex = envLines.findIndex((line) => line.trim() === `[env.${networkType}]`);
48
+ const config: EnvConfig = {
49
+ chainId: chainId,
50
+ originalPublishedId: '',
51
+ latestPublishedId: '',
52
+ publishedVersion: 0
53
+ };
54
+
55
+ if (networkSectionIndex === -1) {
56
+ // If network section is not found, add a new section
57
+ if (operation === 'publish') {
58
+ config.originalPublishedId = publishedId;
59
+ config.latestPublishedId = publishedId;
60
+ config.publishedVersion = 1;
61
+ } else {
62
+ throw new Error(
63
+ `Network type [env.${networkType}] not found in the file and cannot upgrade.`
64
+ );
65
+ }
66
+ } else {
67
+ for (let i = networkSectionIndex + 1; i < envLines.length; i++) {
68
+ const line = envLines[i].trim();
69
+ if (line.startsWith('[')) break; // End of the current network section
70
+
71
+ const [key, value] = line.split('=').map((part) => part.trim().replace(/"/g, ''));
72
+ switch (key) {
73
+ case 'original-published-id':
74
+ config.originalPublishedId = value;
75
+ break;
76
+ case 'latest-published-id':
77
+ config.latestPublishedId = value;
78
+ break;
79
+ case 'published-version':
80
+ config.publishedVersion = parseInt(value, 10);
81
+ break;
82
+ }
83
+ }
84
+
85
+ if (operation === 'publish') {
86
+ config.originalPublishedId = publishedId;
87
+ config.latestPublishedId = publishedId;
88
+ config.publishedVersion = 1;
89
+ } else if (operation === 'upgrade') {
90
+ config.latestPublishedId = publishedId;
91
+ config.publishedVersion += 1;
92
+ }
93
+ }
94
+
95
+ const updatedSection = `
103
96
  [env.${networkType}]
104
97
  chain-id = "${config.chainId}"
105
98
  original-published-id = "${config.originalPublishedId}"
@@ -107,13 +100,12 @@ latest-published-id = "${config.latestPublishedId}"
107
100
  published-version = "${config.publishedVersion}"
108
101
  `;
109
102
 
110
- const newEnvContent =
111
- networkSectionIndex === -1
112
- ? envContent + updatedSection
113
- : envLines.slice(0, networkSectionIndex).join('\n') +
114
- updatedSection;
103
+ const newEnvContent =
104
+ networkSectionIndex === -1
105
+ ? envContent + updatedSection
106
+ : envLines.slice(0, networkSectionIndex).join('\n') + updatedSection;
115
107
 
116
- fs.writeFileSync(envFilePath, newEnvContent, 'utf-8');
108
+ fs.writeFileSync(envFilePath, newEnvContent, 'utf-8');
117
109
  }
118
110
  // function capitalizeAndRemoveUnderscores(input: string): string {
119
111
  // return input
@@ -132,304 +124,263 @@ published-version = "${config.publishedVersion}"
132
124
  // }
133
125
 
134
126
  function buildContract(projectPath: string): string[][] {
135
- let modules: any, dependencies: any;
136
- try {
137
- const buildResult = JSON.parse(
138
- execSync(
139
- `sui move build --dump-bytecode-as-base64 --path ${projectPath}`,
140
- {
141
- encoding: 'utf-8',
142
- stdio: 'pipe',
143
- }
144
- )
145
- );
146
- modules = buildResult.modules;
147
- dependencies = buildResult.dependencies;
148
- } catch (error: any) {
149
- console.error(chalk.red(' └─ Build failed'));
150
- console.error(error.stdout);
151
- process.exit(1);
152
- }
153
- return [modules, dependencies];
127
+ let modules: any, dependencies: any;
128
+ try {
129
+ const buildResult = JSON.parse(
130
+ execSync(`sui move build --dump-bytecode-as-base64 --path ${projectPath}`, {
131
+ encoding: 'utf-8',
132
+ stdio: 'pipe'
133
+ })
134
+ );
135
+ modules = buildResult.modules;
136
+ dependencies = buildResult.dependencies;
137
+ } catch (error: any) {
138
+ console.error(chalk.red(' └─ Build failed'));
139
+ console.error(error.stdout);
140
+ process.exit(1);
141
+ }
142
+ return [modules, dependencies];
154
143
  }
155
144
 
156
145
  async function publishContract(
157
- dubhe: Dubhe,
158
- dubheConfig: DubheConfig,
159
- network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
160
- projectPath: string,
161
- gasBudget?: number
146
+ dubhe: Dubhe,
147
+ dubheConfig: DubheConfig,
148
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
149
+ projectPath: string,
150
+ gasBudget?: number
162
151
  ) {
163
- const chainId =
164
- await dubhe.suiInteractor.currentClient.getChainIdentifier();
165
- await removeEnvContent(`${projectPath}/Move.lock`, network);
166
- console.log('\n🚀 Starting Contract Publication...');
167
- console.log(` ├─ Project: ${projectPath}`);
168
- console.log(` ├─ Network: ${network}`);
169
- console.log(` ├─ ChainId: ${chainId}`);
170
- console.log(' ├─ Validating Environment...');
171
-
172
- console.log(` └─ Account: ${dubhe.getAddress()}`);
173
-
174
- console.log('\n📦 Building Contract...');
175
- const [modules, dependencies] = buildContract(projectPath);
176
-
177
- console.log('\n🔄 Publishing Contract...');
178
- const tx = new Transaction();
179
- if (gasBudget) {
180
- tx.setGasBudget(gasBudget);
181
- }
182
- const [upgradeCap] = tx.publish({ modules, dependencies });
183
- tx.transferObjects([upgradeCap], dubhe.getAddress());
184
-
185
- let result;
186
- try {
187
- result = await dubhe.signAndSendTxn({tx});
188
- } catch (error: any) {
189
- console.error(chalk.red(' └─ Publication failed'));
190
- console.error(error.message);
191
- process.exit(1);
192
- }
193
-
194
- if (result.effects?.status.status === 'failure') {
195
- console.log(chalk.red(' └─ Publication failed'));
196
- process.exit(1);
197
- }
198
-
199
- console.log(' ├─ Processing publication results...');
200
- let version = 1;
201
- let packageId = '';
202
- let schemaId = '';
203
- let schemas = dubheConfig.schemas;
204
- let upgradeCapId = '';
205
-
206
- result.objectChanges!.map(object => {
207
- if (object.type === 'published') {
208
- console.log(` ├─ Package ID: ${object.packageId}`);
209
- packageId = object.packageId;
210
- }
211
- if (
212
- object.type === 'created' &&
213
- object.objectType === '0x2::package::UpgradeCap'
214
- ) {
215
- console.log(` ├─ Upgrade Cap: ${object.objectId}`);
216
- upgradeCapId = object.objectId;
217
- }
218
- });
219
-
220
- console.log(` └─ Transaction: ${result.digest}`);
221
-
222
- updateEnvFile(
223
- `${projectPath}/Move.lock`,
224
- network,
225
- 'publish',
226
- chainId,
227
- packageId
228
- );
229
-
230
- console.log('\n⚡ Executing Deploy Hook...');
231
- await delay(5000);
232
-
233
- const deployHookTx = new Transaction();
234
- deployHookTx.moveCall({
235
- target: `${packageId}::${dubheConfig.name}_genesis::run`,
236
- arguments: [deployHookTx.object('0x6')],
237
- });
238
-
239
- let deployHookResult;
240
- try {
241
- deployHookResult = await dubhe.signAndSendTxn({tx: deployHookTx});
242
- } catch (error: any) {
243
- console.error(chalk.red(' └─ Deploy hook execution failed'));
244
- console.error(error.message);
245
- process.exit(1);
246
- }
247
-
248
- if (deployHookResult.effects?.status.status === 'success') {
249
- console.log(' ├─ Hook execution successful');
250
- console.log(` ├─ Transaction: ${deployHookResult.digest}`);
251
-
252
- console.log('\n📋 Created Schemas:');
253
- deployHookResult.objectChanges?.map(object => {
254
- if (object.type === 'created' && object.objectType.includes('schema::Schema')) {
255
- schemaId = object.objectId;
256
- }
257
- if (
258
- object.type === 'created' &&
259
- object.objectType.includes('schema') &&
260
- !object.objectType.includes('dynamic_field')
261
- ) {
262
- console.log(` ├─ ${object.objectType}`);
263
- console.log(` └─ ID: ${object.objectId}`);
264
- }
265
- });
266
-
267
- saveContractData(
268
- dubheConfig.name,
269
- network,
270
- packageId,
271
- schemaId,
272
- upgradeCapId,
273
- version,
274
- schemas
275
- );
276
- console.log('\n✅ Contract Publication Complete\n');
277
- } else {
278
- console.log(chalk.yellow(' └─ Deploy hook execution failed'));
279
- console.log(
280
- chalk.yellow(
281
- ' Please republish or manually call deploy_hook::run'
282
- )
283
- );
284
- console.log(chalk.yellow(' Please check the transaction digest:'));
285
- console.log(chalk.yellow(` ${deployHookResult.digest}`));
286
- process.exit(1);
287
- }
152
+ const chainId = await dubhe.suiInteractor.currentClient.getChainIdentifier();
153
+ await removeEnvContent(`${projectPath}/Move.lock`, network);
154
+ console.log('\n🚀 Starting Contract Publication...');
155
+ console.log(` ├─ Project: ${projectPath}`);
156
+ console.log(` ├─ Network: ${network}`);
157
+ console.log(` ├─ ChainId: ${chainId}`);
158
+ console.log(' ├─ Validating Environment...');
159
+
160
+ console.log(` └─ Account: ${dubhe.getAddress()}`);
161
+
162
+ console.log('\n📦 Building Contract...');
163
+ const [modules, dependencies] = buildContract(projectPath);
164
+
165
+ console.log('\n🔄 Publishing Contract...');
166
+ const tx = new Transaction();
167
+ if (gasBudget) {
168
+ tx.setGasBudget(gasBudget);
169
+ }
170
+ const [upgradeCap] = tx.publish({ modules, dependencies });
171
+ tx.transferObjects([upgradeCap], dubhe.getAddress());
172
+
173
+ let result;
174
+ try {
175
+ result = await dubhe.signAndSendTxn({ tx });
176
+ } catch (error: any) {
177
+ console.error(chalk.red(' └─ Publication failed'));
178
+ console.error(error.message);
179
+ process.exit(1);
180
+ }
181
+
182
+ if (result.effects?.status.status === 'failure') {
183
+ console.log(chalk.red(' └─ Publication failed'));
184
+ process.exit(1);
185
+ }
186
+
187
+ console.log(' ├─ Processing publication results...');
188
+ let version = 1;
189
+ let packageId = '';
190
+ let schemaId = '';
191
+ let schemas = dubheConfig.schemas;
192
+ let upgradeCapId = '';
193
+
194
+ result.objectChanges!.map((object) => {
195
+ if (object.type === 'published') {
196
+ console.log(` ├─ Package ID: ${object.packageId}`);
197
+ packageId = object.packageId;
198
+ }
199
+ if (object.type === 'created' && object.objectType === '0x2::package::UpgradeCap') {
200
+ console.log(` ├─ Upgrade Cap: ${object.objectId}`);
201
+ upgradeCapId = object.objectId;
202
+ }
203
+ });
204
+
205
+ console.log(` └─ Transaction: ${result.digest}`);
206
+
207
+ updateEnvFile(`${projectPath}/Move.lock`, network, 'publish', chainId, packageId);
208
+
209
+ console.log('\n⚡ Executing Deploy Hook...');
210
+ await delay(5000);
211
+
212
+ const deployHookTx = new Transaction();
213
+ deployHookTx.moveCall({
214
+ target: `${packageId}::${dubheConfig.name}_genesis::run`,
215
+ arguments: [deployHookTx.object('0x6')]
216
+ });
217
+
218
+ let deployHookResult;
219
+ try {
220
+ deployHookResult = await dubhe.signAndSendTxn({ tx: deployHookTx });
221
+ } catch (error: any) {
222
+ console.error(chalk.red(' └─ Deploy hook execution failed'));
223
+ console.error(error.message);
224
+ process.exit(1);
225
+ }
226
+
227
+ if (deployHookResult.effects?.status.status === 'success') {
228
+ console.log(' ├─ Hook execution successful');
229
+ console.log(` ├─ Transaction: ${deployHookResult.digest}`);
230
+
231
+ console.log('\n📋 Created Schemas:');
232
+ deployHookResult.objectChanges?.map((object) => {
233
+ if (object.type === 'created' && object.objectType.includes('schema::Schema')) {
234
+ schemaId = object.objectId;
235
+ }
236
+ if (
237
+ object.type === 'created' &&
238
+ object.objectType.includes('schema') &&
239
+ !object.objectType.includes('dynamic_field')
240
+ ) {
241
+ console.log(` ├─ ${object.objectType}`);
242
+ console.log(` └─ ID: ${object.objectId}`);
243
+ }
244
+ });
245
+
246
+ saveContractData(
247
+ dubheConfig.name,
248
+ network,
249
+ packageId,
250
+ schemaId,
251
+ upgradeCapId,
252
+ version,
253
+ schemas
254
+ );
255
+ console.log('\n✅ Contract Publication Complete\n');
256
+ } else {
257
+ console.log(chalk.yellow(' └─ Deploy hook execution failed'));
258
+ console.log(chalk.yellow(' Please republish or manually call deploy_hook::run'));
259
+ console.log(chalk.yellow(' Please check the transaction digest:'));
260
+ console.log(chalk.yellow(` ${deployHookResult.digest}`));
261
+ process.exit(1);
262
+ }
288
263
  }
289
264
 
290
265
  async function checkDubheFramework(projectPath: string): Promise<boolean> {
291
- if (!fs.existsSync(projectPath)) {
292
- console.log(chalk.yellow('\nℹ️ Dubhe Framework Files Not Found'));
293
- console.log(chalk.yellow(' ├─ Expected Path:'), projectPath);
294
- console.log(chalk.yellow(' ├─ To set up Dubhe Framework:'));
295
- console.log(
296
- chalk.yellow(
297
- ' │ 1. Create directory: mkdir -p contracts/dubhe-framework'
298
- )
299
- );
300
- console.log(
301
- chalk.yellow(
302
- ' │ 2. Clone repository: git clone https://github.com/0xobelisk/dubhe-framework contracts/dubhe-framework'
303
- )
304
- );
305
- console.log(
306
- chalk.yellow(
307
- ' │ 3. Or download from: https://github.com/0xobelisk/dubhe-framework'
308
- )
309
- );
310
- console.log(chalk.yellow(' └─ After setup, restart the local node'));
311
- return false;
312
- }
313
- return true;
266
+ if (!fs.existsSync(projectPath)) {
267
+ console.log(chalk.yellow('\nℹ️ Dubhe Framework Files Not Found'));
268
+ console.log(chalk.yellow(' ├─ Expected Path:'), projectPath);
269
+ console.log(chalk.yellow(' ├─ To set up Dubhe Framework:'));
270
+ console.log(chalk.yellow(' │ 1. Create directory: mkdir -p contracts/dubhe-framework'));
271
+ console.log(
272
+ chalk.yellow(
273
+ ' │ 2. Clone repository: git clone https://github.com/0xobelisk/dubhe-framework contracts/dubhe-framework'
274
+ )
275
+ );
276
+ console.log(
277
+ chalk.yellow(' │ 3. Or download from: https://github.com/0xobelisk/dubhe-framework')
278
+ );
279
+ console.log(chalk.yellow(' └─ After setup, restart the local node'));
280
+ return false;
281
+ }
282
+ return true;
314
283
  }
315
284
 
316
285
  export async function publishDubheFramework(
317
- dubhe: Dubhe,
318
- network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
286
+ dubhe: Dubhe,
287
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
319
288
  ) {
320
- const path = process.cwd();
321
- const projectPath = `${path}/contracts/dubhe-framework`;
322
-
323
- if (!(await checkDubheFramework(projectPath))) {
324
- console.log(chalk.yellow('\n❗ Framework Deployment Skipped'));
325
- return;
326
- }
327
-
328
- // const chainId = await client.getChainIdentifier();
329
- const chainId =
330
- await dubhe.suiInteractor.currentClient.getChainIdentifier();
331
- await removeEnvContent(`${projectPath}/Move.lock`, network);
332
- console.log('\n🚀 Starting Contract Publication...');
333
- console.log(` ├─ Project: ${projectPath}`);
334
- console.log(` ├─ Network: ${network}`);
335
-
336
- console.log(` └─ Account: ${dubhe.getAddress()}`);
337
-
338
- console.log('\n📦 Building Contract...');
339
- const [modules, dependencies] = buildContract(projectPath);
340
-
341
- console.log('\n🔄 Publishing Contract...');
342
- const tx = new Transaction();
343
- const [upgradeCap] = tx.publish({ modules, dependencies });
344
- tx.transferObjects([upgradeCap], dubhe.getAddress());
345
-
346
- let result;
347
- try {
348
- result = await dubhe.signAndSendTxn({ tx });
349
- } catch (error: any) {
350
- console.error(chalk.red(' └─ Publication failed'));
351
- console.error(error.message);
352
- process.exit(1);
353
- }
354
-
355
- if (result.effects?.status.status === 'failure') {
356
- console.log(chalk.red(' └─ Publication failed'));
357
- process.exit(1);
358
- }
359
-
360
- let version = 1;
361
- let packageId = '';
362
- let schemas: Record<string, string> = {};
363
- let upgradeCapId = '';
364
-
365
- result.objectChanges!.map(object => {
366
- if (object.type === 'published') {
367
- console.log(` ├─ Package ID: ${object.packageId}`);
368
- packageId = object.packageId;
369
- }
370
- if (
371
- object.type === 'created' &&
372
- object.objectType === '0x2::package::UpgradeCap'
373
- ) {
374
- console.log(` ├─ Upgrade Cap: ${object.objectId}`);
375
- upgradeCapId = object.objectId;
376
- }
377
- });
378
-
379
- console.log(` └─ Transaction: ${result.digest}`);
380
-
381
- updateEnvFile(
382
- `${projectPath}/Move.lock`,
383
- network,
384
- 'publish',
385
- chainId,
386
- packageId
387
- );
388
-
389
- saveContractData(
390
- 'dubhe-framework',
391
- network,
392
- packageId,
393
- '',
394
- upgradeCapId,
395
- version,
396
- schemas
397
- );
398
- await delay(1000);
399
- console.log(chalk.green('\n✅ Dubhe Framework deployed successfully'));
289
+ const path = process.cwd();
290
+ const projectPath = `${path}/contracts/dubhe-framework`;
291
+
292
+ if (!(await checkDubheFramework(projectPath))) {
293
+ console.log(chalk.yellow('\n❗ Framework Deployment Skipped'));
294
+ return;
295
+ }
296
+
297
+ // const chainId = await client.getChainIdentifier();
298
+ const chainId = await dubhe.suiInteractor.currentClient.getChainIdentifier();
299
+ await removeEnvContent(`${projectPath}/Move.lock`, network);
300
+ console.log('\n🚀 Starting Contract Publication...');
301
+ console.log(` ├─ Project: ${projectPath}`);
302
+ console.log(` ├─ Network: ${network}`);
303
+
304
+ console.log(` └─ Account: ${dubhe.getAddress()}`);
305
+
306
+ console.log('\n📦 Building Contract...');
307
+ const [modules, dependencies] = buildContract(projectPath);
308
+
309
+ console.log('\n🔄 Publishing Contract...');
310
+ const tx = new Transaction();
311
+ const [upgradeCap] = tx.publish({ modules, dependencies });
312
+ tx.transferObjects([upgradeCap], dubhe.getAddress());
313
+
314
+ let result;
315
+ try {
316
+ result = await dubhe.signAndSendTxn({ tx });
317
+ } catch (error: any) {
318
+ console.error(chalk.red(' └─ Publication failed'));
319
+ console.error(error.message);
320
+ process.exit(1);
321
+ }
322
+
323
+ if (result.effects?.status.status === 'failure') {
324
+ console.log(chalk.red(' └─ Publication failed'));
325
+ process.exit(1);
326
+ }
327
+
328
+ let version = 1;
329
+ let packageId = '';
330
+ let schemas: Record<string, string> = {};
331
+ let upgradeCapId = '';
332
+
333
+ result.objectChanges!.map((object) => {
334
+ if (object.type === 'published') {
335
+ console.log(` ├─ Package ID: ${object.packageId}`);
336
+ packageId = object.packageId;
337
+ }
338
+ if (object.type === 'created' && object.objectType === '0x2::package::UpgradeCap') {
339
+ console.log(` ├─ Upgrade Cap: ${object.objectId}`);
340
+ upgradeCapId = object.objectId;
341
+ }
342
+ });
343
+
344
+ console.log(` └─ Transaction: ${result.digest}`);
345
+
346
+ updateEnvFile(`${projectPath}/Move.lock`, network, 'publish', chainId, packageId);
347
+
348
+ saveContractData('dubhe-framework', network, packageId, '', upgradeCapId, version, schemas);
349
+ await delay(1000);
350
+ console.log(chalk.green('\n✅ Dubhe Framework deployed successfully'));
400
351
  }
401
352
 
402
353
  export async function publishHandler(
403
- dubheConfig: DubheConfig,
404
- network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
405
- gasBudget?: number
354
+ dubheConfig: DubheConfig,
355
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
356
+ gasBudget?: number
406
357
  ) {
407
- await switchEnv(network);
358
+ await switchEnv(network);
408
359
 
409
- const privateKey = process.env.PRIVATE_KEY;
410
- if (!privateKey) {
411
- throw new DubheCliError(
412
- `Missing PRIVATE_KEY environment variable.
360
+ const privateKey = process.env.PRIVATE_KEY;
361
+ if (!privateKey) {
362
+ throw new DubheCliError(
363
+ `Missing PRIVATE_KEY environment variable.
413
364
  Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
414
365
  in your contracts directory to use the default sui private key.`
415
- );
416
- }
417
- const privateKeyFormat = validatePrivateKey(privateKey);
418
- if (privateKeyFormat === false) {
419
- throw new DubheCliError(`Please check your privateKey.`);
420
- }
421
-
422
- const dubhe = new Dubhe({
423
- secretKey: privateKeyFormat,
424
- networkType: network,
425
- });
426
-
427
- if (network === 'localnet') {
428
- await publishDubheFramework(dubhe, network);
429
- }
430
-
431
- const path = process.cwd();
432
- const projectPath = `${path}/contracts/${dubheConfig.name}`;
433
- await updateDubheDependency(`${projectPath}/Move.toml`, network);
434
- await publishContract(dubhe, dubheConfig, network, projectPath, gasBudget);
366
+ );
367
+ }
368
+ const privateKeyFormat = validatePrivateKey(privateKey);
369
+ if (privateKeyFormat === false) {
370
+ throw new DubheCliError(`Please check your privateKey.`);
371
+ }
372
+
373
+ const dubhe = new Dubhe({
374
+ secretKey: privateKeyFormat,
375
+ networkType: network
376
+ });
377
+
378
+ if (network === 'localnet') {
379
+ await publishDubheFramework(dubhe, network);
380
+ }
381
+
382
+ const path = process.cwd();
383
+ const projectPath = `${path}/contracts/${dubheConfig.name}`;
384
+ await updateDubheDependency(`${projectPath}/Move.toml`, network);
385
+ await publishContract(dubhe, dubheConfig, network, projectPath, gasBudget);
435
386
  }