-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/jsutils: add a tool to get slash count (#2569)
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ethers } from "ethers"; | ||
import program from "commander"; | ||
|
||
program.option("--Rpc <Rpc>", "Rpc"); | ||
program.option("--Num <Num>", "num", 0) | ||
program.parse(process.argv); | ||
|
||
const provider = new ethers.JsonRpcProvider(program.Rpc); | ||
|
||
const slashAbi = [ | ||
"function getSlashIndicator(address validatorAddr) external view returns (uint256, uint256)" | ||
] | ||
const validatorSetAbi = [ | ||
"function getLivingValidators() external view returns (address[], bytes[])" | ||
] | ||
const addrValidatorSet = '0x0000000000000000000000000000000000001000'; | ||
const addrSlash = '0x0000000000000000000000000000000000001001'; | ||
const validatorSet = new ethers.Contract(addrValidatorSet, validatorSetAbi, provider); | ||
const slashIndicator = new ethers.Contract(addrSlash, slashAbi, provider) | ||
|
||
|
||
const main = async () => { | ||
let blockNum = ethers.getNumber(program.Num) | ||
if (blockNum === 0) { | ||
blockNum = await provider.getBlockNumber() | ||
} | ||
let block = await provider.getBlock(blockNum) | ||
console.log("current block", blockNum, "time", block.date) | ||
const data = await validatorSet.getLivingValidators({blockTag:blockNum}) | ||
for (let i = 0; i < data[0].length; i++) { | ||
let addr = data[0][i]; | ||
let info = await slashIndicator.getSlashIndicator(addr, {blockTag:blockNum}) | ||
console.log("index:", i, "address:", addr, "slashes:", ethers.toNumber(info[1])) | ||
} | ||
}; | ||
main().then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |