Skip to content

Commit

Permalink
- general improved error handling for address pages
Browse files Browse the repository at this point in the history
- specific handling of long-history address errors - issue #67 - with user-visible messaging
  • Loading branch information
janoside committed Nov 14, 2018
1 parent 91f4ce6 commit 5abe069
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
6 changes: 5 additions & 1 deletion app/api/electrumApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ function connectToServer(host, port) {
function runOnServer(electrumClient, f) {
return new Promise(function(resolve, reject) {
f(electrumClient).then(function(result) {
resolve({result:result, server:electrumClient.host});
if (result.success) {
resolve({result:result.response, server:electrumClient.host});

} else {
reject({error:result.error, server:electrumClient.host});
}
}).catch(function(err) {
console.log("Error dif0e21qdh: " + err + ", host=" + electrumClient.host + ", port=" + electrumClient.port);

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"crypto-js": "3.1.9-1",
"debug": "~2.6.0",
"decimal.js": "7.2.3",
"electrum-client": "github:chaintools/node-electrum-client#72d910d59",
"electrum-client": "github:chaintools/node-electrum-client#43a999036f9c5",
"express": "^4.16.4",
"express-session": "1.15.6",
"jstransformer-markdown-it": "^2.0.0",
Expand Down
27 changes: 20 additions & 7 deletions routes/baseActionsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ router.get("/address/:address", function(req, res) {

txidResult = result.conflictedResults[0];

} else {
} else if (result.result != null) {
txidResult = result;
}

Expand All @@ -607,9 +607,11 @@ router.get("/address/:address", function(req, res) {
var txids = [];
var blockHeightsByTxid = {};

for (var i = 0; i < txidResult.result.length; i++) {
txids.push(txidResult.result[i].tx_hash);
blockHeightsByTxid[txidResult.result[i].tx_hash] = txidResult.result[i].height;
if (txidResult) {
for (var i = 0; i < txidResult.result.length; i++) {
txids.push(txidResult.result[i].tx_hash);
blockHeightsByTxid[txidResult.result[i].tx_hash] = txidResult.result[i].height;
}
}

if (sort == "desc") {
Expand All @@ -625,8 +627,11 @@ router.get("/address/:address", function(req, res) {
}
}

// always request the first txid; we'll use it to show "first seen" info for the address
pagedTxids.unshift(txidResult.result[0].tx_hash);
if (txidResult && txidResult.result != null) {
// since we always request the first txid (to determine "first seen" info for the address),
// remove it for proper paging
pagedTxids.unshift(txidResult.result[0].tx_hash);
}

coreApi.getRawTransactionsWithInputs(pagedTxids).then(function(rawTxResult) {
// first result is always the earliest tx, but doesn't fit into the current paging;
Expand Down Expand Up @@ -681,10 +686,16 @@ router.get("/address/:address", function(req, res) {
resolve();

}).catch(function(err) {
console.log("Error asdgf07uh23: " + err + ", error json: " + JSON.stringify(err));

reject(err);
});

}).catch(function(err) {
res.locals.electrumHistoryError = err;

console.log("Error 23t07ug2wghefud: " + err + ", error json: " + JSON.stringify(err));

reject(err);
});
}));
Expand All @@ -696,13 +707,15 @@ router.get("/address/:address", function(req, res) {
resolve();

}).catch(function(err) {
console.log("Error 132r80h32rh: " + err + ", error json: " + JSON.stringify(err));

reject(err);
});
}));
}

Promise.all(promises).catch(function(err) {
console.log(err);
console.log("Error 32197rgh327g2: " + err + ", error json: " + JSON.stringify(err));

}).finally(function() {
qrcode.toDataURL(address, function(err, url) {
Expand Down
7 changes: 6 additions & 1 deletion views/address.pug
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,12 @@ block content


if (advancedFunctionality)
if (transactions.length == 0)
if (electrumHistoryError && electrumHistoryError.error && electrumHistoryError.error.code && electrumHistoryError.error.code == -32600)
span Error retrieving transaction history from ElectrumX. See
a(href="https://github.com/janoside/btc-rpc-explorer/issues/67") Issue #67
span for more information.

else if (transactions.length == 0)
span No transactions found

each tx, txIndex in transactions
Expand Down

0 comments on commit 5abe069

Please sign in to comment.