Merge pull request #518 from gordonwritescode/feature/copay-shell

WIP: Copay Shell Integration
This commit is contained in:
Matias Alejo Garcia 2014-06-02 18:46:13 -03:00
commit 49b340eb8e
8 changed files with 172 additions and 103 deletions

View file

@ -24,7 +24,7 @@ grunt shell --target=dev
Open Copay: Open Copay:
``` ```
node app.js npm start
``` ```
Then visit localhost:3000 in your browser. Then visit localhost:3000 in your browser.
@ -33,16 +33,16 @@ Then visit localhost:3000 in your browser.
## Running copay ## Running copay
To run on a different port: To run on a different port:
``` ```
PORT=3001 node app.js PORT=3001 npm start
``` ```
To open up five different instances to test 3-of-5 multisig with yourself, then run this in 5 different terminals: To open up five different instances to test 3-of-5 multisig with yourself, then run this in 5 different terminals:
``` ```
PORT=3001 node app.js PORT=3001 npm start
PORT=3002 node app.js PORT=3002 npm start
PORT=3003 node app.js PORT=3003 npm start
PORT=3004 node app.js PORT=3004 npm start
PORT=3005 node app.js PORT=3005 npm start
``` ```
To open n different instances more easily, just run: To open n different instances more easily, just run:
@ -51,12 +51,22 @@ n=5
node launch.js $n & node launch.js $n &
``` ```
To require Copay as a module for use within you application:
```js
require('copay').start(3000, function(location) {
console.log('Copay server running at: ' + location);
});
```
## Configuration ## Configuration
Default configuration can be found in the config.js file. Default configuration can be found in the config.js file.
See config.js for more info on configuration options. See config.js for more info on configuration options.
# About Copay # About Copay
General General
@ -140,13 +150,3 @@ Peer Authentication
It is important to note that - except for private keys - *all data* in the wallet is shared with *all members of the wallet*. It is important to note that - except for private keys - *all data* in the wallet is shared with *all members of the wallet*.
Private keys are never shared with anyone and are never sent over the network. There are no *private* messages between Private keys are never shared with anyone and are never sent over the network. There are no *private* messages between
individual members of the wallet. All members of a wallet see everything that happens in that wallet. individual members of the wallet. All members of a wallet see everything that happens in that wallet.

21
app.js
View file

@ -1,12 +1,15 @@
var express=require("express"); var express = require('express');
var http=require("http"); var http = require('http');
var app = express();
var app=express(); app.start = function(port, callback) {
var port = process.env.PORT || 3000; app.set('port', port);
app.set("port", port); app.use(express.static(__dirname));
app.use(express.static(__dirname));
app.listen(port, function(){ app.listen(port, function() {
console.log("Listening at: http://localhost:" + port); callback('http://localhost:' + port);
}); });
};
module.exports = app;

View file

@ -736,7 +736,7 @@ on supported browsers please check <a href="http://www.webrtc.org/">http://www.w
<script src="config.js"></script> <script src="config.js"></script>
<script src="js/shell.js"></script>
<script src="lib/angular/angular.min.js"></script> <script src="lib/angular/angular.min.js"></script>
<script src="lib/moment/moment.js"></script> <script src="lib/moment/moment.js"></script>
<script src="lib/angular-moment/angular-moment.js"></script> <script src="lib/angular-moment/angular-moment.js"></script>

View file

@ -59,4 +59,3 @@ angular.module('copay.video', []);
angular.module('copay.import', []); angular.module('copay.import', []);
angular.module('copay.passphrase', []); angular.module('copay.passphrase', []);
angular.module('copay.settings', []); angular.module('copay.settings', []);

60
js/shell.js Normal file
View file

@ -0,0 +1,60 @@
/*
** copay-shell integration
*/
(function() {
/*
** This is a monkey patch for when Copay is running from
** within Copay-Shell (atom-shell). Since the renderer (the frontend)
** receives context from Node.js, we get a `module.exports` contruct
** available to us. Because of this, some libs (specifically Moment.js)
** attempt to assume their CommonJS form and bind to this. This causes
** there to be no references in the window to these libs, so let's trick
** the renderer into thinking that we are _not_ in a CommonJS environment.
*/
if (typeof module !== 'undefined') module = { exports: null };
// are we running in copay shell?
if (process && process.type === 'renderer') initCopayShellBindings();
function controller(name) {
return angular.element(
document.querySelectorAll(
'[ng-controller="' + name + '"], [data-ng-controller="' + name + '"]'
)
).scope();
};
function initCopayShellBindings() {
var ipc = require('ipc');
ipc.on('address:create', function(data) {
location.href = '#/addresses';
controller('AddressesController').newAddr();
});
ipc.on('transactions:send', function(data) {
location.href = '#/send';
});
ipc.on('transactions:all', function(data) {
location.href = '#/transactions';
controller('TransactionsController').show();
});
ipc.on('transactions:pending', function(data) {
location.href = '#/transactions';
controller('TransactionsController').show(true);
});
ipc.on('backup:download', function(data) {
});
ipc.on('backup:email', function(data) {
});
};
})();

View file

@ -26,7 +26,6 @@ var DEFAULT_PORT = process.env.DEFAULT_PORT || 3000;
for (var i=0; i<N; i++) { for (var i=0; i<N; i++) {
var port =(i+DEFAULT_PORT); var port =(i+DEFAULT_PORT);
console.log('Simulating copayer #'+(i+1)+' at http://localhost:'+port); console.log('Simulating copayer #'+(i+1)+' at http://localhost:'+port);
var command = 'PORT='+port+' node app.js &' var command = 'PORT='+port+' npm start &'
exec(command, puts); exec(command, puts);
} }

View file

@ -17,7 +17,9 @@
"bugs": { "bugs": {
"url": "https://github.com/bitpay/copay/issues" "url": "https://github.com/bitpay/copay/issues"
}, },
"main": "app.js",
"scripts": { "scripts": {
"start": "node server.js",
"test": "mocha" "test": "mocha"
}, },
"homepage": "https://github.com/bitpay/copay", "homepage": "https://github.com/bitpay/copay",

6
server.js Normal file
View file

@ -0,0 +1,6 @@
var server = require('./app');
var port = process.env.PORT || 3000;
server.start(port, function(loc){
console.log('Listening at: ' + loc);
});