Skip to content

Commit

Permalink
cmd/jsutil: add --miner when count tx (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlacfzy authored Jan 19, 2024
1 parent d8b8583 commit 04d62b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cmd/jsutils/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Requirement

- nodejs: v20.10.0
- npm: v10.2.3
- nodejs >= v16.20.2
- npm >= v8.19.4

## Prepare
Recommend use [nvm](https://github.com/nvm-sh/nvm) to manage node version.
Expand All @@ -21,5 +21,5 @@ testnet validators version
```
Transaction count
```bash
node gettxcount.js --rpc ${url} --startNum ${start} --endNum ${end}
node gettxcount.js --rpc ${url} --startNum ${start} --endNum ${end} --miner ${miner} (optional)
```
19 changes: 13 additions & 6 deletions cmd/jsutils/gettxcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import program from "commander";
program.option("--rpc <rpc>", "Rpc");
program.option("--startNum <startNum>", "start num")
program.option("--endNum <endNum>", "end num")
program.option("--miner <miner>", "miner", "")
program.parse(process.argv);

const provider = new ethers.JsonRpcProvider(program.rpc)
Expand All @@ -13,13 +14,19 @@ const main = async () => {
let num = 0;
console.log("Find the max txs count between", program.startNum, "and", program.endNum);
for (let i = program.startNum; i < program.endNum; i++) {
let x = await provider.send("eth_getBlockTransactionCountByNumber", [
if (program.miner !== "") {
let blockData = await provider.getBlock(Number(i))
if (program.miner !== blockData.miner) {
continue
}
}
let x = await provider.send("eth_getBlockTransactionCountByNumber", [
ethers.toQuantity(i)]);
let a = ethers.toNumber(x)
if (a > txCount) {
num = i;
txCount = a;
}
let a = ethers.toNumber(x)
if (a > txCount) {
num = i;
txCount = a;
}
}
console.log("BlockNum = ", num, "TxCount =", txCount);
};
Expand Down

0 comments on commit 04d62b5

Please sign in to comment.