Skip to content

Commit

Permalink
Improve scripts/check_pending.js
Browse files Browse the repository at this point in the history
  • Loading branch information
varasev committed Dec 21, 2020
1 parent 40dfd96 commit 1c86654
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion scripts/check_pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const BN = web3.utils.BN;
main();

async function main() {
const netId = await web3.eth.net.getId();

console.log(`Retrieving pending transactions from ${RPC} ...`);
const pending = await getPendingList(RPC);

Expand All @@ -17,7 +19,7 @@ async function main() {

for (let i = 0; i < pending.result.length; i++) {
const from = pending.result[i].from.toLowerCase();
addresses[from] = { balance: new BN(0), nonce: new BN(0) };
addresses[from] = { balance: new BN(0), nonce: new BN(0), certified: false };
}

const addressArray = Object.keys(addresses);
Expand Down Expand Up @@ -51,6 +53,28 @@ async function main() {
}
await batch.execute();
const balances = await Promise.all(promises);

if (netId == 100) { // if this is xDai chain
// Retrieve `certified` boolean flag for each address
const Certifier = new web3.eth.Contract([{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"certify","inputs":[{"type":"address","name":"_who"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":""}],"name":"isInitialized","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"initialize","inputs":[{"type":"address[]","name":"_certifiedAddresses"},{"type":"address","name":"_validatorSet"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"revoke","inputs":[{"type":"address","name":"_who"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":""}],"name":"certified","inputs":[{"type":"address","name":"_who"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":""}],"name":"validatorSetContract","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":""}],"name":"certifiedExplicitly","inputs":[{"type":"address","name":"_who"}],"constant":true},{"type":"event","name":"Confirmed","inputs":[{"type":"address","name":"who","indexed":true}],"anonymous":false},{"type":"event","name":"Revoked","inputs":[{"type":"address","name":"who","indexed":true}],"anonymous":false}], '0xD218aA7619900da0ff5a04C6bBC3411D76d7F6c9');
promises = [];
batch = new web3.BatchRequest();
for (let i = 0; i < addressArray.length; i++) {
const address = addressArray[i];
promises.push(new Promise((resolve, reject) => {
batch.add(Certifier.methods.certified(address).call.request((err, result) => {
if (err) reject(err);
else resolve(result);
}));
}));
}
await batch.execute();
const certified = await Promise.all(promises);
for (let i = 0; i < addressArray.length; i++) {
const address = addressArray[i];
addresses[address].certified = certified[i];
}
}

for (let i = 0; i < addressArray.length; i++) {
const address = addressArray[i];
Expand All @@ -74,6 +98,13 @@ async function main() {
minGasLimit = new BN('21064');
}

if (netId == 100) { // if this is xDai chain
// check for zero gas price allowance
if (txGasPrice.isZero() && !addresses[from].certified) {
continue;
}
}

if (txNonce.eq(addresses[from].nonce) && txGas.lt(gasLimit) && txGas.gte(minGasLimit) && txValuePlusGas.lte(addresses[from].balance)) {
console.log(`Correct TX:`);
console.log(tx);
Expand Down

0 comments on commit 1c86654

Please sign in to comment.