|
|
@ -15,7 +15,7 @@ var ClientError = require('./clienterror'); |
|
|
|
var Utils = require('./utils'); |
|
|
|
var Storage = require('./storage'); |
|
|
|
var NotificationBroadcaster = require('./notificationbroadcaster'); |
|
|
|
var BlockExplorer = require('./blockexplorer'); |
|
|
|
var BlockchainExplorer = require('./blockchainexplorer'); |
|
|
|
|
|
|
|
var Wallet = require('./model/wallet'); |
|
|
|
var Copayer = require('./model/copayer'); |
|
|
@ -24,7 +24,7 @@ var TxProposal = require('./model/txproposal'); |
|
|
|
var Notification = require('./model/notification'); |
|
|
|
|
|
|
|
var initialized = false; |
|
|
|
var storage, blockExplorer; |
|
|
|
var storage, blockchainExplorer; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -36,7 +36,7 @@ function WalletService() { |
|
|
|
throw new Error('Server not initialized'); |
|
|
|
|
|
|
|
this.storage = storage; |
|
|
|
this.blockExplorer = blockExplorer; |
|
|
|
this.blockchainExplorer = blockchainExplorer; |
|
|
|
this.notifyTicker = 0; |
|
|
|
}; |
|
|
|
|
|
|
@ -48,12 +48,12 @@ WalletService.onNotification = function(func) { |
|
|
|
* Initializes global settings for all instances. |
|
|
|
* @param {Object} opts |
|
|
|
* @param {Storage} [opts.storage] - The storage provider. |
|
|
|
* @param {Storage} [opts.blockExplorer] - The blockExporer provider. |
|
|
|
* @param {Storage} [opts.blockchainExplorer] - The blockchainExporer provider. |
|
|
|
*/ |
|
|
|
WalletService.initialize = function(opts) { |
|
|
|
opts = opts || {}; |
|
|
|
storage = opts.storage || new Storage(); |
|
|
|
blockExplorer = opts.blockExplorer; |
|
|
|
blockchainExplorer = opts.blockchainExplorer; |
|
|
|
initialized = true; |
|
|
|
}; |
|
|
|
|
|
|
@ -335,15 +335,15 @@ WalletService.prototype.verifyMessageSignature = function(opts, cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
WalletService.prototype._getBlockExplorer = function(provider, network) { |
|
|
|
if (!this.blockExplorer) { |
|
|
|
this.blockExplorer = new BlockExplorer({ |
|
|
|
WalletService.prototype._getBlockchainExplorer = function(provider, network) { |
|
|
|
if (!this.blockchainExplorer) { |
|
|
|
this.blockchainExplorer = new BlockchainExplorer({ |
|
|
|
provider: provider, |
|
|
|
network: network, |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return this.blockExplorer; |
|
|
|
return this.blockchainExplorer; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
@ -363,7 +363,7 @@ WalletService.prototype._getUtxos = function(cb) { |
|
|
|
var addressToPath = _.indexBy(addresses, 'address'); // TODO : check performance
|
|
|
|
var networkName = Bitcore.Address(addressStrs[0]).toObject().network; |
|
|
|
|
|
|
|
var bc = self._getBlockExplorer('insight', networkName); |
|
|
|
var bc = self._getBlockchainExplorer('insight', networkName); |
|
|
|
bc.getUnspentUtxos(addressStrs, function(err, inutxos) { |
|
|
|
if (err) return cb(err); |
|
|
|
var utxos = _.map(inutxos, function(i) { |
|
|
@ -669,7 +669,7 @@ WalletService.prototype._broadcastTx = function(txp, cb) { |
|
|
|
} catch (ex) { |
|
|
|
return cb(ex); |
|
|
|
} |
|
|
|
var bc = this._getBlockExplorer('insight', txp.getNetworkName()); |
|
|
|
var bc = this._getBlockchainExplorer('insight', txp.getNetworkName()); |
|
|
|
bc.broadcast(raw, function(err, txid) { |
|
|
|
return cb(err, txid); |
|
|
|
}) |
|
|
@ -1014,7 +1014,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { |
|
|
|
var addressStrs = _.pluck(addresses, 'address'); |
|
|
|
var networkName = Bitcore.Address(addressStrs[0]).toObject().network; |
|
|
|
|
|
|
|
var bc = self._getBlockExplorer('insight', networkName); |
|
|
|
var bc = self._getBlockchainExplorer('insight', networkName); |
|
|
|
async.parallel([ |
|
|
|
|
|
|
|
function(next) { |
|
|
|