Skip to content

Commit

Permalink
fixed stack overflow with extremely large funding lists
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Mar 3, 2023
1 parent 72ce57b commit 0a43ad8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testnet-funding-tool",
"version": "1.0.4",
"version": "1.0.5",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
36 changes: 22 additions & 14 deletions src/funding-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,8 @@ async function main() {
};

if(options['fundings']) {
var fundingList = fs.readFileSync(options['fundings'], "utf8");
Array.prototype.push.apply(fundings, fundingList.split("\n").map((fundingLine) => {
var cmtPos;
if((cmtPos = fundingLine.indexOf("#")) !== -1)
fundingLine = fundingLine.substring(0, cmtPos);
var fundingEntry = fundingLine.trim().split(":");
if(fundingEntry.length < 2)
return;
return {
address: fundingEntry[0],
amount: BigInt(fundingEntry[1].replace(/ETH/i, "000000000000000000"))
};
}).filter((entry) => !!entry));
var fundingList = fs.readFileSync(options['fundings'], "utf8").split("\n");
loadFundingFile(fundings, fundingList);
}
if(options['fundings-js']) {
var fundingsJsCode = fs.readFileSync(options['fundings-js'], "utf8");
Expand All @@ -141,7 +130,10 @@ async function main() {
fundingsJsRes = fundingsJsRes();
if(fundingsJsRes && typeof fundingsJsRes.then === "function")
fundingsJsRes = await fundingsJsRes;
Array.prototype.push.apply(fundings, fundingsJsRes);

for(var i = 0; i < fundingsJsRes.length; i++) {
fundings.push(fundingsJsRes[i]);
}
}

if(!fundings || fundings.length == 0) {
Expand Down Expand Up @@ -181,6 +173,22 @@ function weiToEth(wei) {
return parseInt((wei / 1000000000000000n).toString()) / 1000;
}

function loadFundingFile(resArray, fundingList) {
var fundingLine, cmtPos, fundingEntry;
for(var i = 0; i < fundingList.length; i++) {
fundingLine = fundingList[i];
if((cmtPos = fundingLine.indexOf("#")) !== -1)
fundingLine = fundingLine.substring(0, cmtPos);
fundingEntry = fundingLine.trim().split(":");
if(fundingEntry.length < 2)
continue;
resArray.push({
address: fundingEntry[0],
amount: BigInt(fundingEntry[1].replace(/ETH/i, "000000000000000000"))
});
}
}

async function startWeb3() {
try {
console.log("connecting to web3 rpc: " + options['rpchost']);
Expand Down

0 comments on commit 0a43ad8

Please sign in to comment.