#!/usr/bin/env -S deno run -A import { readLines } from "https://deno.land/std/io/mod.ts"; import { GearApi } from "https://gear-js.deno.dev/api/index.ts"; import { encodeAddress } from "https://deno.land/x/polkadot/util-crypto/mod.ts"; async function initGearApi() { const PROVIDER = Deno.env.get("PROVIDER") ?? "wss://rpc.vara-network.io"; return await GearApi.create({ providerAddress: PROVIDER, noInitWarn: true }); } const api = await initGearApi(); function validateAndNormalize(addr: string): string { return encodeAddress(addr, 137); } let validators = (await api.query.session.validators()).toJSON() for await (const line of readLines(Deno.stdin)) { let token = line.trim(); if (token === "") continue; let address = validateAndNormalize(token); let number = (await api.query.system.number()).toHuman(); let bonded = (await api.query.staking.bonded(address)).toHuman(); let bondedToSelf = address == bonded; let bondedActive = validators.includes(address); let payee = (await api.query.staking.payee(address)).toHuman() payee = ((x)=>x.Account?x.Account:x)(payee) let account = (await api.query.system.account(address)).toHuman(); let bondedLedger = (await api.query.staking.ledger(bonded)).toHuman() // if (bondedLedger.total != bondedLedger.active) { console.log(bondedLedger) } let json = JSON.stringify( { address, number, bonded, bondedActive, bondedToSelf, bondedValue: bondedLedger.active.replaceAll(",", ''), bondedEnough: BigInt(bondedLedger.active.replaceAll(",", '')) >= BigInt('100000'+'0'.repeat(12)), payee, account, }, null, "", ); console.log(json); } Deno.exit();