mirror of https://github.com/BTCPrivate/copay.git
fix join wallet WIP
This commit is contained in:
parent
e676f4e69d
commit
8856683a17
|
@ -41,7 +41,6 @@ angular.module('copay.header').controller('HeaderController',
|
||||||
w.disconnect();
|
w.disconnect();
|
||||||
delete $rootScope['wallet'];
|
delete $rootScope['wallet'];
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
$rootScope.$digest();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,14 @@ console.log('[signin.js.42:create:]'); //TODO
|
||||||
$scope.join = function(cid) {
|
$scope.join = function(cid) {
|
||||||
console.log('[signin.js.42:join:]'); //TODO
|
console.log('[signin.js.42:join:]'); //TODO
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
|
walletFactory.connectTo(cid, function(w) {
|
||||||
|
console.log('[signin.js.50]'); //TODO
|
||||||
|
_setupUxHandlers(w);
|
||||||
|
w.netStart();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// if (cid) {
|
// if (cid) {
|
||||||
// var w = walletFactory.(walletId);
|
// var w = walletFactory.(walletId);
|
||||||
|
@ -62,7 +70,6 @@ console.log('[signin.js.42:join:]'); //TODO
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
};
|
|
||||||
|
|
||||||
// if (peerData && peerData.peerId && peerData.connectedPeers.length > 0) {
|
// if (peerData && peerData.peerId && peerData.connectedPeers.length > 0) {
|
||||||
// $rootScope.peerId = peerData.peerId;
|
// $rootScope.peerId = peerData.peerId;
|
||||||
|
|
|
@ -39,7 +39,6 @@ Wallet.getRandomId = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||||
this.openWalletId(data.walletId);
|
|
||||||
this.log('RECV PUBLICKEYRING:',data);
|
this.log('RECV PUBLICKEYRING:',data);
|
||||||
|
|
||||||
var shouldSend = false;
|
var shouldSend = false;
|
||||||
|
@ -66,7 +65,6 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
||||||
this.openWalletId(data.walletId);
|
|
||||||
this.log('RECV TXPROPOSAL:',data); //TODO
|
this.log('RECV TXPROPOSAL:',data); //TODO
|
||||||
|
|
||||||
var shouldSend = false;
|
var shouldSend = false;
|
||||||
|
@ -94,6 +92,11 @@ 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)
|
||||||
|
throw new Error('wrong message received: Bad wallet ID');
|
||||||
|
|
||||||
|
|
||||||
switch(data.type) {
|
switch(data.type) {
|
||||||
case 'publicKeyRing':
|
case 'publicKeyRing':
|
||||||
this._handlePublicKeyRing(senderId, data, isInbound);
|
this._handlePublicKeyRing(senderId, data, isInbound);
|
||||||
|
@ -108,9 +111,13 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype._handleNetworkChange = function(newPeer) {
|
Wallet.prototype._handleNetworkChange = function(newPeer) {
|
||||||
|
|
||||||
|
console.log('[Wallet.js.112:newPeer:]',newPeer); //TODO
|
||||||
if (!newPeer) return;
|
if (!newPeer) return;
|
||||||
|
|
||||||
|
console.log('[Wallet.js.112:newPeer:]',newPeer); //TODO
|
||||||
this.log('#### Setting new PEER:', newPeer);
|
this.log('#### Setting new PEER:', newPeer);
|
||||||
|
this.sendWalletId(newPeer);
|
||||||
this.sendPublicKeyRing(newPeer);
|
this.sendPublicKeyRing(newPeer);
|
||||||
this.sendTxProposals(newPeer);
|
this.sendTxProposals(newPeer);
|
||||||
};
|
};
|
||||||
|
@ -118,8 +125,8 @@ Wallet.prototype._handleNetworkChange = function(newPeer) {
|
||||||
Wallet.prototype.netStart = function() {
|
Wallet.prototype.netStart = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var net = this.network;
|
var net = this.network;
|
||||||
net.on('networkChange', function() { self._handleNetworkChange(); } );
|
net.on('networkChange', self._handleNetworkChange.bind(self) );
|
||||||
net.on('data', function() { self._handleData();});
|
net.on('data', self._handleData.bind(self) );
|
||||||
net.on('open', function() {}); // TODO
|
net.on('open', function() {}); // TODO
|
||||||
net.on('close', function() {}); // TODO
|
net.on('close', function() {}); // TODO
|
||||||
net.start(function(peerId) {
|
net.start(function(peerId) {
|
||||||
|
@ -151,6 +158,17 @@ Wallet.prototype.sendTxProposals = function(recipients) {
|
||||||
this.emit('txProposalsUpdated', this.txProposals);
|
this.emit('txProposalsUpdated', this.txProposals);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Wallet.prototype.sendWalletId = function(recipients) {
|
||||||
|
this.log('### SENDING walletId TO:', recipients||'All', this.walletId);
|
||||||
|
|
||||||
|
this.network.send(recipients, {
|
||||||
|
type: 'walletId',
|
||||||
|
walletId: this.id,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
||||||
this.log('### SENDING publicKeyRing TO:', recipients||'All', this.publicKeyRing.toObj());
|
this.log('### SENDING publicKeyRing TO:', recipients||'All', this.publicKeyRing.toObj());
|
||||||
|
|
||||||
|
@ -308,8 +326,13 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.connectTo = function(peerId) {
|
Wallet.prototype.connectTo = function(peerId) {
|
||||||
this.network.connectTo(peerId);
|
throw new Error('Wallet.connectTo.. not yet implemented!');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.disconnect = function() {
|
||||||
|
this.network.disconnect();
|
||||||
|
};
|
||||||
|
|
||||||
// // HERE? not sure
|
// // HERE? not sure
|
||||||
// Wallet.prototype.cleanPeers = function() {
|
// Wallet.prototype.cleanPeers = function() {
|
||||||
// this.storage.remove('peerData');
|
// this.storage.remove('peerData');
|
||||||
|
|
|
@ -60,6 +60,7 @@ WalletFactory.prototype.read = function(walletId) {
|
||||||
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.verbose = this.verbose;
|
||||||
|
|
||||||
var w = new Wallet(opts);
|
var w = new Wallet(opts);
|
||||||
|
|
||||||
|
@ -102,6 +103,8 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
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.verbose = this.verbose;
|
||||||
|
|
||||||
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
||||||
opts.requiredCopayers = requiredCopayers;
|
opts.requiredCopayers = requiredCopayers;
|
||||||
opts.totalCopayers = totalCopayers;
|
opts.totalCopayers = totalCopayers;
|
||||||
|
@ -112,9 +115,44 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.open = function(walletId) {
|
WalletFactory.prototype.open = function(walletId) {
|
||||||
if(!WalletFactory.read(walletId)) {
|
var w = this.read(walletId) || this.create({id: walletId});
|
||||||
WalletFactory.create({id: walletId});
|
return w;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
WalletFactory.prototype.openRemote = function(peedId) {
|
||||||
|
var s = WalletFactory.storage;
|
||||||
|
opts = opts || {};
|
||||||
|
this.log('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID'));
|
||||||
|
|
||||||
|
opts.privateKey = opts.privateKey || new PrivateKey({ networkName: this.networkName });
|
||||||
|
this.log('\t### PrivateKey Initialized');
|
||||||
|
|
||||||
|
var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers;
|
||||||
|
var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers;
|
||||||
|
|
||||||
|
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
|
||||||
|
networkName: this.networkName,
|
||||||
|
requiredCopayers: requiredCopayers,
|
||||||
|
totalCopayers: totalCopayers,
|
||||||
|
});
|
||||||
|
opts.publicKeyRing.addCopayer(opts.privateKey.getBIP32().extendedPublicKeyString());
|
||||||
|
this.log('\t### PublicKeyRing Initialized');
|
||||||
|
|
||||||
|
opts.txProposals = opts.txProposals || new TxProposals({
|
||||||
|
networkName: this.networkName,
|
||||||
|
});
|
||||||
|
this.log('\t### TxProposals Initialized');
|
||||||
|
|
||||||
|
opts.storage = this.storage;
|
||||||
|
opts.network = this.network;
|
||||||
|
opts.blockchain = this.blockchain;
|
||||||
|
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
||||||
|
opts.requiredCopayers = requiredCopayers;
|
||||||
|
opts.totalCopayers = totalCopayers;
|
||||||
|
var w = new Wallet(opts);
|
||||||
|
w.store();
|
||||||
|
this.addWalletId(w.id);
|
||||||
|
return w;
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.getWalletIds = function() {
|
WalletFactory.prototype.getWalletIds = function() {
|
||||||
|
@ -142,4 +180,16 @@ WalletFactory.prototype.addWalletId = function(walletId) {
|
||||||
this.storage.setGlobal('walletIds', ids);
|
this.storage.setGlobal('walletIds', ids);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
WalletFactory.prototype.connectTo = function(peerId, cb) {
|
||||||
|
var self=this;
|
||||||
|
self.network.start(function() {
|
||||||
|
self.network.connectTo(peerId)
|
||||||
|
self.network.on('walletId', function(walletId) {
|
||||||
|
console.log('[WalletFactory.js.187]'); //TODO
|
||||||
|
return cb(self.open(walletId));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = require('soop')(WalletFactory);
|
module.exports = require('soop')(WalletFactory);
|
||||||
|
|
|
@ -103,6 +103,9 @@ Network.prototype._onData = function(data, isInbound) {
|
||||||
case 'disconnect':
|
case 'disconnect':
|
||||||
this._onClose(obj.sender);
|
this._onClose(obj.sender);
|
||||||
break;
|
break;
|
||||||
|
case 'walletId':
|
||||||
|
this.emit('walletId', obj.data.walletId);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
this.emit('data', obj.sender, obj.data, isInbound);
|
this.emit('data', obj.sender, obj.data, isInbound);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +161,6 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
||||||
dataConn.on('close', function() {
|
dataConn.on('close', function() {
|
||||||
if (self.closing) return;
|
if (self.closing) return;
|
||||||
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');
|
this.emit('close');
|
||||||
});
|
});
|
||||||
|
@ -166,6 +168,8 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
||||||
|
|
||||||
Network.prototype._notify = function(newPeer) {
|
Network.prototype._notify = function(newPeer) {
|
||||||
this._showConnectedPeers();
|
this._showConnectedPeers();
|
||||||
|
|
||||||
|
console.log('[WebRTC.js.172]', newPeer); //TODO
|
||||||
this.emit('networkChange', newPeer);
|
this.emit('networkChange', newPeer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -269,7 +273,7 @@ Network.prototype.connectTo = function(peerId) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Network.prototype.disconnect = function(peerId, cb) {
|
Network.prototype.disconnect = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.closing = 1;
|
self.closing = 1;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ var should = chai.should();
|
||||||
|
|
||||||
var WebRTC = require('../js/models/network/WebRTC');
|
var WebRTC = require('../js/models/network/WebRTC');
|
||||||
var Insight = require('../js/models/blockchain/Insight');
|
var Insight = require('../js/models/blockchain/Insight');
|
||||||
var FakeStorage = require('./FakeStorage');
|
var FakeStorage = require('./mocks/FakeStorage');
|
||||||
|
|
||||||
var WalletFactory = typeof copay === 'undefined' ? require('soop').load('../js/models/core/WalletFactory',{
|
var WalletFactory = typeof copay === 'undefined' ? require('soop').load('../js/models/core/WalletFactory',{
|
||||||
Network: WebRTC,
|
Network: WebRTC,
|
||||||
|
|
Loading…
Reference in New Issue