wative 1.2.8 → 1.2.10
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/package.json +21 -22
- package/src/account.ts +0 -864
- package/src/assets.ts +0 -399
- package/src/chain.ts +0 -28
- package/src/config.ts +0 -2074
- package/src/daemon-watcher.js +0 -181
- package/src/home_page.ts +0 -36
- package/src/index.d.ts +0 -12
- package/src/index.ts +0 -53
- package/src/network.ts +0 -819
- package/src/ssh/client.ts +0 -389
- package/src/ssh/config_manager.ts +0 -304
- package/src/ssh/index.ts +0 -66
- package/src/ssh/service_manager.ts +0 -685
- package/src/ssh/types.ts +0 -50
- package/src/ssh/utils.ts +0 -89
- package/src/ssh/wative_server.ts +0 -534
- package/src/tools.ts +0 -923
- package/src/tx_gas_utils.ts +0 -119
- package/src/utils.ts +0 -916
- package/src/wallet-cli.ts +0 -39
- package/src/wative.ts +0 -633
- package/src/web3.ts +0 -415
package/src/tools.ts
DELETED
|
@@ -1,923 +0,0 @@
|
|
|
1
|
-
const chalk = require('chalk');
|
|
2
|
-
import { BigNumber } from 'bignumber.js';
|
|
3
|
-
import inquirer from 'inquirer';
|
|
4
|
-
import { addrValidator, chainAddressValidator, confirmSomething, editorSomething, gasValidator, getAccountChainType, hexValidator, inputSomething, numberValidator, selectSomething, getAccountNameByKeystoreSlug, getAccountIndexByKeystoreSlug } from "./utils";
|
|
5
|
-
import { loginIn } from './account';
|
|
6
|
-
import { getAccountBalance, getDefaultNetworkByAddress, getEvmNetworks, getNetworkInfoByName, getNetworkTypeByName } from './network';
|
|
7
|
-
import { GasUtil } from './tx_gas_utils';
|
|
8
|
-
import { deleteTokenBalance, getAccountBalanceInEvm, getAccountBalanceInSolana, getAccountInfoInSolana, getCodeInEvm, getLatestBlockhash, getPrioritizationFee, getTokenBalanceInEvm, getTokenBalanceInSolana, getTokenInfoInEvm, getTokenInfoInSolana, getTransferTokenData } from './web3';
|
|
9
|
-
import { getAssetListByTokenName } from './assets';
|
|
10
|
-
import { ComputeBudgetProgram, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
|
|
11
|
-
import {
|
|
12
|
-
getAssociatedTokenAddressSync,
|
|
13
|
-
createTransferInstruction,
|
|
14
|
-
createAssociatedTokenAccountInstruction
|
|
15
|
-
} from "@solana/spl-token";
|
|
16
|
-
|
|
17
|
-
const { WativeCore } = require("wative-core");
|
|
18
|
-
|
|
19
|
-
const confirmEvmRawTransaction = async (tx_params: any): Promise<any> => {
|
|
20
|
-
let option_send_evm_raw_transaction_list: any = [
|
|
21
|
-
new inquirer.Separator("————Tx Detail—————-"),
|
|
22
|
-
`from: ${tx_params.from}`,
|
|
23
|
-
`to: ${tx_params.to}`,
|
|
24
|
-
`nonce: ${tx_params.nonce}`,
|
|
25
|
-
`gasPrice: ${tx_params.gasPrice}`,
|
|
26
|
-
`data: ${tx_params.data}`,
|
|
27
|
-
`value: ${tx_params.value}`,
|
|
28
|
-
`gas: ${tx_params.gas}`,
|
|
29
|
-
new inquirer.Separator("——————————————-"),
|
|
30
|
-
"Send it now",
|
|
31
|
-
"Back",
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
let selected_send_evm_raw_transaction = await selectSomething(option_send_evm_raw_transaction_list);
|
|
35
|
-
let option_id = option_send_evm_raw_transaction_list.indexOf(selected_send_evm_raw_transaction);
|
|
36
|
-
|
|
37
|
-
if (option_id === 1) {
|
|
38
|
-
tx_params.from = await inputSomething("from", chainAddressValidator);
|
|
39
|
-
}
|
|
40
|
-
if (option_id === 2) {
|
|
41
|
-
tx_params.to = await inputSomething("to", chainAddressValidator);
|
|
42
|
-
}
|
|
43
|
-
if (option_id === 3) {
|
|
44
|
-
tx_params.nonce = await inputSomething("nonce");
|
|
45
|
-
}
|
|
46
|
-
if (option_id === 4) {
|
|
47
|
-
tx_params.gasPrice = await inputSomething("gasPrice");
|
|
48
|
-
}
|
|
49
|
-
if (option_id === 5) {
|
|
50
|
-
tx_params.data = await editorSomething("data");
|
|
51
|
-
}
|
|
52
|
-
if (option_id === 6) {
|
|
53
|
-
tx_params.value = await inputSomething("value");
|
|
54
|
-
}
|
|
55
|
-
if (option_id === 7) {
|
|
56
|
-
tx_params.gas = await inputSomething("gas");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (option_id === 9) {
|
|
60
|
-
return tx_params;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (option_id === 10) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return await confirmEvmRawTransaction(tx_params);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const sendEvmRawTransaction = async (chain_id: string, chain_rpc_url: string, chain_symbols: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
71
|
-
const to = await inputSomething("to", chainAddressValidator);
|
|
72
|
-
const gasUtil = new GasUtil(chain_rpc_url);
|
|
73
|
-
const estimateGasPrice = await gasUtil.getGasPrice();
|
|
74
|
-
const estimateGasPriceEthers = (new BigNumber(estimateGasPrice.toString())).dividedBy(1e9);
|
|
75
|
-
const _estimateGasPrice = estimateGasPriceEthers.toFixed(4, BigNumber.ROUND_FLOOR);
|
|
76
|
-
const inputGasPrice = await inputSomething(`Gas price (${_estimateGasPrice}), agree or enter`, gasValidator);
|
|
77
|
-
let gasPrice = inputGasPrice ? inputGasPrice : _estimateGasPrice;
|
|
78
|
-
gasPrice = (new BigNumber(gasPrice)).multipliedBy(1e9).toFixed(0);
|
|
79
|
-
|
|
80
|
-
let code_result = await getCodeInEvm(to, chain_rpc_url);
|
|
81
|
-
if (!code_result.status) {
|
|
82
|
-
console.log(chalk.red(code_result.output));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let transfer_gas_limit: string;
|
|
87
|
-
if (chain_id === "42161" || chain_id === "421614") {
|
|
88
|
-
transfer_gas_limit = "1700000";
|
|
89
|
-
} else {
|
|
90
|
-
transfer_gas_limit = "21000";
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let data: string;
|
|
94
|
-
let value: any;
|
|
95
|
-
if (code_result.output === "0x") {
|
|
96
|
-
data = "0x";
|
|
97
|
-
|
|
98
|
-
let account_balance_result = await getAccountBalanceInEvm(account_address, chain_rpc_url);
|
|
99
|
-
if (!account_balance_result.status) {
|
|
100
|
-
console.log(chalk.red(account_balance_result.output));
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
let account_balance = new BigNumber(account_balance_result.output);
|
|
104
|
-
let tx_gas_price = new BigNumber(gasPrice);
|
|
105
|
-
let max_value = account_balance.minus(tx_gas_price.multipliedBy(Number(transfer_gas_limit))).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
106
|
-
let total_balance = (new BigNumber(max_value)).dividedBy(1e18).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
107
|
-
|
|
108
|
-
if (new BigNumber(total_balance) < new BigNumber(0)) {
|
|
109
|
-
console.log(chalk.red("Not enough balance"));
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
value = await getTransferValue(
|
|
114
|
-
total_balance,
|
|
115
|
-
max_value,
|
|
116
|
-
chain_symbols,
|
|
117
|
-
18
|
|
118
|
-
);
|
|
119
|
-
} else {
|
|
120
|
-
data = await editorSomething("data", hexValidator);
|
|
121
|
-
value = await inputSomething("value", numberValidator);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const estimateNonce = await gasUtil.getTransactionCount(account_address);
|
|
125
|
-
const _nonce = await inputSomething(`Nonce (${estimateNonce}), agree or enter`);
|
|
126
|
-
const nonce = _nonce ? _nonce : estimateNonce.toString();
|
|
127
|
-
let txParams: any = {
|
|
128
|
-
from: account_address,
|
|
129
|
-
to: to,
|
|
130
|
-
nonce: nonce,
|
|
131
|
-
gasPrice: gasPrice,
|
|
132
|
-
data: data,
|
|
133
|
-
value: value
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
if (data === '0x') {
|
|
137
|
-
txParams['gas'] = transfer_gas_limit;
|
|
138
|
-
} else {
|
|
139
|
-
let sendGasPrice = txParams.gasPrice;
|
|
140
|
-
delete txParams.gasPrice;
|
|
141
|
-
try {
|
|
142
|
-
txParams['gas'] = (await gasUtil.estimateTxGas(txParams)).toString();
|
|
143
|
-
} catch (err) {
|
|
144
|
-
console.log(
|
|
145
|
-
chalk.red("Error: " + err)
|
|
146
|
-
);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
txParams.gasPrice = sendGasPrice;
|
|
151
|
-
}
|
|
152
|
-
txParams = await confirmEvmRawTransaction(txParams);
|
|
153
|
-
if (!txParams) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const signed_message_result = await wative_core.account.signTransaction(
|
|
158
|
-
account_address,
|
|
159
|
-
txParams,
|
|
160
|
-
chain_rpc_url
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
if (!signed_message_result.status) {
|
|
164
|
-
console.log(chalk.red(signed_message_result.output));
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
console.log(chalk.green(`Transaction hash: ${signed_message_result.output.transactionHash}`));
|
|
169
|
-
|
|
170
|
-
wative_core.account.sendSignedTransaction(account_address, signed_message_result.output.rawTransaction, chain_rpc_url);
|
|
171
|
-
deleteTokenBalance(
|
|
172
|
-
chain_id,
|
|
173
|
-
[
|
|
174
|
-
account_address,
|
|
175
|
-
to
|
|
176
|
-
],
|
|
177
|
-
[
|
|
178
|
-
"0"
|
|
179
|
-
]
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export const sendSolanaRawTransaction = async (chain_id: string, chain_rpc_url: string, chain_symbols: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
184
|
-
const to = await inputSomething("to", chainAddressValidator);
|
|
185
|
-
|
|
186
|
-
let transaction = new Transaction().add(SystemProgram.transfer({
|
|
187
|
-
fromPubkey: new PublicKey(account_address),
|
|
188
|
-
toPubkey: new PublicKey(to),
|
|
189
|
-
lamports: 1000000
|
|
190
|
-
}));
|
|
191
|
-
transaction.add(
|
|
192
|
-
ComputeBudgetProgram.setComputeUnitLimit({
|
|
193
|
-
units: 200000
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
transaction.add(
|
|
197
|
-
ComputeBudgetProgram.setComputeUnitPrice({
|
|
198
|
-
microLamports: 1000
|
|
199
|
-
})
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
transaction.feePayer = new PublicKey(account_address);
|
|
203
|
-
|
|
204
|
-
let last_blockhash: any = await getLatestBlockhash(chain_rpc_url);
|
|
205
|
-
if (!last_blockhash.status) {
|
|
206
|
-
console.log(chalk.red(last_blockhash.output));
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
transaction.recentBlockhash = last_blockhash.output.blockhash;
|
|
210
|
-
const simulate_result = await wative_core.account.simulateTransaction(
|
|
211
|
-
account_address,
|
|
212
|
-
chain_rpc_url,
|
|
213
|
-
transaction
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
if (!simulate_result.status) {
|
|
217
|
-
console.log(chalk.red(simulate_result.output));
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (!simulate_result.output || !simulate_result.output.value || simulate_result.output.value.unitsConsumed === 0 || simulate_result.output.value.err) {
|
|
222
|
-
console.log(chalk.red("Simulate error"));
|
|
223
|
-
console.log("==================reason=====================");
|
|
224
|
-
console.log(JSON.stringify(simulate_result.output, null, 4));
|
|
225
|
-
console.log("==============================================");
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
let baseUnitsConsumed = new BigNumber(simulate_result.output.value.unitsConsumed.toString()).multipliedBy(1.2).toFixed(0, BigNumber.ROUND_CEIL);
|
|
230
|
-
let unitsConsumed = new BigNumber(baseUnitsConsumed);
|
|
231
|
-
const prioritization_fee_result = await getPrioritizationFee(chain_rpc_url);
|
|
232
|
-
if (!prioritization_fee_result.status) {
|
|
233
|
-
console.log(chalk.red(prioritization_fee_result.output));
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const prioritization_fee = new BigNumber(prioritization_fee_result.output.toString());
|
|
238
|
-
const used_prioritization_fee = unitsConsumed.multipliedBy(prioritization_fee).dividedBy(1e6).toFixed(0, BigNumber.ROUND_CEIL);
|
|
239
|
-
|
|
240
|
-
const account_balance_result = await getAccountBalanceInSolana(account_address, chain_rpc_url);
|
|
241
|
-
if (!account_balance_result.status) {
|
|
242
|
-
console.log(chalk.red(account_balance_result.output));
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const account_balance = new BigNumber(account_balance_result.output);
|
|
247
|
-
|
|
248
|
-
const max_value = account_balance.minus(5000).minus(used_prioritization_fee);
|
|
249
|
-
let total_balance = (new BigNumber(max_value)).dividedBy(1e9).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
250
|
-
if (new BigNumber(total_balance) < new BigNumber(0)) {
|
|
251
|
-
console.log(chalk.red("Not enough balance"));
|
|
252
|
-
return
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
let transfer_amount = await getTransferValue(
|
|
256
|
-
total_balance,
|
|
257
|
-
max_value.toString(),
|
|
258
|
-
chain_symbols,
|
|
259
|
-
9
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
let transactions = new Transaction();
|
|
263
|
-
transactions.add(
|
|
264
|
-
ComputeBudgetProgram.setComputeUnitLimit({
|
|
265
|
-
units: Number(unitsConsumed)
|
|
266
|
-
})
|
|
267
|
-
);
|
|
268
|
-
transactions.add(
|
|
269
|
-
ComputeBudgetProgram.setComputeUnitPrice({
|
|
270
|
-
microLamports: Number(prioritization_fee)
|
|
271
|
-
})
|
|
272
|
-
);
|
|
273
|
-
transactions.add(SystemProgram.transfer({
|
|
274
|
-
fromPubkey: new PublicKey(account_address),
|
|
275
|
-
toPubkey: new PublicKey(to),
|
|
276
|
-
lamports: Number(transfer_amount)
|
|
277
|
-
}));
|
|
278
|
-
|
|
279
|
-
transactions.feePayer = new PublicKey(account_address);
|
|
280
|
-
transactions.recentBlockhash = last_blockhash.output.blockhash;
|
|
281
|
-
|
|
282
|
-
const signed_message_result = await wative_core.account.signTransaction(
|
|
283
|
-
account_address,
|
|
284
|
-
transactions,
|
|
285
|
-
chain_rpc_url
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
if (!signed_message_result.status) {
|
|
289
|
-
console.log(chalk.red(signed_message_result.output));
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
let transaction_receipt_result = await wative_core.account.sendSignedTransaction(account_address, signed_message_result.output, chain_rpc_url);
|
|
293
|
-
if (!transaction_receipt_result.status) {
|
|
294
|
-
console.log(chalk.red(transaction_receipt_result.output));
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
deleteTokenBalance(
|
|
299
|
-
chain_id,
|
|
300
|
-
[
|
|
301
|
-
account_address,
|
|
302
|
-
to
|
|
303
|
-
],
|
|
304
|
-
[
|
|
305
|
-
"0"
|
|
306
|
-
]
|
|
307
|
-
);
|
|
308
|
-
console.log(chalk.green(`Transaction hash: ${transaction_receipt_result.output}`));
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const getTransferValue = async (total_balance: string, max_value: string, chain_symbols: string, decimals: number): Promise<string> => {
|
|
313
|
-
let option_select_value_list: any = [
|
|
314
|
-
'> Input value',
|
|
315
|
-
`> Total Balance (${total_balance} ${chain_symbols})`
|
|
316
|
-
]
|
|
317
|
-
let selected_value = await selectSomething(option_select_value_list);
|
|
318
|
-
let value_id = option_select_value_list.indexOf(selected_value);
|
|
319
|
-
let value = "0";
|
|
320
|
-
if (value_id === 0) {
|
|
321
|
-
let input_value = await inputSomething("value", numberValidator);
|
|
322
|
-
value = new BigNumber(input_value).multipliedBy(10 ** decimals).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
323
|
-
} else if (value_id === 1) {
|
|
324
|
-
value = max_value;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if ((new BigNumber(value)).isLessThanOrEqualTo(new BigNumber(max_value))) {
|
|
328
|
-
return value;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
console.log(chalk.red("Not enough balance"));
|
|
332
|
-
return getTransferValue(total_balance, max_value, chain_symbols, decimals);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: string, chain_id: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
336
|
-
const option_token_type = [
|
|
337
|
-
'> Input token ticker',
|
|
338
|
-
'> Input token contract address'
|
|
339
|
-
];
|
|
340
|
-
let selected_token_type = await selectSomething(option_token_type);
|
|
341
|
-
let token_address: any;
|
|
342
|
-
let token_decimals: any;
|
|
343
|
-
let token_name: any;
|
|
344
|
-
switch (selected_token_type) {
|
|
345
|
-
case '> Input token ticker':
|
|
346
|
-
token_name = await inputSomething("token ticker");
|
|
347
|
-
|
|
348
|
-
let token_address_list = await getAssetListByTokenName(keystore_path, chain_id, token_name);
|
|
349
|
-
if (token_address_list.length === 0) {
|
|
350
|
-
console.log(chalk.red("Token not found"));
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
let option_token_address_list: string[] = [];
|
|
355
|
-
for (let i = 0; i < token_address_list.length; i++) {
|
|
356
|
-
const token_balance_result = await getTokenBalanceInEvm(account_address, token_address_list[i].address, chain_rpc_url);
|
|
357
|
-
if (!token_balance_result.status) {
|
|
358
|
-
console.log(chalk.red(token_balance_result.output));
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
let raw_token_balance = new BigNumber(token_balance_result.output);
|
|
364
|
-
let token_balance = raw_token_balance.dividedBy(10 ** Number(token_address_list[i].decimals)).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
365
|
-
if (token_address_list.length === 1) {
|
|
366
|
-
option_token_address_list.push(
|
|
367
|
-
`> 1. ${token_name} Balance: ${token_balance}`
|
|
368
|
-
);
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
option_token_address_list.push(
|
|
373
|
-
`> ${i + 1}. ${token_name} Balance: ${token_balance}(${token_address_list[i].address})`
|
|
374
|
-
);
|
|
375
|
-
|
|
376
|
-
option_token_address_list.push(token_address_list[i].address);
|
|
377
|
-
}
|
|
378
|
-
let selected_token_address = await selectSomething(option_token_address_list);
|
|
379
|
-
const token_ticker_info = token_address_list[option_token_address_list.indexOf(selected_token_address)];
|
|
380
|
-
token_address = token_ticker_info.address;
|
|
381
|
-
token_decimals = Number(token_ticker_info.decimals);
|
|
382
|
-
break;
|
|
383
|
-
case '> Input token contract address':
|
|
384
|
-
token_address = await inputSomething("token contract address", chainAddressValidator);
|
|
385
|
-
let token_info: any = await getTokenInfoInEvm(token_address, chain_rpc_url);
|
|
386
|
-
if (!token_info.status) {
|
|
387
|
-
console.log(chalk.red(token_info.output));
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
token_decimals = Number(token_info.output.decimals);
|
|
391
|
-
token_name = token_info.output.name;
|
|
392
|
-
break;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const receipt = await inputSomething("Receipt", chainAddressValidator);
|
|
396
|
-
const token_balance_result = await getTokenBalanceInEvm(account_address, token_address, chain_rpc_url);
|
|
397
|
-
if (!token_balance_result.status) {
|
|
398
|
-
console.log(chalk.red(token_balance_result.output));
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const gasUtil = new GasUtil(chain_rpc_url);
|
|
403
|
-
const estimateGasPrice = await gasUtil.getGasPrice();
|
|
404
|
-
const estimateGasPriceEthers = (new BigNumber(estimateGasPrice.toString())).dividedBy(1e9);
|
|
405
|
-
const _estimateGasPrice = estimateGasPriceEthers.toFixed(4, BigNumber.ROUND_FLOOR);
|
|
406
|
-
const inputGasPrice = await inputSomething(`Gas price (${_estimateGasPrice}), agree or enter`, gasValidator);
|
|
407
|
-
let gasPrice = inputGasPrice ? inputGasPrice : _estimateGasPrice;
|
|
408
|
-
gasPrice = (new BigNumber(gasPrice)).multipliedBy(1e9).toFixed(0);
|
|
409
|
-
let transfer_amount = await getTransferTokenAmount(
|
|
410
|
-
token_balance_result.output,
|
|
411
|
-
token_name,
|
|
412
|
-
token_decimals
|
|
413
|
-
);
|
|
414
|
-
|
|
415
|
-
const data = await getTransferTokenData(receipt, transfer_amount, chain_rpc_url);
|
|
416
|
-
|
|
417
|
-
const estimateNonce = await gasUtil.getTransactionCount(account_address);
|
|
418
|
-
const _nonce = await inputSomething(`Nonce (${estimateNonce}), agree or enter`);
|
|
419
|
-
const nonce = _nonce ? _nonce : estimateNonce.toString();
|
|
420
|
-
let txParams: any = {
|
|
421
|
-
from: account_address,
|
|
422
|
-
to: token_address,
|
|
423
|
-
nonce: nonce,
|
|
424
|
-
gasPrice: gasPrice,
|
|
425
|
-
data: data,
|
|
426
|
-
value: "0",
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
if (data === '0x') {
|
|
430
|
-
if (chain_id === "42161" || chain_id === "421614") {
|
|
431
|
-
txParams['gas'] = "1700000";
|
|
432
|
-
} else {
|
|
433
|
-
txParams['gas'] = "21000";
|
|
434
|
-
}
|
|
435
|
-
} else {
|
|
436
|
-
let sendGasPrice = txParams.gasPrice;
|
|
437
|
-
delete txParams.gasPrice;
|
|
438
|
-
try {
|
|
439
|
-
txParams['gas'] = (await gasUtil.estimateTxGas(txParams)).toString();
|
|
440
|
-
} catch (err: any) {
|
|
441
|
-
console.log(
|
|
442
|
-
chalk.red("Failed to estimate gas, " + err.message)
|
|
443
|
-
);
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
txParams.gasPrice = sendGasPrice;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
txParams = await confirmEvmRawTransaction(txParams);
|
|
451
|
-
if (!txParams) {
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
const signed_message_result = await wative_core.account.signTransaction(
|
|
456
|
-
account_address,
|
|
457
|
-
txParams,
|
|
458
|
-
chain_rpc_url
|
|
459
|
-
);
|
|
460
|
-
|
|
461
|
-
if (!signed_message_result.status) {
|
|
462
|
-
console.log(chalk.red(signed_message_result.output));
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
console.log(chalk.green(`Transaction hash: ${signed_message_result.output.transactionHash}`));
|
|
467
|
-
wative_core.account.sendSignedTransaction(account_address, signed_message_result.output.rawTransaction, chain_rpc_url);
|
|
468
|
-
|
|
469
|
-
deleteTokenBalance(
|
|
470
|
-
chain_id,
|
|
471
|
-
[
|
|
472
|
-
account_address,
|
|
473
|
-
receipt
|
|
474
|
-
],
|
|
475
|
-
[
|
|
476
|
-
"0",
|
|
477
|
-
token_address
|
|
478
|
-
]
|
|
479
|
-
);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url: string, chain_id: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
483
|
-
const option_token_type = [
|
|
484
|
-
'> Input token ticker',
|
|
485
|
-
'> Input token contract address'
|
|
486
|
-
];
|
|
487
|
-
let selected_token_type = await selectSomething(option_token_type);
|
|
488
|
-
|
|
489
|
-
let token_address: any;
|
|
490
|
-
let token_decimals: any;
|
|
491
|
-
let token_name: any;
|
|
492
|
-
switch (selected_token_type) {
|
|
493
|
-
case '> Input token ticker':
|
|
494
|
-
token_name = await inputSomething("token ticker");
|
|
495
|
-
|
|
496
|
-
let token_address_list = await getAssetListByTokenName(keystore_path, chain_id, token_name);
|
|
497
|
-
if (token_address_list.length === 0) {
|
|
498
|
-
console.log(chalk.red("Token not found"));
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
let option_token_address_list: string[] = [];
|
|
503
|
-
for (let i = 0; i < token_address_list.length; i++) {
|
|
504
|
-
const token_balance_result = await getTokenBalanceInSolana(account_address, token_address_list[i].address, chain_rpc_url);
|
|
505
|
-
if (!token_balance_result.status) {
|
|
506
|
-
console.log(chalk.red(token_balance_result.output));
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
let raw_token_balance = new BigNumber(token_balance_result.output);
|
|
511
|
-
let token_balance = raw_token_balance.dividedBy(10 ** Number(token_address_list[i].decimals)).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
512
|
-
if (token_address_list.length === 1) {
|
|
513
|
-
option_token_address_list.push(
|
|
514
|
-
`> 1. ${token_name} Balance: ${token_balance}`
|
|
515
|
-
);
|
|
516
|
-
break;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
option_token_address_list.push(
|
|
520
|
-
`> ${i + 1}. ${token_name} Balance: ${token_balance}(${token_address_list[i].address})`
|
|
521
|
-
);
|
|
522
|
-
|
|
523
|
-
option_token_address_list.push(token_address_list[i].address);
|
|
524
|
-
}
|
|
525
|
-
let selected_token_address = await selectSomething(option_token_address_list);
|
|
526
|
-
const token_ticker_info = token_address_list[option_token_address_list.indexOf(selected_token_address)];
|
|
527
|
-
|
|
528
|
-
token_address = token_ticker_info.address;
|
|
529
|
-
token_decimals = Number(token_ticker_info.decimals);
|
|
530
|
-
break;
|
|
531
|
-
case '> Input token contract address':
|
|
532
|
-
token_address = await inputSomething("token contract address", chainAddressValidator);
|
|
533
|
-
let token_info: any = await getTokenInfoInSolana(token_address, chain_rpc_url);
|
|
534
|
-
if (!token_info.status) {
|
|
535
|
-
console.log(chalk.red(token_info.output));
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
token_decimals = Number(token_info.output.decimals);
|
|
539
|
-
token_name = token_info.output.name;
|
|
540
|
-
break;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const receipt = await inputSomething("Receipt", chainAddressValidator);
|
|
544
|
-
const token_balance_result = await getTokenBalanceInSolana(account_address, token_address, chain_rpc_url);
|
|
545
|
-
if (!token_balance_result.status) {
|
|
546
|
-
console.log(chalk.red(token_balance_result.output));
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
let transfer_amount = await getTransferTokenAmount(
|
|
551
|
-
token_balance_result.output,
|
|
552
|
-
token_name,
|
|
553
|
-
token_decimals
|
|
554
|
-
);
|
|
555
|
-
let from_token_account = getAssociatedTokenAddressSync(
|
|
556
|
-
new PublicKey(token_address),
|
|
557
|
-
new PublicKey(account_address),
|
|
558
|
-
true
|
|
559
|
-
);
|
|
560
|
-
|
|
561
|
-
const from_token_account_info_result = await getAccountInfoInSolana(from_token_account.toString(), chain_rpc_url);
|
|
562
|
-
if (!from_token_account_info_result.status) {
|
|
563
|
-
console.log(chalk.red(from_token_account_info_result.output));
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
if (!from_token_account_info_result.output || from_token_account_info_result.output.owner.toString() === PublicKey.default) {
|
|
568
|
-
console.log(chalk.red("From token account not found"));
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
let receipt_token_account = getAssociatedTokenAddressSync(
|
|
573
|
-
new PublicKey(token_address),
|
|
574
|
-
new PublicKey(receipt),
|
|
575
|
-
false
|
|
576
|
-
);
|
|
577
|
-
const receipt_token_account_info_result = await getAccountInfoInSolana(receipt_token_account.toString(), chain_rpc_url);
|
|
578
|
-
if (!receipt_token_account_info_result.status) {
|
|
579
|
-
console.log(chalk.red(receipt_token_account_info_result.output));
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
let transaction = new Transaction();
|
|
584
|
-
let transactions = new Transaction();
|
|
585
|
-
if (!receipt_token_account_info_result.output || receipt_token_account_info_result.output.owner.toString() === PublicKey.default) {
|
|
586
|
-
transaction.add(
|
|
587
|
-
createAssociatedTokenAccountInstruction(
|
|
588
|
-
new PublicKey(account_address),
|
|
589
|
-
new PublicKey(receipt_token_account),
|
|
590
|
-
new PublicKey(receipt),
|
|
591
|
-
new PublicKey(token_address)
|
|
592
|
-
)
|
|
593
|
-
);
|
|
594
|
-
transactions.add(
|
|
595
|
-
createAssociatedTokenAccountInstruction(
|
|
596
|
-
new PublicKey(account_address),
|
|
597
|
-
new PublicKey(receipt_token_account),
|
|
598
|
-
new PublicKey(receipt),
|
|
599
|
-
new PublicKey(token_address)
|
|
600
|
-
)
|
|
601
|
-
);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
transaction.add(
|
|
605
|
-
createTransferInstruction(
|
|
606
|
-
from_token_account,
|
|
607
|
-
receipt_token_account,
|
|
608
|
-
new PublicKey(account_address),
|
|
609
|
-
Number(transfer_amount)
|
|
610
|
-
)
|
|
611
|
-
);
|
|
612
|
-
|
|
613
|
-
transaction.add(
|
|
614
|
-
ComputeBudgetProgram.setComputeUnitLimit({
|
|
615
|
-
units: 200000
|
|
616
|
-
})
|
|
617
|
-
);
|
|
618
|
-
transaction.add(
|
|
619
|
-
ComputeBudgetProgram.setComputeUnitPrice({
|
|
620
|
-
microLamports: 1000
|
|
621
|
-
})
|
|
622
|
-
);
|
|
623
|
-
|
|
624
|
-
transaction.feePayer = new PublicKey(account_address);
|
|
625
|
-
|
|
626
|
-
const simulate_result = await wative_core.account.simulateTransaction(
|
|
627
|
-
account_address,
|
|
628
|
-
chain_rpc_url,
|
|
629
|
-
transaction
|
|
630
|
-
);
|
|
631
|
-
|
|
632
|
-
if (!simulate_result.status) {
|
|
633
|
-
console.log(chalk.red(simulate_result.output));
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
if (!simulate_result.output || !simulate_result.output.value || simulate_result.output.value.unitsConsumed === 0 || simulate_result.output.value.err) {
|
|
638
|
-
console.log(chalk.red("Simulate error"));
|
|
639
|
-
console.log("==================reason=====================");
|
|
640
|
-
console.log(JSON.stringify(simulate_result.output, null, 4));
|
|
641
|
-
console.log("==============================================");
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
let unitsConsumed = new BigNumber(simulate_result.output.value.unitsConsumed.toString());
|
|
646
|
-
unitsConsumed = new BigNumber(Math.ceil(Number(unitsConsumed) * 1.2));
|
|
647
|
-
const prioritization_fee_result = await getPrioritizationFee(chain_rpc_url);
|
|
648
|
-
if (!prioritization_fee_result.status) {
|
|
649
|
-
console.log(chalk.red(prioritization_fee_result.output));
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
const prioritization_fee = new BigNumber(prioritization_fee_result.output.toString());
|
|
654
|
-
|
|
655
|
-
transactions.add(
|
|
656
|
-
createTransferInstruction(
|
|
657
|
-
from_token_account,
|
|
658
|
-
receipt_token_account,
|
|
659
|
-
new PublicKey(account_address),
|
|
660
|
-
Number(transfer_amount)
|
|
661
|
-
)
|
|
662
|
-
);
|
|
663
|
-
|
|
664
|
-
transactions.add(
|
|
665
|
-
ComputeBudgetProgram.setComputeUnitLimit({
|
|
666
|
-
units: Number(unitsConsumed)
|
|
667
|
-
})
|
|
668
|
-
);
|
|
669
|
-
transactions.add(
|
|
670
|
-
ComputeBudgetProgram.setComputeUnitPrice({
|
|
671
|
-
microLamports: Number(prioritization_fee)
|
|
672
|
-
})
|
|
673
|
-
);
|
|
674
|
-
|
|
675
|
-
transaction.feePayer = new PublicKey(account_address);
|
|
676
|
-
const signed_message_result = await wative_core.account.signTransaction(
|
|
677
|
-
account_address,
|
|
678
|
-
transactions,
|
|
679
|
-
chain_rpc_url
|
|
680
|
-
);
|
|
681
|
-
|
|
682
|
-
if (!signed_message_result.status) {
|
|
683
|
-
console.log(chalk.red(signed_message_result.output));
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
let transaction_receipt_result = await wative_core.account.sendSignedTransaction(account_address, signed_message_result.output, chain_rpc_url);
|
|
687
|
-
if (!transaction_receipt_result.status) {
|
|
688
|
-
console.log(chalk.red(transaction_receipt_result.output));
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
deleteTokenBalance(
|
|
693
|
-
chain_id,
|
|
694
|
-
[
|
|
695
|
-
account_address,
|
|
696
|
-
receipt
|
|
697
|
-
],
|
|
698
|
-
[
|
|
699
|
-
"0",
|
|
700
|
-
token_address
|
|
701
|
-
]
|
|
702
|
-
);
|
|
703
|
-
|
|
704
|
-
console.log(chalk.green(`Transaction hash: ${transaction_receipt_result.output}`));
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
const getTransferTokenAmount = async (max_value: string, token_symbols: string, decimals: number): Promise<string> => {
|
|
709
|
-
let total_balance = (new BigNumber(max_value)).dividedBy(10 ** decimals).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
710
|
-
|
|
711
|
-
let option_select_value_list: any = [
|
|
712
|
-
'> Input amount',
|
|
713
|
-
`> Total Balance (${total_balance} ${token_symbols})`
|
|
714
|
-
]
|
|
715
|
-
let selected_value = await selectSomething(option_select_value_list);
|
|
716
|
-
let value_id = option_select_value_list.indexOf(selected_value);
|
|
717
|
-
let value = "0";
|
|
718
|
-
if (value_id === 0) {
|
|
719
|
-
let input_value = await inputSomething("amount", numberValidator);
|
|
720
|
-
value = new BigNumber(input_value).multipliedBy(10 ** decimals).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
721
|
-
} else if (value_id === 1) {
|
|
722
|
-
value = max_value;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
if ((new BigNumber(value)).isLessThanOrEqualTo(new BigNumber(max_value))) {
|
|
726
|
-
return value;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
console.log(chalk.red("Not enough balance"));
|
|
730
|
-
return getTransferTokenAmount(max_value, token_symbols, decimals);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
const excuteTools = async (keystore_path: string, keystore_slug: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
734
|
-
let default_network = getDefaultNetworkByAddress(keystore_path, keystore_slug, account_address);
|
|
735
|
-
let network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
736
|
-
let account_chain_type = getAccountChainType(account_address);
|
|
737
|
-
|
|
738
|
-
if (network_type !== account_chain_type) {
|
|
739
|
-
if (account_chain_type === "evm") {
|
|
740
|
-
default_network = "Ethereum Mainnet"
|
|
741
|
-
}
|
|
742
|
-
if (account_chain_type === "solana") {
|
|
743
|
-
default_network = "Solana Mainnet"
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
if (network_type === "evm") {
|
|
750
|
-
let confirm = await confirmSomething(`Network (${default_network}), want a change?`, false);
|
|
751
|
-
if (confirm) {
|
|
752
|
-
const evm_networks = getEvmNetworks(keystore_path);
|
|
753
|
-
const selected_network = await selectSomething(evm_networks, "Select a network");
|
|
754
|
-
default_network = selected_network;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
let account_balance = await getAccountBalance(account_address, keystore_path, default_network);
|
|
759
|
-
|
|
760
|
-
if (!account_balance.status) {
|
|
761
|
-
console.log(chalk.red(account_balance.output));
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
const network_info = getNetworkInfoByName(keystore_path, default_network);
|
|
765
|
-
|
|
766
|
-
console.log(
|
|
767
|
-
chalk.green(` ${network_info.nativeCurrency.symbol} Balance: ${account_balance.output}`)
|
|
768
|
-
);
|
|
769
|
-
|
|
770
|
-
const option_send_tx = [
|
|
771
|
-
'> Send Raw Tx',
|
|
772
|
-
'> Send Token',
|
|
773
|
-
new inquirer.Separator('----------------------------------'),
|
|
774
|
-
'> Back',
|
|
775
|
-
];
|
|
776
|
-
|
|
777
|
-
const selected_send_tx = await selectSomething(option_send_tx);
|
|
778
|
-
|
|
779
|
-
switch (selected_send_tx) {
|
|
780
|
-
case '> Send Raw Tx': {
|
|
781
|
-
if (account_chain_type === "evm") {
|
|
782
|
-
await sendEvmRawTransaction(
|
|
783
|
-
network_info.chainId.toString(),
|
|
784
|
-
network_info.rpcUrl,
|
|
785
|
-
network_info.nativeCurrency.symbol,
|
|
786
|
-
account_address,
|
|
787
|
-
wative_core
|
|
788
|
-
);
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
if (account_chain_type === "solana") {
|
|
792
|
-
await sendSolanaRawTransaction(
|
|
793
|
-
network_info.chainId.toString(),
|
|
794
|
-
network_info.rpcUrl,
|
|
795
|
-
network_info.nativeCurrency.symbol,
|
|
796
|
-
account_address,
|
|
797
|
-
wative_core
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
break;
|
|
801
|
-
}
|
|
802
|
-
case '> Send Token': {
|
|
803
|
-
if (account_chain_type === "evm") {
|
|
804
|
-
await sendEvmTokenTransaction(
|
|
805
|
-
keystore_path,
|
|
806
|
-
network_info.rpcUrl,
|
|
807
|
-
network_info.chainId.toString(),
|
|
808
|
-
account_address,
|
|
809
|
-
wative_core
|
|
810
|
-
);
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
if (account_chain_type === "solana") {
|
|
814
|
-
await sendSolanaTokenTransaction(
|
|
815
|
-
keystore_path,
|
|
816
|
-
network_info.rpcUrl,
|
|
817
|
-
network_info.chainId.toString(),
|
|
818
|
-
account_address,
|
|
819
|
-
wative_core
|
|
820
|
-
);
|
|
821
|
-
}
|
|
822
|
-
break;
|
|
823
|
-
}
|
|
824
|
-
case '> Back': {
|
|
825
|
-
return;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
export const selectToolsOptions = async (keystore_path: string, keystore_slug: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
831
|
-
const tools_options = [
|
|
832
|
-
'> SendTx',
|
|
833
|
-
'> SignMessage',
|
|
834
|
-
new inquirer.Separator('----------------------------------'),
|
|
835
|
-
'> Back'
|
|
836
|
-
];
|
|
837
|
-
|
|
838
|
-
const selected_tools_option = await selectSomething(tools_options);
|
|
839
|
-
switch (selected_tools_option) {
|
|
840
|
-
case '> SendTx': {
|
|
841
|
-
await excuteTools(keystore_path, keystore_slug, account_address, wative_core);
|
|
842
|
-
break;
|
|
843
|
-
}
|
|
844
|
-
case '> SignMessage': {
|
|
845
|
-
const message = await editorSomething("Input the message to sign");
|
|
846
|
-
const signed_message = wative_core.account.signMessage(account_address, message);
|
|
847
|
-
if (!signed_message.status) {
|
|
848
|
-
console.log(chalk.red(signed_message.output));
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
console.log(
|
|
852
|
-
chalk.green("Signature: " + signed_message.output)
|
|
853
|
-
);
|
|
854
|
-
break;
|
|
855
|
-
}
|
|
856
|
-
case '> Back': {
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
await selectToolsOptions(keystore_path, keystore_slug, account_address, wative_core);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
export const showTools = async (keystore_path: string, wative_core: typeof WativeCore) => {
|
|
864
|
-
let options = [
|
|
865
|
-
"> Send Tx",
|
|
866
|
-
"> Search Accounts",
|
|
867
|
-
new inquirer.Separator('----------------------------------'),
|
|
868
|
-
"> Back"
|
|
869
|
-
];
|
|
870
|
-
|
|
871
|
-
let selected_option = await selectSomething(options);
|
|
872
|
-
|
|
873
|
-
if (selected_option === "> Back") {
|
|
874
|
-
return;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
let account_address: any;
|
|
878
|
-
if (selected_option === "> Send Tx") {
|
|
879
|
-
account_address = await inputSomething("Input address to send tx", chainAddressValidator);
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
if (selected_option === "> Search Accounts") {
|
|
883
|
-
account_address = await inputSomething("Input part address to send tx", addrValidator);
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
let keystore_slug_info = wative_core.account.getAccountLabel(account_address);
|
|
887
|
-
if (keystore_slug_info === null) {
|
|
888
|
-
console.log(chalk.red("Account not found"));
|
|
889
|
-
await showTools(keystore_path, wative_core);
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
let keystore_slug = keystore_slug_info.account_label;
|
|
894
|
-
let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
|
|
895
|
-
account_address = keystore_slug_info.account_address;
|
|
896
|
-
if (keystore_slug === null) {
|
|
897
|
-
console.log(chalk.red("Account not found"));
|
|
898
|
-
await showTools(keystore_path, wative_core);
|
|
899
|
-
return;
|
|
900
|
-
}
|
|
901
|
-
const account_index = await getAccountIndexByKeystoreSlug(keystore_path, keystore_slug, account_address);
|
|
902
|
-
if (account_index === null) {
|
|
903
|
-
console.log(chalk.red("Account not found"));
|
|
904
|
-
await showTools(keystore_path, wative_core);
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
console.log(
|
|
909
|
-
chalk.green(`Address found!
|
|
910
|
-
address: ${account_address}
|
|
911
|
-
account name: [${account_name}]
|
|
912
|
-
account index: #${account_index}`
|
|
913
|
-
)
|
|
914
|
-
);
|
|
915
|
-
|
|
916
|
-
let login_result = await loginIn(keystore_path, keystore_slug, wative_core);
|
|
917
|
-
if (!login_result.isLoginIn) {
|
|
918
|
-
await showTools(keystore_path, wative_core);
|
|
919
|
-
return;
|
|
920
|
-
}
|
|
921
|
-
await selectToolsOptions(keystore_path, keystore_slug, account_address, wative_core);
|
|
922
|
-
await showTools(keystore_path, wative_core);
|
|
923
|
-
}
|