From 82cbbbbc779f185cf9587fcf3ad991089840e6c9 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Wed, 19 Jun 2024 10:36:40 +0200 Subject: [PATCH] Added script to fetch Sharding Table --- scripts/get_sharding_table.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/get_sharding_table.ts diff --git a/scripts/get_sharding_table.ts b/scripts/get_sharding_table.ts new file mode 100644 index 00000000..ce9aa873 --- /dev/null +++ b/scripts/get_sharding_table.ts @@ -0,0 +1,29 @@ +import fs from 'fs'; + +import hre from 'hardhat'; + +import { ShardingTableStructsV1 } from '../typechain/contracts/v2/ShardingTable.sol/ShardingTableV2'; + +async function main() { + const ShardingTableContract = await hre.ethers.getContractAt( + hre.helpers.getAbi('ShardingTableV2'), + hre.helpers.contractDeployments.contracts['ShardingTable'].evmAddress, + ); + const shardingTable = await ShardingTableContract['getShardingTable()'](); + const shardingTableMapped = shardingTable.map((x: ShardingTableStructsV1.NodeInfoStructOutput) => ({ + nodeId: hre.ethers.utils.toUtf8String(x.nodeId), + sha256: hre.ethers.utils.sha256(x.nodeId), + identityId: Number(x.identityId.toString()), + ask: hre.ethers.utils.formatEther(x.ask), + stake: hre.ethers.utils.formatEther(x.stake), + })); + + fs.writeFileSync(`${hre.network.name}.json`, JSON.stringify(shardingTableMapped, null, 4)); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + });