From cad1ed3b521dfb2d5b2d7e029621a160d470c481 Mon Sep 17 00:00:00 2001 From: alwx Date: Mon, 6 Mar 2017 17:29:20 +0300 Subject: [PATCH] switch-node command --- README.md | 65 +++++++++++++++++++++++++++++++++------------------- index.js | 17 ++++++++++++++ package.json | 2 +- 3 files changed, 59 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index d6cde5c..9042921 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,47 @@ Additional tools for DApps developers. These tools allows to speed up the proces npm i -g status-dev-cli ``` -## How to +## API + +**Common additional parameters:** + +* `--ip ` to specify your device's IP address. + +#### 1. Adding a DApp + +`status-dev-cli add-dapp [dapp]` + +* `dapp` — JSON containing DApp information. It is not required if your DApp contains `package.json` file. Otherwise, this map should contain `whisper-identity`, `dapp-url` and `name` fields (see the example in **Scenario** section) + +You can additionally specify `--dapp-port ` if your DApp uses port other than 8080 and you don't specify a `dapp`JSON. + +#### 2. Removing a DApp + +`status-dev-cli remove-dapp [dapp]` + +* `dapp` — JSON containing `whisper-identity` field. It is not required if your DApp contains `package.json` file. + +#### 3. Refreshing a DApp automatically + +`status-dev-cli watch-dapp [dappDir] [dapp]` + +* `dapp_dir` — dir that should be observed. Not required; +* `dapp` — JSON containing `whisper-identity` field. It is not required if your DApp contains `package.json` file. + +#### 4. Switching network + +***Requires Status 0.9.4+ & status-dev-cli 2.2.0+!*** + +Typically when developing DApps, a developer uses his own private chain or a simulator. +Status inserts its own web3 object into the DApp, however, this web3 object is connected to a different network than the development one. +This command allows to switch a network. Next time you login the network will be switched back. + +`status-dev-cli switch-node ` + +* `url` (required) — the network that will be used instead of `http://localhost:8545` + + +## DApp development To make debugging work we run a web server on your device. It runs on port 5561 on both iOS and Android, but only if you need it. @@ -39,26 +79,3 @@ your DApp by typing http://localhost:8080 in your browser. 1. Add a DApp to Status by executing `status-dev-cli add-dapp '{"whisper-identity": "dapp-test", "dapp-url": "http://localhost:8080/", "name": "My Dapp"}'`; 2. Open the "My Dapp" on your device; 3. Optional: Execute `status-dev-cli watch-dapp . '{"whisper-identity": "dapp-test"}'` to start automatically refreshing your DApp in Status browser when you change the DApp's code. - -## API - -You can specify a --dapp-port in the case your DApp uses port other than 8080. - -### Adding DApp - -`status-dev-cli add-dapp [dapp]` - -* `dapp` — JSON containing DApp information. It is not required if your DApp contains `package.json` file. Otherwise, this map should contain `whisper-identity`, `dapp-url` and `name` fields (see the example in **Scenario** section) - -### Removing DApp - -`status-dev-cli remove-dapp [dapp]` - -* `dapp` — JSON containing `whisper-identity` field. It is not required if your DApp contains `package.json` file. - -### Watching for DApp changes and refreshing DApp automatically - -`status-dev-cli watch-dapp [dappDir] [dapp]` - -* `dapp_dir` — dir that should be observed. Not required; -* `dapp` — JSON containing `whisper-identity` field. It is not required if your DApp contains `package.json` file. diff --git a/index.js b/index.js index 602eb5e..dcecb2c 100755 --- a/index.js +++ b/index.js @@ -182,6 +182,23 @@ cli.command("watch-dapp [dappDir] [dapp]") ); }); +cli.command("switch-node ") + .description("Switches the current RPC node") + .action(function (url) { + request({ + url: "http://" + (cli.ip || defaultIp) + ":5561/switch-node", + method: "POST", + json: true, + body: {encoded: fromAscii(JSON.stringify({"url": url}))} + }, function (error, response, body) { + if (error) { + printMan(); + } else { + console.log(chalk.green("DApp has been removed succesfully.")); + } + }); + }); + cli.on("*", function(command) { console.error("Unknown command " + command[0] + ". See --help for valid commands.") }); diff --git a/package.json b/package.json index aab287a..c2657a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "status-dev-cli", - "version": "2.1.1", + "version": "2.2.0", "description": "CLI for Status", "main": "index.js", "bin": {