test passing
This commit is contained in:
parent
e0b04401c9
commit
2c354525ea
5 changed files with 19 additions and 31 deletions
|
|
@ -53,6 +53,7 @@ function Wallet(opts) {
|
|||
this.addressBook = opts.addressBook || {};
|
||||
this.publicKey = this.privateKey.publicHex;
|
||||
this.lastTimestamp = opts.lastTimestamp || undefined;
|
||||
this.lastMessageFrom = {};
|
||||
|
||||
this.paymentRequests = opts.paymentRequests || {};
|
||||
|
||||
|
|
@ -313,7 +314,7 @@ Wallet.prototype.updateTimestamp = function(ts) {
|
|||
|
||||
Wallet.prototype._onNoMessages = function() {
|
||||
console.log('No messages at the server. Requesting sync'); //TODO
|
||||
this.sendWalletReady(senderId);
|
||||
this.sendWalletReady();
|
||||
};
|
||||
|
||||
Wallet.prototype._onData = function(senderId, data, ts) {
|
||||
|
|
@ -323,7 +324,7 @@ Wallet.prototype._onData = function(senderId, data, ts) {
|
|||
preconditions.checkArgument(ts);
|
||||
preconditions.checkArgument(typeof ts === 'number');
|
||||
|
||||
//console.log('RECV', senderId, data);
|
||||
console.log('RECV', senderId, data);
|
||||
|
||||
if (data.type !== 'walletId' && this.id !== data.walletId) {
|
||||
this.emit('corrupt', senderId);
|
||||
|
|
@ -331,15 +332,18 @@ Wallet.prototype._onData = function(senderId, data, ts) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (data.type) {
|
||||
// This handler is repeaded on WalletFactory (#join). TODO
|
||||
case 'walletId':
|
||||
this.sendWalletReady(senderId);
|
||||
break;
|
||||
case 'walletReady':
|
||||
this.sendPublicKeyRing(senderId);
|
||||
this.sendAddressBook(senderId);
|
||||
this.sendAllTxProposals(senderId); // send old txps
|
||||
if (this.lastMessageFrom[senderId] !== 'walletReady') {
|
||||
this.sendPublicKeyRing(senderId);
|
||||
this.sendAddressBook(senderId);
|
||||
this.sendAllTxProposals(senderId); // send old txps
|
||||
}
|
||||
break;
|
||||
case 'publicKeyRing':
|
||||
this._onPublicKeyRing(senderId, data);
|
||||
|
|
@ -359,13 +363,15 @@ Wallet.prototype._onData = function(senderId, data, ts) {
|
|||
case 'addressbook':
|
||||
this._onAddressBook(senderId, data);
|
||||
break;
|
||||
// unused messages
|
||||
// unused messages
|
||||
case 'disconnect':
|
||||
//case 'an other unused message':
|
||||
break;
|
||||
default:
|
||||
throw new Error('unknown message type received: '+ data.type + ' from: ' + senderId)
|
||||
throw new Error('unknown message type received: ' + data.type + ' from: ' + senderId)
|
||||
}
|
||||
|
||||
this.lastMessageFrom[senderId] = data.type;
|
||||
this.updateTimestamp(ts);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -290,6 +290,8 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
this._setupConnectionHandlers(openCallback);
|
||||
this.socket.emit('subscribe', pubkey);
|
||||
|
||||
|
||||
var fromTs = opts.lastTimestamp + 1;
|
||||
var self = this,
|
||||
tries = 0;
|
||||
self.socket.on('insight-error', function(m) {
|
||||
|
|
@ -299,13 +301,13 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
if (tries++ > 5) {
|
||||
self.emit('serverError');
|
||||
} else {
|
||||
self.socket.emit('sync', opts.lastTimestamp + 1);
|
||||
self.socket.emit('sync', fromTs);
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
|
||||
|
||||
self.socket.emit('sync', opts.lastTimestamp);
|
||||
self.socket.emit('sync', fromTs);
|
||||
self.started = true;
|
||||
};
|
||||
|
||||
|
|
@ -358,9 +360,7 @@ Network.prototype.send = function(dest, payload, cb) {
|
|||
var to = dest[ii];
|
||||
if (to == this.copayerId)
|
||||
continue;
|
||||
console.log('SEND to: ' + to, this.copayerId, payload);
|
||||
|
||||
|
||||
//console.log('SEND to: ' + to, this.copayerId, payload);
|
||||
var message = this.encode(to, payload);
|
||||
this.socket.emit('message', message);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue