|
@ -4,9 +4,6 @@ var $ = require('preconditions').singleton(); |
|
|
var async = require('async'); |
|
|
var async = require('async'); |
|
|
var log = require('npmlog'); |
|
|
var log = require('npmlog'); |
|
|
log.debug = log.verbose; |
|
|
log.debug = log.verbose; |
|
|
var inherits = require('inherits'); |
|
|
|
|
|
var events = require('events'); |
|
|
|
|
|
var nodeutil = require('util'); |
|
|
|
|
|
|
|
|
|
|
|
var WalletUtils = require('bitcore-wallet-utils'); |
|
|
var WalletUtils = require('bitcore-wallet-utils'); |
|
|
var Bitcore = WalletUtils.Bitcore; |
|
|
var Bitcore = WalletUtils.Bitcore; |
|
@ -18,6 +15,7 @@ var Explorers = require('bitcore-explorers'); |
|
|
var ClientError = require('./clienterror'); |
|
|
var ClientError = require('./clienterror'); |
|
|
var Utils = require('./utils'); |
|
|
var Utils = require('./utils'); |
|
|
var Storage = require('./storage'); |
|
|
var Storage = require('./storage'); |
|
|
|
|
|
var EventBroadcaster = require('./eventbroadcaster'); |
|
|
|
|
|
|
|
|
var Wallet = require('./model/wallet'); |
|
|
var Wallet = require('./model/wallet'); |
|
|
var Copayer = require('./model/copayer'); |
|
|
var Copayer = require('./model/copayer'); |
|
@ -29,22 +27,6 @@ var initialized = false; |
|
|
var storage, blockExplorer; |
|
|
var storage, blockExplorer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function EventBroadcaster() {}; |
|
|
|
|
|
|
|
|
|
|
|
nodeutil.inherits(EventBroadcaster, events.EventEmitter); |
|
|
|
|
|
|
|
|
|
|
|
EventBroadcaster.prototype.broadcast = function(service, args) { |
|
|
|
|
|
this.emit(service, args); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var _eventBroadcasterInstance; |
|
|
|
|
|
EventBroadcaster.singleton = function() { |
|
|
|
|
|
if (!_eventBroadcasterInstance) { |
|
|
|
|
|
_eventBroadcasterInstance = new EventBroadcaster(); |
|
|
|
|
|
} |
|
|
|
|
|
return _eventBroadcasterInstance; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Creates an instance of the Bitcore Wallet Service. |
|
|
* Creates an instance of the Bitcore Wallet Service. |
|
|
* @constructor |
|
|
* @constructor |
|
@ -58,6 +40,10 @@ function WalletService() { |
|
|
this.notifyTicker = 0; |
|
|
this.notifyTicker = 0; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
WalletService.onNotification = function(func) { |
|
|
|
|
|
EventBroadcaster.on('notification', func); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Initializes global settings for all instances. |
|
|
* Initializes global settings for all instances. |
|
|
* @param {Object} opts |
|
|
* @param {Object} opts |
|
@ -175,8 +161,13 @@ WalletService.prototype._verifySignature = function(text, signature, pubKey) { |
|
|
return WalletUtils.verifyMessage(text, signature, pubKey); |
|
|
return WalletUtils.verifyMessage(text, signature, pubKey); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* _emit |
|
|
|
|
|
* |
|
|
|
|
|
* @param {Object} args |
|
|
|
|
|
*/ |
|
|
WalletService.prototype._emit = function(args) { |
|
|
WalletService.prototype._emit = function(args) { |
|
|
EventBroadcaster.singleton().broadcast(this, args); |
|
|
EventBroadcaster.broadcast(this, args); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|