Browse Source

- general improved error handling for address pages

- specific handling of long-history address errors - issue #67 - with user-visible messaging
fix-133-memory-crash
Dan Janosik 6 years ago
parent
commit
5abe069168
  1. 6
      app/api/electrumApi.js
  2. 4
      package-lock.json
  3. 2
      package.json
  4. 27
      routes/baseActionsRouter.js
  5. 7
      views/address.pug

6
app/api/electrumApi.js

@ -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);

4
package-lock.json

@ -684,8 +684,8 @@
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"electrum-client": {
"version": "github:chaintools/node-electrum-client#90e533753eeb13a403f87cb7b4e46647553856dc",
"from": "github:chaintools/node-electrum-client#90e533753"
"version": "github:chaintools/node-electrum-client#43a999036f9c5457030d4d2dc5ec56fa8d94aa99",
"from": "github:chaintools/node-electrum-client#43a999036f9c5"
},
"encodeurl": {
"version": "1.0.2",

2
package.json

@ -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",

27
routes/baseActionsRouter.js

@ -598,7 +598,7 @@ router.get("/address/:address", function(req, res) {
txidResult = result.conflictedResults[0];
} else {
} else if (result.result != null) {
txidResult = result;
}
@ -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") {
@ -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;
@ -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);
});
}));
@ -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) {

7
views/address.pug

@ -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

Loading…
Cancel
Save