@0xobelisk/sui-cli 0.5.16 → 0.5.18

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.
@@ -1,53 +1,53 @@
1
- import type { CommandModule } from "yargs";
2
- import { logError } from "../utils/errors";
3
- import { upgradeHandler } from "../utils";
4
- import { ObeliskConfig, loadConfig, ValueType } from "@0xobelisk/sui-common";
5
-
6
- type Options = {
7
- network: any;
8
- configPath: string;
9
- };
10
-
11
- const commandModule: CommandModule<Options, Options> = {
12
- command: "upgrade",
13
-
14
- describe: "Upgrade your move contracts",
15
-
16
- builder(yargs) {
17
- return yargs.options({
18
- network: {
19
- type: "string",
20
- choices: ["mainnet", "testnet", "devnet", "localnet"],
21
- desc: "Network of the node (mainnet/testnet/devnet/localnet)",
22
- },
23
- configPath: {
24
- type: "string",
25
- default: "obelisk.config.ts",
26
- decs: "Path to the config file",
27
- },
28
- });
29
- },
30
-
31
- async handler({ network, configPath }) {
32
- try {
33
- const obeliskConfig = (await loadConfig(configPath)) as ObeliskConfig;
34
-
35
- let schemaNames = Object.keys(obeliskConfig.schemas).filter(
36
- (key) =>
37
- !(
38
- typeof obeliskConfig.schemas === "object" &&
39
- "ephemeral" in obeliskConfig.schemas &&
40
- (obeliskConfig.schemas[key] as ValueType).ephemeral
41
- )
42
- );
43
-
44
- await upgradeHandler(obeliskConfig.name, network, schemaNames);
45
- } catch (error: any) {
46
- logError(error);
47
- process.exit(1);
48
- }
49
- process.exit(0);
50
- },
51
- };
52
-
53
- export default commandModule;
1
+ // import type { CommandModule } from "yargs";
2
+ // import { logError } from "../utils/errors";
3
+ // import { upgradeHandler } from "../utils";
4
+ // import { ObeliskConfig, loadConfig, ValueType } from "@0xobelisk/sui-common";
5
+
6
+ // type Options = {
7
+ // network: any;
8
+ // configPath: string;
9
+ // };
10
+
11
+ // const commandModule: CommandModule<Options, Options> = {
12
+ // command: "upgrade",
13
+
14
+ // describe: "Upgrade your move contracts",
15
+
16
+ // builder(yargs) {
17
+ // return yargs.options({
18
+ // network: {
19
+ // type: "string",
20
+ // choices: ["mainnet", "testnet", "devnet", "localnet"],
21
+ // desc: "Network of the node (mainnet/testnet/devnet/localnet)",
22
+ // },
23
+ // configPath: {
24
+ // type: "string",
25
+ // default: "obelisk.config.ts",
26
+ // decs: "Path to the config file",
27
+ // },
28
+ // });
29
+ // },
30
+
31
+ // async handler({ network, configPath }) {
32
+ // try {
33
+ // const obeliskConfig = (await loadConfig(configPath)) as ObeliskConfig;
34
+
35
+ // let schemaNames = Object.keys(obeliskConfig.schemas).filter(
36
+ // (key) =>
37
+ // !(
38
+ // typeof obeliskConfig.schemas === "object" &&
39
+ // "ephemeral" in obeliskConfig.schemas &&
40
+ // (obeliskConfig.schemas[key] as ValueType).ephemeral
41
+ // )
42
+ // );
43
+
44
+ // await upgradeHandler(obeliskConfig.name, network, schemaNames);
45
+ // } catch (error: any) {
46
+ // logError(error);
47
+ // process.exit(1);
48
+ // }
49
+ // process.exit(0);
50
+ // },
51
+ // };
52
+
53
+ // export default commandModule;
@@ -1,5 +1,5 @@
1
- export * from "./publishHandler";
2
- export * from "./upgradeHandler";
3
- export * from "./errors";
4
- export * from "./printObelisk";
5
- export * from "./utils";
1
+ export * from './publishHandler';
2
+ // export * from "./upgradeHandler";
3
+ export * from './errors';
4
+ export * from './printObelisk';
5
+ export * from './utils';
@@ -0,0 +1,3 @@
1
+ export { startLocalnode } from './start';
2
+ export { checkLocalNodeStatus } from './status';
3
+ export { stopLocalnode } from './stop';
@@ -0,0 +1,87 @@
1
+ import { execSync, spawn } from 'child_process';
2
+ import chalk from 'chalk';
3
+
4
+ function isSuiStartRunning(): boolean {
5
+ try {
6
+ const result = execSync('pgrep -f "sui start"').toString().trim();
7
+ return result.length > 0;
8
+ } catch (error) {
9
+ return false;
10
+ }
11
+ }
12
+
13
+ export async function startLocalnode(background: boolean = false) {
14
+ console.log(chalk.blue('Checking if sui start process is running...'));
15
+
16
+ if (isSuiStartRunning()) {
17
+ console.log(
18
+ chalk.yellow('Warning: sui start process is already running.')
19
+ );
20
+ console.log(
21
+ chalk.yellow(
22
+ 'Cannot start a new local node. Please stop the existing sui start process first.'
23
+ )
24
+ );
25
+ return;
26
+ }
27
+
28
+ console.log(chalk.green('Starting local node...'));
29
+ try {
30
+ const suiProcess = spawn(
31
+ 'sui',
32
+ ['start', '--with-faucet', '--force-regenesis'],
33
+ {
34
+ env: { ...process.env, RUST_LOG: 'off,sui_node=info' },
35
+ stdio: background ? 'ignore' : 'inherit',
36
+ detached: background,
37
+ }
38
+ );
39
+
40
+ suiProcess.on('error', error => {
41
+ console.error(chalk.red('Failed to start local node:'), error);
42
+ });
43
+
44
+ if (!background) {
45
+ suiProcess.on('exit', code => {
46
+ if (code === 0) {
47
+ console.log(chalk.green('Local node has exited normally'));
48
+ } else {
49
+ console.error(
50
+ chalk.red(
51
+ `Local node exited abnormally with code: ${code}`
52
+ )
53
+ );
54
+ }
55
+ });
56
+
57
+ console.log(chalk.cyan('Local node is running...'));
58
+ console.log(chalk.cyan('Press Ctrl+C to stop the local node'));
59
+
60
+ // Keep the script running
61
+ await new Promise(() => {});
62
+ } else {
63
+ suiProcess.unref();
64
+ console.log(
65
+ chalk.green('Local node has been started in the background')
66
+ );
67
+ console.log(
68
+ chalk.cyan(
69
+ 'Use "pgrep -f \'sui start\'" to check the process ID'
70
+ )
71
+ );
72
+ console.log(
73
+ chalk.cyan(
74
+ 'Use "kill <process_id>" to stop the background node'
75
+ )
76
+ );
77
+ }
78
+ } catch (error) {
79
+ console.error(chalk.red('Failed to start local node:'), error);
80
+ }
81
+ }
82
+
83
+ // Get the background flag from command line arguments
84
+ const args = process.argv.slice(2);
85
+ const runInBackground = args.includes('--background') || args.includes('-b');
86
+
87
+ // startLocalnode(runInBackground);
@@ -0,0 +1,39 @@
1
+ import { execSync } from 'child_process';
2
+ import chalk from 'chalk';
3
+
4
+ export async function checkLocalNodeStatus() {
5
+ try {
6
+ const output = execSync(
7
+ "ps aux | grep '[s]ui start --with-faucet --force-regenesis'",
8
+ {
9
+ encoding: 'utf8',
10
+ }
11
+ );
12
+
13
+ const lines = output.split('\n').filter(Boolean);
14
+
15
+ if (lines.length > 0) {
16
+ console.log(chalk.green('✓ Sui Local Node Status: Running'));
17
+ console.log(chalk.gray('Process Details:'));
18
+ for (const line of lines) {
19
+ console.log(chalk.gray(` ${line}`));
20
+ }
21
+ } else {
22
+ console.log(chalk.red('✗ Sui Local Node Status: Not Running'));
23
+ console.log(
24
+ chalk.yellow(
25
+ 'Tip: Use `pnpm run start-localnode` to start the local node'
26
+ )
27
+ );
28
+ }
29
+ } catch (error) {
30
+ console.log(chalk.red('✗ Sui Local Node Status: Not Running'));
31
+ console.log(
32
+ chalk.yellow(
33
+ 'Tip: Use `pnpm run start-localnode` to start the local node'
34
+ )
35
+ );
36
+ }
37
+ }
38
+
39
+ // checkLocalNodeStatus();
@@ -0,0 +1,35 @@
1
+ import { execSync } from 'child_process';
2
+
3
+ export async function stopLocalnode() {
4
+ console.log('Stopping local node...');
5
+
6
+ try {
7
+ // Find localnode process using ps command
8
+ const output = execSync(
9
+ "ps aux | grep '[s]ui start --with-faucet --force-regenesis'",
10
+ {
11
+ encoding: 'utf8',
12
+ }
13
+ );
14
+
15
+ if (!output) {
16
+ console.log('No running local node process found');
17
+ return;
18
+ }
19
+
20
+ // Get process ID
21
+ const pid = output.toString().split(/\s+/)[1];
22
+
23
+ // Kill the process
24
+ process.kill(Number(pid));
25
+ console.log('✅ Local node stopped successfully');
26
+ } catch (error: any) {
27
+ if (error.code === 'ESRCH') {
28
+ console.log('No running local node process found');
29
+ } else {
30
+ console.error('❌ Error stopping local node:', error.message);
31
+ }
32
+ }
33
+ }
34
+
35
+ // stopLocalnode();
@@ -11,17 +11,29 @@ import { ObeliskCliError } from './errors';
11
11
  import {
12
12
  updateVersionInFile,
13
13
  saveContractData,
14
- validatePrivateKey, schema,
14
+ validatePrivateKey,
15
+ schema,
15
16
  } from './utils';
16
- import {log} from "node:util";
17
+
18
+ async function getDappsObjectId(
19
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
20
+ ) {
21
+ switch (network) {
22
+ case 'testnet':
23
+ return '0xa66942c08d9fc318a70ab9d0cfd7e75f1a2dd1ac31aff12fde008d25bfa9604b';
24
+ default:
25
+ return '0xa66942c08d9fc318a70ab9d0cfd7e75f1a2dd1ac31aff12fde008d25bfa9604b';
26
+ }
27
+ }
17
28
 
18
29
  export async function publishHandler(
19
30
  name: string,
20
- network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
31
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
32
+ dappsObjectId?: string
21
33
  ) {
22
34
  const path = process.cwd();
23
35
  const projectPath = `${path}/contracts/${name}`;
24
-
36
+ dappsObjectId = dappsObjectId || (await getDappsObjectId(network));
25
37
  const privateKey = process.env.PRIVATE_KEY;
26
38
  if (!privateKey)
27
39
  throw new ObeliskCliError(
@@ -71,10 +83,7 @@ in your contracts directory to use the default sui private key.`
71
83
  modules,
72
84
  dependencies,
73
85
  });
74
- tx.transferObjects(
75
- [upgradeCap],
76
- keypair.toSuiAddress()
77
- );
86
+ tx.transferObjects([upgradeCap], keypair.toSuiAddress());
78
87
 
79
88
  let result: SuiTransactionBlockResponse;
80
89
  try {
@@ -126,8 +135,8 @@ in your contracts directory to use the default sui private key.`
126
135
  deployHookTx.moveCall({
127
136
  target: `${packageId}::deploy_hook::run`,
128
137
  arguments: [
129
- deployHookTx.object("0xa66942c08d9fc318a70ab9d0cfd7e75f1a2dd1ac31aff12fde008d25bfa9604b"),
130
- deployHookTx.object("0x6"),
138
+ deployHookTx.object(dappsObjectId),
139
+ deployHookTx.object('0x6'),
131
140
  ],
132
141
  });
133
142
 
@@ -138,7 +147,7 @@ in your contracts directory to use the default sui private key.`
138
147
  transaction: deployHookTx,
139
148
  options: {
140
149
  showEffects: true,
141
- showObjectChanges: true
150
+ showObjectChanges: true,
142
151
  },
143
152
  });
144
153
  } catch (error: any) {
@@ -159,10 +168,17 @@ in your contracts directory to use the default sui private key.`
159
168
  );
160
169
  deployHookResult.objectChanges?.map(object => {
161
170
  if (
162
- object.type === 'created' && object.objectType.includes("schema")
171
+ object.type === 'created' &&
172
+ object.objectType.includes('schema')
163
173
  ) {
164
- console.log(chalk.blue(`${name} Schema Object id: ${object.objectId}`));
165
- console.log(chalk.blue(`${name} Schema Object type: ${object.objectType}`));
174
+ console.log(
175
+ chalk.blue(`${name} Schema Object id: ${object.objectId}`)
176
+ );
177
+ console.log(
178
+ chalk.blue(
179
+ `${name} Schema Object type: ${object.objectType}`
180
+ )
181
+ );
166
182
  schemas.push({
167
183
  name: object.objectType,
168
184
  objectId: object.objectId,