瀏覽代碼

[contract_manager] Add a script to list wormhole contracts (#1659)

* script to list wormhole contracts

* minor

* minor
Jayant Krishnamurthy 1 年之前
父節點
當前提交
d553f198f0
共有 1 個文件被更改,包括 41 次插入0 次删除
  1. 41 0
      contract_manager/scripts/list_wormhole_contracts.ts

+ 41 - 0
contract_manager/scripts/list_wormhole_contracts.ts

@@ -0,0 +1,41 @@
+import yargs from "yargs";
+import { hideBin } from "yargs/helpers";
+import { DefaultStore, EvmWormholeContract } from "../src";
+
+const parser = yargs(hideBin(process.argv))
+  .usage("Usage: $0")
+  .options({
+    testnet: {
+      type: "boolean",
+      default: false,
+      desc: "Fetch testnet contracts instead of mainnet",
+    },
+  });
+
+async function main() {
+  const argv = await parser.argv;
+  const entries = [];
+  for (const contract of Object.values(DefaultStore.wormhole_contracts)) {
+    if (
+      contract instanceof EvmWormholeContract &&
+      contract.getChain().isMainnet() !== argv.testnet
+    ) {
+      try {
+        const index = await contract.getCurrentGuardianSetIndex();
+        const chainId = await contract.getChainId();
+        entries.push({
+          chain: contract.getChain().getId(),
+          contract: contract.address,
+          guardianSetIndex: index,
+          chainId: chainId,
+        });
+        console.log(`Fetched contract for ${contract.getId()}`);
+      } catch (e) {
+        console.error(`Error fetching contract for ${contract.getId()}`, e);
+      }
+    }
+  }
+  console.table(entries);
+}
+
+main();