From 72bf2bb8e4c376e49ce1496ca318a0ee70a12e76 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 26 Sep 2018 10:31:52 -0300 Subject: [PATCH] fix(server): Fix unconfirmed utxo results Fix unconfirmed utxo results, by better parsing getTx from Bitcore v8 --- lib/blockchainexplorers/v8.js | 13 ++++++++++--- lib/blockchainexplorers/v8/client.js | 1 + lib/server.js | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/blockchainexplorers/v8.js b/lib/blockchainexplorers/v8.js index c08e569ece1..f819b59421f 100644 --- a/lib/blockchainexplorers/v8.js +++ b/lib/blockchainexplorers/v8.js @@ -182,7 +182,7 @@ V8.prototype.getUtxos = function(wallet, cb) { var client = this._getAuthClient(wallet); client.getCoins({pubKey: wallet.beAuthPublicKey, payload: {} }) .then( (unspent) => { -console.log('[v8.js.184:unspent:]',unspent); //TODO +console.log('[v8.js.184:unspent:]',unspent.length); //TODO _.each(unspent, function(x) { if (self.addressFormat) { x.address = self.translateResultAddresses(x.address); @@ -235,14 +235,21 @@ console.log('[v8.js.207] GET TX', txid); //TODO var client = this._getClient(); client.getTx({txid: txid }) .then( (tx) => { - if (!tx || _.isEmpty(tx)) { return cb(); } self.translateTx(tx); return cb(null, tx); }) - .catch(cb); + .catch((err) =>{ + // The TX was not found + if (err.statusCode == '404') { + return cb(); + } else { + return cb(err); + } + + }); }; V8.prototype.getTransactions = function(wallet, since, limit, cb) { diff --git a/lib/blockchainexplorers/v8/client.js b/lib/blockchainexplorers/v8/client.js index 10c6e33f928..07b48f3c18d 100644 --- a/lib/blockchainexplorers/v8/client.js +++ b/lib/blockchainexplorers/v8/client.js @@ -56,6 +56,7 @@ Client.prototype.getAddressTxos = async function (params) { Client.prototype.getTx = async function (params) { const { txid } = params; const url = `${this.baseUrl}/tx/${txid}`; +console.log('[client.js.59:url:]',url); //TODO return request.get(url, { json: true }); diff --git a/lib/server.js b/lib/server.js index d0d16925fe4..18a8e3b1f84 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1249,7 +1249,7 @@ WalletService.prototype._getUtxosWithGrouping = function(wallet, cb) { return u; }); -console.log('END [server.js.1219:utxos:]',utxos); //TODO +console.log('END [server.js.1219:utxos:]', utxos.length); //TODO return cb(null, utxos); }); }; @@ -2661,6 +2661,8 @@ WalletService.prototype._checkTxInBlockchain = function(txp, cb) { var bc = this._getBlockchainExplorer(txp.coin, txp.network); if (!bc) return cb(new Error('Could not get blockchain explorer instance')); bc.getTransaction(txp.txid, function(err, tx) { +console.log('[server.js.2639:tx:]',tx); //TODO +console.log('[server.js.2639:err:]',err); //TODO if (err) return cb(err); return cb(null, !!tx); })