diff --git a/index.js b/index.js index 907686f..994c58c 100755 --- a/index.js +++ b/index.js @@ -92,28 +92,30 @@ if (cluster.isMaster) { args.numWallets; spinner.start(); } else if (message.counter) { - addps++; + addps += message.counter; } }); } } else { const worker_env = process.env; - while (true) { - if (process.send) { + setInterval(function() { + var res = VanityEth.getVanityWallet( + worker_env.input, + worker_env.isChecksum == "true", + worker_env.isContract == "true", + 1000 + ); + if(res[1] > 0) { process.send({ - account: VanityEth.getVanityWallet( - worker_env.input, - worker_env.isChecksum == "true", - worker_env.isContract == "true", - function () { - process.send({ - counter: true, - }); - } - ), + counter: res[1], }); } - } + if(res[0]) { + process.send({ + account: res[0], + }); + } + }, 1000); } process.stdin.resume(); const cleanup = function (options, err) { diff --git a/libs/VanityEth.js b/libs/VanityEth.js index da142ef..f861dfb 100644 --- a/libs/VanityEth.js +++ b/libs/VanityEth.js @@ -31,17 +31,24 @@ var getVanityWallet = function ( input = "", isChecksum = false, isContract = false, - counter = function () {} + maxTime = 0 ) { if (!isValidHex(input)) throw new Error(ERRORS.invalidHex); input = isChecksum ? input : input.toLowerCase(); var _wallet = getRandomWallet(); + var now = (new Date()).getTime(); + var startTime = now; + var loopCount = 0; while (!isValidVanityWallet(_wallet, input, isChecksum, isContract)) { - counter(); + loopCount++; _wallet = getRandomWallet(isChecksum); + if(maxTime && loopCount % 10 === 0 && (new Date()).getTime() - startTime > maxTime) { + return [null, loopCount]; + } } + if (isChecksum) _wallet.address = ethUtils.toChecksumAddress(_wallet.address); - return _wallet; + return [ _wallet, loopCount ]; }; var getDeterministicContractAddress = function (address) { return (