Skip to content

Commit

Permalink
fixed high memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed May 4, 2023
1 parent 8f4a2cc commit e45015c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
30 changes: 16 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions libs/VanityEth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit e45015c

Please sign in to comment.