better sync for incomplete wallets after close/open
This commit is contained in:
parent
bc706d6373
commit
614ed087c7
3 changed files with 35 additions and 15 deletions
|
|
@ -150,13 +150,12 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
||||||
$scope.error = null;
|
$scope.error = null;
|
||||||
if (err) {
|
if (err) {
|
||||||
var msg = err.toString();
|
var msg = err.toString();
|
||||||
|
$scope.createStep = 'email';
|
||||||
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
|
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
|
||||||
msg = 'This profile already exists'
|
msg = 'This profile already exists'
|
||||||
$scope.createStep = 'email';
|
|
||||||
}
|
}
|
||||||
if (msg.indexOf('EMAILERROR') >= 0) {
|
if (msg.indexOf('EMAILERROR') >= 0) {
|
||||||
msg = 'Could not send verification email. Please check your email address.';
|
msg = 'Could not send verification email. Please check your email address.';
|
||||||
$scope.createStep = 'email';
|
|
||||||
}
|
}
|
||||||
$scope.error = msg;
|
$scope.error = msg;
|
||||||
$scope.passwordStrength = null;
|
$scope.passwordStrength = null;
|
||||||
|
|
|
||||||
|
|
@ -106,10 +106,14 @@ Network.prototype._deletePeer = function(peerId) {
|
||||||
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
|
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._addConnectedCopayer = function(copayerId) {
|
Network.prototype._addCopayer = function(copayerId) {
|
||||||
var peerId = this.peerFromCopayer(copayerId);
|
var peerId = this.peerFromCopayer(copayerId);
|
||||||
this._addCopayerMap(peerId, copayerId);
|
this._addCopayerMap(peerId, copayerId);
|
||||||
Network._arrayPushOnce(peerId, this.connectedPeers);
|
Network._arrayPushOnce(peerId, this.connectedPeers);
|
||||||
|
};
|
||||||
|
|
||||||
|
Network.prototype._addConnectedCopayer = function(copayerId) {
|
||||||
|
this._addCopayer(copayerId);
|
||||||
this.emit('connect', copayerId);
|
this.emit('connect', copayerId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -272,8 +276,8 @@ Network.prototype._setupSocketHandlers = function(opts, cb) {
|
||||||
}, 1);
|
}, 1);
|
||||||
});
|
});
|
||||||
self.socket.on('error', self._onError.bind(self));
|
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('no messages', self.emit.bind(self, 'no_messages'));
|
||||||
self.socket.on('connect', function() {
|
self.socket.on('connect', function() {
|
||||||
var pubkey = self.getKey().public.toString('hex');
|
var pubkey = self.getKey().public.toString('hex');
|
||||||
log.debug('Async subscribing to pubkey:', pubkey);
|
log.debug('Async subscribing to pubkey:', pubkey);
|
||||||
|
|
@ -331,7 +335,6 @@ Network.prototype.start = function(opts, openCallback) {
|
||||||
preconditions.checkArgument(opts);
|
preconditions.checkArgument(opts);
|
||||||
preconditions.checkArgument(opts.privkey);
|
preconditions.checkArgument(opts.privkey);
|
||||||
preconditions.checkArgument(opts.copayerId);
|
preconditions.checkArgument(opts.copayerId);
|
||||||
preconditions.checkState(this.connectedPeers && this.connectedPeers.length === 0);
|
|
||||||
|
|
||||||
if (this.started) {
|
if (this.started) {
|
||||||
log.debug('Async: Networing already started for this wallet.')
|
log.debug('Async: Networing already started for this wallet.')
|
||||||
|
|
@ -368,6 +371,7 @@ Network.prototype.getCopayerIds = function() {
|
||||||
for (var peerId in this.copayerForPeer) {
|
for (var peerId in this.copayerForPeer) {
|
||||||
copayerIds.push(this.copayerForPeer[peerId]);
|
copayerIds.push(this.copayerForPeer[peerId]);
|
||||||
}
|
}
|
||||||
|
console.log('[Async.js.373]', copayerIds); //TODO
|
||||||
return copayerIds;
|
return copayerIds;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -380,6 +384,7 @@ Network.prototype.send = function(dest, payload, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!dest) {
|
if (!dest) {
|
||||||
dest = this.getCopayerIds();
|
dest = this.getCopayerIds();
|
||||||
|
console.log('[Async.js.383:dest:]', dest); //TODO
|
||||||
payload.isBroadcast = 1;
|
payload.isBroadcast = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -388,6 +393,7 @@ Network.prototype.send = function(dest, payload, cb) {
|
||||||
|
|
||||||
var l = dest.length;
|
var l = dest.length;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
for (var ii in dest) {
|
for (var ii in dest) {
|
||||||
var to = dest[ii];
|
var to = dest[ii];
|
||||||
if (to == this.copayerId)
|
if (to == this.copayerId)
|
||||||
|
|
@ -423,4 +429,10 @@ Network.prototype.lockIncommingConnections = function(allowedCopayerIdsArray) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Network.prototype.setCopayers = function(copayersIdsArray) {
|
||||||
|
for (var i in copayersIdsArray) {
|
||||||
|
this._addCopayer(copayersIdsArray[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = Network;
|
module.exports = Network;
|
||||||
|
|
|
||||||
|
|
@ -687,8 +687,13 @@ Wallet.prototype.updateSyncedTimestamp = function(ts) {
|
||||||
* Triggers a call to {@link Wallet#sendWalletReady}
|
* Triggers a call to {@link Wallet#sendWalletReady}
|
||||||
*/
|
*/
|
||||||
Wallet.prototype._onNoMessages = function() {
|
Wallet.prototype._onNoMessages = function() {
|
||||||
log.debug('Wallet:' + this.id + ' No messages at the server. Requesting peer sync from: ' + (this.syncedTimestamp + 1));
|
if (this.isComplete()) {
|
||||||
this.sendWalletReady(null, parseInt((this.syncedTimestamp + 1) / 1000000));
|
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));
|
||||||
|
} else {
|
||||||
|
log.debug('Incomplete wallet:' + this.getName() + ' No messages at the server. Requesting forced peer sync from 0');
|
||||||
|
this.sendWalletReady(null, 0, true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -723,7 +728,7 @@ Wallet.prototype._onData = function(senderId, data, ts) {
|
||||||
this.sendWalletReady(senderId);
|
this.sendWalletReady(senderId);
|
||||||
break;
|
break;
|
||||||
case 'walletReady':
|
case 'walletReady':
|
||||||
if (this.lastMessageFrom[senderId] !== 'walletReady') {
|
if (this.lastMessageFrom[senderId] !== 'walletReady' || data.force) {
|
||||||
log.debug('Wallet:' + this.id + ' peer Sync received. since: ' + (data.sinceTs || 0));
|
log.debug('Wallet:' + this.id + ' peer Sync received. since: ' + (data.sinceTs || 0));
|
||||||
this.sendPublicKeyRing(senderId);
|
this.sendPublicKeyRing(senderId);
|
||||||
this.sendAddressBook(senderId);
|
this.sendAddressBook(senderId);
|
||||||
|
|
@ -986,7 +991,10 @@ Wallet.prototype.netStart = function() {
|
||||||
|
|
||||||
if (this.publicKeyRing.isComplete()) {
|
if (this.publicKeyRing.isComplete()) {
|
||||||
this._lockIncomming(this.publicKeyRing.getAllCopayerIds());
|
this._lockIncomming(this.publicKeyRing.getAllCopayerIds());
|
||||||
|
} else {
|
||||||
|
this.network.setCopayers(this.publicKeyRing.getAllCopayerIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug('Wallet:' + self.id + ' Starting network.');
|
log.debug('Wallet:' + self.id + ' Starting network.');
|
||||||
this.network.start(startOpts, function() {
|
this.network.start(startOpts, function() {
|
||||||
self.emitAndKeepAlive(self.isComplete() ? 'ready' : 'waitingCopayers');
|
self.emitAndKeepAlive(self.isComplete() ? 'ready' : 'waitingCopayers');
|
||||||
|
|
@ -1191,7 +1199,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.blockchainOpts = readOpts.blockchainOpts;
|
||||||
opts.networkOpts = readOpts.networkOpts;
|
opts.networkOpts = readOpts.networkOpts;
|
||||||
|
|
||||||
|
|
@ -1208,7 +1216,7 @@ Wallet.fromObj = function(o, readOpts) {
|
||||||
Wallet.prototype._sendToPeers = function(recipients, obj) {
|
Wallet.prototype._sendToPeers = function(recipients, obj) {
|
||||||
if (!this.isShared()) return;
|
if (!this.isShared()) return;
|
||||||
log.info('Wallet:' + this.getName() + ' ### Sending ' + obj.type);
|
log.info('Wallet:' + this.getName() + ' ### Sending ' + obj.type);
|
||||||
log.debug('Sending obj', obj);
|
log.debug('Sending:', recipients, obj);
|
||||||
|
|
||||||
this.network.send(recipients, obj);
|
this.network.send(recipients, obj);
|
||||||
};
|
};
|
||||||
|
|
@ -1293,11 +1301,12 @@ Wallet.prototype.sendSignature = function(ntxid) {
|
||||||
* @desc Notify other peers that a wallet has been backed up and it's ready to be used
|
* @desc Notify other peers that a wallet has been backed up and it's ready to be used
|
||||||
* @param {string[]} [recipients] - the pubkeys of the recipients
|
* @param {string[]} [recipients] - the pubkeys of the recipients
|
||||||
*/
|
*/
|
||||||
Wallet.prototype.sendWalletReady = function(recipients, sinceTs) {
|
Wallet.prototype.sendWalletReady = function(recipients, sinceTs, force) {
|
||||||
this._sendToPeers(recipients, {
|
this._sendToPeers(recipients, {
|
||||||
type: 'walletReady',
|
type: 'walletReady',
|
||||||
walletId: this.id,
|
walletId: this.id,
|
||||||
sinceTs: sinceTs,
|
sinceTs: sinceTs,
|
||||||
|
force: force,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1442,7 +1451,7 @@ Wallet.prototype.getPendingTxProposalsCount = function() {
|
||||||
_.each(txps, function(inTxp, ntxid) {
|
_.each(txps, function(inTxp, ntxid) {
|
||||||
if (!inTxp.isPending(maxRejectCount))
|
if (!inTxp.isPending(maxRejectCount))
|
||||||
return;
|
return;
|
||||||
// TODO: are the uxtos availables?
|
// TODO: are the uxtos availables?
|
||||||
//
|
//
|
||||||
pending++;
|
pending++;
|
||||||
|
|
||||||
|
|
@ -1631,7 +1640,7 @@ Wallet.prototype.broadcastToBitcoinNetwork = function(ntxid, cb) {
|
||||||
|
|
||||||
this.blockchain.broadcast(txHex, function(err, txid) {
|
this.blockchain.broadcast(txHex, function(err, txid) {
|
||||||
if (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) {
|
self._checkIfTxIsSent(ntxid, function(err, txid) {
|
||||||
return cb(err, txid);
|
return cb(err, txid);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue