-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd-account.js
69 lines (60 loc) · 2.37 KB
/
cmd-account.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
/*
* Copyright (C) 2017 Igor Konovalov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const config = require('./lib/config');
const Ethereum = require('./lib/libethereum');
const ethereum = new Ethereum(config);
const ethereumKeys = require('./lib/libcrypto');
const ask = require('./lib/libask');
const colors = require('colors');
const validator = require('validator');
module.exports = {
keys: (arg, options) => {
if (!arg) {
console.log('Account not specified. Use account index or address (hex)');
return;
}
const dataDir = config.eth.datadir;
const ethAccounts = ethereum.listAccounts();
const numberInput = validator.isInt(arg);
if (numberInput && arg > ethAccounts.length) {
console.log(`You have ${ethAccounts.length} accounts only. But your's input was ${arg}.`.red);
return;
}
const account = numberInput ? ethAccounts[arg] : arg;
if (numberInput) {
console.log(`Account ${account}`)
}
let password = ask.password({ignoreConfig: true});
const keys = ethereumKeys.keyPair(dataDir, account, password);
console.log(`Private key:\t${keys.privateKey.toString('hex')}`.red.bold);
console.log(`Public key:\t${keys.publicKey.toString('hex')}`)
},
ls: (arg, options) => {
let coinbase = ethereum.coinbase();
ethereum.listAccounts().forEach(
(account, index) => {
let out = `[${index}] ${account}`;
if (account == coinbase) {
console.log(`${out.green.bold} <- coinbase`)
} else {
console.log(out)
}
if (arg === 'balance') {
console.log(`\tBalance ${ethereum.getBalance(account)} ETH`);
}
});
}
};