From c2484b3b7aa8834d9f8b286a763d7b2953e647a1 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 6 Apr 2015 13:29:02 -0300 Subject: [PATCH 1/3] Add error check on insight response for tx history --- lib/blockchainexplorer.js | 8 +++++--- lib/server.js | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/blockchainexplorer.js b/lib/blockchainexplorer.js index e66f670..fc033e0 100644 --- a/lib/blockchainexplorer.js +++ b/lib/blockchainexplorer.js @@ -16,7 +16,7 @@ function BlockChainExplorer(opts) { var network = opts.network || 'livenet'; var dfltUrl = network == 'livenet' ? 'https://insight.bitpay.com:443' : 'https://test-insight.bitpay.com:443'; - var url = opts.url || dfltUrl; + var url = opts.url || 'http://localhost:3003'; var url; switch (provider) { @@ -44,9 +44,11 @@ function getTransactionsInsight(url, addresses, from, to, cb) { json: { addrs: [].concat(addresses).join(',') } - }, function(err, res, body) { + }, function(err, res, txs) { if (err || res.statusCode != 200) return cb(err || res); - return cb(null, body); + if (!_.isArray(txs) || _.compact(txs).length == 0) return cb(new Error('Could not retrieve transactions from blockchain')); + + return cb(null, txs); }); }; diff --git a/lib/server.js b/lib/server.js index d181d4b..9f804b8 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1231,7 +1231,9 @@ WalletService.prototype.startScan = function(opts, cb) { self.scan(opts, scanFinished); }, 100); - return cb(null, {started: true}); + return cb(null, { + started: true + }); }); }; From 7243fcd32cf55024278097a49380ba81ae4892d2 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 6 Apr 2015 15:13:30 -0300 Subject: [PATCH 2/3] Fix history --- lib/blockchainexplorer.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/blockchainexplorer.js b/lib/blockchainexplorer.js index fc033e0..ae125e2 100644 --- a/lib/blockchainexplorer.js +++ b/lib/blockchainexplorer.js @@ -16,7 +16,7 @@ function BlockChainExplorer(opts) { var network = opts.network || 'livenet'; var dfltUrl = network == 'livenet' ? 'https://insight.bitpay.com:443' : 'https://test-insight.bitpay.com:443'; - var url = opts.url || 'http://localhost:3003'; + var url = opts.url || dfltUrl; var url; switch (provider) { @@ -46,8 +46,9 @@ function getTransactionsInsight(url, addresses, from, to, cb) { } }, function(err, res, txs) { if (err || res.statusCode != 200) return cb(err || res); + // NOTE: Whenever Insight breaks communication with bitcoind, it returns invalid data but no error code. if (!_.isArray(txs) || _.compact(txs).length == 0) return cb(new Error('Could not retrieve transactions from blockchain')); - + return cb(null, txs); }); }; From 3e279e74f268d2c2b77a37e690fd70d390569e31 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 6 Apr 2015 17:41:04 -0300 Subject: [PATCH 3/3] fix for 0 records retrieved --- lib/blockchainexplorer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/blockchainexplorer.js b/lib/blockchainexplorer.js index ae125e2..6005fc0 100644 --- a/lib/blockchainexplorer.js +++ b/lib/blockchainexplorer.js @@ -47,8 +47,8 @@ function getTransactionsInsight(url, addresses, from, to, cb) { }, function(err, res, txs) { if (err || res.statusCode != 200) return cb(err || res); // NOTE: Whenever Insight breaks communication with bitcoind, it returns invalid data but no error code. - if (!_.isArray(txs) || _.compact(txs).length == 0) return cb(new Error('Could not retrieve transactions from blockchain')); - + if (!_.isArray(txs) || (txs.length != _.compact(txs).length)) return cb(new Error('Could not retrieve transactions from blockchain')); + return cb(null, txs); }); };