Watching for DApp changes

This commit is contained in:
alwx 2017-02-02 17:48:56 +03:00
parent f1abb94aa1
commit 7ef0c6dbfe
4 changed files with 107 additions and 9 deletions

View File

@ -7,8 +7,9 @@ Additional tools for DApps developers. These tools allows to speed up the proces
## Requirements
1. Geth (https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum);
2. Node.js
3. NPM
2. Node.js;
3. NPM;
4. Watchman (https://facebook.github.io/watchman/docs/install.html).
## Installing standalone
@ -39,7 +40,7 @@ Example:
### Removing DApp
`./status-dev-cli add-dapp <attach_to> <public_key> <dapp_identity>`
`./status-dev-cli remove-dapp <attach_to> <public_key> <dapp_identity>`
* `attach_to` — Geth endpoint;
* `public_key` — Public key of your user (you can find it in your profile);
@ -50,3 +51,20 @@ Example:
```
./status-dev-cli remove-dapp http://localhost:8545 "0x04..." "dapp-test"
```
### Watching for DApp changes and updating it automatically
`./status-dev-cli watch-dapp <attach_to> <public_key> <dapp_identity> <dapp_dir>`
* `attach_to` — Geth endpoint;
* `public_key` — Public key of your user (you can find it in your profile);
* `dapp_identity``whisper-identity` of your DApp;
* `dapp_dir` dir that should be observed.
Example:
```
./status-dev-cli watch-dapp http://localhost:8545 "0x04..." "dapp-test" ~/Documents/DApps/dapp-test/
```

View File

@ -27,7 +27,7 @@ var status = {
"ttl": 2,
"payload": web3.fromAscii("{:type :debug :action :dapp-changed :args \"" + argsHex + "\"}\n")
});
return "DApp has been removed";
return "Notification sent";
}
};

View File

@ -1,11 +1,14 @@
#!/usr/bin/env node
const cli = require("commander")
const child = require('child_process')
const pkgJson = require(__dirname + '/package.json');
const watchman = require('fb-watchman');
const pkgJson = require(__dirname + '/package.json');
const devtoolsPath = __dirname + '/devtools.js';
var fromAscii = function(str) {
var client = new watchman.Client();
function fromAscii(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var code = str.charCodeAt(i);
@ -16,6 +19,42 @@ var fromAscii = function(str) {
return "0x" + hex;
};
function makeSubscription(client, watch, relativePath, attachTo, publicKey, dapp) {
sub = {
expression: ["allof", ["match", "*.*"]],
fields: ["name"]
};
if (relativePath) {
sub.relative_root = relativePath;
}
client.command(['subscribe', watch, 'dapp-subscription', sub],
function (error, resp) {
if (error) {
console.error('Failed to subscribe: ', error);
return;
}
console.log('Subscription established');
}
);
client.on('subscription', function (resp) {
if (resp.subscription !== 'dapp-subscription') return;
resp.files.forEach(function (file) {
console.log('File changed: ' + file);
});
child.execSync(
"geth --exec '" +
"loadScript(\"" + devtoolsPath + "\");" +
"status.notifyDAppChanged(\"" + publicKey + "\", \"" + dapp + "\");'" +
" " +
"attach " + attachTo
);
});
}
cli.version(pkgJson.version);
cli.command("add-dapp <attach_to> <public_key> <dapp>")
@ -32,7 +71,7 @@ cli.command("add-dapp <attach_to> <public_key> <dapp>")
});
cli.command("remove-dapp <attach_to> <public_key> <dapp_identity>")
.description("Adds a DApp to contacts and chats")
.description("Removes a debuggable DApp")
.action(function (attachTo, publicKey, dappIdentity) {
dapp = fromAscii(JSON.stringify({"whisper-identity": dappIdentity}));
child.execSync(
@ -44,6 +83,46 @@ cli.command("remove-dapp <attach_to> <public_key> <dapp_identity>")
);
});
cli.command("watch-dapp <attach_to> <public_key> <dapp_identity> <dapp_dir>")
.description("Starts watching for DApp changes")
.action(function (attachTo, publicKey, dappIdentity, dappDir) {
dapp = fromAscii(JSON.stringify({"whisper-identity": dappIdentity}));
client.capabilityCheck(
{optional:[], required:['relative_root']},
function (error, resp) {
if (error) {
console.log(error);
client.end();
return;
}
client.command(
['watch-project', dappDir],
function (error, resp) {
if (error) {
console.error('Error initiating watch:', error);
return;
}
if ('warning' in resp) {
console.log('Warning: ', resp.warning);
}
makeSubscription(
client,
resp.watch,
resp.relative_path,
attachTo,
publicKey,
dapp
);
}
);
}
);
});
cli.on("*", function(command) {
console.error("Unknown command " + command[0] + ". See --help for valid commands")
});

View File

@ -9,6 +9,7 @@
"author": "Status.im",
"license": "MPL-2.0",
"dependencies": {
"commander": "^2.9.0"
"commander": "^2.9.0",
"fb-watchman": "^2.0.0"
}
}