@0xobelisk/sui-cli 1.2.0-pre.1 → 1.2.0-pre.100
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 +3 -3
- package/dist/dubhe.js +125 -66
- package/dist/dubhe.js.map +1 -1
- package/package.json +31 -19
- package/src/commands/build.ts +47 -16
- package/src/commands/call.ts +83 -83
- package/src/commands/checkBalance.ts +12 -5
- package/src/commands/configStore.ts +12 -4
- package/src/commands/convertJson.ts +70 -0
- package/src/commands/doctor.ts +1515 -0
- package/src/commands/faucet.ts +11 -7
- package/src/commands/generateKey.ts +3 -2
- package/src/commands/index.ts +16 -7
- package/src/commands/info.ts +55 -0
- package/src/commands/loadMetadata.ts +57 -0
- package/src/commands/localnode.ts +22 -12
- package/src/commands/publish.ts +21 -7
- package/src/commands/query.ts +101 -101
- package/src/commands/schemagen.ts +15 -4
- package/src/commands/shell.ts +198 -0
- package/src/commands/switchEnv.ts +26 -0
- package/src/commands/test.ts +54 -11
- package/src/commands/upgrade.ts +11 -4
- package/src/commands/wait.ts +333 -22
- package/src/commands/watch.ts +2 -1
- package/src/dubhe.ts +12 -4
- package/src/utils/axios-downloader.ts +116 -0
- package/src/utils/callHandler.ts +118 -118
- package/src/utils/constants.ts +5 -0
- package/src/utils/generateAccount.ts +1 -1
- package/src/utils/index.ts +4 -3
- package/src/utils/metadataHandler.ts +16 -0
- package/src/utils/publishHandler.ts +295 -290
- package/src/utils/queryStorage.ts +141 -141
- package/src/utils/startNode.ts +165 -108
- package/src/utils/storeConfig.ts +6 -12
- package/src/utils/upgradeHandler.ts +147 -86
- package/src/utils/utils.ts +771 -54
package/src/commands/faucet.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
|
-
import {
|
|
2
|
+
import { requestSuiFromFaucetV2, getFaucetHost } from '@mysten/sui/faucet';
|
|
3
3
|
import { SuiClient, getFullnodeUrl, GetBalanceParams } from '@mysten/sui/client';
|
|
4
4
|
import { initializeDubhe } from '../utils';
|
|
5
|
+
import { handlerExit } from './shell';
|
|
5
6
|
|
|
6
7
|
type Options = {
|
|
7
8
|
network: any;
|
|
@@ -63,26 +64,29 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
63
64
|
isInterrupted = true;
|
|
64
65
|
process.stdout.write('\r' + ' '.repeat(50) + '\r');
|
|
65
66
|
console.log('\n └─ Operation cancelled by user');
|
|
66
|
-
|
|
67
|
+
handlerExit(1);
|
|
67
68
|
};
|
|
68
69
|
process.on('SIGINT', handleInterrupt);
|
|
69
70
|
|
|
70
71
|
try {
|
|
71
72
|
while (retryCount < MAX_RETRIES && !success && !isInterrupted) {
|
|
72
73
|
try {
|
|
73
|
-
await
|
|
74
|
+
await requestSuiFromFaucetV2({
|
|
74
75
|
host: getFaucetHost(network),
|
|
75
76
|
recipient: faucet_address
|
|
76
77
|
});
|
|
77
78
|
success = true;
|
|
78
|
-
} catch (
|
|
79
|
+
} catch (_error) {
|
|
79
80
|
if (isInterrupted) break;
|
|
80
81
|
|
|
81
82
|
retryCount++;
|
|
82
83
|
if (retryCount === MAX_RETRIES) {
|
|
83
84
|
console.log(` └─ Failed to request funds after ${MAX_RETRIES} attempts.`);
|
|
84
85
|
console.log(' └─ Please check your network connection and try again later.');
|
|
85
|
-
|
|
86
|
+
console.log(
|
|
87
|
+
' └─ You can visit https://faucet.testnet.sui.io/ to request funds manually.'
|
|
88
|
+
);
|
|
89
|
+
handlerExit(1);
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
|
|
@@ -98,7 +102,7 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
if (isInterrupted) {
|
|
101
|
-
|
|
105
|
+
handlerExit(1);
|
|
102
106
|
}
|
|
103
107
|
process.stdout.write('\r' + ' '.repeat(50) + '\r');
|
|
104
108
|
|
|
@@ -115,7 +119,7 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
115
119
|
console.log(` └─ Balance: ${(Number(balance.totalBalance) / 1_000_000_000).toFixed(4)} SUI`);
|
|
116
120
|
|
|
117
121
|
console.log('\n✅ Faucet Operation Complete\n');
|
|
118
|
-
|
|
122
|
+
handlerExit();
|
|
119
123
|
}
|
|
120
124
|
};
|
|
121
125
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
2
|
import { generateAccountHandler } from '../utils/generateAccount';
|
|
3
|
+
import { handlerExit } from './shell';
|
|
3
4
|
|
|
4
5
|
type Options = {
|
|
5
6
|
force?: boolean;
|
|
@@ -26,9 +27,9 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
26
27
|
await generateAccountHandler(force, useNextPublic);
|
|
27
28
|
} catch (error) {
|
|
28
29
|
console.error('Error generating account:', error);
|
|
29
|
-
|
|
30
|
+
handlerExit(1);
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
handlerExit();
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
|
package/src/commands/index.ts
CHANGED
|
@@ -4,24 +4,27 @@ import localnode from './localnode';
|
|
|
4
4
|
import faucet from './faucet';
|
|
5
5
|
import schemagen from './schemagen';
|
|
6
6
|
import publish from './publish';
|
|
7
|
-
import upgrade from './upgrade';
|
|
8
7
|
import test from './test';
|
|
9
8
|
import build from './build';
|
|
10
9
|
import hello from './hello';
|
|
11
10
|
import generateKey from './generateKey';
|
|
12
11
|
import checkBalance from './checkBalance';
|
|
13
12
|
import configStore from './configStore';
|
|
14
|
-
import query from './query';
|
|
15
|
-
import call from './call';
|
|
16
13
|
import watch from './watch';
|
|
17
14
|
import wait from './wait';
|
|
15
|
+
import switchEnv from './switchEnv';
|
|
16
|
+
import info from './info';
|
|
17
|
+
import loadMetadata from './loadMetadata';
|
|
18
|
+
import doctor from './doctor';
|
|
19
|
+
import convertJson from './convertJson';
|
|
20
|
+
import upgrade from './upgrade';
|
|
21
|
+
import shell from './shell';
|
|
18
22
|
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Each command has different options
|
|
20
23
|
export const commands: CommandModule<any, any>[] = [
|
|
21
24
|
localnode,
|
|
22
25
|
publish,
|
|
23
|
-
call,
|
|
24
|
-
query,
|
|
26
|
+
// call,
|
|
27
|
+
// query,
|
|
25
28
|
faucet,
|
|
26
29
|
schemagen,
|
|
27
30
|
upgrade,
|
|
@@ -32,5 +35,11 @@ export const commands: CommandModule<any, any>[] = [
|
|
|
32
35
|
checkBalance,
|
|
33
36
|
configStore,
|
|
34
37
|
watch,
|
|
35
|
-
wait
|
|
38
|
+
wait,
|
|
39
|
+
switchEnv,
|
|
40
|
+
info,
|
|
41
|
+
loadMetadata,
|
|
42
|
+
doctor,
|
|
43
|
+
convertJson,
|
|
44
|
+
shell
|
|
36
45
|
];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CommandModule } from 'yargs';
|
|
2
|
+
import { logError, initializeDubhe, getDefaultNetwork } from '../utils';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { handlerExit } from './shell';
|
|
6
|
+
dotenv.config();
|
|
7
|
+
|
|
8
|
+
type Options = {
|
|
9
|
+
network: any;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const InfoCommand: CommandModule<Options, Options> = {
|
|
13
|
+
command: 'info',
|
|
14
|
+
describe: 'Get information about the current Sui node',
|
|
15
|
+
builder(yargs) {
|
|
16
|
+
return yargs.options({
|
|
17
|
+
network: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'],
|
|
20
|
+
default: 'default',
|
|
21
|
+
desc: 'Node network (mainnet/testnet/devnet/localnet)'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
handler: async ({ network }) => {
|
|
26
|
+
try {
|
|
27
|
+
if (network == 'default') {
|
|
28
|
+
network = await getDefaultNetwork();
|
|
29
|
+
console.log(chalk.yellow(`Use default network: [${network}]`));
|
|
30
|
+
}
|
|
31
|
+
const dubhe = initializeDubhe({ network });
|
|
32
|
+
const keypair = dubhe.getSigner();
|
|
33
|
+
|
|
34
|
+
console.log(chalk.blue('Account Information:'));
|
|
35
|
+
console.log(` Network: ${chalk.green(network)}`);
|
|
36
|
+
console.log(` Address: ${chalk.green(keypair.toSuiAddress())}`);
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const balance = await dubhe.getBalance('0x2::sui::SUI');
|
|
40
|
+
const suiBalance = (Number(balance.totalBalance) / 10 ** 9).toFixed(4);
|
|
41
|
+
console.log(` Balance: ${chalk.green(suiBalance)} SUI`);
|
|
42
|
+
} catch (_error) {
|
|
43
|
+
console.log(
|
|
44
|
+
` Balance: ${chalk.red('Failed to fetch balance')} ${chalk.gray('(Network error)')}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
handlerExit();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logError(error);
|
|
50
|
+
handlerExit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default InfoCommand;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CommandModule } from 'yargs';
|
|
2
|
+
import { logError } from '../utils/errors';
|
|
3
|
+
import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
4
|
+
import { loadMetadataHandler } from '../utils/metadataHandler';
|
|
5
|
+
import { handlerExit } from './shell';
|
|
6
|
+
import { getDefaultNetwork } from '../utils';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
|
|
9
|
+
type Options = {
|
|
10
|
+
network: any;
|
|
11
|
+
'config-path': string;
|
|
12
|
+
'package-id'?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const commandModule: CommandModule<Options, Options> = {
|
|
16
|
+
command: 'load-metadata',
|
|
17
|
+
|
|
18
|
+
describe: 'Load metadata for a package',
|
|
19
|
+
|
|
20
|
+
builder(yargs) {
|
|
21
|
+
return yargs.options({
|
|
22
|
+
network: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'],
|
|
25
|
+
default: 'default',
|
|
26
|
+
desc: 'Node network (mainnet/testnet/devnet/localnet)'
|
|
27
|
+
},
|
|
28
|
+
'config-path': {
|
|
29
|
+
type: 'string',
|
|
30
|
+
desc: 'Configuration file path',
|
|
31
|
+
default: 'dubhe.config.ts'
|
|
32
|
+
},
|
|
33
|
+
'package-id': {
|
|
34
|
+
type: 'string',
|
|
35
|
+
desc: 'Package ID to load metadata for',
|
|
36
|
+
optional: true
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
async handler({ network, 'config-path': configPath, 'package-id': packageId }) {
|
|
42
|
+
try {
|
|
43
|
+
if (network == 'default') {
|
|
44
|
+
network = await getDefaultNetwork();
|
|
45
|
+
console.log(chalk.yellow(`Use default network: [${network}]`));
|
|
46
|
+
}
|
|
47
|
+
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
48
|
+
await loadMetadataHandler(dubheConfig, network, packageId);
|
|
49
|
+
} catch (error: any) {
|
|
50
|
+
logError(error);
|
|
51
|
+
handlerExit(1);
|
|
52
|
+
}
|
|
53
|
+
handlerExit();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default commandModule;
|
|
@@ -1,28 +1,38 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
2
|
import { startLocalNode } from '../utils/startNode';
|
|
3
|
+
import { handlerExit } from './shell';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
type Options = {
|
|
6
|
+
'data-dir': string;
|
|
7
|
+
force: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const commandModule: CommandModule<Options, Options> = {
|
|
5
11
|
command: 'node',
|
|
6
12
|
|
|
7
13
|
describe: 'Manage local Sui node',
|
|
8
14
|
|
|
9
|
-
builder
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
builder: {
|
|
16
|
+
'data-dir': {
|
|
17
|
+
type: 'string',
|
|
18
|
+
default: '.chk',
|
|
19
|
+
desc: 'Path to the data directory'
|
|
20
|
+
},
|
|
21
|
+
force: {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
default: false,
|
|
24
|
+
desc: 'Force restart: stop existing node and remove data directory'
|
|
25
|
+
}
|
|
17
26
|
},
|
|
18
27
|
|
|
19
|
-
async handler(
|
|
28
|
+
async handler({ 'data-dir': data_dir, force }) {
|
|
20
29
|
try {
|
|
21
|
-
await startLocalNode(
|
|
30
|
+
await startLocalNode(data_dir, force);
|
|
22
31
|
} catch (error) {
|
|
23
32
|
console.error('Error executing command:', error);
|
|
24
|
-
|
|
33
|
+
handlerExit(1);
|
|
25
34
|
}
|
|
35
|
+
handlerExit();
|
|
26
36
|
}
|
|
27
37
|
};
|
|
28
38
|
|
package/src/commands/publish.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
2
|
import { logError } from '../utils/errors';
|
|
3
|
-
import { publishHandler } from '../utils';
|
|
3
|
+
import { getDefaultNetwork, publishHandler } from '../utils';
|
|
4
4
|
import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
import { handlerExit } from './shell';
|
|
7
|
+
import chalk from 'chalk';
|
|
5
8
|
|
|
6
9
|
type Options = {
|
|
7
10
|
network: any;
|
|
8
11
|
'config-path': string;
|
|
12
|
+
force: boolean;
|
|
9
13
|
'gas-budget'?: number;
|
|
10
14
|
};
|
|
11
15
|
|
|
@@ -18,8 +22,8 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
18
22
|
return yargs.options({
|
|
19
23
|
network: {
|
|
20
24
|
type: 'string',
|
|
21
|
-
choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
22
|
-
default: '
|
|
25
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'],
|
|
26
|
+
default: 'default',
|
|
23
27
|
desc: 'Node network (mainnet/testnet/devnet/localnet)'
|
|
24
28
|
},
|
|
25
29
|
'config-path': {
|
|
@@ -31,19 +35,29 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
31
35
|
type: 'number',
|
|
32
36
|
desc: 'Optional gas budget for the transaction',
|
|
33
37
|
optional: true
|
|
38
|
+
},
|
|
39
|
+
force: {
|
|
40
|
+
type: 'boolean',
|
|
41
|
+
default: true,
|
|
42
|
+
desc: 'Force publish: do not update dependencies'
|
|
34
43
|
}
|
|
35
44
|
});
|
|
36
45
|
},
|
|
37
46
|
|
|
38
|
-
async handler({ network, 'config-path': configPath, 'gas-budget': gasBudget }) {
|
|
47
|
+
async handler({ network, 'config-path': configPath, 'gas-budget': gasBudget, force }) {
|
|
39
48
|
try {
|
|
49
|
+
if (network == 'default') {
|
|
50
|
+
network = await getDefaultNetwork();
|
|
51
|
+
console.log(chalk.yellow(`Use default network: [${network}]`));
|
|
52
|
+
}
|
|
40
53
|
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
41
|
-
|
|
54
|
+
execSync(`pnpm dubhe convert-json --config-path ${configPath}`, { encoding: 'utf-8' });
|
|
55
|
+
await publishHandler(dubheConfig, network, force, gasBudget);
|
|
42
56
|
} catch (error: any) {
|
|
43
57
|
logError(error);
|
|
44
|
-
|
|
58
|
+
handlerExit(1);
|
|
45
59
|
}
|
|
46
|
-
|
|
60
|
+
handlerExit();
|
|
47
61
|
}
|
|
48
62
|
};
|
|
49
63
|
|
package/src/commands/query.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const commandModule: CommandModule<Options, Options> = {
|
|
39
|
-
|
|
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
|
-
|
|
41
|
+
// describe: 'Query dubhe schema struct state',
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
2
|
import { schemaGen, loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { handlerExit } from './shell';
|
|
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
|
};
|
|
9
12
|
|
|
10
13
|
const commandModule: CommandModule<Options, Options> = {
|
|
@@ -20,19 +23,27 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
20
23
|
},
|
|
21
24
|
network: {
|
|
22
25
|
type: 'string',
|
|
23
|
-
choices: ['mainnet', 'testnet', 'devnet', 'localnet'] as const,
|
|
26
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet', 'default'] as const,
|
|
27
|
+
default: 'default',
|
|
24
28
|
desc: 'Node network (mainnet/testnet/devnet/localnet)'
|
|
25
29
|
}
|
|
26
30
|
},
|
|
27
31
|
|
|
28
32
|
async handler({ 'config-path': configPath, network }) {
|
|
29
33
|
try {
|
|
34
|
+
if (!configPath) throw new Error('Config path is required');
|
|
35
|
+
if (network == 'default') {
|
|
36
|
+
network = await getDefaultNetwork();
|
|
37
|
+
console.log(chalk.yellow(`Use default network: [${network}]`));
|
|
38
|
+
}
|
|
30
39
|
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
const rootDir = path.dirname(configPath);
|
|
41
|
+
await schemaGen(rootDir, dubheConfig, network);
|
|
42
|
+
handlerExit();
|
|
33
43
|
} catch (error: any) {
|
|
34
44
|
console.log(chalk.red('Schemagen failed!'));
|
|
35
45
|
console.error(error.message);
|
|
46
|
+
handlerExit(1);
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
};
|