@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/commands/test.ts
CHANGED
|
@@ -3,49 +3,49 @@ import { execSync } from 'child_process';
|
|
|
3
3
|
import { DubheConfig, loadConfig } from '@0xobelisk/sui-common';
|
|
4
4
|
|
|
5
5
|
type Options = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
'config-path': string;
|
|
7
|
+
test?: string;
|
|
8
|
+
'gas-limit'?: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const commandModule: CommandModule<Options, Options> = {
|
|
12
|
-
|
|
12
|
+
command: 'test',
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
describe: 'Run tests in Dubhe contracts',
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
builder(yargs) {
|
|
17
|
+
return yargs.options({
|
|
18
|
+
'config-path': {
|
|
19
|
+
type: 'string',
|
|
20
|
+
default: 'dubhe.config.ts',
|
|
21
|
+
description: 'Options to pass to forge test'
|
|
22
|
+
},
|
|
23
|
+
test: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
desc: 'Run a specific test'
|
|
26
|
+
},
|
|
27
|
+
'gas-limit': {
|
|
28
|
+
type: 'string',
|
|
29
|
+
desc: 'Set the gas limit for the test'
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
async handler({ 'config-path': configPath, test, 'gas-limit': gasLimit }) {
|
|
35
|
+
// Start an internal anvil process if no world address is provided
|
|
36
|
+
try {
|
|
37
|
+
console.log('🚀 Running move test');
|
|
38
|
+
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
39
|
+
const path = process.cwd();
|
|
40
|
+
const projectPath = `${path}/contracts/${dubheConfig.name}`;
|
|
41
|
+
const command = `sui move test --path ${projectPath} ${
|
|
42
|
+
test ? ` --test ${test}` : ''
|
|
43
|
+
} ${gasLimit ? ` --gas-limit ${gasLimit}` : ''}`;
|
|
44
|
+
execSync(command, { stdio: 'inherit', encoding: 'utf-8' });
|
|
45
|
+
} catch (error: any) {
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
export default commandModule;
|
package/src/commands/upgrade.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
7
|
+
network: any;
|
|
8
|
+
'config-path': string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const commandModule: CommandModule<Options, Options> = {
|
|
12
|
-
|
|
12
|
+
command: 'upgrade',
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
describe: 'Upgrade your move contracts',
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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;
|
package/src/commands/watch.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type { CommandModule } from
|
|
2
|
-
import chokidar from
|
|
3
|
-
import { exec } from
|
|
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:
|
|
6
|
+
command: 'watch',
|
|
7
7
|
|
|
8
|
-
describe:
|
|
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 =
|
|
15
|
+
const configFilePath = 'dubhe.config.ts';
|
|
16
16
|
|
|
17
17
|
const runSchemagen = () => {
|
|
18
|
-
exec(
|
|
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(
|
|
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(
|
|
42
|
+
process.on('SIGINT', () => {
|
|
43
43
|
watcher.close();
|
|
44
|
-
console.log(
|
|
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
|
|
4
|
-
import { hideBin } from
|
|
5
|
-
import { commands } from
|
|
6
|
-
import { logError } from
|
|
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
|
|
10
|
-
import chalk from
|
|
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(
|
|
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(
|
|
24
|
+
if (msg.includes('Missing required argument')) {
|
|
25
25
|
console.log(
|
|
26
|
-
chalk.yellow(
|
|
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:
|
|
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
|
|
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
|
|
11
|
+
declare module 'rollup-plugin-preserve-shebang';
|
package/src/utils/callHandler.ts
CHANGED
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
74
|
+
return params.map((param) => formatBCS(tx, param));
|
|
80
75
|
}
|
|
81
76
|
|
|
82
77
|
export async function callHandler({
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
dubheConfig,
|
|
79
|
+
moduleName,
|
|
80
|
+
funcName,
|
|
81
|
+
params,
|
|
82
|
+
network,
|
|
83
|
+
packageId,
|
|
84
|
+
metadataFilePath
|
|
90
85
|
}: {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
const privateKeyFormat = validatePrivateKey(privateKey);
|
|
103
|
+
if (privateKeyFormat === false) {
|
|
104
|
+
throw new DubheCliError(`Please check your privateKey.`);
|
|
105
|
+
}
|
|
111
106
|
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
const path = process.cwd();
|
|
108
|
+
const projectPath = `${path}/contracts/${dubheConfig.name}`;
|
|
114
109
|
|
|
115
|
-
|
|
110
|
+
packageId = packageId || (await getOldPackageId(projectPath, network));
|
|
116
111
|
|
|
117
|
-
|
|
112
|
+
// objectId = objectId || (await getObjectId(projectPath, network, schema));
|
|
118
113
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
142
|
+
// const storageType = dubheConfig.schemas[schema].structure[struct];
|
|
148
143
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
155
|
+
const result = (await dubhe.tx[moduleName][funcName]({
|
|
156
|
+
tx,
|
|
157
|
+
params: formattedParams
|
|
158
|
+
})) as TransactionResult;
|
|
164
159
|
|
|
165
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
const privateKeyFormat = validatePrivateKey(privateKey);
|
|
19
|
+
if (privateKeyFormat === false) {
|
|
20
|
+
throw new DubheCliError(`Please check your privateKey.`);
|
|
21
|
+
}
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const dubhe = new Dubhe({
|
|
24
|
+
secretKey: process.env.PRIVATE_KEY,
|
|
25
|
+
networkType: network as NetworkType
|
|
26
|
+
});
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const balance = await dubhe.getBalance();
|
|
29
|
+
const balanceInSUI = Number(balance.totalBalance) / 1_000_000_000;
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
}
|