mirror of https://github.com/BTCPrivate/copay.git
fix conflicts
This commit is contained in:
commit
2c0b733025
|
@ -45,6 +45,7 @@ public/css/main.css
|
||||||
|
|
||||||
README.html
|
README.html
|
||||||
|
|
||||||
lib
|
lib/*
|
||||||
|
!lib/socket.io.js
|
||||||
|
|
||||||
js/copayBundle.js
|
js/copayBundle.js
|
||||||
|
|
116
index.html
116
index.html
|
@ -17,8 +17,9 @@
|
||||||
<img src="./img/logo-negative.svg" alt="" width="130">
|
<img src="./img/logo-negative.svg" alt="" width="130">
|
||||||
</figure>
|
</figure>
|
||||||
<div class="text-right" ng-show="$root.wallet">
|
<div class="text-right" ng-show="$root.wallet">
|
||||||
<h5>Company Funds</h5>
|
<h5 ng-show="$root.wallet.id">Wallet ID:{{$root.wallet.id}}</h5>
|
||||||
<p>4.324 BTC</p>
|
<p ng-show="totalBalance">{{totalBalance}} BTC</p>
|
||||||
|
<p ng-show="!totalBalance">0 BTC</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -47,9 +48,27 @@
|
||||||
<div ng-if='$root.flashMessage.message' class="panel callout radius" style="color:red" >
|
<div ng-if='$root.flashMessage.message' class="panel callout radius" style="color:red" >
|
||||||
{{$root.flashMessage.type}}:
|
{{$root.flashMessage.type}}:
|
||||||
{{$root.flashMessage.message}}
|
{{$root.flashMessage.message}}
|
||||||
<a href="#" ng-click="clearFlashMessage()" class="button tiny">Dismiss</a>
|
<a ng-click="clearFlashMessage()" class="button tiny">Dismiss</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div ng-if='$root.wallet && !$root.wallet.publicKeyRing.isComplete() && !loading' class="panel radius" >
|
||||||
|
|
||||||
|
<p class="panel panel-sign"> <i class="fi-alert size-40"></i>
|
||||||
|
NOTE: Your wallet is not complete yet.
|
||||||
|
<span ng-show="$root.wallet.publicKeyRing.totalCopayers - $root.wallet.publicKeyRing.registeredCopayers()>1">
|
||||||
|
{{$root.wallet.publicKeyRing.totalCopayers - $root.wallet.publicKeyRing.registeredCopayers() }} keys are
|
||||||
|
</span>
|
||||||
|
<span ng-show="$root.wallet.publicKeyRing.totalCopayers - $root.wallet.publicKeyRing.registeredCopayers()==1">
|
||||||
|
One key is
|
||||||
|
</span>
|
||||||
|
|
||||||
|
missing. Ask your copayers to join your session: <b>{{$root.wallet.network.peerId}}</b>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -63,17 +82,6 @@
|
||||||
Connecting to wallet...
|
Connecting to wallet...
|
||||||
</div>
|
</div>
|
||||||
<div ng-show="!loading">
|
<div ng-show="!loading">
|
||||||
<div class="row">
|
|
||||||
<div class="large-6 columns">
|
|
||||||
<h3>Open a Existing Wallet</h3>
|
|
||||||
<select class="form-control" ng-model="selectedWalletId" ng-options="walletId for walletId in listWalletIds()">
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="large-3 columns">
|
|
||||||
<button class="button primary expand round" type="button" ng-click="open(selectedWalletId)">Open</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<hr>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-6 columns">
|
<div class="large-6 columns">
|
||||||
<h3>Join a Network Wallet</h3>
|
<h3>Join a Network Wallet</h3>
|
||||||
|
@ -83,15 +91,44 @@
|
||||||
<button class="button primary expand round" type="button" ng-click="join(connectionId)">Join</button>
|
<button class="button primary expand round" type="button" ng-click="join(connectionId)">Join</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="row">
|
<div ng-show="!walletIds.length">
|
||||||
<div class="large-6 columns">
|
<div class="row">
|
||||||
<h3>Create a New Wallet</h3>
|
<div class="large-6 columns">
|
||||||
|
<h3>Create a New Wallet</h3>
|
||||||
|
</div>
|
||||||
|
<div class="large-3 columns">
|
||||||
|
<button class="button secondary expand round" ng-click="create()">Create</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="large-3 columns">
|
<hr>
|
||||||
<button class="button secondary expand round" ng-click="create()">Create</button>
|
<div class="row">
|
||||||
|
<div class="text-center">
|
||||||
|
<a ng-click="import()">Import from file</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div ng-show="walletIds.length>0">
|
||||||
|
<div class="row">
|
||||||
|
<div class="large-6 columns">
|
||||||
|
<h3>Open a Existing Wallet</h3>
|
||||||
|
<select class="form-control" ng-model="selectedWalletId" ng-options="walletId for walletId in walletIds">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="large-3 columns">
|
||||||
|
<button class="button primary expand round" type="button" ng-click="open(selectedWalletId)">Open</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="text-center">
|
||||||
|
<a ng-click="create()">Create a new wallet</a>
|
||||||
|
· <a ng-click="import()">Import from file</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
@ -126,6 +163,11 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="text-center">
|
||||||
|
<a href="#signin">Go back</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
@ -142,28 +184,23 @@
|
||||||
<p class="panel panel-sign"> <i class="fi-page-copy size-22"></i> </p>
|
<p class="panel panel-sign"> <i class="fi-page-copy size-22"></i> </p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul class="no-bullet" style="font-size: 0.7rem;">
|
|
||||||
<li> [DEBUG] Pubkeys that you have: {{$root.wallet.publicKeyRing.registeredCopayers()}}
|
|
||||||
<li> [DEBUG] WalletId: {{$root.wallet.id}}
|
|
||||||
<li class="panel" style="word-wrap: break-word;" ng-repeat="pub in $root.wallet.publicKeyRing.copayersBIP32">
|
|
||||||
${{pub.extendedPublicKeyString()}}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="large-6 columns p70l">
|
<div class="large-6 columns p70l">
|
||||||
<h3 class="panel-title">Copayers ({{$root.wallet.network.connectedPeers.length}}/{{$root.wallet.publicKeyRing.requiredCopayers}})</h3>
|
<h3 class="panel-title">Online Copayers: {{$root.wallet.network.connectedPeers.length}}</h3>
|
||||||
|
|
||||||
|
<p class="panel panel-sign" ng-show="$root.wallet.publicKeyRing.requiredCopayers > $root.wallet.network.connectedPeers.length"> <i class="fi-alert size-28"></i>
|
||||||
|
{{$root.wallet.publicKeyRing.requiredCopayers}} copayers needed for signning transactions
|
||||||
|
|
||||||
|
|
||||||
<ul class="no-bullet">
|
<ul class="no-bullet">
|
||||||
<li class="panel" ng-repeat="copayer in $root.wallet.network.connectedPeers">
|
<li class="panel" ng-repeat="copayer in $root.wallet.network.connectedPeers">
|
||||||
<span ng-if="copayer == $root.peerId"> You ({{$root.peerId}})<i class="fi-check size-24"></i></span>
|
<span ng-if="copayer == $root.wallet.network.peerId"> You ({{copayer}})<i class="fi-check size-24"></i></span>
|
||||||
<span ng-if="copayer != $root.peerId">{{copayer}}</span>
|
<span ng-if="copayer !== $root.wallet.network.peerId">{{copayer}}</span>
|
||||||
<span>
|
<span>
|
||||||
<i class="fi-check size-16 panel-sign right p5h br100"></i>
|
<i class="fi-check size-16 panel-sign right p5h br100"></i>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="text-center">
|
|
||||||
<button href="#/home" class="button secondary round right">Go to home</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
@ -173,6 +210,7 @@
|
||||||
<!-- HOME -->
|
<!-- HOME -->
|
||||||
<script type="text/ng-template" id="home.html">
|
<script type="text/ng-template" id="home.html">
|
||||||
<div class="home" data-ng-controller="HomeController">
|
<div class="home" data-ng-controller="HomeController">
|
||||||
|
<div ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||||
<h3>Address</h3>
|
<h3>Address</h3>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -181,7 +219,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="large-3 columns line-dashed-v text-center">
|
<div class="large-3 columns line-dashed-v text-center">
|
||||||
<qrcode size="160" data="{{selectedAddr}}"></qrcode>
|
<qrcode size="160" data="{{selectedAddr}}"></qrcode>
|
||||||
<p class="m10t"> <strong> 2.5432 BTC </strong> </p>
|
<p class="m10t" ng-repeat="addr in addrs" ng-if="selectedAddr==addr"> <strong> {{addrBalance[addr]}} BTC </strong> </p>
|
||||||
</div>
|
</div>
|
||||||
<div class="large-1 columns"> </div>
|
<div class="large-1 columns"> </div>
|
||||||
<div class="large-2 columns">
|
<div class="large-2 columns">
|
||||||
|
@ -189,6 +227,7 @@
|
||||||
<button class="secondary round expand" ng-click="newAddr()"> Create </button>
|
<button class="secondary round expand" ng-click="newAddr()"> Create </button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -196,8 +235,7 @@
|
||||||
<!-- TRANSACTIONS -->
|
<!-- TRANSACTIONS -->
|
||||||
<script type="text/ng-template" id="transactions.html">
|
<script type="text/ng-template" id="transactions.html">
|
||||||
<div class="transactions" data-ng-controller="TransactionsController">
|
<div class="transactions" data-ng-controller="TransactionsController">
|
||||||
|
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||||
<div class="row">
|
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<h3>Pending Transactions <small>({{txsoutput.length}})</small></h3>
|
<h3>Pending Transactions <small>({{txsoutput.length}})</small></h3>
|
||||||
<div class="panel pending" ng-repeat="txp in txsoutput">
|
<div class="panel pending" ng-repeat="txp in txsoutput">
|
||||||
|
@ -260,8 +298,7 @@
|
||||||
<!-- SEND -->
|
<!-- SEND -->
|
||||||
<script type="text/ng-template" id="send.html">
|
<script type="text/ng-template" id="send.html">
|
||||||
<div class="send" data-ng-controller="SendController">
|
<div class="send" data-ng-controller="SendController">
|
||||||
<h3>{{title}}</h3>
|
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||||
<div class="row">
|
|
||||||
<div class="large-8 columns">
|
<div class="large-8 columns">
|
||||||
<form>
|
<form>
|
||||||
<label for="address">To
|
<label for="address">To
|
||||||
|
@ -308,6 +345,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- / <div class="large-4 columns box-backup">Backup to Dropbox</div>
|
<!-- / <div class="large-4 columns box-backup">Backup to Dropbox</div>
|
||||||
// <div class="large-4 columns box-backup">Backup to email</div> -->
|
// <div class="large-4 columns box-backup">Backup to email</div> -->
|
||||||
<!-- NOT FOUND -->
|
<!-- NOT FOUND -->
|
||||||
|
@ -327,15 +365,17 @@
|
||||||
<script src="lib/bitcore.js"></script>
|
<script src="lib/bitcore.js"></script>
|
||||||
<script src="lib/crypto-js/rollups/aes.js"></script>
|
<script src="lib/crypto-js/rollups/aes.js"></script>
|
||||||
<script src="lib/file-saver/FileSaver.js"></script>
|
<script src="lib/file-saver/FileSaver.js"></script>
|
||||||
|
<script src="lib/socket.io.js"></script>
|
||||||
<script src="js/copayBundle.js"></script>
|
<script src="js/copayBundle.js"></script>
|
||||||
|
|
||||||
|
|
||||||
<script src="js/app.js"></script>
|
<script src="js/app.js"></script>
|
||||||
<script src="js/config.js"></script>
|
<script src="js/config.js"></script>
|
||||||
<script src="js/routes.js"></script>
|
<script src="js/routes.js"></script>
|
||||||
<script src="js/directives.js"></script>
|
<script src="js/directives.js"></script>
|
||||||
<script src="js/filters.js"></script>
|
<script src="js/filters.js"></script>
|
||||||
|
<script src="js/services/socket.js"></script>
|
||||||
<script src="js/services/walletFactory.js"></script>
|
<script src="js/services/walletFactory.js"></script>
|
||||||
|
<script src="js/services/controllerUtils.js"></script>
|
||||||
|
|
||||||
<script src="js/controllers/header.js"></script>
|
<script src="js/controllers/header.js"></script>
|
||||||
<script src="js/controllers/home.js"></script>
|
<script src="js/controllers/home.js"></script>
|
||||||
|
|
|
@ -11,6 +11,8 @@ angular.module('copay',[
|
||||||
'copay.backup',
|
'copay.backup',
|
||||||
'copay.walletFactory',
|
'copay.walletFactory',
|
||||||
'copay.signin',
|
'copay.signin',
|
||||||
|
'copay.socket',
|
||||||
|
'copay.controllerUtils',
|
||||||
'copay.setup',
|
'copay.setup',
|
||||||
'copay.peer'
|
'copay.peer'
|
||||||
]);
|
]);
|
||||||
|
@ -21,7 +23,9 @@ angular.module('copay.transactions', []);
|
||||||
angular.module('copay.send', []);
|
angular.module('copay.send', []);
|
||||||
angular.module('copay.backup', []);
|
angular.module('copay.backup', []);
|
||||||
angular.module('copay.walletFactory', []);
|
angular.module('copay.walletFactory', []);
|
||||||
|
angular.module('copay.controllerUtils', []);
|
||||||
angular.module('copay.signin', []);
|
angular.module('copay.signin', []);
|
||||||
angular.module('copay.setup', []);
|
angular.module('copay.setup', []);
|
||||||
angular.module('copay.peer', []);
|
angular.module('copay.peer', []);
|
||||||
|
angular.module('copay.socket', []);
|
||||||
|
|
||||||
|
|
17
js/config.js
17
js/config.js
|
@ -3,7 +3,12 @@
|
||||||
var config = {
|
var config = {
|
||||||
networkName: 'testnet',
|
networkName: 'testnet',
|
||||||
network: {
|
network: {
|
||||||
apiKey: 'lwjd5qra8257b9',
|
key: 'lwjd5qra8257b9',
|
||||||
|
// This is for running local peerJs with params: ./peerjs -p 10009 -k 'sdfjhwefh'
|
||||||
|
// key: 'sdfjhwefh',
|
||||||
|
// host: 'localhost',
|
||||||
|
// port: 10009,
|
||||||
|
// path: '/',
|
||||||
maxPeers: 3,
|
maxPeers: 3,
|
||||||
debug: 3,
|
debug: 3,
|
||||||
},
|
},
|
||||||
|
@ -18,10 +23,12 @@ var config = {
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
},
|
},
|
||||||
blockchain: {
|
blockchain: {
|
||||||
host: 'test.insight.is',
|
host: 'localhost',
|
||||||
port: 80
|
port: 3001
|
||||||
// host: 'localhost',
|
},
|
||||||
// port: 3001
|
socket: {
|
||||||
|
host: 'localhost',
|
||||||
|
port: 3001
|
||||||
},
|
},
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.backup').controller('BackupController',
|
angular.module('copay.backup').controller('BackupController',
|
||||||
function($scope, $rootScope, $location, $window, $timeout) {
|
function($scope, $rootScope, $location, $window, $timeout, Socket, controllerUtils) {
|
||||||
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
if (!$rootScope.wallet.id) {
|
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
|
}
|
||||||
|
|
||||||
$scope.title = 'Backup';
|
$scope.title = 'Backup';
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.header').controller('HeaderController',
|
angular.module('copay.header').controller('HeaderController',
|
||||||
function($scope, $rootScope, $location, walletFactory) {
|
function($scope, $rootScope, $location, walletFactory, controllerUtils) {
|
||||||
$scope.menu = [{
|
$scope.menu = [{
|
||||||
'title': 'Home',
|
'title': 'Home',
|
||||||
'icon': 'fi-home',
|
'icon': 'fi-home',
|
||||||
|
@ -24,7 +24,7 @@ angular.module('copay.header').controller('HeaderController',
|
||||||
'link': '#/backup'
|
'link': '#/backup'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
if (!$rootScope.peerId) {
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ angular.module('copay.header').controller('HeaderController',
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
if (w) {
|
if (w) {
|
||||||
w.disconnect();
|
w.disconnect();
|
||||||
delete $rootScope['wallet'];
|
controllerUtils.logout();
|
||||||
$location.path('signin');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.clearFlashMessage = function() {
|
$scope.clearFlashMessage = function() {
|
||||||
$rootScope.flashMessage = {};
|
$rootScope.flashMessage = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.home').controller('HomeController',
|
angular.module('copay.home').controller('HomeController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||||
$scope.title = 'Home';
|
$scope.title = 'Home';
|
||||||
|
|
||||||
$scope.oneAtATime = true;
|
$scope.oneAtATime = true;
|
||||||
$scope.addrBalance = {};
|
$scope.addrBalance = {};
|
||||||
|
|
||||||
var _getBalance = function() {
|
var _getBalance = function() {
|
||||||
$scope.addrs.forEach(function(addr) {
|
$scope.addrs.forEach(function(addr) {
|
||||||
$rootScope.wallet.blockchain.listUnspent([addr], function(unspent) {
|
$rootScope.wallet.getBalance([addr], function(balance) {
|
||||||
var balance = $rootScope.wallet.blockchain.getBalance(unspent);
|
|
||||||
$scope.addrBalance[addr] = balance;
|
$scope.addrBalance[addr] = balance;
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
});
|
});
|
||||||
|
@ -24,13 +23,17 @@ angular.module('copay.home').controller('HomeController',
|
||||||
$scope.selectedAddr = $scope.addrs[0];
|
$scope.selectedAddr = $scope.addrs[0];
|
||||||
|
|
||||||
_getBalance();
|
_getBalance();
|
||||||
|
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.newAddr = function() {
|
$scope.newAddr = function() {
|
||||||
var a = $rootScope.wallet.generateAddress().toString();
|
var a = $rootScope.wallet.generateAddress().toString();
|
||||||
$scope.addrs.push(a);
|
$scope.addrs.push(a);
|
||||||
|
|
||||||
_getBalance();
|
_getBalance();
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.selectAddr = function(addr) {
|
$scope.selectAddr = function(addr) {
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.peer').controller('PeerController',
|
angular.module('copay.peer').controller('PeerController',
|
||||||
function($scope, $rootScope, $location, $routeParams) {
|
function($scope, $rootScope, $location, $routeParams, Socket, controllerUtils) {
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
//Network.connect($rootScope.masterId);
|
//Network.connect($rootScope.masterId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
|
$location.path('signin');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.send').controller('SendController',
|
angular.module('copay.send').controller('SendController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||||
$scope.title = 'Send';
|
$scope.title = 'Send';
|
||||||
|
|
||||||
if (!$rootScope.wallet.id) {
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var socket = Socket($scope);
|
||||||
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$scope.sendTest = function() {
|
$scope.sendTest = function() {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.setup').controller('SetupController',
|
angular.module('copay.setup').controller('SetupController',
|
||||||
function($scope, $rootScope, $location, walletFactory) {
|
function($scope, $rootScope, $location, walletFactory, controllerUtils) {
|
||||||
|
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
|
|
||||||
|
@ -32,16 +32,7 @@ angular.module('copay.setup').controller('SetupController',
|
||||||
totalCopayers: totalCopayers
|
totalCopayers: totalCopayers
|
||||||
};
|
};
|
||||||
var w = walletFactory.create(opts);
|
var w = walletFactory.create(opts);
|
||||||
w.on('created', function(){
|
controllerUtils.setupUxHandlers(w);
|
||||||
$location.path('peer');
|
|
||||||
$rootScope.wallet = w;
|
|
||||||
$rootScope.$digest();
|
|
||||||
});
|
|
||||||
w.on('openError', function(){
|
|
||||||
$scope.loading = false;
|
|
||||||
$rootScope.flashMessage = {type:'error', message: 'Wallet not found'};
|
|
||||||
$location.path('signin');
|
|
||||||
});
|
|
||||||
w.netStart();
|
w.netStart();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,17 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
angular.module('copay.signin').controller('SigninController',
|
angular.module('copay.signin').controller('SigninController',
|
||||||
function($scope, $rootScope, $location, walletFactory) {
|
function($scope, $rootScope, $location, walletFactory, controllerUtils) {
|
||||||
|
|
||||||
// var peerData = Storage.get($rootScope.walletId, 'peerData');
|
// var peerData = Storage.get($rootScope.walletId, 'peerData');
|
||||||
// $rootScope.peerId = peerData ? peerData.peerId : null;
|
// $rootScope.peerId = peerData ? peerData.peerId : null;
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
|
|
||||||
$scope.selectedWalletId = false;
|
$scope.walletIds = walletFactory.getWalletIds();
|
||||||
|
|
||||||
$scope.listWalletIds = function() {
|
$scope.selectedWalletId = $scope.walletIds.length ? $scope.walletIds[0]:null;
|
||||||
return walletFactory.getWalletIds();
|
|
||||||
};
|
|
||||||
|
|
||||||
var _setupUxHandlers = function(w) {
|
|
||||||
w.on('created', function() {
|
|
||||||
$location.path('peer');
|
|
||||||
$rootScope.wallet = w;
|
|
||||||
$rootScope.$digest();
|
|
||||||
});
|
|
||||||
w.on('refresh', function() {
|
|
||||||
|
|
||||||
console.log('[signin.js.23] RECEIVED REFRESH'); //TODO
|
|
||||||
$rootScope.$digest();
|
|
||||||
});
|
|
||||||
|
|
||||||
w.on('openError', function(){
|
|
||||||
$scope.loading = false;
|
|
||||||
$rootScope.flashMessage = {type:'error', message: 'Wallet not found'};
|
|
||||||
$location.path('signin');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.create = function() {
|
$scope.create = function() {
|
||||||
$location.path('setup');
|
$location.path('setup');
|
||||||
|
@ -40,16 +21,18 @@ console.log('[signin.js.23] RECEIVED REFRESH'); //TODO
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
|
|
||||||
var w = walletFactory.open(walletId);
|
var w = walletFactory.open(walletId);
|
||||||
_setupUxHandlers(w);
|
controllerUtils.setupUxHandlers(w);
|
||||||
w.netStart();
|
w.netStart();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.join = function(cid) {
|
$scope.join = function(cid) {
|
||||||
console.log('[signin.js.42:join:]'); //TODO
|
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
|
walletFactory.network.on('openError', function() {
|
||||||
|
controllerUtils.onError($scope);
|
||||||
|
$rootScope.$digest();
|
||||||
|
});
|
||||||
walletFactory.connectTo(cid, function(w) {
|
walletFactory.connectTo(cid, function(w) {
|
||||||
console.log('[signin.js.50]'); //TODO
|
controllerUtils.setupUxHandlers(w);
|
||||||
_setupUxHandlers(w);
|
|
||||||
w.netStart();
|
w.netStart();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,29 +1,33 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.transactions').controller('TransactionsController',
|
angular.module('copay.transactions').controller('TransactionsController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location, Socket, controllerUtils) {
|
||||||
$scope.title = 'Transactions';
|
$scope.title = 'Transactions';
|
||||||
|
|
||||||
$scope.oneAtATime = true;
|
$scope.oneAtATime = true;
|
||||||
|
|
||||||
if (!$rootScope.wallet.id) {
|
if (!$rootScope.wallet || !$rootScope.wallet.id) {
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$scope.txsinput = [
|
||||||
|
{
|
||||||
|
fromAddr: "n3zUqNR7Bbbc4zJhPVj1vG2Lx66K3Xhzvb",
|
||||||
|
toAddr: "msvv2mDfE298s7boXwALq4Dqv77K3TWRZ1",
|
||||||
|
amount: 23.9982
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fromAddr: "my9wnLwwUrwpNfEgSrWY62ymEGf1edKf4J",
|
||||||
|
toAddr: "monCusNiDuptf68rtr58hEjKpJt6cW6zwS",
|
||||||
|
amount: 2.22
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
$scope.txsinput = [
|
$scope.txsoutput = $rootScope.wallet.getTxProposals();
|
||||||
{
|
|
||||||
fromAddr: "n3zUqNR7Bbbc4zJhPVj1vG2Lx66K3Xhzvb",
|
var socket = Socket($scope);
|
||||||
toAddr: "msvv2mDfE298s7boXwALq4Dqv77K3TWRZ1",
|
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||||
amount: 23.9982
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fromAddr: "my9wnLwwUrwpNfEgSrWY62ymEGf1edKf4J",
|
|
||||||
toAddr: "monCusNiDuptf68rtr58hEjKpJt6cW6zwS",
|
|
||||||
amount: 2.22
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
|
||||||
$scope.txsoutput = $rootScope.wallet.getTxProposals();
|
|
||||||
|
|
||||||
$scope.sign = function (ntxid) {
|
$scope.sign = function (ntxid) {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
|
|
@ -29,15 +29,6 @@ function _asyncForEach(array, fn, callback) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Insight.prototype.getBalance = function(unspent) {
|
|
||||||
var balance = 0;
|
|
||||||
for(var i=0;i<unspent.length; i++) {
|
|
||||||
balance = balance + unspent[i].amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return balance;
|
|
||||||
};
|
|
||||||
|
|
||||||
Insight.prototype.listUnspent = function(addresses, cb) {
|
Insight.prototype.listUnspent = function(addresses, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
|
@ -166,10 +166,7 @@ PublicKeyRing.prototype.getAddress = function (index, isChange) {
|
||||||
this._checkIndexRange(index, isChange);
|
this._checkIndexRange(index, isChange);
|
||||||
|
|
||||||
var script = this.getRedeemScript(index,isChange);
|
var script = this.getRedeemScript(index,isChange);
|
||||||
var hash = coinUtil.sha256ripe160(script.getBuffer());
|
return Address.fromScript(script, this.network.name);
|
||||||
var version = this.network.P2SHVersion;
|
|
||||||
var addr = new Address(version, hash);
|
|
||||||
return addr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PublicKeyRing.prototype.getScriptPubKeyHex = function (index, isChange) {
|
PublicKeyRing.prototype.getScriptPubKeyHex = function (index, isChange) {
|
||||||
|
@ -185,10 +182,11 @@ PublicKeyRing.prototype.generateAddress = function(isChange) {
|
||||||
|
|
||||||
var ret =
|
var ret =
|
||||||
this.getAddress(isChange ? this.changeAddressIndex : this.addressIndex, isChange);
|
this.getAddress(isChange ? this.changeAddressIndex : this.addressIndex, isChange);
|
||||||
if (isChange)
|
if (isChange) {
|
||||||
this.changeAddressIndex++;
|
this.changeAddressIndex++;
|
||||||
else
|
} else {
|
||||||
this.addressIndex++;
|
this.addressIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
|
@ -96,11 +96,12 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
||||||
|
|
||||||
Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
||||||
|
|
||||||
if (this.id !== data.walletId)
|
if (this.id !== data.walletId) {
|
||||||
throw new Error('wrong message received: Bad wallet ID');
|
this.emit('badMessage',senderId);
|
||||||
|
this.log('badMessage FROM:', senderId); //TODO
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.log('[Wallet.js.98]' , data.type); //TODO
|
this.log('[Wallet.js.98]' , data.type); //TODO
|
||||||
|
|
||||||
switch(data.type) {
|
switch(data.type) {
|
||||||
case 'publicKeyRing':
|
case 'publicKeyRing':
|
||||||
this._handlePublicKeyRing(senderId, data, isInbound);
|
this._handlePublicKeyRing(senderId, data, isInbound);
|
||||||
|
@ -108,18 +109,17 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
||||||
case 'txProposals':
|
case 'txProposals':
|
||||||
this._handleTxProposals(senderId, data, isInbound);
|
this._handleTxProposals(senderId, data, isInbound);
|
||||||
break;
|
break;
|
||||||
case 'abort':
|
|
||||||
this.emit('abort');
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype._handleNetworkChange = function(newPeer) {
|
Wallet.prototype._handleNetworkChange = function(newPeer) {
|
||||||
if (!newPeer) return;
|
if (newPeer) {
|
||||||
this.log('#### Setting new PEER:', newPeer);
|
this.log('#### Setting new PEER:', newPeer);
|
||||||
this.sendWalletId(newPeer);
|
this.sendWalletId(newPeer);
|
||||||
this.sendPublicKeyRing(newPeer);
|
this.sendPublicKeyRing(newPeer);
|
||||||
this.sendTxProposals(newPeer);
|
this.sendTxProposals(newPeer);
|
||||||
|
}
|
||||||
|
this.emit('refresh');
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype._optsToObj = function () {
|
Wallet.prototype._optsToObj = function () {
|
||||||
|
@ -136,10 +136,17 @@ Wallet.prototype._optsToObj = function () {
|
||||||
Wallet.prototype.netStart = function() {
|
Wallet.prototype.netStart = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var net = this.network;
|
var net = this.network;
|
||||||
|
net.removeAllListeners();
|
||||||
net.on('networkChange', self._handleNetworkChange.bind(self) );
|
net.on('networkChange', self._handleNetworkChange.bind(self) );
|
||||||
net.on('data', self._handleData.bind(self) );
|
net.on('data', self._handleData.bind(self) );
|
||||||
net.on('open', function() {}); // TODO
|
net.on('open', function() {}); // TODO
|
||||||
net.on('close', function() {}); // TODO
|
net.on('openError', function() {
|
||||||
|
this.log('[Wallet.js.132:openError:] GOT openError'); //TODO
|
||||||
|
self.emit('openError');
|
||||||
|
});
|
||||||
|
net.on('close', function() {
|
||||||
|
self.emit('close');
|
||||||
|
});
|
||||||
net.start(function(peerId) {
|
net.start(function(peerId) {
|
||||||
self.emit('created');
|
self.emit('created');
|
||||||
});
|
});
|
||||||
|
@ -211,6 +218,7 @@ Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
||||||
this.emit('publicKeyRingUpdated', this.publicKeyRing);
|
this.emit('publicKeyRingUpdated', this.publicKeyRing);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.generateAddress = function() {
|
Wallet.prototype.generateAddress = function() {
|
||||||
var addr = this.publicKeyRing.generateAddress();
|
var addr = this.publicKeyRing.generateAddress();
|
||||||
this.store();
|
this.store();
|
||||||
|
@ -303,10 +311,34 @@ Wallet.prototype.getAddressesStr = function() {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.getTotalBalance = function(cb) {
|
||||||
|
this.getBalance(this.getAddressesStr(), function(balance) {
|
||||||
|
return cb(balance);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.getBalance = function(addrs, cb) {
|
||||||
|
var balance = 0;
|
||||||
|
this.listUnspent(addrs, function(utxos) {
|
||||||
|
for(var i=0;i<utxos.length; i++) {
|
||||||
|
balance = balance + utxos[i].amount;
|
||||||
|
}
|
||||||
|
if (balance) {
|
||||||
|
if (balance === parseInt(balance)) {
|
||||||
|
balance = balance;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
balance = balance.toFixed(8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cb(balance);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Wallet.prototype.listUnspent = function(cb) {
|
Wallet.prototype.listUnspent = function(addrs, cb) {
|
||||||
this.blockchain.listUnspent(this.getAddressesStr(), cb);
|
this.blockchain.listUnspent(addrs, function(utxos) {
|
||||||
|
return cb(utxos);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -326,7 +358,7 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
|
||||||
opts.remainderOut={ address: this.publicKeyRing.generateAddress(true).toString()};
|
opts.remainderOut={ address: this.publicKeyRing.generateAddress(true).toString()};
|
||||||
}
|
}
|
||||||
|
|
||||||
self.listUnspent(function(utxos) {
|
self.listUnspent(self.getAddressesStr(), function(utxos) {
|
||||||
// TODO check enough funds, etc.
|
// TODO check enough funds, etc.
|
||||||
self.createTxSync(toAddress, amountSatStr, utxos, opts);
|
self.createTxSync(toAddress, amountSatStr, utxos, opts);
|
||||||
self.store();
|
self.store();
|
||||||
|
|
|
@ -148,12 +148,14 @@ WalletFactory.prototype.openRemote = function(peedId) {
|
||||||
opts.storage = this.storage;
|
opts.storage = this.storage;
|
||||||
opts.network = this.network;
|
opts.network = this.network;
|
||||||
opts.blockchain = this.blockchain;
|
opts.blockchain = this.blockchain;
|
||||||
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
|
||||||
|
opts.spendUnconfirmed = typeof opts.spendUnconfirmed === undefined
|
||||||
|
?this.walletDefaults.spendUnconfirmed : opts.spendUnconfirmed;
|
||||||
|
|
||||||
opts.requiredCopayers = requiredCopayers;
|
opts.requiredCopayers = requiredCopayers;
|
||||||
opts.totalCopayers = totalCopayers;
|
opts.totalCopayers = totalCopayers;
|
||||||
var w = new Wallet(opts);
|
var w = new Wallet(opts);
|
||||||
w.store();
|
w.store();
|
||||||
this.addWalletId(w.id);
|
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,18 @@ var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Network(opts) {
|
function Network(opts) {
|
||||||
|
var self = this;
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
this.peerId = opts.peerId;
|
this.peerId = opts.peerId;
|
||||||
this.apiKey = opts.apiKey || 'lwjd5qra8257b9';
|
this.apiKey = opts.apiKey || 'lwjd5qra8257b9';
|
||||||
this.debug = opts.debug || 3;
|
this.debug = opts.debug || 3;
|
||||||
this.maxPeers = opts.maxPeers || 5;
|
this.maxPeers = opts.maxPeers || 5;
|
||||||
|
this.opts = { key: opts.key };
|
||||||
|
|
||||||
|
// For using your own peerJs server
|
||||||
|
['port', 'host', 'path', 'debug'].forEach(function(k) {
|
||||||
|
if (opts[k]) self.opts[k]=opts[k];
|
||||||
|
});
|
||||||
this.connectedPeers = [];
|
this.connectedPeers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,14 +68,9 @@ Network._arrayRemove = function(el, array) {
|
||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
// DEBUG
|
|
||||||
Network.prototype._showConnectedPeers = function() {
|
|
||||||
// console.log("### CONNECTED PEERS", this.connectedPeers);
|
|
||||||
};
|
|
||||||
|
|
||||||
Network.prototype._onClose = function(peerId) {
|
Network.prototype._onClose = function(peerId) {
|
||||||
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
|
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
|
||||||
this._notify();
|
this._notifyNetworkChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._connectToPeers = function(peerIds) {
|
Network.prototype._connectToPeers = function(peerIds) {
|
||||||
|
@ -97,7 +99,7 @@ Network.prototype._onData = function(data, isInbound) {
|
||||||
switch(obj.data.type) {
|
switch(obj.data.type) {
|
||||||
case 'peerList':
|
case 'peerList':
|
||||||
this._connectToPeers(obj.data.peers);
|
this._connectToPeers(obj.data.peers);
|
||||||
this._notify();
|
this._notifyNetworkChange();
|
||||||
break;
|
break;
|
||||||
case 'disconnect':
|
case 'disconnect':
|
||||||
this._onClose(obj.sender);
|
this._onClose(obj.sender);
|
||||||
|
@ -133,6 +135,13 @@ Network.prototype._addPeer = function(peerId, isInbound) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Network.prototype._checkAnyPeer = function() {
|
||||||
|
if (!this.connectedPeers.length) {
|
||||||
|
console.log('EMIT openError: no more peers, not even you!');
|
||||||
|
this.emit('openError');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
||||||
|
|
||||||
var self=this;
|
var self=this;
|
||||||
|
@ -144,7 +153,7 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
||||||
dataConn.peer, isInbound);
|
dataConn.peer, isInbound);
|
||||||
|
|
||||||
self._addPeer(dataConn.peer, isInbound);
|
self._addPeer(dataConn.peer, isInbound);
|
||||||
self._notify( isInbound ? dataConn.peer : null);
|
self._notifyNetworkChange( isInbound ? dataConn.peer : null);
|
||||||
this.emit('open');
|
this.emit('open');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -155,19 +164,19 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
||||||
|
|
||||||
dataConn.on('error', function(e) {
|
dataConn.on('error', function(e) {
|
||||||
console.log('### DATA ERROR',e ); //TODO
|
console.log('### DATA ERROR',e ); //TODO
|
||||||
|
self.emit('dataError');
|
||||||
});
|
});
|
||||||
|
|
||||||
dataConn.on('close', function() {
|
dataConn.on('close', function() {
|
||||||
if (self.closing) return;
|
if (self.closing) return;
|
||||||
self.closing=1;
|
|
||||||
console.log('### CLOSE RECV FROM:', dataConn.peer);
|
console.log('### CLOSE RECV FROM:', dataConn.peer);
|
||||||
self._onClose(dataConn.peer);
|
self._onClose(dataConn.peer);
|
||||||
this.emit('close');
|
self._checkAnyPeer();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._notify = function(newPeer) {
|
Network.prototype._notifyNetworkChange = function(newPeer) {
|
||||||
this._showConnectedPeers();
|
console.log('[WebRTC.js.164:_notifyNetworkChange:]', newPeer); //TODO
|
||||||
this.emit('networkChange', newPeer);
|
this.emit('networkChange', newPeer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -178,7 +187,7 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
|
||||||
p.on('open', function(peerId) {
|
p.on('open', function(peerId) {
|
||||||
self.peerId = peerId;
|
self.peerId = peerId;
|
||||||
self.connectedPeers = [peerId];
|
self.connectedPeers = [peerId];
|
||||||
self._notify();
|
self._notifyNetworkChange();
|
||||||
return openCallback(peerId);
|
return openCallback(peerId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -187,7 +196,7 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
|
||||||
self.peer.disconnect();
|
self.peer.disconnect();
|
||||||
self.peer.destroy();
|
self.peer.destroy();
|
||||||
self.peer = null;
|
self.peer = null;
|
||||||
this.emit('abort');
|
self._checkAnyPeer();
|
||||||
});
|
});
|
||||||
|
|
||||||
p.on('connection', function(dataConn) {
|
p.on('connection', function(dataConn) {
|
||||||
|
@ -210,11 +219,7 @@ Network.prototype.start = function(openCallback) {
|
||||||
// Start PeerJS Peer
|
// Start PeerJS Peer
|
||||||
if (this.peer) return openCallback(); // This is for connectTo-> peer is started before
|
if (this.peer) return openCallback(); // This is for connectTo-> peer is started before
|
||||||
|
|
||||||
this.peer = new Peer(this.peerId, {
|
this.peer = new Peer(this.peerId, this.opts);
|
||||||
key: this.apiKey, // TODO: we need our own PeerServer KEY (http://peerjs.com/peerserver)
|
|
||||||
debug: this.debug,
|
|
||||||
});
|
|
||||||
|
|
||||||
this._setupPeerHandlers(openCallback);
|
this._setupPeerHandlers(openCallback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -239,6 +244,7 @@ Network.prototype._sendToOne = function(peerId, data, cb) {
|
||||||
|
|
||||||
Network.prototype.send = function(peerIds, data, cb) {
|
Network.prototype.send = function(peerIds, data, cb) {
|
||||||
var self=this;
|
var self=this;
|
||||||
|
console.log('[WebRTC.js.242] SENDING ', data.type); //TODO
|
||||||
if (!peerIds) {
|
if (!peerIds) {
|
||||||
peerIds = this.connectedPeers;
|
peerIds = this.connectedPeers;
|
||||||
data.isBroadcast = 1;
|
data.isBroadcast = 1;
|
||||||
|
@ -248,6 +254,7 @@ Network.prototype.send = function(peerIds, data, cb) {
|
||||||
var l = peerIds.length;
|
var l = peerIds.length;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
peerIds.forEach(function(peerId) {
|
peerIds.forEach(function(peerId) {
|
||||||
|
console.log('[WebRTC.js.258:peerId:]',peerId); //TODO
|
||||||
self._sendToOne(peerId, data, function () {
|
self._sendToOne(peerId, data, function () {
|
||||||
if (++i === l && typeof cb === 'function') cb();
|
if (++i === l && typeof cb === 'function') cb();
|
||||||
});
|
});
|
||||||
|
@ -263,7 +270,6 @@ Network.prototype.connectTo = function(peerId) {
|
||||||
console.log('### STARTING TO CONNECT TO:' + peerId );
|
console.log('### STARTING TO CONNECT TO:' + peerId );
|
||||||
|
|
||||||
var dataConn = this.peer.connect(peerId, {
|
var dataConn = this.peer.connect(peerId, {
|
||||||
// label: 'wallet',
|
|
||||||
serialization: 'none',
|
serialization: 'none',
|
||||||
reliable: true,
|
reliable: true,
|
||||||
metadata: { message: 'hi copayer!' }
|
metadata: { message: 'hi copayer!' }
|
||||||
|
@ -276,7 +282,6 @@ Network.prototype.connectTo = function(peerId) {
|
||||||
Network.prototype.disconnect = function(cb) {
|
Network.prototype.disconnect = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.closing = 1;
|
self.closing = 1;
|
||||||
|
|
||||||
this.send(null, { type: 'disconnect' }, function() {
|
this.send(null, { type: 'disconnect' }, function() {
|
||||||
self.connectedPeers = [];
|
self.connectedPeers = [];
|
||||||
self.peerId = null;
|
self.peerId = null;
|
||||||
|
|
|
@ -54,13 +54,17 @@ Storage.prototype.remove = function(walletId, k) {
|
||||||
|
|
||||||
Storage.prototype.getWalletIds = function() {
|
Storage.prototype.getWalletIds = function() {
|
||||||
var walletIds = [];
|
var walletIds = [];
|
||||||
|
var uniq = {};
|
||||||
|
|
||||||
for (var i = 0; i < localStorage.length; i++) {
|
for (var i = 0; i < localStorage.length; i++) {
|
||||||
var key = localStorage.key(i);
|
var key = localStorage.key(i);
|
||||||
var split = key.split('::');
|
var split = key.split('::');
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
var walletId = split[0];
|
var walletId = split[0];
|
||||||
walletIds.push(walletId);
|
if (typeof uniq[walletId] === 'undefined' ) {
|
||||||
|
walletIds.push(walletId);
|
||||||
|
uniq[walletId] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copay.controllerUtils').factory('controllerUtils', function ($rootScope, $location, Socket) {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
root.logout = function(scope) {
|
||||||
|
delete $rootScope['wallet'];
|
||||||
|
$rootScope.totalBalance = 0;
|
||||||
|
$location.path('signin');
|
||||||
|
};
|
||||||
|
|
||||||
|
root.onError = function(scope) {
|
||||||
|
if (scope) scope.loading = false;
|
||||||
|
$rootScope.flashMessage = {type:'error', message: 'Could not connect to peer'};
|
||||||
|
root.logout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
root.onErrorDigest = function(scope) {
|
||||||
|
root.onError(scope);
|
||||||
|
$rootScope.$digest();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
root.setupUxHandlers = function(w) {
|
||||||
|
|
||||||
|
w.on('badMessage', function(peerId) {
|
||||||
|
$rootScope.flashMessage = {type:'error', message: 'Received wrong message from peer id:' + peerId};
|
||||||
|
});
|
||||||
|
|
||||||
|
w.on('created', function() {
|
||||||
|
$location.path('peer');
|
||||||
|
$rootScope.wallet = w;
|
||||||
|
|
||||||
|
// Initial getBalance
|
||||||
|
$rootScope.wallet.getTotalBalance(function(balance) {
|
||||||
|
$rootScope.totalBalance = balance;
|
||||||
|
$rootScope.$digest();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
w.on('refresh', function() {
|
||||||
|
console.log('[controllerUtils.js] Refreshing'); //TODO
|
||||||
|
$rootScope.$digest();
|
||||||
|
});
|
||||||
|
w.on('openError', root.onErrorDigest);
|
||||||
|
w.on('close', root.onErrorDigest);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.handleTransactionByAddress = function(scope) {
|
||||||
|
var socket = Socket(scope);
|
||||||
|
var addrs = $rootScope.wallet.getAddressesStr();
|
||||||
|
socket.emit('subscribe', 'inv');
|
||||||
|
for(var i=0;i<addrs.length;i++) {
|
||||||
|
socket.emit('subscribe', addrs[i]);
|
||||||
|
}
|
||||||
|
addrs.forEach(function(addr) {
|
||||||
|
socket.on(addr, function(txid) {
|
||||||
|
console.log('Received!', txid);
|
||||||
|
$rootScope.wallet.getTotalBalance(function(balance) {
|
||||||
|
scope.$apply(function() {
|
||||||
|
$rootScope.totalBalance = balance;
|
||||||
|
});
|
||||||
|
console.log('New balance:', balance);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var ScopedSocket = function(socket, $rootScope) {
|
||||||
|
this.socket = socket;
|
||||||
|
this.$rootScope = $rootScope;
|
||||||
|
this.listeners = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
ScopedSocket.prototype.removeAllListeners = function(opts) {
|
||||||
|
if (!opts) opts = {};
|
||||||
|
for (var i = 0; i < this.listeners.length; i++) {
|
||||||
|
var details = this.listeners[i];
|
||||||
|
if (opts.skipConnect && details.event === 'connect') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
this.socket.removeListener(details.event, details.fn);
|
||||||
|
}
|
||||||
|
this.listeners = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
ScopedSocket.prototype.on = function(event, callback) {
|
||||||
|
var socket = this.socket;
|
||||||
|
var $rootScope = this.$rootScope;
|
||||||
|
|
||||||
|
var wrapped_callback = function() {
|
||||||
|
var args = arguments;
|
||||||
|
$rootScope.$apply(function() {
|
||||||
|
callback.apply(socket, args);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
socket.on(event, wrapped_callback);
|
||||||
|
|
||||||
|
this.listeners.push({
|
||||||
|
event: event,
|
||||||
|
fn: wrapped_callback
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ScopedSocket.prototype.emit = function(event, data, callback) {
|
||||||
|
var socket = this.socket;
|
||||||
|
var $rootScope = this.$rootScope;
|
||||||
|
|
||||||
|
socket.emit(event, data, function() {
|
||||||
|
var args = arguments;
|
||||||
|
$rootScope.$apply(function() {
|
||||||
|
if (callback) {
|
||||||
|
callback.apply(socket, args);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
angular.module('copay.socket').factory('Socket',
|
||||||
|
function($rootScope) {
|
||||||
|
var server = 'http://' + config.socket.host + ':' + config.socket.port;
|
||||||
|
var socket = io.connect(server, {
|
||||||
|
'reconnect': true,
|
||||||
|
'reconnection delay': 500,
|
||||||
|
});
|
||||||
|
return function(scope) {
|
||||||
|
var scopedSocket = new ScopedSocket(socket, $rootScope);
|
||||||
|
scope.$on('$destroy', function() {
|
||||||
|
scopedSocket.removeAllListeners();
|
||||||
|
});
|
||||||
|
socket.on('connect', function() {
|
||||||
|
scopedSocket.removeAllListeners({
|
||||||
|
skipConnect: true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return scopedSocket;
|
||||||
|
};
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
|
@ -56,7 +56,7 @@ describe('PublicKeyRing model', function() {
|
||||||
w2.registeredCopayers().should.equal(0);
|
w2.registeredCopayers().should.equal(0);
|
||||||
w2.isComplete().should.equal(false);
|
w2.isComplete().should.equal(false);
|
||||||
|
|
||||||
w2.getAddress.bind(false).should.throw();
|
(function() {w2.getAddress(0, false);}).should.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add and check when adding shared pub keys', function () {
|
it('should add and check when adding shared pub keys', function () {
|
||||||
|
@ -65,19 +65,25 @@ describe('PublicKeyRing model', function() {
|
||||||
var copayers = k.copayers;
|
var copayers = k.copayers;
|
||||||
|
|
||||||
w.isComplete().should.equal(true);
|
w.isComplete().should.equal(true);
|
||||||
w.addCopayer.bind().should.throw();
|
w.addCopayer.should.throw();
|
||||||
for(var i =0; i<5; i++)
|
for(var i =0; i<5; i++) {
|
||||||
w.addCopayer.bind(copayers[i]).should.throw();
|
(function() {w.addCopayer(copayers[i])}).should.throw();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('show be able to tostore and read', function () {
|
it('show be able to tostore and read', function () {
|
||||||
var k = createW();
|
var k = createW();
|
||||||
var w = k.w;
|
var w = k.w;
|
||||||
var copayers = k.copayers;
|
var copayers = k.copayers;
|
||||||
for(var i=0; i<3; i++)
|
var changeN = 2;
|
||||||
|
var addressN = 2;
|
||||||
|
var start = new Date().getTime();
|
||||||
|
for(var i=0; i<changeN; i++) {
|
||||||
w.generateAddress(true);
|
w.generateAddress(true);
|
||||||
for(var i=0; i<5; i++)
|
}
|
||||||
|
for(var i=0; i<addressN; i++) {
|
||||||
w.generateAddress(false);
|
w.generateAddress(false);
|
||||||
|
}
|
||||||
|
|
||||||
var data = w.toObj();
|
var data = w.toObj();
|
||||||
should.exist(data);
|
should.exist(data);
|
||||||
|
@ -85,12 +91,13 @@ describe('PublicKeyRing model', function() {
|
||||||
var w2 = PublicKeyRing.fromObj(data);
|
var w2 = PublicKeyRing.fromObj(data);
|
||||||
w2.walletId.should.equal(w.walletId);
|
w2.walletId.should.equal(w.walletId);
|
||||||
w2.isComplete().should.equal(true);
|
w2.isComplete().should.equal(true);
|
||||||
w2.addCopayer.bind().should.throw();
|
w2.addCopayer.should.throw();
|
||||||
for(var i =0; i<5; i++)
|
for(var i =0; i<5; i++) {
|
||||||
w2.addCopayer.bind(copayers[i]).should.throw();
|
(function() {w.addCopayer(copayers[i])}).should.throw();
|
||||||
|
}
|
||||||
|
|
||||||
w2.changeAddressIndex.should.equal(3);
|
w2.changeAddressIndex.should.equal(changeN);
|
||||||
w2.addressIndex.should.equal(5);
|
w2.addressIndex.should.equal(addressN);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,7 +106,7 @@ describe('PublicKeyRing model', function() {
|
||||||
var w = k.w;
|
var w = k.w;
|
||||||
|
|
||||||
for(var isChange=0; isChange<2; isChange++) {
|
for(var isChange=0; isChange<2; isChange++) {
|
||||||
for(var i=0; i<5; i++) {
|
for(var i=0; i<2; i++) {
|
||||||
var a = w.generateAddress(isChange);
|
var a = w.generateAddress(isChange);
|
||||||
a.isValid().should.equal(true);
|
a.isValid().should.equal(true);
|
||||||
a.isScript().should.equal(true);
|
a.isScript().should.equal(true);
|
||||||
|
@ -121,11 +128,11 @@ describe('PublicKeyRing model', function() {
|
||||||
a.length.should.equal(0);
|
a.length.should.equal(0);
|
||||||
|
|
||||||
for(var isChange=0; isChange<2; isChange++)
|
for(var isChange=0; isChange<2; isChange++)
|
||||||
for(var i=0; i<6; i++)
|
for(var i=0; i<2; i++)
|
||||||
w.generateAddress(isChange);
|
w.generateAddress(isChange);
|
||||||
|
|
||||||
var as = w.getAddresses();
|
var as = w.getAddresses();
|
||||||
as.length.should.equal(12);
|
as.length.should.equal(4);
|
||||||
for(var j in as) {
|
for(var j in as) {
|
||||||
var a = as[j];
|
var a = as[j];
|
||||||
a.isValid().should.equal(true);
|
a.isValid().should.equal(true);
|
||||||
|
@ -138,11 +145,11 @@ describe('PublicKeyRing model', function() {
|
||||||
|
|
||||||
for(var i=0; i<3; i++)
|
for(var i=0; i<3; i++)
|
||||||
w.generateAddress(true);
|
w.generateAddress(true);
|
||||||
for(var i=0; i<5; i++)
|
for(var i=0; i<2; i++)
|
||||||
w.generateAddress(false);
|
w.generateAddress(false);
|
||||||
|
|
||||||
w.changeAddressIndex.should.equal(3);
|
w.changeAddressIndex.should.equal(3);
|
||||||
w.addressIndex.should.equal(5);
|
w.addressIndex.should.equal(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#merge index tests', function () {
|
it('#merge index tests', function () {
|
||||||
|
@ -279,11 +286,11 @@ describe('PublicKeyRing model', function() {
|
||||||
|
|
||||||
for(var i=0; i<2; i++)
|
for(var i=0; i<2; i++)
|
||||||
w.generateAddress(true);
|
w.generateAddress(true);
|
||||||
for(var i=0; i<3; i++)
|
for(var i=0; i<2; i++)
|
||||||
w.generateAddress(false);
|
w.generateAddress(false);
|
||||||
|
|
||||||
var m = w.getRedeemScriptMap();
|
var m = w.getRedeemScriptMap();
|
||||||
Object.keys(m).length.should.equal(5);
|
Object.keys(m).length.should.equal(4);
|
||||||
Object.keys(m).forEach(function (k) {
|
Object.keys(m).forEach(function (k) {
|
||||||
should.exist(m[k]);
|
should.exist(m[k]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -109,6 +109,7 @@ describe('TxProposals model', function() {
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
});
|
});
|
||||||
|
var start = new Date().getTime();
|
||||||
var pkr=createPKR([priv.getBIP32()]);
|
var pkr=createPKR([priv.getBIP32()]);
|
||||||
var ts = Date.now();
|
var ts = Date.now();
|
||||||
var isChange=0;
|
var isChange=0;
|
||||||
|
|
|
@ -61,12 +61,6 @@ describe('Insight model', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should return balance', function () {
|
|
||||||
var w = new Insight();
|
|
||||||
var b = w.getBalance(unspent);
|
|
||||||
should.exist(b);
|
|
||||||
b.should.equal(91);
|
|
||||||
});
|
|
||||||
it.skip('should return txid', function (done) {
|
it.skip('should return txid', function (done) {
|
||||||
var w = new Insight();
|
var w = new Insight();
|
||||||
w.sendRawTransaction(rawtx, function(a) {
|
w.sendRawTransaction(rawtx, function(a) {
|
||||||
|
|
Loading…
Reference in New Issue