diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 1ae29657e..395f952d3 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -4,6 +4,7 @@ var EventEmitter = require('events').EventEmitter; var async = require('async'); var preconditions = require('preconditions').singleton(); var util = require('util'); +var microtime = require('microtime'); var bitcore = require('bitcore'); var bignum = bitcore.Bignum; @@ -315,6 +316,11 @@ Wallet.prototype._onAddressBook = function(senderId, data, isInbound) { } }; + +Wallet.prototype.updateTimestamp = function() { + this.lastTimestamp = microtime.now(); +}; + Wallet.prototype._onData = function(senderId, data, isInbound) { preconditions.checkArgument(senderId); preconditions.checkArgument(data); @@ -326,6 +332,8 @@ Wallet.prototype._onData = function(senderId, data, isInbound) { return; } + this.updateTimestamp(); + switch (data.type) { // This handler is repeaded on WalletFactory (#join). TODO case 'walletId': @@ -438,7 +446,8 @@ Wallet.prototype.netStart = function(callback) { var startOpts = { copayerId: myId, privkey: myIdPriv, - maxPeers: self.totalCopayers + maxPeers: self.totalCopayers, + lastTimestamp: this.lastTimestamp, }; if (this.publicKeyRing.isComplete()) { diff --git a/js/models/network/Async.js b/js/models/network/Async.js index 6e1835bbe..195773b27 100644 --- a/js/models/network/Async.js +++ b/js/models/network/Async.js @@ -326,7 +326,7 @@ Network.prototype.start = function(opts, openCallback) { this._setupConnectionHandlers(openCallback); var pubkey = this.getKey().public.toString('hex'); this.socket.emit('subscribe', pubkey); - //this.socket.emit('sync'); + this.socket.emit('sync', opts.lastTimestamp); this.started = true; }; diff --git a/package.json b/package.json index d68f10f9f..fe84e9ba1 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "version": "0.4.7", "dependencies": { + "microtime": "^1.0.1", "mocha": "^1.18.2", "mocha-lcov-reporter": "0.0.1", "optimist": "^0.6.1",