Created
March 28, 2024 09:08
-
-
Save DylanVerstraete/7c16c602b301f79ec059f690da594500 to your computer and use it in GitHub Desktop.
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
const { ApiPromise, WsProvider } = require('@polkadot/api') | |
async function main () { | |
const provider = new WsProvider('wss://rpc.cc3-testnet.creditcoin.network/ws') | |
const api = await ApiPromise.create({ provider }) | |
const entries = await api.query.staking.validators.entries(); | |
const validators = entries.map(([key, v]) => { | |
return key.args.map((k) => k.toHuman()); | |
}); | |
const activeEra = await api.query.staking.activeEra(); | |
// for each validator get the era stakers storage | |
const promises = validators.map(async v => { | |
return api.query.staking.erasStakers(activeEra.toJSON().index, v[0]) | |
}) | |
const res = await Promise.all(promises) | |
const result = res.map(r => r.toJSON()) | |
// If total stake === 0 => inactive | |
const inactive = result.filter(r => r.total === 0) | |
// If not 0 => active | |
const active = result.filter(r => r.total !== 0) | |
console.log(`inactive validators ${inactive.length}/${validators.length}`) | |
console.log(`active validators ${active.length}/${validators.length}`) | |
process.exit(0) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment