Browse Source

bug fixes

feat/estimateFee-limit
Ivan Socolsky 8 years ago
parent
commit
565bc01339
No known key found for this signature in database GPG Key ID: FAECE6A05FAA4F56
  1. 4
      lib/expressapp.js
  2. 69
      lib/server.js

4
lib/expressapp.js

@ -100,7 +100,7 @@ ExpressApp.prototype.start = function(opts, cb) {
var status = (err.code == 'NOT_AUTHORIZED') ? 401 : 400;
if (!opts.disableLogs)
log.info('Client Err: ' + status + ' ' + req.url + ' ' + err);
log.info('Client Err: ' + status + ' ' + req.url + ' ' + JSON.stringify(err));
res.status(status).json({
code: err.code,
@ -312,7 +312,7 @@ ExpressApp.prototype.start = function(opts, cb) {
onlySupportStaff: true
}, function(server) {
var opts = {
identifier: req.query.identifier,
identifier: req.params['identifier'],
};
server.getWalletFromIdentifier(opts, function(err, wallet) {
if (err) return returnError(err, res, req);

69
lib/server.js

@ -408,22 +408,22 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) {
var walletId;
async.parallel([
function(next) {
self.storage.fetchWallet(identifier, function(err, wallet) {
function(done) {
self.storage.fetchWallet(opts.identifier, function(err, wallet) {
if (wallet) walletId = wallet.id;
return next(err);
return done(err);
});
},
function(next) {
self.storage.fetchAddress(identifier, function(err, address) {
function(done) {
self.storage.fetchAddress(opts.identifier, function(err, address) {
if (address) walletId = address.walletId;
return next(err);
return done(err);
});
},
function(next) {
self.storage.fetchTxByHash(identifier, function(err, tx) {
function(done) {
self.storage.fetchTxByHash(opts.identifier, function(err, tx) {
if (tx) walletId = tx.walletId;
return next(err);
return done(err);
});
},
], function(err) {
@ -433,42 +433,31 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) {
}
// Is identifier a txid form an incomming tx?
async.eachSeries(['livenet', 'testnet'], function(network, nextNetwork) {
var bc = self._getBlockchainExplorer('livenet');
bc.getTransaction(identifier, function(err, tx) {
if (err || !tx) return cb(err);
async.detectSeries(_.values(Constants.NETWORKS), function(network, nextNetwork) {
var bc = self._getBlockchainExplorer(network);
bc.getTransaction(opts.identifier, function(err, tx) {
if (err || !tx) return nextNetwork(err, false);
var outputs = _.first(self._normalizeTxHistory(tx)).outputs;
var toAddresses = _.pluck(outputs, 'address');
async.detect(toAddresses, function(addressStr, nextAddress) {
self.storage.fetchAddress(addressStr, function(err, address) {
if (err || !address) return nextAddress(false);
if (err || !address) return nextAddress(err, false);
walletId = address.walletId;
return nextAddress(true);
nextAddress(null, true);
});
}, function() {
if (walletId) {
return self.storage.fetchWallet(walletId, cb);
}
return cb();
}, function(err) {
nextNetwork(err, !!walletId);
});
});
return nextNetwork();
}, function(err) {
if (err) return cb(err);
if (walletId) {
return self.storage.fetchWallet(walletId, cb);
}
return cb();
cb();
});
});
self.storage.fetchWallet(self.walletId, function(err, wallet) {
if (err) return cb(err);
if (!wallet) return cb(Errors.WALLET_NOT_FOUND);
return cb(null, wallet);
});
};
/**
@ -1031,19 +1020,17 @@ WalletService.prototype.verifyMessageSignature = function(opts, cb) {
WalletService.prototype._getBlockchainExplorer = function(network) {
if (!this.blockchainExplorer) {
var opts = {};
if (this.blockchainExplorerOpts && this.blockchainExplorerOpts[network]) {
opts = this.blockchainExplorerOpts[network];
}
// TODO: provider should be configurable
opts.provider = 'insight';
opts.network = network;
opts.userAgent = WalletService.getServiceVersion();
this.blockchainExplorer = new BlockchainExplorer(opts);
}
var opts = {};
return this.blockchainExplorer;
if (this.blockchainExplorer) return this.blockchainExplorer;
if (this.blockchainExplorerOpts && this.blockchainExplorerOpts[network]) {
opts = this.blockchainExplorerOpts[network];
}
// TODO: provider should be configurable
opts.provider = 'insight';
opts.network = network;
opts.userAgent = WalletService.getServiceVersion();
return new BlockchainExplorer(opts);
};
WalletService.prototype._getUtxos = function(addresses, cb) {

Loading…
Cancel
Save