forked from MyEtherWallet/VanityEth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·99 lines (97 loc) · 3.54 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /usr/bin/env node
var VanityEth = require('./libs/VanityEth');
const ora = require('ora');
var cluster = require('cluster')
var TimeFormat = require('hh-mm-ss')
var numCPUs = require('os').cpus().length
var argv = require('yargs')
.usage('Usage: $0 <command> [options]')
.example('$0 -checksum -i B00B5', 'get a wallet where address matches B00B5 in checksum format')
.example('$0 --contract -i ABC', 'get a wallet where 0 nonce contract address matches the vanity')
.example('$0 -n 25 -i ABC', 'get 25 vanity wallets')
.example('$0 -n 1000', 'get 1000 random wallets')
.alias('i', 'input')
.string('i')
.describe('i', 'input hex string')
.alias('c', 'checksum')
.boolean('c')
.describe('c', 'check against the checksum address')
.alias('n', 'count')
.number('n')
.describe('n', 'number of wallets')
.boolean('contract')
.describe('contract', 'contract address for contract deployment')
.alias('l', 'log')
.boolean('l')
.describe('l', 'log output to file')
.help('h')
.alias('h', 'help')
.epilog('copyright 2018')
.argv;
if (cluster.isMaster) {
const args = {
input: argv.input ? argv.input : '',
isChecksum: argv.checksum ? true : false,
numWallets: argv.count ? argv.count : 1,
isContract: argv.contract ? true : false,
log: argv.log ? true : false,
logFname: argv.log ? 'VanityEth-log-' + Date.now() + '.txt' : ''
}
if (!VanityEth.isValidHex(args.input)) {
console.error(args.input + ' is not valid hexadecimal');
process.exit(1);
}
if (args.log) {
var fs = require('fs');
console.log('logging into ' + args.logFname);
var logStream = fs.createWriteStream(args.logFname, { 'flags': 'a' });
}
var walletsFound = 0;
const spinner = ora('generating vanity address 1/' + args.numWallets).start();
let addps = 0;
setInterval(function(){
spinner.text ='Approximate ETA for an account ' + TimeFormat.fromS((Math.pow(16,20)/Math.pow(16,20-args.input.length))/addps, 'hh:mm:ss');
addps = 0;
},1000)
for (var i = 0; i < numCPUs; i++) {
const worker_env = {
input: args.input,
isChecksum: args.isChecksum,
isContract: args.isContract
}
proc = cluster.fork(worker_env);
proc.on('message', function(message) {
if(message.account){
spinner.succeed(JSON.stringify(message));
if (args.log) logStream.write(JSON.stringify(message) + "\n");
walletsFound++;
if (walletsFound >= args.numWallets) {
cleanup();
}
spinner.text ='generating vanity address ' + (walletsFound + 1) +'/' + args.numWallets;
spinner.start();
} else if(message.counter){
addps++
}
});
}
} else {
const worker_env = process.env;
while (true) {
process.send({
account: VanityEth.getVanityWallet(worker_env.input, worker_env.isChecksum == 'true', worker_env.isContract == 'true', function (){
process.send({
counter: true
})
})})
}
}
process.stdin.resume();
var cleanup = function(options, err) {
if (err) console.log(err.stack);
for (var id in cluster.workers) cluster.workers[id].process.kill();
process.exit();
}
process.on('exit', cleanup.bind(null, {}));
process.on('SIGINT', cleanup.bind(null, {}));
process.on('uncaughtException', cleanup.bind(null, {}));