Browse Source

clients/js: add worm info namespace (#2603)

This PR adds a new namespace worm info, which includes commands showing static data of chain-id, contract addresses and rpc endpoints.
Alber 2 years ago
parent
commit
5a2fc6e1ef

+ 1 - 1
aptos/README.md

@@ -97,7 +97,7 @@ set up with all the necessary dependencies. This is the command that runs in CI.
 Simply run
 Simply run
 
 
 ``` sh
 ``` sh
-worm start-validator aptos
+worm aptos start-validator
 ```
 ```
 
 
 which will start a local aptos validator with an RPC endpoint at `0.0.0.0:8080`
 which will start a local aptos validator with an RPC endpoint at `0.0.0.0:8080`

+ 1 - 1
aptos/scripts/README.md

@@ -17,7 +17,7 @@ and then.
 First start the local aptos validator by running
 First start the local aptos validator by running
 
 
 ``` shell
 ``` shell
-worm start-validator aptos
+worm aptos start-validator
 ```
 ```
 
 
 Then build & deploy the contracts
 Then build & deploy the contracts

+ 16 - 11
clients/js/README.md

@@ -17,15 +17,20 @@ private keys, based on `.env.sample` in this folder.
 worm [command]
 worm [command]
 
 
 Commands:
 Commands:
-  worm generate                             generate VAAs (devnet and testnet
-                                            only)
-  worm parse <vaa>                          Parse a VAA (can be in either hex or
-                                            base64 format)
-  worm recover <digest> <signature>         Recover an address from a signature
-  worm contract <network> <chain> <module>  Print contract address
-  worm rpc <network> <chain>                Print RPC address
-  worm evm                                  EVM utilites
-  worm submit <vaa>                         Execute a VAA
+  worm generate                                   generate VAAs (devnet and testnet
+                                                  only)
+  worm parse <vaa>                                Parse a VAA (can be in either hex or
+                                                  base64 format)
+  worm recover <digest> <signature>               Recover an address from a signature
+  worm info contract <network> <chain> <module>   Print contract address
+  worm info rpc <network> <chain>                 Print RPC address
+  worm info chain-id <chain>                      Print the wormhole chain ID integer
+                                                  associated with the specified chain name
+  worm evm                                        EVM utilites
+  worm aptos                                      Aptos utilities
+  worm near                                       NEAR utilities
+  worm submit <vaa>                               Execute a VAA
+  worm update                                     Update this tool by rebuilding it
 
 
 Options:
 Options:
   --help     Show help                                                 [boolean]
   --help     Show help                                                 [boolean]
@@ -185,8 +190,8 @@ $ worm evm info -c bsc -n mainnet -m TokenBridge
 
 
 To get the contract address for a module:
 To get the contract address for a module:
 
 
-    $ worm contract mainnet bsc NFTBridge
+    $ worm info contract mainnet bsc NFTBridge
 
 
 To get the RPC address for a chain
 To get the RPC address for a chain
 
 
-    $ worm rpc mainnet bsc
+    $ worm info rpc mainnet bsc

+ 11 - 1
clients/js/cmds/aptos.ts

@@ -8,6 +8,7 @@ import { callEntryFunc, deriveResourceAccount, deriveWrappedAssetAddress } from
 import { config } from '../config';
 import { config } from '../config';
 import { NETWORKS } from "../networks";
 import { NETWORKS } from "../networks";
 import { evm_address, hex } from "../consts";
 import { evm_address, hex } from "../consts";
+import { runCommand, validator_args } from '../start-validator';
 
 
 type Network = "MAINNET" | "TESTNET" | "DEVNET"
 type Network = "MAINNET" | "TESTNET" | "DEVNET"
 
 
@@ -350,7 +351,16 @@ exports.builder = function(y: typeof yargs) {
         const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL);
         const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL);
         await faucetClient.fundAccount(account, amount);
         await faucetClient.fundAccount(account, amount);
         console.log(`Funded ${account} with ${amount} coins`);
         console.log(`Funded ${account} with ${amount} coins`);
-      })
+    })
+    .command("start-validator", "Start a local aptos validator", (yargs) => {
+      return yargs
+        .option("validator-args", validator_args)
+    }, (argv) => {
+        const dir = `${config.wormholeDir}/aptos`;
+        checkAptosBinary();
+        const cmd = `cd ${dir} && aptos node run-local-testnet --with-faucet --force-restart --assume-yes`;
+        runCommand(cmd, argv['validator-args']);
+    })
     .strict().demandCommand();
     .strict().demandCommand();
 }
 }
 
 

+ 10 - 0
clients/js/cmds/evm.ts

@@ -10,6 +10,8 @@ import {
   toChainName,
   toChainName,
 } from "@certusone/wormhole-sdk/lib/cjs/utils/consts";
 } from "@certusone/wormhole-sdk/lib/cjs/utils/consts";
 import { evm_address } from "../consts";
 import { evm_address } from "../consts";
+import { config } from '../config';
+import { runCommand, validator_args } from '../start-validator';
 
 
 exports.command = "evm";
 exports.command = "evm";
 exports.desc = "EVM utilities";
 exports.desc = "EVM utilities";
@@ -193,6 +195,14 @@ exports.builder = function (y: typeof yargs) {
         );
         );
       }
       }
     )
     )
+    .command("start-validator", "Start a local EVM validator", (yargs) => {
+      return yargs
+      .option("validator-args", validator_args)
+    }, (argv) => {
+        const dir = `${config.wormholeDir}/ethereum`;
+        const cmd = `cd ${dir} && npx ganache-cli -e 10000 --deterministic --time="1970-01-01T00:00:00+00:00"`;
+        runCommand(cmd, argv['validator-args'])
+    })
     .strict()
     .strict()
     .demandCommand();
     .demandCommand();
 };
 };

+ 11 - 0
clients/js/cmds/info.ts

@@ -0,0 +1,11 @@
+import yargs from "yargs";
+
+exports.command = "info";
+exports.desc = "Contract, chain and rpc information utilities";
+exports.builder = (y: typeof yargs) => {
+  // Imports modules logic from root commands, more info here -> https://github.com/yargs/yargs/blob/main/docs/advanced.md#providing-a-command-module
+  return y
+  .command(require('./chainId'))
+  .command(require('./rpc'))
+  .command(require('./contractAddress'))
+};

+ 0 - 34
clients/js/cmds/start.ts

@@ -1,34 +0,0 @@
-import yargs from "yargs";
-import { spawnSync } from 'child_process';
-import { config } from '../config';
-import { checkAptosBinary } from "./aptos";
-
-exports.command = 'start-validator';
-exports.desc = 'Start a local validator';
-exports.builder = function(y: typeof yargs) {
-    return y.option("validator-args", {
-        alias: "a",
-        type: "string",
-        array: true,
-        default: [],
-        describe: "Additional args to validator",
-    }).command("aptos", "Start a local aptos validator", (_yargs) => {
-    }, (argv) => {
-        const dir = `${config.wormholeDir}/aptos`;
-        checkAptosBinary();
-        const cmd = `cd ${dir} && aptos node run-local-testnet --with-faucet --force-restart --assume-yes`;
-        runCommand(cmd, argv['validator-args']);
-    }).command("evm", "Start a local EVM validator", (_yargs) => {
-    }, (argv) => {
-        const dir = `${config.wormholeDir}/ethereum`;
-        const cmd = `cd ${dir} && npx ganache-cli -e 10000 --deterministic --time="1970-01-01T00:00:00+00:00"`;
-        runCommand(cmd, argv['validator-args']);
-    }).strict().demandCommand();
-}
-
-function runCommand(baseCmd: string, args: string[]) {
-    const args_string = args.map(a => `"${a}"`).join(" ");
-    const cmd = `${baseCmd} ${args_string}`;
-    console.log("\x1b[33m%s\x1b[0m", cmd);
-    spawnSync(cmd, { shell: true, stdio: "inherit" });
-}

+ 2 - 2
clients/js/package-lock.json

@@ -1,12 +1,12 @@
 {
 {
   "name": "@wormhole-foundation/wormhole-client",
   "name": "@wormhole-foundation/wormhole-client",
-  "version": "0.0.1",
+  "version": "0.0.3",
   "lockfileVersion": 2,
   "lockfileVersion": 2,
   "requires": true,
   "requires": true,
   "packages": {
   "packages": {
     "": {
     "": {
       "name": "@wormhole-foundation/wormhole-client",
       "name": "@wormhole-foundation/wormhole-client",
-      "version": "0.0.1",
+      "version": "0.0.3",
       "dependencies": {
       "dependencies": {
         "@celo-tools/celo-ethers-wrapper": "^0.1.0",
         "@celo-tools/celo-ethers-wrapper": "^0.1.0",
         "@certusone/wormhole-sdk": "^0.9.11",
         "@certusone/wormhole-sdk": "^0.9.11",

+ 1 - 1
clients/js/package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "@wormhole-foundation/wormhole-client",
   "name": "@wormhole-foundation/wormhole-client",
-  "version": "0.0.1",
+  "version": "0.0.3",
   "dependencies": {
   "dependencies": {
     "@celo-tools/celo-ethers-wrapper": "^0.1.0",
     "@celo-tools/celo-ethers-wrapper": "^0.1.0",
     "@certusone/wormhole-sdk": "^0.9.11",
     "@certusone/wormhole-sdk": "^0.9.11",

+ 16 - 0
clients/js/start-validator.ts

@@ -0,0 +1,16 @@
+import { spawnSync } from 'child_process';
+
+export const validator_args = {
+  alias: "a",
+  type: "string",
+  array: true,
+  default: [],
+  describe: "Additional args to validator",
+} as const;
+
+export function runCommand(baseCmd: string, args: readonly string[]) {
+  const args_string = args.map(a => `"${a}"`).join(" ");
+  const cmd = `${baseCmd} ${args_string}`;
+  console.log("\x1b[33m%s\x1b[0m", cmd);
+  spawnSync(cmd, { shell: true, stdio: "inherit" });
+}