add timestamp sync
This commit is contained in:
parent
1b783df70a
commit
981c56f091
3 changed files with 12 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ var EventEmitter = require('events').EventEmitter;
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var preconditions = require('preconditions').singleton();
|
var preconditions = require('preconditions').singleton();
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
var microtime = require('microtime');
|
||||||
|
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var bignum = bitcore.Bignum;
|
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) {
|
Wallet.prototype._onData = function(senderId, data, isInbound) {
|
||||||
preconditions.checkArgument(senderId);
|
preconditions.checkArgument(senderId);
|
||||||
preconditions.checkArgument(data);
|
preconditions.checkArgument(data);
|
||||||
|
|
@ -326,6 +332,8 @@ Wallet.prototype._onData = function(senderId, data, isInbound) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateTimestamp();
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
// This handler is repeaded on WalletFactory (#join). TODO
|
// This handler is repeaded on WalletFactory (#join). TODO
|
||||||
case 'walletId':
|
case 'walletId':
|
||||||
|
|
@ -438,7 +446,8 @@ Wallet.prototype.netStart = function(callback) {
|
||||||
var startOpts = {
|
var startOpts = {
|
||||||
copayerId: myId,
|
copayerId: myId,
|
||||||
privkey: myIdPriv,
|
privkey: myIdPriv,
|
||||||
maxPeers: self.totalCopayers
|
maxPeers: self.totalCopayers,
|
||||||
|
lastTimestamp: this.lastTimestamp,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.publicKeyRing.isComplete()) {
|
if (this.publicKeyRing.isComplete()) {
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ Network.prototype.start = function(opts, openCallback) {
|
||||||
this._setupConnectionHandlers(openCallback);
|
this._setupConnectionHandlers(openCallback);
|
||||||
var pubkey = this.getKey().public.toString('hex');
|
var pubkey = this.getKey().public.toString('hex');
|
||||||
this.socket.emit('subscribe', pubkey);
|
this.socket.emit('subscribe', pubkey);
|
||||||
//this.socket.emit('sync');
|
this.socket.emit('sync', opts.lastTimestamp);
|
||||||
this.started = true;
|
this.started = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
},
|
},
|
||||||
"version": "0.4.7",
|
"version": "0.4.7",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"microtime": "^1.0.1",
|
||||||
"mocha": "^1.18.2",
|
"mocha": "^1.18.2",
|
||||||
"mocha-lcov-reporter": "0.0.1",
|
"mocha-lcov-reporter": "0.0.1",
|
||||||
"optimist": "^0.6.1",
|
"optimist": "^0.6.1",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue