@0xobelisk/sui-cli 1.1.5 → 1.1.7

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.
@@ -4,41 +4,41 @@ import { upgradeHandler } from '../utils/upgradeHandler';
4
4
  import { DubheConfig, loadConfig } from '@0xobelisk/sui-common';
5
5
 
6
6
  type Options = {
7
- network: any;
8
- 'config-path': string;
7
+ network: any;
8
+ 'config-path': string;
9
9
  };
10
10
 
11
11
  const commandModule: CommandModule<Options, Options> = {
12
- command: 'upgrade',
12
+ command: 'upgrade',
13
13
 
14
- describe: 'Upgrade your move contracts',
14
+ describe: 'Upgrade your move contracts',
15
15
 
16
- builder(yargs) {
17
- return yargs.options({
18
- network: {
19
- type: 'string',
20
- choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
21
- default: 'localnet',
22
- desc: 'Network of the node (mainnet/testnet/devnet/localnet)',
23
- },
24
- 'config-path': {
25
- type: 'string',
26
- default: 'dubhe.config.ts',
27
- decs: 'Path to the config file',
28
- },
29
- });
30
- },
16
+ builder(yargs) {
17
+ return yargs.options({
18
+ network: {
19
+ type: 'string',
20
+ choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
21
+ default: 'localnet',
22
+ desc: 'Network of the node (mainnet/testnet/devnet/localnet)'
23
+ },
24
+ 'config-path': {
25
+ type: 'string',
26
+ default: 'dubhe.config.ts',
27
+ decs: 'Path to the config file'
28
+ }
29
+ });
30
+ },
31
31
 
32
- async handler({ network, 'config-path': configPath }) {
33
- try {
34
- const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
35
- await upgradeHandler(dubheConfig, dubheConfig.name, network);
36
- } catch (error: any) {
37
- logError(error);
38
- process.exit(1);
39
- }
40
- process.exit(0);
41
- },
32
+ async handler({ network, 'config-path': configPath }) {
33
+ try {
34
+ const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
35
+ await upgradeHandler(dubheConfig, dubheConfig.name, network);
36
+ } catch (error: any) {
37
+ logError(error);
38
+ process.exit(1);
39
+ }
40
+ process.exit(0);
41
+ }
42
42
  };
43
43
 
44
44
  export default commandModule;
@@ -1,21 +1,21 @@
1
- import type { CommandModule } from "yargs";
2
- import chokidar from "chokidar";
3
- import { exec } from "child_process";
1
+ import type { CommandModule } from 'yargs';
2
+ import chokidar from 'chokidar';
3
+ import { exec } from 'child_process';
4
4
 
5
5
  const commandModule: CommandModule = {
6
- command: "watch",
6
+ command: 'watch',
7
7
 
8
- describe: "Watch dubhe config",
8
+ describe: 'Watch dubhe config',
9
9
 
10
10
  builder(yargs) {
11
11
  return yargs;
12
12
  },
13
13
 
14
14
  async handler() {
15
- const configFilePath = "dubhe.config.ts";
15
+ const configFilePath = 'dubhe.config.ts';
16
16
 
17
17
  const runSchemagen = () => {
18
- exec("pnpm dubhe schemagen", (error, stdout, stderr) => {
18
+ exec('pnpm dubhe schemagen', (error, stdout, stderr) => {
19
19
  if (error) {
20
20
  console.error(`Error executing schemagen: ${error.message}`);
21
21
  return;
@@ -29,22 +29,22 @@ const commandModule: CommandModule = {
29
29
  };
30
30
 
31
31
  const watcher = chokidar.watch(configFilePath, {
32
- persistent: true,
32
+ persistent: true
33
33
  });
34
34
 
35
- watcher.on("change", (path) => {
35
+ watcher.on('change', (path) => {
36
36
  console.log(`${path} has been changed. Running schemagen...`);
37
37
  runSchemagen();
38
38
  });
39
39
 
40
40
  console.log(`Watching for changes in ${configFilePath}...`);
41
41
 
42
- process.on("SIGINT", () => {
42
+ process.on('SIGINT', () => {
43
43
  watcher.close();
44
- console.log("\nWatch stopped.");
44
+ console.log('\nWatch stopped.');
45
45
  process.exit();
46
46
  });
47
- },
47
+ }
48
48
  };
49
49
 
50
50
  export default commandModule;
package/src/dubhe.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from "yargs";
4
- import { hideBin } from "yargs/helpers";
5
- import { commands } from "./commands";
6
- import { logError } from "./utils/errors";
3
+ import yargs from 'yargs';
4
+ import { hideBin } from 'yargs/helpers';
5
+ import { commands } from './commands';
6
+ import { logError } from './utils/errors';
7
7
 
8
8
  // Load .env file into process.env
9
- import * as dotenv from "dotenv";
10
- import chalk from "chalk";
9
+ import * as dotenv from 'dotenv';
10
+ import chalk from 'chalk';
11
11
  dotenv.config();
12
12
 
13
13
  yargs(hideBin(process.argv))
14
14
  // Explicit name to display in help (by default it's the entry file, which may not be "dubhe" for e.g. ts-node)
15
- .scriptName("dubhe")
15
+ .scriptName('dubhe')
16
16
  // Use the commands directory to scaffold
17
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- command array overload isn't typed, see https://github.com/yargs/yargs/blob/main/docs/advanced.md#esm-hierarchy
18
18
  .command(commands as any)
@@ -21,16 +21,18 @@ yargs(hideBin(process.argv))
21
21
  // Custom error handler
22
22
  .fail((msg, err) => {
23
23
  console.error(chalk.red(msg));
24
- if (msg.includes("Missing required argument")) {
24
+ if (msg.includes('Missing required argument')) {
25
25
  console.log(
26
- chalk.yellow(`Run 'pnpm dubhe ${process.argv[2]} --help' for a list of available and required arguments.`)
26
+ chalk.yellow(
27
+ `Run 'pnpm dubhe ${process.argv[2]} --help' for a list of available and required arguments.`
28
+ )
27
29
  );
28
30
  }
29
- console.log("");
31
+ console.log('');
30
32
  logError(err);
31
- console.log("");
33
+ console.log('');
32
34
 
33
35
  process.exit(1);
34
36
  })
35
37
  // Useful aliases.
36
- .alias({ h: "help" }).argv;
38
+ .alias({ h: 'help' }).argv;
package/src/modules.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // adding .js to minimal would break clients down the line because it probably won't get a synthetic default import
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
- declare module "protobufjs/minimal" {
3
+ declare module 'protobufjs/minimal' {
4
4
  export const configure: any;
5
5
  export const util: any;
6
6
  export const Reader: any;
@@ -8,4 +8,4 @@ declare module "protobufjs/minimal" {
8
8
  export const Writer: any;
9
9
  export type Writer = any;
10
10
  }
11
- declare module "rollup-plugin-preserve-shebang";
11
+ declare module 'rollup-plugin-preserve-shebang';
@@ -1,39 +1,34 @@
1
- import {
2
- Dubhe,
3
- loadMetadata,
4
- Transaction,
5
- TransactionResult,
6
- } from '@0xobelisk/sui-client';
1
+ import { Dubhe, loadMetadata, Transaction, TransactionResult } from '@0xobelisk/sui-client';
7
2
  import { DubheCliError } from './errors';
8
3
  import { validatePrivateKey, getOldPackageId } from './utils';
9
4
  import { DubheConfig } from '@0xobelisk/sui-common';
10
5
  import { loadMetadataFromFile } from './queryStorage';
11
6
 
12
7
  const BaseTxType = [
13
- 'u8',
14
- 'u16',
15
- 'u32',
16
- 'u64',
17
- 'u128',
18
- 'u256',
19
- 'bool',
20
- 'id',
21
- 'string',
22
- 'address',
23
- 'object',
8
+ 'u8',
9
+ 'u16',
10
+ 'u32',
11
+ 'u64',
12
+ 'u128',
13
+ 'u256',
14
+ 'bool',
15
+ 'id',
16
+ 'string',
17
+ 'address',
18
+ 'object'
24
19
  ];
25
20
 
26
21
  function validateParams(params: any[]) {
27
- try {
28
- params.forEach(param => {
29
- const [type, _] = param.split(':');
30
- if (!BaseTxType.includes(type)) {
31
- throw new Error(`Invalid param type: ${type}`);
32
- }
33
- });
34
- } catch (error) {
35
- throw new Error(`Invalid params: ${error}`);
36
- }
22
+ try {
23
+ params.forEach((param) => {
24
+ const [type, _] = param.split(':');
25
+ if (!BaseTxType.includes(type)) {
26
+ throw new Error(`Invalid param type: ${type}`);
27
+ }
28
+ });
29
+ } catch (error) {
30
+ throw new Error(`Invalid params: ${error}`);
31
+ }
37
32
  }
38
33
 
39
34
  // param:
@@ -48,119 +43,119 @@ function validateParams(params: any[]) {
48
43
  // bool:true
49
44
  // string:"hello"
50
45
  function formatBCS(tx: Transaction, param: string) {
51
- const [type, value] = param.split(':');
52
- switch (type) {
53
- case 'u8':
54
- return tx.pure.u8(parseInt(value));
55
- case 'u16':
56
- return tx.pure.u16(parseInt(value));
57
- case 'u32':
58
- return tx.pure.u32(parseInt(value));
59
- case 'u64':
60
- return tx.pure.u64(parseInt(value));
61
- case 'u128':
62
- return tx.pure.u128(parseInt(value));
63
- case 'u256':
64
- return tx.pure.u256(parseInt(value));
65
- case 'object':
66
- return tx.object(value);
67
- case 'address':
68
- return tx.pure.address(value);
69
- case 'bool':
70
- return tx.pure.bool(value === 'true');
71
- case 'string':
72
- return tx.pure.string(value);
73
- default:
74
- throw new Error(`Invalid param type: ${type}`);
75
- }
46
+ const [type, value] = param.split(':');
47
+ switch (type) {
48
+ case 'u8':
49
+ return tx.pure.u8(parseInt(value));
50
+ case 'u16':
51
+ return tx.pure.u16(parseInt(value));
52
+ case 'u32':
53
+ return tx.pure.u32(parseInt(value));
54
+ case 'u64':
55
+ return tx.pure.u64(parseInt(value));
56
+ case 'u128':
57
+ return tx.pure.u128(parseInt(value));
58
+ case 'u256':
59
+ return tx.pure.u256(parseInt(value));
60
+ case 'object':
61
+ return tx.object(value);
62
+ case 'address':
63
+ return tx.pure.address(value);
64
+ case 'bool':
65
+ return tx.pure.bool(value === 'true');
66
+ case 'string':
67
+ return tx.pure.string(value);
68
+ default:
69
+ throw new Error(`Invalid param type: ${type}`);
70
+ }
76
71
  }
77
72
 
78
73
  function formatBCSParams(tx: Transaction, params: any[]) {
79
- return params.map(param => formatBCS(tx, param));
74
+ return params.map((param) => formatBCS(tx, param));
80
75
  }
81
76
 
82
77
  export async function callHandler({
83
- dubheConfig,
84
- moduleName,
85
- funcName,
86
- params,
87
- network,
88
- packageId,
89
- metadataFilePath,
78
+ dubheConfig,
79
+ moduleName,
80
+ funcName,
81
+ params,
82
+ network,
83
+ packageId,
84
+ metadataFilePath
90
85
  }: {
91
- dubheConfig: DubheConfig;
92
- moduleName: string;
93
- funcName: string;
94
- params?: any[];
95
- network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
96
- packageId?: string;
97
- metadataFilePath?: string;
86
+ dubheConfig: DubheConfig;
87
+ moduleName: string;
88
+ funcName: string;
89
+ params?: any[];
90
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
91
+ packageId?: string;
92
+ metadataFilePath?: string;
98
93
  }) {
99
- const privateKey = process.env.PRIVATE_KEY;
100
- if (!privateKey) {
101
- throw new DubheCliError(
102
- `Missing PRIVATE_KEY environment variable.
94
+ const privateKey = process.env.PRIVATE_KEY;
95
+ if (!privateKey) {
96
+ throw new DubheCliError(
97
+ `Missing PRIVATE_KEY environment variable.
103
98
  Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
104
99
  in your contracts directory to use the default sui private key.`
105
- );
106
- }
107
- const privateKeyFormat = validatePrivateKey(privateKey);
108
- if (privateKeyFormat === false) {
109
- throw new DubheCliError(`Please check your privateKey.`);
110
- }
100
+ );
101
+ }
102
+ const privateKeyFormat = validatePrivateKey(privateKey);
103
+ if (privateKeyFormat === false) {
104
+ throw new DubheCliError(`Please check your privateKey.`);
105
+ }
111
106
 
112
- const path = process.cwd();
113
- const projectPath = `${path}/contracts/${dubheConfig.name}`;
107
+ const path = process.cwd();
108
+ const projectPath = `${path}/contracts/${dubheConfig.name}`;
114
109
 
115
- packageId = packageId || (await getOldPackageId(projectPath, network));
110
+ packageId = packageId || (await getOldPackageId(projectPath, network));
116
111
 
117
- // objectId = objectId || (await getObjectId(projectPath, network, schema));
112
+ // objectId = objectId || (await getObjectId(projectPath, network, schema));
118
113
 
119
- let metadata;
120
- if (metadataFilePath) {
121
- metadata = await loadMetadataFromFile(metadataFilePath);
122
- } else {
123
- metadata = await loadMetadata(network, packageId);
124
- }
125
- if (!metadata) {
126
- throw new DubheCliError(
127
- `Metadata file not found. Please provide a metadata file path or set the packageId.`
128
- );
129
- }
114
+ let metadata;
115
+ if (metadataFilePath) {
116
+ metadata = await loadMetadataFromFile(metadataFilePath);
117
+ } else {
118
+ metadata = await loadMetadata(network, packageId);
119
+ }
120
+ if (!metadata) {
121
+ throw new DubheCliError(
122
+ `Metadata file not found. Please provide a metadata file path or set the packageId.`
123
+ );
124
+ }
130
125
 
131
- // if (!dubheConfig.schemas[schema]) {
132
- // throw new DubheCliError(
133
- // `Schema "${schema}" not found in dubhe config. Available schemas: ${Object.keys(
134
- // dubheConfig.schemas
135
- // ).join(', ')}`
136
- // );
137
- // }
126
+ // if (!dubheConfig.schemas[schema]) {
127
+ // throw new DubheCliError(
128
+ // `Schema "${schema}" not found in dubhe config. Available schemas: ${Object.keys(
129
+ // dubheConfig.schemas
130
+ // ).join(', ')}`
131
+ // );
132
+ // }
138
133
 
139
- // if (!dubheConfig.schemas[schema].structure[struct]) {
140
- // throw new DubheCliError(
141
- // `Struct "${struct}" not found in schema "${schema}". Available structs: ${Object.keys(
142
- // dubheConfig.schemas[schema].structure
143
- // ).join(', ')}`
144
- // );
145
- // }
134
+ // if (!dubheConfig.schemas[schema].structure[struct]) {
135
+ // throw new DubheCliError(
136
+ // `Struct "${struct}" not found in schema "${schema}". Available structs: ${Object.keys(
137
+ // dubheConfig.schemas[schema].structure
138
+ // ).join(', ')}`
139
+ // );
140
+ // }
146
141
 
147
- // const storageType = dubheConfig.schemas[schema].structure[struct];
142
+ // const storageType = dubheConfig.schemas[schema].structure[struct];
148
143
 
149
- const processedParams = params || [];
150
- validateParams(processedParams);
151
- const dubhe = new Dubhe({
152
- secretKey: privateKeyFormat,
153
- networkType: network,
154
- packageId,
155
- metadata,
156
- });
157
- const tx = new Transaction();
158
- const formattedParams = formatBCSParams(tx, processedParams);
144
+ const processedParams = params || [];
145
+ validateParams(processedParams);
146
+ const dubhe = new Dubhe({
147
+ secretKey: privateKeyFormat,
148
+ networkType: network,
149
+ packageId,
150
+ metadata
151
+ });
152
+ const tx = new Transaction();
153
+ const formattedParams = formatBCSParams(tx, processedParams);
159
154
 
160
- const result = (await dubhe.tx[moduleName][funcName]({
161
- tx,
162
- params: formattedParams,
163
- })) as TransactionResult;
155
+ const result = (await dubhe.tx[moduleName][funcName]({
156
+ tx,
157
+ params: formattedParams
158
+ })) as TransactionResult;
164
159
 
165
- console.log(JSON.stringify(result, null, 2));
160
+ console.log(JSON.stringify(result, null, 2));
166
161
  }
@@ -5,43 +5,35 @@ import { validatePrivateKey } from './utils';
5
5
  import { DubheCliError } from './errors';
6
6
  dotenv.config();
7
7
 
8
- export async function checkBalanceHandler(
9
- network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
10
- ) {
11
- try {
12
- const privateKey = process.env.PRIVATE_KEY;
13
- if (!privateKey) {
14
- throw new DubheCliError(
15
- `Missing PRIVATE_KEY environment variable.
8
+ export async function checkBalanceHandler(network: 'mainnet' | 'testnet' | 'devnet' | 'localnet') {
9
+ try {
10
+ const privateKey = process.env.PRIVATE_KEY;
11
+ if (!privateKey) {
12
+ throw new DubheCliError(
13
+ `Missing PRIVATE_KEY environment variable.
16
14
  Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
17
15
  in your contracts directory to use the default sui private key.`
18
- );
19
- }
20
- const privateKeyFormat = validatePrivateKey(privateKey);
21
- if (privateKeyFormat === false) {
22
- throw new DubheCliError(`Please check your privateKey.`);
23
- }
16
+ );
17
+ }
18
+ const privateKeyFormat = validatePrivateKey(privateKey);
19
+ if (privateKeyFormat === false) {
20
+ throw new DubheCliError(`Please check your privateKey.`);
21
+ }
24
22
 
25
- const dubhe = new Dubhe({
26
- secretKey: process.env.PRIVATE_KEY,
27
- networkType: network as NetworkType,
28
- });
23
+ const dubhe = new Dubhe({
24
+ secretKey: process.env.PRIVATE_KEY,
25
+ networkType: network as NetworkType
26
+ });
29
27
 
30
- const balance = await dubhe.getBalance();
31
- const balanceInSUI = Number(balance.totalBalance) / 1_000_000_000;
28
+ const balance = await dubhe.getBalance();
29
+ const balanceInSUI = Number(balance.totalBalance) / 1_000_000_000;
32
30
 
33
- if (balanceInSUI === 0) {
34
- throw new DubheCliError(
35
- `Your account balance is 0 SUI. Please get some SUI to proceed.`
36
- );
37
- }
31
+ if (balanceInSUI === 0) {
32
+ throw new DubheCliError(`Your account balance is 0 SUI. Please get some SUI to proceed.`);
33
+ }
38
34
 
39
- console.log(
40
- chalk.green(
41
- `Current account balance: ${balanceInSUI.toFixed(4)} SUI`
42
- )
43
- );
44
- } catch (error) {
45
- throw new DubheCliError('Failed to check balance: ' + error);
46
- }
35
+ console.log(chalk.green(`Current account balance: ${balanceInSUI.toFixed(4)} SUI`));
36
+ } catch (error) {
37
+ throw new DubheCliError('Failed to check balance: ' + error);
38
+ }
47
39
  }
@@ -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
- name = 'NotInsideProjectError';
7
- message = 'You are not inside a Dubhe project';
6
+ name = 'NotInsideProjectError';
7
+ message = 'You are not inside a Dubhe project';
8
8
  }
9
9
 
10
10
  export class DubheCliError extends Error {
11
- name = 'DubheCliError';
11
+ name = 'DubheCliError';
12
12
  }
13
13
 
14
14
  export class UpgradeError extends Error {
15
- name = 'UpgradeError';
15
+ name = 'UpgradeError';
16
16
  }
17
17
 
18
18
  export class FsIibError extends Error {
19
- name = 'FsIibError';
19
+ name = 'FsIibError';
20
20
  }
21
21
 
22
22
  export function logError(error: unknown) {
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
- }
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
  }