Merge pull request #2270 from matiu/bug/joinSync
better sync for incomplete wallets after close/open
This commit is contained in:
commit
1138870fc5
3 changed files with 35 additions and 14 deletions
|
|
@ -150,13 +150,12 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
$scope.error = null;
|
||||
if (err) {
|
||||
var msg = err.toString();
|
||||
$scope.createStep = 'email';
|
||||
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
|
||||
msg = 'This profile already exists'
|
||||
$scope.createStep = 'email';
|
||||
}
|
||||
if (msg.indexOf('EMAILERROR') >= 0) {
|
||||
msg = 'Could not send verification email. Please check your email address.';
|
||||
$scope.createStep = 'email';
|
||||
}
|
||||
$scope.error = msg;
|
||||
$scope.passwordStrength = null;
|
||||
|
|
|
|||
|
|
@ -106,10 +106,14 @@ Network.prototype._deletePeer = function(peerId) {
|
|||
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
|
||||
};
|
||||
|
||||
Network.prototype._addConnectedCopayer = function(copayerId) {
|
||||
Network.prototype._addCopayer = function(copayerId) {
|
||||
var peerId = this.peerFromCopayer(copayerId);
|
||||
this._addCopayerMap(peerId, copayerId);
|
||||
Network._arrayPushOnce(peerId, this.connectedPeers);
|
||||
};
|
||||
|
||||
Network.prototype._addConnectedCopayer = function(copayerId) {
|
||||
this._addCopayer(copayerId);
|
||||
this.emit('connect', copayerId);
|
||||
};
|
||||
|
||||
|
|
@ -255,7 +259,7 @@ Network.prototype._setupSocketHandlers = function(opts, cb) {
|
|||
|
||||
// We ask for this message, and then ignore it, only to see if the
|
||||
// server has erased our old messages.
|
||||
|
||||
|
||||
if (fromTs) {
|
||||
self.ignoreMessageFromTs = fromTs;
|
||||
}
|
||||
|
|
@ -272,8 +276,8 @@ Network.prototype._setupSocketHandlers = function(opts, cb) {
|
|||
}, 1);
|
||||
});
|
||||
self.socket.on('error', self._onError.bind(self));
|
||||
|
||||
self.socket.on('no_messages', self.emit.bind(self, 'no_messages'));
|
||||
self.socket.on('no messages', self.emit.bind(self, 'no_messages'));
|
||||
self.socket.on('connect', function() {
|
||||
var pubkey = self.getKey().public.toString('hex');
|
||||
log.debug('Async subscribing to pubkey:', pubkey);
|
||||
|
|
@ -331,7 +335,6 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
preconditions.checkArgument(opts);
|
||||
preconditions.checkArgument(opts.privkey);
|
||||
preconditions.checkArgument(opts.copayerId);
|
||||
preconditions.checkState(this.connectedPeers && this.connectedPeers.length === 0);
|
||||
|
||||
if (this.started) {
|
||||
log.debug('Async: Networing already started for this wallet.')
|
||||
|
|
@ -388,6 +391,7 @@ Network.prototype.send = function(dest, payload, cb) {
|
|||
|
||||
var l = dest.length;
|
||||
var i = 0;
|
||||
|
||||
for (var ii in dest) {
|
||||
var to = dest[ii];
|
||||
if (to == this.copayerId)
|
||||
|
|
@ -423,4 +427,10 @@ Network.prototype.lockIncommingConnections = function(allowedCopayerIdsArray) {
|
|||
}
|
||||
};
|
||||
|
||||
Network.prototype.setCopayers = function(copayersIdsArray) {
|
||||
for (var i in copayersIdsArray) {
|
||||
this._addCopayer(copayersIdsArray[i]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Network;
|
||||
|
|
|
|||
|
|
@ -687,8 +687,10 @@ Wallet.prototype.updateSyncedTimestamp = function(ts) {
|
|||
* Triggers a call to {@link Wallet#sendWalletReady}
|
||||
*/
|
||||
Wallet.prototype._onNoMessages = function() {
|
||||
log.debug('Wallet:' + this.id + ' No messages at the server. Requesting peer sync from: ' + (this.syncedTimestamp + 1));
|
||||
this.sendWalletReady(null, parseInt((this.syncedTimestamp + 1) / 1000000));
|
||||
if (this.isComplete()) {
|
||||
log.debug('Wallet:' + this.getName() + ' No messages at the server. Requesting peer sync from: ' + (this.syncedTimestamp + 1));
|
||||
this.sendWalletReady(null, parseInt((this.syncedTimestamp + 1) / 1000000));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -986,9 +988,20 @@ Wallet.prototype.netStart = function() {
|
|||
|
||||
if (this.publicKeyRing.isComplete()) {
|
||||
this._lockIncomming(this.publicKeyRing.getAllCopayerIds());
|
||||
} else {
|
||||
//Partially complete wallet.
|
||||
if (this.publicKeyRing.getAllCopayerIds().length > 1) {
|
||||
this.network.setCopayers(this.publicKeyRing.getAllCopayerIds());
|
||||
}
|
||||
}
|
||||
|
||||
log.debug('Wallet:' + self.id + ' Starting network.');
|
||||
this.network.start(startOpts, function() {
|
||||
//Partially complete wallet.
|
||||
if (self.publicKeyRing.getAllCopayerIds().length > 1) {
|
||||
log.debug('Incomplete wallet opened:' + self.getName() + '. forced peer sync from 0');
|
||||
self.sendWalletReady(null, 0);
|
||||
}
|
||||
self.emitAndKeepAlive(self.isComplete() ? 'ready' : 'waitingCopayers');
|
||||
});
|
||||
};
|
||||
|
|
@ -1191,7 +1204,7 @@ Wallet.fromObj = function(o, readOpts) {
|
|||
});
|
||||
}
|
||||
|
||||
opts.syncedTimestamp = o.syncedTimestamp || 0;
|
||||
opts.syncedTimestamp = opts.publicKeyRing.isComplete() ? o.syncedTimestamp || 0 : 0;
|
||||
opts.blockchainOpts = readOpts.blockchainOpts;
|
||||
opts.networkOpts = readOpts.networkOpts;
|
||||
|
||||
|
|
@ -1208,7 +1221,7 @@ Wallet.fromObj = function(o, readOpts) {
|
|||
Wallet.prototype._sendToPeers = function(recipients, obj) {
|
||||
if (!this.isShared()) return;
|
||||
log.info('Wallet:' + this.getName() + ' ### Sending ' + obj.type);
|
||||
log.debug('Sending obj', obj);
|
||||
log.debug('Sending:', recipients, obj);
|
||||
|
||||
this.network.send(recipients, obj);
|
||||
};
|
||||
|
|
@ -1297,7 +1310,7 @@ Wallet.prototype.sendWalletReady = function(recipients, sinceTs) {
|
|||
this._sendToPeers(recipients, {
|
||||
type: 'walletReady',
|
||||
walletId: this.id,
|
||||
sinceTs: sinceTs,
|
||||
sinceTs: sinceTs
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -1442,7 +1455,7 @@ Wallet.prototype.getPendingTxProposalsCount = function() {
|
|||
_.each(txps, function(inTxp, ntxid) {
|
||||
if (!inTxp.isPending(maxRejectCount))
|
||||
return;
|
||||
// TODO: are the uxtos availables?
|
||||
// TODO: are the uxtos availables?
|
||||
//
|
||||
pending++;
|
||||
|
||||
|
|
@ -1631,7 +1644,7 @@ Wallet.prototype.broadcastToBitcoinNetwork = function(ntxid, cb) {
|
|||
|
||||
this.blockchain.broadcast(txHex, function(err, txid) {
|
||||
if (err || !txid) {
|
||||
log.debug('Wallet:' + self.getName() + ' Send failed:' + err );
|
||||
log.debug('Wallet:' + self.getName() + ' Send failed:' + err);
|
||||
|
||||
self._checkIfTxIsSent(ntxid, function(err, txid) {
|
||||
return cb(err, txid);
|
||||
|
|
@ -2205,7 +2218,6 @@ Wallet.prototype.getUnspent = function(cb) {
|
|||
if (self.cache.unspent != null) {
|
||||
log.debug('Wallet ' + this.getName() + ': Get unspent cache hit');
|
||||
return self.computeUnspent(self.cache.unspent, cb);
|
||||
return
|
||||
}
|
||||
|
||||
var addresses = this.getAddresses();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue