@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
package/src/utils/errors.ts
CHANGED
|
@@ -3,44 +3,44 @@ import { ZodError } from 'zod';
|
|
|
3
3
|
import { fromZodError, ValidationError } from 'zod-validation-error';
|
|
4
4
|
|
|
5
5
|
export class NotInsideProjectError extends Error {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
name = 'NotInsideProjectError';
|
|
7
|
+
message = 'You are not inside a Dubhe project';
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export class DubheCliError extends Error {
|
|
11
|
-
|
|
11
|
+
name = 'DubheCliError';
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export class UpgradeError extends Error {
|
|
15
|
-
|
|
15
|
+
name = 'UpgradeError';
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export class FsIibError extends Error {
|
|
19
|
-
|
|
19
|
+
name = 'FsIibError';
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function logError(error: unknown) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
if (error instanceof ValidationError) {
|
|
24
|
+
console.log(chalk.redBright(error.message));
|
|
25
|
+
} else if (error instanceof ZodError) {
|
|
26
|
+
// TODO currently this error shouldn't happen, use `fromZodErrorCustom`
|
|
27
|
+
const validationError = fromZodError(error, {
|
|
28
|
+
prefixSeparator: '\n- ',
|
|
29
|
+
issueSeparator: '\n- '
|
|
30
|
+
});
|
|
31
|
+
console.log(chalk.redBright(validationError.message));
|
|
32
|
+
} else if (error instanceof NotInsideProjectError) {
|
|
33
|
+
console.log(chalk.red(error.message));
|
|
34
|
+
console.log('');
|
|
35
|
+
// TODO add docs to the website and update the link to the specific page
|
|
36
|
+
console.log(
|
|
37
|
+
chalk.blue(
|
|
38
|
+
`To learn more about Dubhe's configuration, please go to https://github.com/0xobelisk`
|
|
39
|
+
)
|
|
40
|
+
);
|
|
41
|
+
} else if (error instanceof DubheCliError) {
|
|
42
|
+
console.log(chalk.red(error));
|
|
43
|
+
} else {
|
|
44
|
+
console.log(error);
|
|
45
|
+
}
|
|
46
46
|
}
|
|
@@ -2,111 +2,96 @@ import { Dubhe } from '@0xobelisk/sui-client';
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
|
|
5
|
-
export async function generateAccountHandler(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
const path = process.cwd();
|
|
22
|
-
let privateKey: string;
|
|
5
|
+
export async function generateAccountHandler(force: boolean = false, outputTsPath?: string) {
|
|
6
|
+
if (outputTsPath) {
|
|
7
|
+
console.log(
|
|
8
|
+
chalk.blue(
|
|
9
|
+
'Note: The generated account will be stored in the .env file and the TypeScript file specified by the --output-ts-path option.'
|
|
10
|
+
)
|
|
11
|
+
);
|
|
12
|
+
console.log(
|
|
13
|
+
chalk.yellow('Warning: Do not expose the key file. It is intended for local testing only.\n')
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const path = process.cwd();
|
|
17
|
+
let privateKey: string;
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
if (force) {
|
|
20
|
+
const dubhe = new Dubhe();
|
|
21
|
+
const keypair = dubhe.getSigner();
|
|
22
|
+
privateKey = keypair.getSecretKey();
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
|
|
25
|
+
console.log(chalk.green(`File created at: ${path}/.env`));
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
fs.writeFileSync(
|
|
41
|
-
outputTsPath,
|
|
42
|
-
`export const PRIVATEKEY = '${privateKey}';
|
|
27
|
+
if (outputTsPath) {
|
|
28
|
+
const dir = outputTsPath.substring(0, outputTsPath.lastIndexOf('/'));
|
|
29
|
+
if (!fs.existsSync(dir)) {
|
|
30
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
fs.writeFileSync(
|
|
33
|
+
outputTsPath,
|
|
34
|
+
`export const PRIVATEKEY = '${privateKey}';
|
|
43
35
|
export const ACCOUNT = '${keypair.toSuiAddress()}';
|
|
44
36
|
`
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
);
|
|
38
|
+
console.log(chalk.green(`File created at: ${outputTsPath}\n`));
|
|
39
|
+
}
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
41
|
+
console.log(chalk.blue(`Force generate new Account: ${keypair.toSuiAddress()}`));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
54
44
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
// Check if .env file exists and has content
|
|
46
|
+
try {
|
|
47
|
+
const envContent = fs.readFileSync(`${path}/.env`, 'utf8');
|
|
48
|
+
const match = envContent.match(/PRIVATE_KEY=(.+)/);
|
|
49
|
+
if (match && match[1]) {
|
|
50
|
+
privateKey = match[1];
|
|
51
|
+
const dubhe = new Dubhe({ secretKey: privateKey });
|
|
52
|
+
const keypair = dubhe.getSigner();
|
|
63
53
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
fs.writeFileSync(
|
|
73
|
-
outputTsPath,
|
|
74
|
-
`export const PRIVATEKEY = '${privateKey}';
|
|
54
|
+
if (outputTsPath) {
|
|
55
|
+
const dir = outputTsPath.substring(0, outputTsPath.lastIndexOf('/'));
|
|
56
|
+
if (!fs.existsSync(dir)) {
|
|
57
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
58
|
+
}
|
|
59
|
+
fs.writeFileSync(
|
|
60
|
+
outputTsPath,
|
|
61
|
+
`export const PRIVATEKEY = '${privateKey}';
|
|
75
62
|
export const ACCOUNT = '${keypair.toSuiAddress()}';
|
|
76
63
|
`
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
64
|
+
);
|
|
65
|
+
console.log(chalk.green(`File created at: ${outputTsPath}\n`));
|
|
66
|
+
}
|
|
80
67
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// .env file doesn't exist or failed to read, continue to generate new account
|
|
88
|
-
}
|
|
68
|
+
console.log(chalk.blue(`Using existing Account: ${keypair.toSuiAddress()}`));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
// .env file doesn't exist or failed to read, continue to generate new account
|
|
73
|
+
}
|
|
89
74
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
75
|
+
// If no existing private key, generate new account
|
|
76
|
+
const dubhe = new Dubhe();
|
|
77
|
+
const keypair = dubhe.getSigner();
|
|
78
|
+
privateKey = keypair.getSecretKey();
|
|
79
|
+
fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
|
|
80
|
+
console.log(chalk.green(`File created at: ${path}/.env`));
|
|
96
81
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
82
|
+
if (outputTsPath) {
|
|
83
|
+
const dir = outputTsPath.substring(0, outputTsPath.lastIndexOf('/'));
|
|
84
|
+
if (!fs.existsSync(dir)) {
|
|
85
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
86
|
+
}
|
|
87
|
+
fs.writeFileSync(
|
|
88
|
+
outputTsPath,
|
|
89
|
+
`export const PRIVATEKEY = '${privateKey}';
|
|
105
90
|
export const ACCOUNT = '${keypair.toSuiAddress()}';
|
|
106
91
|
`
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
92
|
+
);
|
|
93
|
+
console.log(chalk.green(`File created at: ${outputTsPath}\n`));
|
|
94
|
+
}
|
|
110
95
|
|
|
111
|
-
|
|
96
|
+
console.log(chalk.blue(`Generate new Account: ${keypair.toSuiAddress()}`));
|
|
112
97
|
}
|