@0xobelisk/sui-cli 1.1.4 → 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.
- package/README.md +0 -2
- package/dist/dubhe.js +48 -59
- package/dist/dubhe.js.map +1 -1
- package/package.json +11 -7
- package/src/commands/build.ts +50 -53
- package/src/commands/call.ts +71 -71
- package/src/commands/checkBalance.ts +20 -20
- package/src/commands/configStore.ts +31 -35
- package/src/commands/faucet.ts +63 -71
- package/src/commands/generateKey.ts +25 -25
- package/src/commands/hello.ts +5 -5
- package/src/commands/index.ts +15 -17
- package/src/commands/indexer.ts +41 -46
- package/src/commands/localnode.ts +14 -29
- package/src/commands/publish.ts +35 -39
- package/src/commands/query.ts +70 -70
- package/src/commands/schemagen.ts +26 -26
- package/src/commands/test.ts +37 -37
- package/src/commands/upgrade.ts +29 -29
- package/src/commands/watch.ts +12 -12
- package/src/dubhe.ts +14 -12
- package/src/modules.d.ts +2 -2
- package/src/utils/callHandler.ts +117 -122
- package/src/utils/checkBalance.ts +25 -33
- package/src/utils/errors.ts +28 -28
- package/src/utils/generateAccount.ts +76 -91
- package/src/utils/indexerHandler.ts +183 -151
- package/src/utils/printDubhe.ts +1 -1
- package/src/utils/publishHandler.ts +325 -346
- package/src/utils/queryStorage.ts +126 -126
- package/src/utils/startNode.ts +102 -120
- package/src/utils/storeConfig.ts +33 -45
- package/src/utils/upgradeHandler.ts +208 -234
- package/src/utils/utils.ts +150 -176
- package/src/commands/install.ts +0 -126
|
@@ -3,105 +3,96 @@ import { execSync } from 'child_process';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { DubheCliError } from './errors';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
saveContractData,
|
|
7
|
+
validatePrivateKey,
|
|
8
|
+
updateDubheDependency,
|
|
9
|
+
switchEnv,
|
|
10
|
+
delay
|
|
10
11
|
} from './utils';
|
|
11
12
|
import { DubheConfig } from '@0xobelisk/sui-common';
|
|
12
13
|
import * as fs from 'fs';
|
|
13
14
|
import * as path from 'path';
|
|
14
|
-
import {homedir} from "node:os";
|
|
15
|
-
import {generateCargoToml, getRepoNameFromUrl} from "../commands/install";
|
|
16
|
-
import {writeFileSync} from "fs";
|
|
17
15
|
|
|
18
16
|
async function removeEnvContent(
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
filePath: string,
|
|
18
|
+
networkType: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
21
19
|
): Promise<void> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
30
|
-
const updatedContent = content.replace(regex, '');
|
|
31
|
-
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');
|
|
32
27
|
}
|
|
33
28
|
|
|
34
29
|
interface EnvConfig {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
chainId: string;
|
|
31
|
+
originalPublishedId: string;
|
|
32
|
+
latestPublishedId: string;
|
|
33
|
+
publishedVersion: number;
|
|
39
34
|
}
|
|
40
35
|
|
|
41
36
|
function updateEnvFile(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
filePath: string,
|
|
38
|
+
networkType: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
39
|
+
operation: 'publish' | 'upgrade',
|
|
40
|
+
chainId: string,
|
|
41
|
+
publishedId: string
|
|
47
42
|
): void {
|
|
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
|
-
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 = `
|
|
105
96
|
[env.${networkType}]
|
|
106
97
|
chain-id = "${config.chainId}"
|
|
107
98
|
original-published-id = "${config.originalPublishedId}"
|
|
@@ -109,13 +100,12 @@ latest-published-id = "${config.latestPublishedId}"
|
|
|
109
100
|
published-version = "${config.publishedVersion}"
|
|
110
101
|
`;
|
|
111
102
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
updatedSection;
|
|
103
|
+
const newEnvContent =
|
|
104
|
+
networkSectionIndex === -1
|
|
105
|
+
? envContent + updatedSection
|
|
106
|
+
: envLines.slice(0, networkSectionIndex).join('\n') + updatedSection;
|
|
117
107
|
|
|
118
|
-
|
|
108
|
+
fs.writeFileSync(envFilePath, newEnvContent, 'utf-8');
|
|
119
109
|
}
|
|
120
110
|
// function capitalizeAndRemoveUnderscores(input: string): string {
|
|
121
111
|
// return input
|
|
@@ -134,274 +124,263 @@ published-version = "${config.publishedVersion}"
|
|
|
134
124
|
// }
|
|
135
125
|
|
|
136
126
|
function buildContract(projectPath: string): string[][] {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
process.exit(1);
|
|
154
|
-
}
|
|
155
|
-
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];
|
|
156
143
|
}
|
|
157
144
|
|
|
158
145
|
async function publishContract(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
146
|
+
dubhe: Dubhe,
|
|
147
|
+
dubheConfig: DubheConfig,
|
|
148
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
149
|
+
projectPath: string,
|
|
150
|
+
gasBudget?: number
|
|
164
151
|
) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function checkDubheFramework(projectPath: string): Promise<boolean> {
|
|
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;
|
|
290
283
|
}
|
|
291
284
|
|
|
292
285
|
export async function publishDubheFramework(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
286
|
+
dubhe: Dubhe,
|
|
287
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
296
288
|
) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
console.error(error.message);
|
|
360
|
-
process.exit(1);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if (deployHookResult.effects?.status.status === 'success') {
|
|
364
|
-
deployHookResult.objectChanges?.map(object => {
|
|
365
|
-
if (object.type === 'created' && object.objectType.includes('schema::Schema')) {
|
|
366
|
-
console.log(` ├─ Schema ID: ${object.objectId}`);
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
}
|
|
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'));
|
|
374
351
|
}
|
|
375
352
|
|
|
376
353
|
export async function publishHandler(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
354
|
+
dubheConfig: DubheConfig,
|
|
355
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
356
|
+
gasBudget?: number
|
|
380
357
|
) {
|
|
381
|
-
|
|
358
|
+
await switchEnv(network);
|
|
382
359
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
360
|
+
const privateKey = process.env.PRIVATE_KEY;
|
|
361
|
+
if (!privateKey) {
|
|
362
|
+
throw new DubheCliError(
|
|
363
|
+
`Missing PRIVATE_KEY environment variable.
|
|
387
364
|
Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
|
|
388
365
|
in your contracts directory to use the default sui private key.`
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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);
|
|
407
386
|
}
|