diff --git a/cmd/jsutils/README.md b/cmd/jsutils/README.md new file mode 100644 index 0000000000..eb6b3cc422 --- /dev/null +++ b/cmd/jsutils/README.md @@ -0,0 +1,21 @@ +## Requirement + +- nodejs: v20.10.0 +- npm: v10.2.3 + +## Prepare +Recommend use [nvm](https://github.com/nvm-sh/nvm) to manage node version. + +Install node.js dependency: +```shell script + npm install +``` +## Run +mainnet +```bash + npm run startMainnet +``` +testnet +```bash + npm run startTestnet +``` \ No newline at end of file diff --git a/cmd/jsutils/getvalidatorversion.js b/cmd/jsutils/getvalidatorversion.js new file mode 100644 index 0000000000..d0d9fc3d90 --- /dev/null +++ b/cmd/jsutils/getvalidatorversion.js @@ -0,0 +1,25 @@ +import { ethers } from "ethers"; +import program from "commander"; + +program.option("--Rpc ", "Rpc"); +program.option("--Num ", "validator num", 21) +program.parse(process.argv); + +const provider = new ethers.JsonRpcProvider(program.Rpc); + +const main = async () => { + const blockNum = await provider.getBlockNumber(); + console.log(blockNum); + for (let i = 0; i < program.Num; i++) { + let blockData = await provider.getBlock(blockNum - i); + let major = ethers.toNumber(ethers.dataSlice(blockData.extraData, 2, 3)) + let minor = ethers.toNumber(ethers.dataSlice(blockData.extraData, 3, 4)) + let patch = ethers.toNumber(ethers.dataSlice(blockData.extraData, 4, 5)) + console.log(blockData.miner, "version =", major + "." + minor + "." + patch) + } +}; +main().then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); \ No newline at end of file diff --git a/cmd/jsutils/package.json b/cmd/jsutils/package.json new file mode 100644 index 0000000000..68a76c9aa4 --- /dev/null +++ b/cmd/jsutils/package.json @@ -0,0 +1,16 @@ +{ + "name": "jsutils", + "version": "1.0.0", + "type": "module", + "description": "jsUtils for bsc", + "main": "index.js", + "scripts": { + "startMainnet": "node getvalidatorversion.js --Rpc https://bsc-dataseed.bnbchain.org --Num 21", + "startTestnet": "node getvalidatorversion.js --Rpc https://bsc-testnet-dataseed.bnbchain.org --Num 7" + }, + "dependencies": { + "commander": "^3.0.1", + "ethers": "^6.2.3" + }, + "author": "BNB Chain" +}