Browse Source

mv blockExplorer -> blockchainExplorer

activeAddress
Ivan Socolsky 10 years ago
parent
commit
cf73449e7c
  1. 4
      lib/blockchainexplorer.js
  2. 24
      lib/server.js
  3. 16
      test/integration/server.js

4
lib/blockexplorer.js → lib/blockchainexplorer.js

@ -10,7 +10,7 @@ var request = require('request');
var io = require('socket.io-client'); var io = require('socket.io-client');
function BlockExplorer(opts) { function BlockChainExplorer(opts) {
$.checkArgument(opts); $.checkArgument(opts);
var provider = opts.provider || 'insight'; var provider = opts.provider || 'insight';
var network = opts.network || 'livenet'; var network = opts.network || 'livenet';
@ -57,4 +57,4 @@ function initSocketInsight(url) {
return socket; return socket;
}; };
module.exports = BlockExplorer; module.exports = BlockChainExplorer;

24
lib/server.js

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

16
test/integration/server.js

@ -150,22 +150,22 @@ helpers.stubUtxos = function(server, wallet, amounts, cb) {
}; };
return obj; return obj;
}); });
blockExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos); blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos);
return cb(utxos); return cb(utxos);
}); });
}; };
helpers.stubBroadcast = function(txid) { helpers.stubBroadcast = function(txid) {
blockExplorer.broadcast = sinon.stub().callsArgWith(1, null, txid); blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, null, txid);
}; };
helpers.stubBroadcastFail = function() { helpers.stubBroadcastFail = function() {
blockExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error'); blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error');
}; };
helpers.stubHistory = function(txs) { helpers.stubHistory = function(txs) {
blockExplorer.getTransactions = sinon.stub().callsArgWith(1, null, txs); blockchainExplorer.getTransactions = sinon.stub().callsArgWith(1, null, txs);
}; };
helpers.clientSign = WalletUtils.signTxp; helpers.clientSign = WalletUtils.signTxp;
@ -198,7 +198,7 @@ helpers.createAddresses = function(server, wallet, main, change, cb) {
}); });
}; };
var db, storage, blockExplorer; var db, storage, blockchainExplorer;
describe('Copay server', function() { describe('Copay server', function() {
@ -209,11 +209,11 @@ describe('Copay server', function() {
storage = new Storage({ storage = new Storage({
db: db db: db
}); });
blockExplorer = sinon.stub(); blockchainExplorer = sinon.stub();
WalletService.initialize({ WalletService.initialize({
storage: storage, storage: storage,
blockExplorer: blockExplorer, blockchainExplorer: blockchainExplorer,
}); });
helpers.offset = 0; helpers.offset = 0;
}); });
@ -699,7 +699,7 @@ describe('Copay server', function() {
}); });
}); });
it('should get balance when there are no funds', function(done) { it('should get balance when there are no funds', function(done) {
blockExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, []); blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, []);
server.createAddress({}, function(err, address) { server.createAddress({}, function(err, address) {
should.not.exist(err); should.not.exist(err);
server.getBalance({}, function(err, balance) { server.getBalance({}, function(err, balance) {

Loading…
Cancel
Save