@0xobelisk/sui-cli 1.2.0-pre.12 → 1.2.0-pre.120

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.
Files changed (40) hide show
  1. package/README.md +7 -7
  2. package/dist/dubhe.js +152 -51
  3. package/dist/dubhe.js.map +1 -1
  4. package/package.json +31 -19
  5. package/src/commands/build.ts +61 -18
  6. package/src/commands/call.ts +83 -83
  7. package/src/commands/checkBalance.ts +27 -12
  8. package/src/commands/convertJson.ts +84 -0
  9. package/src/commands/doctor.ts +1515 -0
  10. package/src/commands/faucet.ts +20 -10
  11. package/src/commands/generate.ts +61 -0
  12. package/src/commands/generateKey.ts +3 -2
  13. package/src/commands/index.ts +20 -11
  14. package/src/commands/info.ts +61 -0
  15. package/src/commands/loadMetadata.ts +68 -0
  16. package/src/commands/localnode.ts +22 -6
  17. package/src/commands/publish.ts +55 -7
  18. package/src/commands/query.ts +101 -101
  19. package/src/commands/shell.ts +208 -0
  20. package/src/commands/{configStore.ts → storeConfig.ts} +13 -5
  21. package/src/commands/switchEnv.ts +33 -0
  22. package/src/commands/test.ts +143 -31
  23. package/src/commands/upgrade.ts +46 -6
  24. package/src/commands/wait.ts +333 -22
  25. package/src/commands/watch.ts +9 -8
  26. package/src/dubhe.ts +12 -4
  27. package/src/utils/axios-downloader.ts +116 -0
  28. package/src/utils/callHandler.ts +118 -118
  29. package/src/utils/checkBalance.ts +6 -2
  30. package/src/utils/constants.ts +9 -0
  31. package/src/utils/generateAccount.ts +1 -1
  32. package/src/utils/index.ts +4 -3
  33. package/src/utils/metadataHandler.ts +17 -0
  34. package/src/utils/publishHandler.ts +404 -289
  35. package/src/utils/queryStorage.ts +141 -141
  36. package/src/utils/startNode.ts +115 -16
  37. package/src/utils/storeConfig.ts +50 -10
  38. package/src/utils/upgradeHandler.ts +210 -86
  39. package/src/utils/utils.ts +1025 -63
  40. package/src/commands/schemagen.ts +0 -40
@@ -1,108 +1,108 @@
1
- import type { CommandModule } from 'yargs';
2
- import { logError } from '../utils/errors';
3
- import { queryStorage } from '../utils';
4
- import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
1
+ // import type { CommandModule } from 'yargs';
2
+ // import { logError } from '../utils/errors';
3
+ // import { queryStorage } from '../utils';
4
+ // import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
5
5
 
6
- type Options = {
7
- network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
8
- 'config-path'?: string;
9
- schema: string;
10
- 'object-id'?: string;
11
- 'package-id'?: string;
12
- 'metadata-path'?: string;
13
- params?: any[];
14
- };
6
+ // type Options = {
7
+ // network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
8
+ // 'config-path'?: string;
9
+ // schema: string;
10
+ // 'object-id'?: string;
11
+ // 'package-id'?: string;
12
+ // 'metadata-path'?: string;
13
+ // params?: any[];
14
+ // };
15
15
 
16
- /**
17
- * CLI command module for querying schema struct state
18
- *
19
- * Examples:
20
- *
21
- * 1. Query StorageValue (no params required):
22
- * ```bash
23
- * dubhe query --config-path dubhe.config.ts --network devnet --schema counter --field value
24
- * ```
25
- *
26
- * 2. Query StorageMap (one param required):
27
- * ```bash
28
- * dubhe query --config-path dubhe.config.ts --network devnet --schema token --field balances \
29
- * --params "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
30
- * ```
31
- *
32
- * 3. Query StorageDoubleMap (two params required):
33
- * ```bash
34
- * dubhe query --config-path dubhe.config.ts --network devnet --schema game --field player_relations \
35
- * --params "0x123...456" "0x789...abc"
36
- * ```
37
- */
38
- const commandModule: CommandModule<Options, Options> = {
39
- command: 'query',
16
+ // /**
17
+ // * CLI command module for querying schema struct state
18
+ // *
19
+ // * Examples:
20
+ // *
21
+ // * 1. Query StorageValue (no params required):
22
+ // * ```bash
23
+ // * dubhe query --config-path dubhe.config.ts --network devnet --schema counter --field value
24
+ // * ```
25
+ // *
26
+ // * 2. Query StorageMap (one param required):
27
+ // * ```bash
28
+ // * dubhe query --config-path dubhe.config.ts --network devnet --schema token --field balances \
29
+ // * --params "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
30
+ // * ```
31
+ // *
32
+ // * 3. Query StorageDoubleMap (two params required):
33
+ // * ```bash
34
+ // * dubhe query --config-path dubhe.config.ts --network devnet --schema game --field player_relations \
35
+ // * --params "0x123...456" "0x789...abc"
36
+ // * ```
37
+ // */
38
+ // const commandModule: CommandModule<Options, Options> = {
39
+ // command: 'query',
40
40
 
41
- describe: 'Query dubhe schema struct state',
41
+ // describe: 'Query dubhe schema struct state',
42
42
 
43
- builder: {
44
- network: {
45
- type: 'string',
46
- choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
47
- default: 'localnet',
48
- desc: 'Node network (mainnet/testnet/devnet/localnet)'
49
- },
50
- 'config-path': {
51
- type: 'string',
52
- default: 'dubhe.config.ts',
53
- desc: 'Configuration file path'
54
- },
55
- schema: {
56
- type: 'string',
57
- desc: 'Schema name',
58
- demandOption: true
59
- },
60
- 'object-id': {
61
- type: 'string',
62
- desc: 'Object ID (optional)'
63
- },
64
- 'package-id': {
65
- type: 'string',
66
- desc: 'Package ID (optional)'
67
- },
68
- 'metadata-path': {
69
- type: 'string',
70
- desc: 'Path to metadata JSON file (optional)'
71
- },
72
- params: {
73
- type: 'array',
74
- desc: 'Params for storage type: StorageValue(no params), StorageMap(1 param), StorageDoubleMap(2 params)',
75
- string: true
76
- }
77
- },
43
+ // builder: {
44
+ // network: {
45
+ // type: 'string',
46
+ // choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
47
+ // default: 'localnet',
48
+ // desc: 'Node network (mainnet/testnet/devnet/localnet)'
49
+ // },
50
+ // 'config-path': {
51
+ // type: 'string',
52
+ // default: 'dubhe.config.ts',
53
+ // desc: 'Configuration file path'
54
+ // },
55
+ // schema: {
56
+ // type: 'string',
57
+ // desc: 'Schema name',
58
+ // demandOption: true
59
+ // },
60
+ // 'object-id': {
61
+ // type: 'string',
62
+ // desc: 'Object ID (optional)'
63
+ // },
64
+ // 'package-id': {
65
+ // type: 'string',
66
+ // desc: 'Package ID (optional)'
67
+ // },
68
+ // 'metadata-path': {
69
+ // type: 'string',
70
+ // desc: 'Path to metadata JSON file (optional)'
71
+ // },
72
+ // params: {
73
+ // type: 'array',
74
+ // desc: 'Params for storage type: StorageValue(no params), StorageMap(1 param), StorageDoubleMap(2 params)',
75
+ // string: true
76
+ // }
77
+ // },
78
78
 
79
- async handler({
80
- network,
81
- 'config-path': configPath,
82
- schema,
83
- 'object-id': objectId,
84
- 'package-id': packageId,
85
- 'metadata-path': metadataPath,
86
- params
87
- }) {
88
- try {
89
- const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
79
+ // async handler({
80
+ // network,
81
+ // 'config-path': configPath,
82
+ // schema,
83
+ // 'object-id': objectId,
84
+ // 'package-id': packageId,
85
+ // 'metadata-path': metadataPath,
86
+ // params
87
+ // }) {
88
+ // try {
89
+ // const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
90
90
 
91
- await queryStorage({
92
- dubheConfig,
93
- schema,
94
- objectId,
95
- network,
96
- packageId,
97
- metadataFilePath: metadataPath,
98
- params
99
- });
100
- } catch (error: any) {
101
- logError(error);
102
- process.exit(1);
103
- }
104
- process.exit(0);
105
- }
106
- };
91
+ // await queryStorage({
92
+ // dubheConfig,
93
+ // schema,
94
+ // objectId,
95
+ // network,
96
+ // packageId,
97
+ // metadataFilePath: metadataPath,
98
+ // params
99
+ // });
100
+ // } catch (error: any) {
101
+ // logError(error);
102
+ // process.exit(1);
103
+ // }
104
+ // process.exit(0);
105
+ // }
106
+ // };
107
107
 
108
- export default commandModule;
108
+ // export default commandModule;
@@ -0,0 +1,208 @@
1
+ import readline from 'readline';
2
+
3
+ import yargs, { CommandModule } from 'yargs';
4
+ import { commands } from '.';
5
+ import chalk from 'chalk';
6
+ import { getDefaultNetwork, printDubhe } from '../utils';
7
+ import dotenv from 'dotenv';
8
+ import { spawn } from 'child_process';
9
+
10
+ dotenv.config();
11
+
12
+ let shouldHandlerExit = true;
13
+
14
+ // Blacklist of commands not available inside shell
15
+ const SHELL_BLACKLIST_COMMANDS = ['shell', 'wait'];
16
+
17
+ export const handlerExit = (status: number = 0) => {
18
+ if (shouldHandlerExit) process.exit(status);
19
+ };
20
+
21
+ type Options = {
22
+ network: any;
23
+ 'rpc-url'?: string;
24
+ };
25
+
26
+ const parseCommandNames = () => {
27
+ return commands
28
+ .filter((command) => !SHELL_BLACKLIST_COMMANDS.includes(command.command as string))
29
+ .map((command) => command.command);
30
+ };
31
+
32
+ const ShellCommand: CommandModule<Options, Options> = {
33
+ command: 'shell',
34
+ describe: 'Open a shell to interact with the Dubhe System',
35
+ builder(yargs) {
36
+ return yargs.options({
37
+ network: {
38
+ type: 'string',
39
+ choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'],
40
+ default: 'default',
41
+ desc: 'Node network (mainnet/testnet/devnet/localnet)'
42
+ },
43
+ 'rpc-url': {
44
+ type: 'string',
45
+ desc: 'Custom RPC endpoint URL injected into every sub-command (overrides the default for the selected network)'
46
+ }
47
+ });
48
+ },
49
+ handler: async ({ network, 'rpc-url': rpcUrl }) => {
50
+ if (network == 'default') {
51
+ network = await getDefaultNetwork();
52
+ console.log(chalk.yellow(`Use default network: [${network}]`));
53
+ }
54
+ shouldHandlerExit = false;
55
+ const commandHistory: string[] = [];
56
+
57
+ function completer(line: string) {
58
+ const hits = parseCommandNames().filter((c) => {
59
+ if (!c) return false;
60
+ return (c as string).startsWith(line.toLowerCase());
61
+ });
62
+ return [hits.length ? hits : parseCommandNames(), line];
63
+ }
64
+
65
+ const rl = readline.createInterface({
66
+ input: process.stdin,
67
+ output: process.stdout,
68
+ prompt: `dubhe(${chalk.green(network)}${
69
+ rpcUrl ? chalk.gray('[custom-rpc]') : ''
70
+ }) ${chalk.bold('>')} `,
71
+ completer: completer,
72
+ historySize: 200
73
+ });
74
+
75
+ rl.on('line', async (line) => {
76
+ const fullCommand = line.trim();
77
+ if (!fullCommand) {
78
+ rl.prompt();
79
+ return;
80
+ }
81
+
82
+ // Add command to history
83
+ commandHistory.push(fullCommand);
84
+
85
+ const parts = fullCommand.split(/\s+/);
86
+ const commandName = parts[0].toLowerCase();
87
+
88
+ const command = commands.find(
89
+ (c) => c.command === commandName && !SHELL_BLACKLIST_COMMANDS.includes(commandName)
90
+ );
91
+
92
+ // Check if user is asking for help
93
+ if (parts.includes('--help') || parts.includes('-h')) {
94
+ if (command) {
95
+ try {
96
+ // Use spawn to call dubhe help externally to avoid validation issues
97
+ const dubheProcess = spawn('node', [process.argv[1], commandName, '--help'], {
98
+ stdio: 'inherit',
99
+ env: { ...process.env }
100
+ });
101
+
102
+ dubheProcess.on('exit', () => {
103
+ rl.prompt();
104
+ });
105
+
106
+ dubheProcess.on('error', () => {
107
+ // Fallback: show basic help information
108
+ console.log(`\n${command.describe || `${commandName} command`}`);
109
+ console.log(`\nUsage: ${commandName} [options]`);
110
+ console.log('\nFor complete help with all options, please exit shell and run:');
111
+ console.log(chalk.cyan(` dubhe ${commandName} --help`));
112
+ rl.prompt();
113
+ });
114
+
115
+ return; // Don't call rl.prompt() here as it's handled in the callbacks
116
+ } catch {
117
+ // Fallback: show basic help information
118
+ console.log(`\n${command.describe || `${commandName} command`}`);
119
+ console.log(`\nUsage: ${commandName} [options]`);
120
+ console.log('\nFor complete help with all options, please exit shell and run:');
121
+ console.log(chalk.cyan(` dubhe ${commandName} --help`));
122
+ }
123
+ } else {
124
+ console.log(
125
+ `🤷 Unknown command: "${commandName}". Type 'help' to see available commands.`
126
+ );
127
+ }
128
+ rl.prompt();
129
+ return;
130
+ }
131
+
132
+ if (command) {
133
+ try {
134
+ const { builder, handler } = command;
135
+ const yargsInstance = yargs().exitProcess(false);
136
+ if (builder) {
137
+ if (typeof builder === 'function') {
138
+ builder(yargsInstance);
139
+ } else {
140
+ yargsInstance.options(builder);
141
+ }
142
+ const userArgs = parts.slice(1);
143
+ const hasNetworkFlag = userArgs.includes('--network') || userArgs.includes('-n');
144
+ const hasRpcUrlFlag = userArgs.includes('--rpc-url');
145
+ const argv = yargsInstance.parseSync([
146
+ commandName,
147
+ ...(hasNetworkFlag ? [] : ['--network', network]),
148
+ ...(hasRpcUrlFlag || !rpcUrl ? [] : ['--rpc-url', rpcUrl]),
149
+ ...userArgs
150
+ ]);
151
+ if (handler) {
152
+ await handler(argv);
153
+ }
154
+ }
155
+ } catch (error) {
156
+ console.log(chalk.red(error));
157
+ }
158
+ } else if (commandName == 'help') {
159
+ console.log('Available dubhe commands:');
160
+
161
+ // Find the longest command name for alignment (excluding blacklisted commands)
162
+ const availableCommands = commands.filter(
163
+ (c) => !SHELL_BLACKLIST_COMMANDS.includes(c.command as string)
164
+ );
165
+ const maxCommandLength = Math.max(
166
+ ...availableCommands.map((c) => {
167
+ const command =
168
+ typeof c.command === 'string'
169
+ ? c.command
170
+ : Array.isArray(c.command)
171
+ ? c.command[0]
172
+ : '';
173
+ return command.length;
174
+ })
175
+ );
176
+
177
+ availableCommands.forEach((c) => {
178
+ const command =
179
+ typeof c.command === 'string'
180
+ ? c.command
181
+ : Array.isArray(c.command)
182
+ ? c.command[0]
183
+ : '';
184
+ const paddedCommand = command.padEnd(maxCommandLength);
185
+ console.log(` ${chalk.green(paddedCommand)} ${c.describe}`);
186
+ });
187
+ rl.prompt();
188
+ return;
189
+ } else if (['exit', 'quit'].indexOf(commandName) !== -1) {
190
+ console.log('Goodbye You will have a nice day! 👋');
191
+ rl.close();
192
+ return;
193
+ } else {
194
+ console.log(`🤷 Unknown command: "${fullCommand}". Type 'help' to see available commands.`);
195
+ }
196
+ rl.prompt();
197
+ });
198
+
199
+ rl.on('close', () => {
200
+ process.exit(0);
201
+ });
202
+
203
+ printDubhe();
204
+ rl.prompt();
205
+ }
206
+ };
207
+
208
+ export default ShellCommand;
@@ -1,15 +1,18 @@
1
1
  import type { CommandModule } from 'yargs';
2
2
  import { storeConfigHandler } from '../utils/storeConfig';
3
3
  import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
4
+ import { handlerExit } from './shell';
5
+ import chalk from 'chalk';
6
+ import { getDefaultNetwork } from '../utils';
4
7
 
5
8
  type Options = {
6
9
  'config-path': string;
7
- network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
10
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet' | 'default';
8
11
  'output-ts-path': string;
9
12
  };
10
13
 
11
14
  const commandModule: CommandModule<Options, Options> = {
12
- command: 'config-store',
15
+ command: 'store-config',
13
16
 
14
17
  describe: 'Store configuration for the Dubhe project',
15
18
 
@@ -21,7 +24,8 @@ const commandModule: CommandModule<Options, Options> = {
21
24
  },
22
25
  network: {
23
26
  type: 'string',
24
- choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
27
+ choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'],
28
+ default: 'default',
25
29
  desc: 'Network to store config for'
26
30
  },
27
31
  'output-ts-path': {
@@ -31,13 +35,17 @@ const commandModule: CommandModule<Options, Options> = {
31
35
  },
32
36
  async handler({ 'config-path': configPath, network, 'output-ts-path': outputTsPath }) {
33
37
  try {
38
+ if (network == 'default') {
39
+ network = await getDefaultNetwork();
40
+ console.log(chalk.yellow(`Use default network: [${network}]`));
41
+ }
34
42
  const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
35
43
  await storeConfigHandler(dubheConfig, network, outputTsPath);
36
44
  } catch (error) {
37
45
  console.error('Error storing config:', error);
38
- process.exit(1);
46
+ handlerExit(1);
39
47
  }
40
- process.exit(0);
48
+ handlerExit();
41
49
  }
42
50
  };
43
51
 
@@ -0,0 +1,33 @@
1
+ import type { CommandModule, ArgumentsCamelCase } from 'yargs';
2
+ import { switchEnv } from '../utils';
3
+ import { handlerExit } from './shell';
4
+
5
+ type Options = {
6
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet' | 'default';
7
+ 'rpc-url'?: string;
8
+ };
9
+
10
+ const commandModule: CommandModule<Options, Options> = {
11
+ command: 'switch-env',
12
+ describe: 'Switch environment',
13
+ builder(yargs) {
14
+ return yargs.options({
15
+ network: {
16
+ type: 'string',
17
+ choices: ['mainnet', 'testnet', 'devnet', 'localnet'] as const,
18
+ default: 'localnet',
19
+ desc: 'Switch to node network (mainnet/testnet/devnet/localnet)'
20
+ },
21
+ 'rpc-url': {
22
+ type: 'string',
23
+ desc: 'Custom RPC endpoint URL (overrides the default for the selected network)'
24
+ }
25
+ }) as any;
26
+ },
27
+ async handler(argv: ArgumentsCamelCase<Options>) {
28
+ await switchEnv(argv.network as 'mainnet' | 'testnet' | 'devnet' | 'localnet', argv['rpc-url']);
29
+ handlerExit();
30
+ }
31
+ };
32
+
33
+ export default commandModule;