Skip to content

Commit

Permalink
Merge pull request #278 from OriginTrail/get-sharding-table-script
Browse files Browse the repository at this point in the history
Added script to fetch Sharding Table
  • Loading branch information
u-hubar authored Jun 19, 2024
2 parents 4fdb972 + 82cbbbb commit 63214f8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scripts/get_sharding_table.ts
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 63214f8

Please sign in to comment.