wative 1.0.35 → 1.0.37
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/lib/index.esm.js +1 -1
- package/lib/index.umd.js +1 -1
- package/package.json +5 -5
- package/src/account.ts +103 -98
- package/src/index.ts +3 -3
- package/src/network.ts +22 -22
- package/src/tools.ts +15 -15
- package/src/utils.ts +37 -40
package/src/account.ts
CHANGED
|
@@ -2,7 +2,7 @@ const chalk = require('chalk');
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
getAccountName,
|
|
6
6
|
selectSomething,
|
|
7
7
|
inputPassword,
|
|
8
8
|
inputSomething,
|
|
@@ -17,9 +17,10 @@ import {
|
|
|
17
17
|
formatAddr,
|
|
18
18
|
listWithLazyBalanceLoading,
|
|
19
19
|
inputPasswordWithoutValidator,
|
|
20
|
-
|
|
20
|
+
getKeystoreSlugByAccountName,
|
|
21
|
+
getAccountNameByKeystoreSlug,
|
|
21
22
|
} from "./utils";
|
|
22
|
-
import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getStatus, selectDefaultNetwork, showAllAccounts,
|
|
23
|
+
import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getStatus, selectDefaultNetwork, showAllAccounts, switchNetworkByAccountName } from "./network";
|
|
23
24
|
import { getAssetList, showAssetsDetail } from './assets';
|
|
24
25
|
import { selectToolsOptions } from './tools';
|
|
25
26
|
import inquirer from "inquirer";
|
|
@@ -30,28 +31,28 @@ const cliProgress = require('cli-progress');
|
|
|
30
31
|
const { WativeCore } = require("wative-core");
|
|
31
32
|
|
|
32
33
|
const DEFAULT_ACCOUNT: any = {
|
|
33
|
-
|
|
34
|
+
keystore_slug: '',
|
|
34
35
|
default_account_index: 0
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
const preAccountImport = async (keystore_path: string) => {
|
|
38
39
|
const networks = getNetworkInfo(keystore_path)
|
|
39
40
|
|
|
40
|
-
let
|
|
41
|
+
let account_name_list: string[] = [];
|
|
41
42
|
if (networks.accounts) {
|
|
42
|
-
|
|
43
|
+
account_name_list = networks.accounts;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
let
|
|
46
|
-
if (
|
|
46
|
+
let account_name = await getAccountName('Account Name', account_name_list);
|
|
47
|
+
if (account_name === null) {
|
|
47
48
|
return null;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
let password = await inputPassword(`Please set a password for Account [${
|
|
51
|
+
let password = await inputPassword(`Please set a password for Account [${account_name}]`);
|
|
51
52
|
let selected_default_network = await selectDefaultNetwork(keystore_path);
|
|
52
53
|
|
|
53
54
|
let pre_account_info = {
|
|
54
|
-
|
|
55
|
+
account_name,
|
|
55
56
|
password,
|
|
56
57
|
selected_default_network
|
|
57
58
|
};
|
|
@@ -72,22 +73,22 @@ const importPassphrase = async (keystore_path: string, wative_core: typeof Wativ
|
|
|
72
73
|
let passphrase = await inputSomething('Please enter a mnemonic [split by space]', passphraseValidator);
|
|
73
74
|
passphrase = passphrase.replace(/\s+/g, " ");
|
|
74
75
|
|
|
75
|
-
let
|
|
76
|
-
const passphrase_account = wative_core.account.generatePPAccount(
|
|
76
|
+
let keystore_slug = getKeystoreSlugByAccountName(pre_account_info.account_name);
|
|
77
|
+
const passphrase_account = wative_core.account.generatePPAccount(keystore_slug, passphrase, pre_account_info.password);
|
|
77
78
|
if (!passphrase_account.status) {
|
|
78
79
|
console.log(
|
|
79
80
|
chalk.red(passphrase_account.output)
|
|
80
81
|
);
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
|
-
let account_info_path = path.join(keystore_path, `accounts/${
|
|
84
|
+
let account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
|
|
84
85
|
|
|
85
86
|
passphrase_account.output.default_network = pre_account_info.selected_default_network;
|
|
86
87
|
fs.writeFileSync(account_info_path, JSON.stringify(passphrase_account.output, null, 4));
|
|
87
88
|
|
|
88
89
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
89
90
|
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
90
|
-
networks.accounts.push(pre_account_info.
|
|
91
|
+
networks.accounts.push(pre_account_info.account_name);
|
|
91
92
|
fs.writeFileSync(network_path, JSON.stringify(networks, null, 4));
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -99,11 +100,11 @@ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeo
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
let private_key = await inputSomething('Please enter a private key');
|
|
102
|
-
let
|
|
103
|
+
let keystore_slug = getKeystoreSlugByAccountName(pre_account_info.account_name);
|
|
103
104
|
await _importAccount(
|
|
104
105
|
keystore_path,
|
|
105
106
|
pre_account_info.password,
|
|
106
|
-
|
|
107
|
+
keystore_slug,
|
|
107
108
|
private_key,
|
|
108
109
|
pre_account_info.selected_default_network,
|
|
109
110
|
wative_core,
|
|
@@ -112,7 +113,7 @@ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeo
|
|
|
112
113
|
|
|
113
114
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
114
115
|
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
115
|
-
networks.accounts.push(pre_account_info.
|
|
116
|
+
networks.accounts.push(pre_account_info.account_name);
|
|
116
117
|
|
|
117
118
|
fs.writeFileSync(network_path, JSON.stringify(networks, null, 4));
|
|
118
119
|
}
|
|
@@ -120,17 +121,17 @@ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeo
|
|
|
120
121
|
const importPrivateKeyAccount = async (
|
|
121
122
|
keystore_path: string,
|
|
122
123
|
password: string,
|
|
123
|
-
|
|
124
|
+
keystore_slug: string,
|
|
124
125
|
wative_core: typeof WativeCore
|
|
125
126
|
) => {
|
|
126
127
|
let private_key = await inputSomething('Please enter a private key');
|
|
127
|
-
let account_info_path = path.join(keystore_path, `accounts/${
|
|
128
|
+
let account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
|
|
128
129
|
let exist_account_info = JSON.parse(fs.readFileSync(account_info_path, 'utf8'));
|
|
129
130
|
|
|
130
131
|
await _importAccount(
|
|
131
132
|
keystore_path,
|
|
132
133
|
password,
|
|
133
|
-
|
|
134
|
+
keystore_slug,
|
|
134
135
|
private_key,
|
|
135
136
|
exist_account_info.default_network,
|
|
136
137
|
wative_core,
|
|
@@ -141,11 +142,11 @@ const importPrivateKeyAccount = async (
|
|
|
141
142
|
const _importAccount = async (
|
|
142
143
|
keystore_path: string,
|
|
143
144
|
password: string,
|
|
144
|
-
|
|
145
|
+
keystore_slug: string,
|
|
145
146
|
private_key: string,
|
|
146
147
|
default_network: string,
|
|
147
148
|
wative_core: typeof WativeCore,
|
|
148
|
-
|
|
149
|
+
generate_keystore_slug: boolean
|
|
149
150
|
) => {
|
|
150
151
|
let network_info = await getNetworkInfoByName(keystore_path, default_network);
|
|
151
152
|
|
|
@@ -154,14 +155,14 @@ const _importAccount = async (
|
|
|
154
155
|
private_key = "0x" + private_key;
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
let privatekey_account = await wative_core.account.generatePKAccount(
|
|
158
|
+
let privatekey_account = await wative_core.account.generatePKAccount(keystore_slug, private_key, password, network_info.chainId.toString(), generate_keystore_slug);
|
|
158
159
|
if (!privatekey_account.status) {
|
|
159
160
|
console.log(
|
|
160
161
|
chalk.red(privatekey_account.output)
|
|
161
162
|
);
|
|
162
163
|
return;
|
|
163
164
|
}
|
|
164
|
-
let account_info_path = path.join(keystore_path, `accounts/${
|
|
165
|
+
let account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
|
|
165
166
|
|
|
166
167
|
let result: any;
|
|
167
168
|
if (fs.existsSync(account_info_path)) {
|
|
@@ -228,29 +229,31 @@ export const getNetworkInfo = (keystore_path: string) => {
|
|
|
228
229
|
return networks;
|
|
229
230
|
}
|
|
230
231
|
|
|
231
|
-
export const getAccountInfo = (keystore_path: string,
|
|
232
|
-
const account_info_path = path.join(keystore_path, `accounts/${
|
|
232
|
+
export const getAccountInfo = (keystore_path: string, keystore_slug: string) => {
|
|
233
|
+
const account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
|
|
233
234
|
const account_info = JSON.parse(fs.readFileSync(account_info_path, 'utf8'));
|
|
234
235
|
return account_info;
|
|
235
236
|
}
|
|
236
237
|
|
|
237
|
-
export const saveAccountInfo = (keystore_path: string,
|
|
238
|
-
const account_info_path = path.join(keystore_path, `accounts/${
|
|
238
|
+
export const saveAccountInfo = (keystore_path: string, keystore_slug: string, account_info: any) => {
|
|
239
|
+
const account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
|
|
239
240
|
fs.writeFileSync(account_info_path, JSON.stringify(account_info, null, 4));
|
|
240
241
|
}
|
|
241
242
|
|
|
242
|
-
export const loginIn = async (
|
|
243
|
-
const is_login = wative_core.account.isLogin(
|
|
243
|
+
export const loginIn = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => {
|
|
244
|
+
const is_login = wative_core.account.isLogin(keystore_slug);
|
|
244
245
|
if (is_login) {
|
|
245
246
|
return { isLoginIn: true };
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
for (let i = 0; i < 3; i++) {
|
|
250
|
+
let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
|
|
251
|
+
|
|
249
252
|
let password: any;
|
|
250
253
|
if (process.env.WativePassword && process.env.WativePassword !== '') {
|
|
251
254
|
password = process.env.WativePassword;
|
|
252
255
|
} else {
|
|
253
|
-
password = await inputPasswordWithoutValidator(`Please input the password for Account [${
|
|
256
|
+
password = await inputPasswordWithoutValidator(`Please input the password for Account [${account_name}]`);
|
|
254
257
|
}
|
|
255
258
|
if (!password) {
|
|
256
259
|
console.log(
|
|
@@ -259,7 +262,7 @@ export const loginIn = async (account_label: string, wative_core: typeof WativeC
|
|
|
259
262
|
return { isLoginIn: false };
|
|
260
263
|
}
|
|
261
264
|
|
|
262
|
-
const login_result = await wative_core.account.login(
|
|
265
|
+
const login_result = await wative_core.account.login(keystore_slug, password);
|
|
263
266
|
if (login_result.status) {
|
|
264
267
|
return { isLoginIn: true, password };
|
|
265
268
|
}
|
|
@@ -280,29 +283,29 @@ export const loginIn = async (account_label: string, wative_core: typeof WativeC
|
|
|
280
283
|
|
|
281
284
|
const selectAccount = async (keystore_path: string, wative_core: typeof WativeCore) => {
|
|
282
285
|
const networks = getNetworkInfo(keystore_path);
|
|
283
|
-
const
|
|
286
|
+
const account_name_list = networks.accounts;
|
|
284
287
|
|
|
285
288
|
let select_account_options = [
|
|
286
289
|
'> Back',
|
|
287
290
|
new inquirer.Separator('----------------------------------')
|
|
288
291
|
];
|
|
289
292
|
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
293
|
+
const account_name_len = account_name_list.length;
|
|
294
|
+
if (account_name_len === 0) {
|
|
292
295
|
console.log(
|
|
293
296
|
chalk.red("No address here yet")
|
|
294
297
|
);
|
|
295
298
|
return;
|
|
296
299
|
}
|
|
297
300
|
|
|
298
|
-
for (let i = 0; i <
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
const account_info = getAccountInfo(keystore_path,
|
|
301
|
+
for (let i = 0; i < account_name_len; i++) {
|
|
302
|
+
const account_name = account_name_list[i];
|
|
303
|
+
const keystore_slug = getKeystoreSlugByAccountName(account_name);
|
|
304
|
+
const account_info = getAccountInfo(keystore_path, keystore_slug);
|
|
302
305
|
if ("data" in account_info) {
|
|
303
|
-
select_account_options.push(`${i + 1}) ${
|
|
306
|
+
select_account_options.push(`${i + 1}) ${account_name} [${account_info.account_type}:${account_info.data.length}]`);
|
|
304
307
|
} else {
|
|
305
|
-
select_account_options.push(`${i + 1}) ${
|
|
308
|
+
select_account_options.push(`${i + 1}) ${account_name} [${account_info.account_type}:1]`);
|
|
306
309
|
}
|
|
307
310
|
}
|
|
308
311
|
|
|
@@ -311,19 +314,19 @@ const selectAccount = async (keystore_path: string, wative_core: typeof WativeCo
|
|
|
311
314
|
return;
|
|
312
315
|
}
|
|
313
316
|
|
|
314
|
-
const
|
|
315
|
-
const
|
|
317
|
+
const selected_account_name = account_name_list[select_account_options.indexOf(selected_account) - 2];
|
|
318
|
+
const keystore_slug = getKeystoreSlugByAccountName(selected_account_name);
|
|
316
319
|
|
|
317
|
-
let login_result = await loginIn(
|
|
320
|
+
let login_result = await loginIn(keystore_path, keystore_slug, wative_core);
|
|
318
321
|
if (login_result.isLoginIn) {
|
|
319
|
-
await accountManager(keystore_path,
|
|
322
|
+
await accountManager(keystore_path, keystore_slug, wative_core, login_result.password);
|
|
320
323
|
}
|
|
321
324
|
|
|
322
325
|
await selectAccount(keystore_path, wative_core);
|
|
323
326
|
}
|
|
324
327
|
|
|
325
|
-
const setDisableAddress = async (keystore_path: string,
|
|
326
|
-
const account_info = await getAccountInfo(keystore_path,
|
|
328
|
+
const setDisableAddress = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => {
|
|
329
|
+
const account_info = await getAccountInfo(keystore_path, keystore_slug);
|
|
327
330
|
|
|
328
331
|
let disable_address_options = [
|
|
329
332
|
"> Disabled Slots",
|
|
@@ -416,7 +419,7 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
|
|
|
416
419
|
let selected_disabled_slots_index = disabled_slots_options.indexOf(selected_disabled_slots) - 2;
|
|
417
420
|
|
|
418
421
|
account_info.disabled_slots.splice(selected_disabled_slots_index, 1);
|
|
419
|
-
saveAccountInfo(keystore_path,
|
|
422
|
+
saveAccountInfo(keystore_path, keystore_slug, account_info);
|
|
420
423
|
|
|
421
424
|
break;
|
|
422
425
|
}
|
|
@@ -439,7 +442,7 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
|
|
|
439
442
|
}];
|
|
440
443
|
}
|
|
441
444
|
|
|
442
|
-
saveAccountInfo(keystore_path,
|
|
445
|
+
saveAccountInfo(keystore_path, keystore_slug, account_info);
|
|
443
446
|
break;
|
|
444
447
|
}
|
|
445
448
|
case "> Add Range": {
|
|
@@ -455,17 +458,17 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
|
|
|
455
458
|
account_info.disabled_slots = [account_range];
|
|
456
459
|
}
|
|
457
460
|
|
|
458
|
-
saveAccountInfo(keystore_path,
|
|
461
|
+
saveAccountInfo(keystore_path, keystore_slug, account_info);
|
|
459
462
|
break;
|
|
460
463
|
}
|
|
461
464
|
}
|
|
462
465
|
|
|
463
|
-
await setDisableAddress(keystore_path,
|
|
466
|
+
await setDisableAddress(keystore_path, keystore_slug, wative_core);
|
|
464
467
|
}
|
|
465
468
|
|
|
466
469
|
|
|
467
|
-
const accountManager = async (keystore_path: string,
|
|
468
|
-
let account_info = await getAccountInfo(keystore_path,
|
|
470
|
+
const accountManager = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore, password: string) => {
|
|
471
|
+
let account_info = await getAccountInfo(keystore_path, keystore_slug);
|
|
469
472
|
|
|
470
473
|
let account_manager_options: any[];
|
|
471
474
|
|
|
@@ -497,7 +500,7 @@ const accountManager = async (keystore_path: string, account_label: string, wati
|
|
|
497
500
|
const selected_account_manager = await selectSomething(account_manager_options);
|
|
498
501
|
switch (selected_account_manager) {
|
|
499
502
|
case '> Address List': {
|
|
500
|
-
await showAccounts(keystore_path,
|
|
503
|
+
await showAccounts(keystore_path, keystore_slug, wative_core);
|
|
501
504
|
break;
|
|
502
505
|
}
|
|
503
506
|
case '> Expand Address': {
|
|
@@ -509,29 +512,30 @@ const accountManager = async (keystore_path: string, account_label: string, wati
|
|
|
509
512
|
break;
|
|
510
513
|
}
|
|
511
514
|
|
|
512
|
-
await expandAddress(keystore_path,
|
|
515
|
+
await expandAddress(keystore_path, keystore_slug, Number(count), wative_core);
|
|
513
516
|
break;
|
|
514
517
|
}
|
|
515
518
|
case '> Import Private Key': {
|
|
516
|
-
await importPrivateKeyAccount(keystore_path, password,
|
|
519
|
+
await importPrivateKeyAccount(keystore_path, password, keystore_slug, wative_core);
|
|
517
520
|
break;
|
|
518
521
|
}
|
|
519
522
|
case '> Slice Address': {
|
|
520
523
|
const last_account_no = await inputSomething('Please input last account number', lastAccountNoValidator);
|
|
521
|
-
await sliceAddress(keystore_path,
|
|
524
|
+
await sliceAddress(keystore_path, keystore_slug, Number(last_account_no), wative_core);
|
|
522
525
|
break;
|
|
523
526
|
}
|
|
524
527
|
case '> Remove Address': {
|
|
525
|
-
await removeAddress(keystore_path,
|
|
528
|
+
await removeAddress(keystore_path, keystore_slug, wative_core);
|
|
526
529
|
break;
|
|
527
530
|
}
|
|
528
531
|
case '> Disable Address': {
|
|
529
|
-
await setDisableAddress(keystore_path,
|
|
532
|
+
await setDisableAddress(keystore_path, keystore_slug, wative_core);
|
|
530
533
|
break;
|
|
531
534
|
}
|
|
532
535
|
case '> Reset Account Password': {
|
|
533
|
-
|
|
534
|
-
const
|
|
536
|
+
let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
|
|
537
|
+
const password1 = await inputPassword(`Please input new password for Account [${account_name}]`);
|
|
538
|
+
const password2 = await inputPassword(`Please confirm new password for Account [${account_name}]`);
|
|
535
539
|
|
|
536
540
|
if (!password1 || !password2 || password1 !== password2) {
|
|
537
541
|
console.log(
|
|
@@ -540,15 +544,15 @@ const accountManager = async (keystore_path: string, account_label: string, wati
|
|
|
540
544
|
break;
|
|
541
545
|
}
|
|
542
546
|
|
|
543
|
-
await wative_core.account.resetPassword(
|
|
547
|
+
await wative_core.account.resetPassword(keystore_slug, password1);
|
|
544
548
|
return;
|
|
545
549
|
}
|
|
546
550
|
case `> Switch Networks [${account_info.default_network}]`: {
|
|
547
|
-
await
|
|
551
|
+
await switchNetworkByAccountName(keystore_path, keystore_slug, true);
|
|
548
552
|
break;
|
|
549
553
|
}
|
|
550
554
|
case '> Remove': {
|
|
551
|
-
await
|
|
555
|
+
await removeAccountName(keystore_path, keystore_slug);
|
|
552
556
|
return;
|
|
553
557
|
}
|
|
554
558
|
case '> Back': {
|
|
@@ -556,11 +560,11 @@ const accountManager = async (keystore_path: string, account_label: string, wati
|
|
|
556
560
|
}
|
|
557
561
|
}
|
|
558
562
|
|
|
559
|
-
await accountManager(keystore_path,
|
|
563
|
+
await accountManager(keystore_path, keystore_slug, wative_core, password);
|
|
560
564
|
}
|
|
561
565
|
|
|
562
|
-
const showAccounts = async (keystore_path: string,
|
|
563
|
-
const account_info = await getAccountInfo(keystore_path,
|
|
566
|
+
const showAccounts = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => {
|
|
567
|
+
const account_info = await getAccountInfo(keystore_path, keystore_slug);
|
|
564
568
|
|
|
565
569
|
let option_accounts: any = [
|
|
566
570
|
'> Back',
|
|
@@ -598,7 +602,7 @@ const showAccounts = async (keystore_path: string, account_label: string, wative
|
|
|
598
602
|
}
|
|
599
603
|
}
|
|
600
604
|
|
|
601
|
-
let selected_default_account = DEFAULT_ACCOUNT.
|
|
605
|
+
let selected_default_account = DEFAULT_ACCOUNT.keystore_slug === keystore_slug ? option_accounts[DEFAULT_ACCOUNT.account_index] : option_accounts[0];
|
|
602
606
|
|
|
603
607
|
let asset_info_list = await getAssetList(keystore_path, network_info.chainId.toString());
|
|
604
608
|
let selected_account = await listWithLazyBalanceLoading(
|
|
@@ -617,18 +621,18 @@ const showAccounts = async (keystore_path: string, account_label: string, wative
|
|
|
617
621
|
return;
|
|
618
622
|
}
|
|
619
623
|
|
|
620
|
-
DEFAULT_ACCOUNT.
|
|
624
|
+
DEFAULT_ACCOUNT.keystore_slug = keystore_slug;
|
|
621
625
|
DEFAULT_ACCOUNT.account_index = option_accounts.indexOf(selected_account);
|
|
622
626
|
|
|
623
|
-
await showAccountDetail(keystore_path,
|
|
624
|
-
await showAccounts(keystore_path,
|
|
627
|
+
await showAccountDetail(keystore_path, keystore_slug, option_accounts.indexOf(selected_account) - 2, wative_core);
|
|
628
|
+
await showAccounts(keystore_path, keystore_slug, wative_core);
|
|
625
629
|
}
|
|
626
630
|
|
|
627
|
-
const showAccountDetail = async (keystore_path: string,
|
|
628
|
-
const account_info = await getAccountInfo(keystore_path,
|
|
631
|
+
const showAccountDetail = async (keystore_path: string, keystore_slug: string, selected_account_id: number, wative_core: typeof WativeCore) => {
|
|
632
|
+
const account_info = await getAccountInfo(keystore_path, keystore_slug);
|
|
629
633
|
|
|
630
634
|
let default_network = account_info.default_network;
|
|
631
|
-
let account_address = getAccountAddress(keystore_path,
|
|
635
|
+
let account_address = getAccountAddress(keystore_path, keystore_slug, selected_account_id);
|
|
632
636
|
|
|
633
637
|
const network = await getNetworkInfoByName(keystore_path, default_network);
|
|
634
638
|
const balance_result = await getAccountBalance(
|
|
@@ -674,11 +678,11 @@ const showAccountDetail = async (keystore_path: string, account_label: string, s
|
|
|
674
678
|
}
|
|
675
679
|
let tag = await inputSomething(current_tag, tagValidator);
|
|
676
680
|
account_info.data[selected_account_id].tag = tag.replace(/\s+/g, " ").trim();
|
|
677
|
-
saveAccountInfo(keystore_path,
|
|
681
|
+
saveAccountInfo(keystore_path, keystore_slug, account_info);
|
|
678
682
|
break;
|
|
679
683
|
}
|
|
680
684
|
case '> Show address': {
|
|
681
|
-
await showAllAccounts(keystore_path,
|
|
685
|
+
await showAllAccounts(keystore_path, keystore_slug, selected_account_id);
|
|
682
686
|
break;
|
|
683
687
|
}
|
|
684
688
|
case '> Assets': {
|
|
@@ -687,11 +691,11 @@ const showAccountDetail = async (keystore_path: string, account_label: string, s
|
|
|
687
691
|
break;
|
|
688
692
|
}
|
|
689
693
|
case '> Tools': {
|
|
690
|
-
await selectToolsOptions(keystore_path,
|
|
694
|
+
await selectToolsOptions(keystore_path, keystore_slug, account_address, wative_core);
|
|
691
695
|
break;
|
|
692
696
|
}
|
|
693
697
|
case '> Dump private key': {
|
|
694
|
-
let account_address = getAccountAddress(keystore_path,
|
|
698
|
+
let account_address = getAccountAddress(keystore_path, keystore_slug, selected_account_id);
|
|
695
699
|
let private_key = await wative_core.account.showPrivateKey(account_address);
|
|
696
700
|
console.log("account: ", account_address);
|
|
697
701
|
console.log("private key: ", private_key);
|
|
@@ -703,13 +707,13 @@ const showAccountDetail = async (keystore_path: string, account_label: string, s
|
|
|
703
707
|
}
|
|
704
708
|
}
|
|
705
709
|
|
|
706
|
-
const expandAddress = async (keystore_path: string,
|
|
707
|
-
const account_info = await getAccountInfo(keystore_path,
|
|
710
|
+
const expandAddress = async (keystore_path: string, keystore_slug: string, expand_amount: number, wative_core: typeof WativeCore) => {
|
|
711
|
+
const account_info = await getAccountInfo(keystore_path, keystore_slug);
|
|
708
712
|
const account_len = account_info.data.length;
|
|
709
713
|
const bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.legacy);
|
|
710
714
|
bar1.start(expand_amount, 0);
|
|
711
715
|
for (let i = account_len; i < account_len + expand_amount; i++) {
|
|
712
|
-
let sub_account = await wative_core.account.generateSubAccount(
|
|
716
|
+
let sub_account = await wative_core.account.generateSubAccount(keystore_slug, i);
|
|
713
717
|
if (!sub_account.status) {
|
|
714
718
|
console.log(
|
|
715
719
|
chalk.red(sub_account.output)
|
|
@@ -723,49 +727,50 @@ const expandAddress = async (keystore_path: string, account_label: string, expan
|
|
|
723
727
|
}
|
|
724
728
|
bar1.stop();
|
|
725
729
|
|
|
726
|
-
saveAccountInfo(keystore_path,
|
|
730
|
+
saveAccountInfo(keystore_path, keystore_slug, account_info);
|
|
727
731
|
wative_core.account.reloadAccount();
|
|
728
732
|
}
|
|
729
733
|
|
|
730
|
-
const sliceAddress = async (keystore_path: string,
|
|
731
|
-
const account_info = await getAccountInfo(keystore_path,
|
|
734
|
+
const sliceAddress = async (keystore_path: string, keystore_slug: string, last_account_no: number, wative_core: typeof WativeCore) => {
|
|
735
|
+
const account_info = await getAccountInfo(keystore_path, keystore_slug);
|
|
732
736
|
account_info.data = account_info.data.slice(0, last_account_no + 1);
|
|
733
|
-
saveAccountInfo(keystore_path,
|
|
737
|
+
saveAccountInfo(keystore_path, keystore_slug, account_info);
|
|
734
738
|
wative_core.account.reloadAccount();
|
|
735
739
|
}
|
|
736
740
|
|
|
737
|
-
const removeAddress = async (keystore_path: string,
|
|
741
|
+
const removeAddress = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => {
|
|
738
742
|
let account_index = await inputSomething('Please input the accountIndex to remove this account', numberValidator);
|
|
739
743
|
if (account_index === "0") {
|
|
740
744
|
console.log(chalk.red("Can't remove the first account"));
|
|
741
745
|
return;
|
|
742
746
|
}
|
|
743
747
|
|
|
744
|
-
let account_info = await getAccountInfo(keystore_path,
|
|
748
|
+
let account_info = await getAccountInfo(keystore_path, keystore_slug);
|
|
745
749
|
let isConfirm = await confirmSomething(`Are you sure you want to remove this account(${account_info.data[account_index].ciphertexts.address})`, true);
|
|
746
750
|
if (!isConfirm) {
|
|
747
751
|
return;
|
|
748
752
|
}
|
|
749
753
|
|
|
750
754
|
account_info.data.splice(Number(account_index), 1);
|
|
751
|
-
saveAccountInfo(keystore_path,
|
|
755
|
+
saveAccountInfo(keystore_path, keystore_slug, account_info);
|
|
752
756
|
wative_core.account.reloadAccount();
|
|
753
757
|
}
|
|
754
758
|
|
|
755
|
-
const
|
|
756
|
-
let
|
|
757
|
-
|
|
759
|
+
const removeAccountName = async (keystore_path: string, keystore_slug: string) => {
|
|
760
|
+
let _account_name = await inputSomething('Please input the account name to remove this account');
|
|
761
|
+
let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
|
|
762
|
+
if (_account_name !== account_name) {
|
|
758
763
|
console.log(chalk.red("Can't remove this account"));
|
|
759
764
|
return;
|
|
760
765
|
}
|
|
761
766
|
|
|
762
|
-
const isConfirm = await confirmSomething(`Are you sure you want to remove this account(${
|
|
767
|
+
const isConfirm = await confirmSomething(`Are you sure you want to remove this account(${account_name})`, true);
|
|
763
768
|
if (!isConfirm) {
|
|
764
769
|
return;
|
|
765
770
|
}
|
|
766
771
|
|
|
767
|
-
let
|
|
768
|
-
fs.rmSync(
|
|
772
|
+
let keystore_slug_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
|
|
773
|
+
fs.rmSync(keystore_slug_path);
|
|
769
774
|
|
|
770
775
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
771
776
|
if (!fs.existsSync(network_path)) {
|
|
@@ -773,8 +778,8 @@ const removeAccountLabel = async (keystore_path: string, account_label: string)
|
|
|
773
778
|
}
|
|
774
779
|
|
|
775
780
|
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
776
|
-
let
|
|
777
|
-
networks.accounts.splice(
|
|
781
|
+
let account_name_index = networks.accounts.indexOf(account_name);
|
|
782
|
+
networks.accounts.splice(account_name_index, 1);
|
|
778
783
|
fs.writeFileSync(network_path, JSON.stringify(networks, null, 2));
|
|
779
784
|
}
|
|
780
785
|
|
|
@@ -785,10 +790,10 @@ export const accountSetting = async (keystore_path: string, wative_core: typeof
|
|
|
785
790
|
}
|
|
786
791
|
|
|
787
792
|
const networks = getNetworkInfo(keystore_path);
|
|
788
|
-
const
|
|
793
|
+
const account_name_list = networks.accounts;
|
|
789
794
|
|
|
790
795
|
let account_setting_options: any[];
|
|
791
|
-
if (
|
|
796
|
+
if (account_name_list.length === 0) {
|
|
792
797
|
account_setting_options = [
|
|
793
798
|
'> Create a new account',
|
|
794
799
|
new inquirer.Separator('----------------------------------'),
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
import { showIntroduction, getKeystorePath, updateStorage,
|
|
3
|
+
import { showIntroduction, getKeystorePath, updateStorage, batchGetKeystoreSlugByAccountName } from "./utils";
|
|
4
4
|
import { createNetwork } from "./network";
|
|
5
5
|
import { showHomePage } from "./home_page";
|
|
6
6
|
|
|
@@ -20,8 +20,8 @@ const main = async () => {
|
|
|
20
20
|
|
|
21
21
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
22
22
|
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
23
|
-
let
|
|
24
|
-
const wative_core = new WativeCore(keystore_path,
|
|
23
|
+
let getKeystoreSlugByAccountName_list = batchGetKeystoreSlugByAccountName(networks.accounts);
|
|
24
|
+
const wative_core = new WativeCore(keystore_path, getKeystoreSlugByAccountName_list, null, true);
|
|
25
25
|
await showHomePage(keystore_path, wative_core);
|
|
26
26
|
}
|
|
27
27
|
|