@0xobelisk/sui-cli 1.2.0-pre.1 → 1.2.0-pre.10
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 +38 -56
- package/dist/dubhe.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/localnode.ts +2 -8
- package/src/utils/publishHandler.ts +12 -3
- package/src/utils/startNode.ts +55 -97
- package/src/utils/utils.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xobelisk/sui-cli",
|
|
3
|
-
"version": "1.2.0-pre.
|
|
3
|
+
"version": "1.2.0-pre.10",
|
|
4
4
|
"description": "Tookit for interacting with move eps framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"yargs": "^17.7.1",
|
|
51
51
|
"zod": "^3.22.3",
|
|
52
52
|
"zod-validation-error": "^1.3.0",
|
|
53
|
-
"@0xobelisk/sui-client": "1.2.0-pre.
|
|
54
|
-
"@0xobelisk/sui-common": "1.2.0-pre.
|
|
53
|
+
"@0xobelisk/sui-client": "1.2.0-pre.10",
|
|
54
|
+
"@0xobelisk/sui-common": "1.2.0-pre.10"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/ejs": "^3.1.1",
|
|
@@ -8,17 +8,11 @@ const commandModule: CommandModule = {
|
|
|
8
8
|
|
|
9
9
|
builder(yargs) {
|
|
10
10
|
return yargs
|
|
11
|
-
.option('force-regenesis', {
|
|
12
|
-
alias: 'f',
|
|
13
|
-
type: 'boolean',
|
|
14
|
-
description: 'Force regenesis the local node',
|
|
15
|
-
default: true
|
|
16
|
-
});
|
|
17
11
|
},
|
|
18
12
|
|
|
19
|
-
async handler(
|
|
13
|
+
async handler() {
|
|
20
14
|
try {
|
|
21
|
-
await startLocalNode(
|
|
15
|
+
await startLocalNode();
|
|
22
16
|
} catch (error) {
|
|
23
17
|
console.error('Error executing command:', error);
|
|
24
18
|
process.exit(1);
|
|
@@ -369,6 +369,8 @@ async function publishContract(
|
|
|
369
369
|
let schemas = dubheConfig.schemas;
|
|
370
370
|
let upgradeCapId = '';
|
|
371
371
|
|
|
372
|
+
let printObjects: any[] = [];
|
|
373
|
+
|
|
372
374
|
result.objectChanges!.map((object: ObjectChange) => {
|
|
373
375
|
if (object.type === 'published') {
|
|
374
376
|
console.log(` ├─ Package ID: ${object.packageId}`);
|
|
@@ -382,6 +384,9 @@ async function publishContract(
|
|
|
382
384
|
console.log(` ├─ Upgrade Cap: ${object.objectId}`);
|
|
383
385
|
upgradeCapId = object.objectId || '';
|
|
384
386
|
}
|
|
387
|
+
if (object.type === 'created') {
|
|
388
|
+
printObjects.push(object);
|
|
389
|
+
}
|
|
385
390
|
});
|
|
386
391
|
|
|
387
392
|
console.log(` └─ Transaction: ${result.digest}`);
|
|
@@ -416,7 +421,7 @@ async function publishContract(
|
|
|
416
421
|
console.log(' ├─ Hook execution successful');
|
|
417
422
|
console.log(` ├─ Transaction: ${deployHookResult.digest}`);
|
|
418
423
|
|
|
419
|
-
console.log('\n📋 Created
|
|
424
|
+
console.log('\n📋 Created Objects:');
|
|
420
425
|
deployHookResult.objectChanges?.map((object: ObjectChange) => {
|
|
421
426
|
if (
|
|
422
427
|
object.type === 'created' &&
|
|
@@ -431,11 +436,15 @@ async function publishContract(
|
|
|
431
436
|
object.objectType.includes('schema') &&
|
|
432
437
|
!object.objectType.includes('dynamic_field')
|
|
433
438
|
) {
|
|
434
|
-
|
|
435
|
-
console.log(` └─ ID: ${object.objectId}`);
|
|
439
|
+
printObjects.push(object);
|
|
436
440
|
}
|
|
437
441
|
});
|
|
438
442
|
|
|
443
|
+
printObjects.map((object: ObjectChange) => {
|
|
444
|
+
console.log(` ├─ Type: ${object.objectType}`);
|
|
445
|
+
console.log(` └─ ID: ${object.objectId}`);
|
|
446
|
+
});
|
|
447
|
+
|
|
439
448
|
saveContractData(
|
|
440
449
|
dubheConfig.name,
|
|
441
450
|
network,
|
package/src/utils/startNode.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { execSync, spawn } from 'child_process';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { printDubhe } from './printDubhe';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { delay, DubheCliError, validatePrivateKey } from '../utils';
|
|
5
|
+
import { Dubhe } from '@0xobelisk/sui-client';
|
|
6
6
|
|
|
7
7
|
function isSuiStartRunning(): boolean {
|
|
8
8
|
try {
|
|
@@ -22,37 +22,39 @@ function isSuiStartRunning(): boolean {
|
|
|
22
22
|
|
|
23
23
|
async function printAccounts() {
|
|
24
24
|
// These private keys are used for testing purposes only, do not use them in production.
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
address: '0x492404a537c32b46610bd6ae9f7f16ba16ff5a607d272543fe86cada69d8cf44'
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
privateKey: 'suiprivkey1qpy3a696eh3m55fwa8h38ss063459u4n2dm9t24w2hlxxzjp2x34q8sdsnc',
|
|
36
|
-
address: '0xd27e203483700d837a462d159ced6104619d8e36f737bf2a20c251153bf39f24'
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
privateKey: 'suiprivkey1qzxwp29favhzrjd95f6uj9nskjwal6nh9g509jpun395y6g72d6jqlmps4c',
|
|
40
|
-
address: '0x018f1f175c9b6739a14bc9c81e7984c134ebf9031015cf796fefcef04b8c4990'
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
privateKey: 'suiprivkey1qzhq4lv38sesah4uzsqkkmeyjx860xqjdz8qgw36tmrdd5tnle3evxpng57',
|
|
44
|
-
address: '0x932f6aab2bc636a25374f99794dc8451c4e27c91e87083e301816ed08bc98ed0'
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
privateKey: 'suiprivkey1qzez45sjjsepjgtksqvpq6jw7dzw3zq0dx7a4sulfypd73acaynw5jl9x2c',
|
|
48
|
-
address: '0x9a66b2da3036badd22529e3de8a00b0cd7dbbfe589873aa03d5f885f5f8c6501'
|
|
49
|
-
}
|
|
25
|
+
const privateKeys = [
|
|
26
|
+
'suiprivkey1qq3ez3dje66l8pypgxynr7yymwps6uhn7vyczespj84974j3zya0wdpu76v',
|
|
27
|
+
'suiprivkey1qp6vcyg8r2x88fllmjmxtpzjl95gd9dugqrgz7xxf50w6rqdqzetg7x4d7s',
|
|
28
|
+
'suiprivkey1qpy3a696eh3m55fwa8h38ss063459u4n2dm9t24w2hlxxzjp2x34q8sdsnc',
|
|
29
|
+
'suiprivkey1qzxwp29favhzrjd95f6uj9nskjwal6nh9g509jpun395y6g72d6jqlmps4c',
|
|
30
|
+
'suiprivkey1qzhq4lv38sesah4uzsqkkmeyjx860xqjdz8qgw36tmrdd5tnle3evxpng57',
|
|
31
|
+
'suiprivkey1qzez45sjjsepjgtksqvpq6jw7dzw3zq0dx7a4sulfypd73acaynw5jl9x2c'
|
|
50
32
|
];
|
|
51
33
|
console.log('📝Accounts');
|
|
52
34
|
console.log('==========');
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
privateKeys.forEach((privateKey, index) => {
|
|
36
|
+
const dubhe = new Dubhe({ secretKey: privateKey });
|
|
37
|
+
const keypair = dubhe.getSigner();
|
|
38
|
+
spawn(
|
|
39
|
+
'curl',
|
|
40
|
+
[
|
|
41
|
+
'--location',
|
|
42
|
+
'--request',
|
|
43
|
+
'POST',
|
|
44
|
+
'http://127.0.0.1:9123/gas',
|
|
45
|
+
'--header',
|
|
46
|
+
'Content-Type: application/json',
|
|
47
|
+
'--data-raw',
|
|
48
|
+
`{"FixedAmountRequest": {"recipient": "${keypair.toSuiAddress()}"}}`
|
|
49
|
+
],
|
|
50
|
+
{
|
|
51
|
+
env: { ...process.env },
|
|
52
|
+
stdio: 'ignore',
|
|
53
|
+
detached: true
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
console.log(` ┌─ Account #${index}: ${keypair.toSuiAddress()}(1000 SUI)`);
|
|
57
|
+
console.log(` └─ Private Key: ${privateKey}`);
|
|
56
58
|
});
|
|
57
59
|
console.log('==========');
|
|
58
60
|
console.log(
|
|
@@ -63,51 +65,6 @@ async function printAccounts() {
|
|
|
63
65
|
);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
async function setupDirectories() {
|
|
67
|
-
const nodeLogsDir = join(process.cwd(), 'node_logs');
|
|
68
|
-
const logsDir = join(nodeLogsDir, 'logs');
|
|
69
|
-
|
|
70
|
-
if (!existsSync(nodeLogsDir)) {
|
|
71
|
-
mkdirSync(nodeLogsDir, { recursive: true });
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!existsSync(logsDir)) {
|
|
75
|
-
mkdirSync(logsDir, { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return { nodeLogsDir, logsDir };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function generateGenesisConfig(nodeLogsDir: string, logsDir: string) {
|
|
82
|
-
console.log(' ├─ Generating genesis configuration...');
|
|
83
|
-
execSync(`sui genesis --write-config ${join(nodeLogsDir, 'sui.yaml')}`);
|
|
84
|
-
|
|
85
|
-
const additionalConfig = `
|
|
86
|
-
- address: "0xe7f93ad7493035bcd674f287f78526091e195a6df9d64f23def61a7ce3adada9"
|
|
87
|
-
gas_amounts:
|
|
88
|
-
- 100000000000000
|
|
89
|
-
- address: "0x492404a537c32b46610bd6ae9f7f16ba16ff5a607d272543fe86cada69d8cf44"
|
|
90
|
-
gas_amounts:
|
|
91
|
-
- 100000000000000
|
|
92
|
-
- address: "0xd27e203483700d837a462d159ced6104619d8e36f737bf2a20c251153bf39f24"
|
|
93
|
-
gas_amounts:
|
|
94
|
-
- 100000000000000
|
|
95
|
-
- address: "0x018f1f175c9b6739a14bc9c81e7984c134ebf9031015cf796fefcef04b8c4990"
|
|
96
|
-
gas_amounts:
|
|
97
|
-
- 100000000000000
|
|
98
|
-
- address: "0x932f6aab2bc636a25374f99794dc8451c4e27c91e87083e301816ed08bc98ed0"
|
|
99
|
-
gas_amounts:
|
|
100
|
-
- 100000000000000
|
|
101
|
-
- address: "0x9a66b2da3036badd22529e3de8a00b0cd7dbbfe589873aa03d5f885f5f8c6501"
|
|
102
|
-
gas_amounts:
|
|
103
|
-
- 100000000000000
|
|
104
|
-
`;
|
|
105
|
-
appendFileSync(join(nodeLogsDir, 'sui.yaml'), additionalConfig);
|
|
106
|
-
|
|
107
|
-
console.log(' ├─ Initializing genesis...');
|
|
108
|
-
execSync(`sui genesis --working-dir ${logsDir} -f --from-config ${join(nodeLogsDir, 'sui.yaml')}`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
68
|
function handleProcessSignals(suiProcess: ReturnType<typeof spawn> | null) {
|
|
112
69
|
const cleanup = () => {
|
|
113
70
|
console.log(chalk.yellow('\n🔔 Stopping Local Node...'));
|
|
@@ -121,7 +78,7 @@ function handleProcessSignals(suiProcess: ReturnType<typeof spawn> | null) {
|
|
|
121
78
|
process.on('SIGTERM', cleanup);
|
|
122
79
|
}
|
|
123
80
|
|
|
124
|
-
export async function startLocalNode(
|
|
81
|
+
export async function startLocalNode() {
|
|
125
82
|
if (isSuiStartRunning()) {
|
|
126
83
|
console.log(chalk.yellow('\n⚠️ Warning: Local Node Already Running'));
|
|
127
84
|
console.log(chalk.yellow(' ├─ Cannot start a new instance'));
|
|
@@ -131,34 +88,35 @@ export async function startLocalNode(options: { forceRegenesis?: boolean } = {})
|
|
|
131
88
|
|
|
132
89
|
printDubhe();
|
|
133
90
|
console.log('🚀 Starting Local Node...');
|
|
134
|
-
|
|
135
91
|
let suiProcess: ReturnType<typeof spawn> | null = null;
|
|
136
|
-
|
|
137
92
|
try {
|
|
138
|
-
|
|
93
|
+
suiProcess = spawn('sui', ['start', '--with-faucet', '--force-regenesis'], {
|
|
94
|
+
env: { ...process.env, RUST_LOG: 'off,sui_node=info' },
|
|
95
|
+
stdio: 'ignore'
|
|
96
|
+
});
|
|
139
97
|
|
|
140
|
-
|
|
141
|
-
console.
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
98
|
+
suiProcess.on('error', (error) => {
|
|
99
|
+
console.error(chalk.red('\n❌ Failed to Start Local Node'));
|
|
100
|
+
console.error(chalk.red(` └─ Error: ${error.message}`));
|
|
101
|
+
});
|
|
102
|
+
await delay(5000);
|
|
147
103
|
console.log(' ├─ Faucet: Enabled');
|
|
104
|
+
console.log(' └─ Force Regenesis: Yes');
|
|
148
105
|
console.log(' └─ HTTP server: http://127.0.0.1:9000/');
|
|
149
106
|
console.log(' └─ Faucet server: http://127.0.0.1:9123/');
|
|
107
|
+
|
|
150
108
|
await printAccounts();
|
|
151
|
-
console.log(chalk.green('🎉 Local environment is ready!'));
|
|
152
109
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
'
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
110
|
+
await delay(2000);
|
|
111
|
+
|
|
112
|
+
const privateKeyFormat = validatePrivateKey(
|
|
113
|
+
'suiprivkey1qzez45sjjsepjgtksqvpq6jw7dzw3zq0dx7a4sulfypd73acaynw5jl9x2c'
|
|
114
|
+
);
|
|
115
|
+
if (privateKeyFormat === false) {
|
|
116
|
+
throw new DubheCliError(`Please check your privateKey.`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.log(chalk.green('🎉 Local environment is ready!'));
|
|
162
120
|
|
|
163
121
|
handleProcessSignals(suiProcess);
|
|
164
122
|
|
|
@@ -173,4 +131,4 @@ export async function startLocalNode(options: { forceRegenesis?: boolean } = {})
|
|
|
173
131
|
}
|
|
174
132
|
process.exit(1);
|
|
175
133
|
}
|
|
176
|
-
}
|
|
134
|
+
}
|
package/src/utils/utils.ts
CHANGED
|
@@ -8,6 +8,7 @@ import chalk from 'chalk';
|
|
|
8
8
|
import { spawn } from 'child_process';
|
|
9
9
|
import { Dubhe, NetworkType, SuiMoveNormalizedModules } from '@0xobelisk/sui-client';
|
|
10
10
|
import { DubheCliError } from './errors';
|
|
11
|
+
import packageJson from '../../package.json';
|
|
11
12
|
|
|
12
13
|
export type DeploymentJsonType = {
|
|
13
14
|
projectName: string;
|
|
@@ -186,11 +187,11 @@ export async function writeOutput(
|
|
|
186
187
|
function getDubheDependency(network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'): string {
|
|
187
188
|
switch (network) {
|
|
188
189
|
case 'localnet':
|
|
189
|
-
return 'Dubhe = { local = "../dubhe
|
|
190
|
+
return 'Dubhe = { local = "../dubhe" }';
|
|
190
191
|
case 'testnet':
|
|
191
|
-
return
|
|
192
|
+
return `Dubhe = { git = "https://github.com/0xobelisk/dubhe-wip.git", subdir = "packages/sui-framework/contracts/dubhe", rev = "${packageJson.version}" }`;
|
|
192
193
|
case 'mainnet':
|
|
193
|
-
return
|
|
194
|
+
return `Dubhe = { git = "https://github.com/0xobelisk/dubhe-wip.git", subdir = "packages/sui-framework/contracts/dubhe", rev = "${packageJson.version}" }`;
|
|
194
195
|
default:
|
|
195
196
|
throw new Error(`Unsupported network: ${network}`);
|
|
196
197
|
}
|