mirror of
https://github.com/janoside/btc-rpc-explorer.git
synced 2026-08-13 12:33:13 +02:00
Fix #300
More thoroughly assess txindex availability: -if node v0.21+ getindexinfo is available and will tell us whether txindex is available -if node pre-v0.21 getindexinfo will be unavailable and instead a known txid query will be run, the successful completion of which will indicate txindex availability; failure the opposite
This commit is contained in:
parent
4551ac7399
commit
76c408799c
2 changed files with 47 additions and 5 deletions
47
app.js
47
app.js
|
|
@ -347,17 +347,54 @@ async function onRpcConnectionVerified(getnetworkinfo, getblockchaininfo) {
|
|||
setInterval(refreshNetworkVolumes, 30 * 60 * 1000);
|
||||
|
||||
|
||||
// try to run getindexinfo to check for txindex
|
||||
// TODO: change this for issue #300
|
||||
assessTxindexAvailability();
|
||||
}
|
||||
|
||||
async function assessTxindexAvailability() {
|
||||
// Here we try to call getindexinfo to assess availability of txindex
|
||||
// However, getindexinfo RPC is only available in v0.21+, so the call
|
||||
// may return an "unsupported" error. If/when it does, we will fall back
|
||||
// to assessing txindex availability by querying a known txid
|
||||
debugLog("txindex check: trying getindexinfo");
|
||||
global.getindexinfo = await coreApi.getIndexInfo();
|
||||
|
||||
debugLog(`txindex check: getindexinfo=${JSON.stringify(global.getindexinfo)}`);
|
||||
|
||||
if (global.getindexinfo.txindex) {
|
||||
// getindexinfo was available, and txindex is also available...easy street
|
||||
|
||||
global.txindexAvailable = true;
|
||||
|
||||
debugLog("txindex check: available!");
|
||||
|
||||
} else if (global.getindexinfo.minRpcVersionNeeded) {
|
||||
// here we ASSUME that txindex is available because we're targeting pre-v0.21
|
||||
// and docs specify that txindex is necessary for pre-v0.21 nodes
|
||||
global.txindexAvailable = true;
|
||||
// here we find out that getindexinfo is unavailable on our node because
|
||||
// we're running pre-v0.21, so we fall back to querying a known txid
|
||||
// to assess txindex availability
|
||||
|
||||
debugLog("txindex check: getindexinfo unavailable, trying txid lookup");
|
||||
|
||||
try {
|
||||
// lookup a known TXID as a test for whether txindex is available
|
||||
let knownTx = await coreApi.getRawTransaction(coinConfig.knownTransactionsByNetwork[global.activeBlockchain]);
|
||||
|
||||
// if we get here without an error being thrown, we know we're able to look up by txid
|
||||
// thus, txindex is available
|
||||
global.txindexAvailable = true;
|
||||
|
||||
debugLog("txindex check: available! (pre-v0.21)");
|
||||
|
||||
} catch (e) {
|
||||
// here we were unable to query by txid, so we believe txindex is unavailable
|
||||
global.txindexAvailable = false;
|
||||
|
||||
debugLog("txindex check: unavailable");
|
||||
}
|
||||
} else {
|
||||
// here getindexinfo is available (i.e. we're on v0.21+), but txindex is NOT available
|
||||
global.txindexAvailable = false;
|
||||
|
||||
debugLog("txindex check: unavailable");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,11 @@ module.exports = {
|
|||
"test": "https://testnet.btc21.org",
|
||||
"signet": "https://signet.btc21.org",
|
||||
},
|
||||
knownTransactionsByNetwork: {
|
||||
main: "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16",
|
||||
test: "22e7e860660f368b5c653c272b0445a0625d19fdec02fc158ef9800a5c3a07e8",
|
||||
signet: "39332e10af6fe491e8ae4ba1e2dd674698fedf8aa3c8c42bf71572debc1bb5b9"
|
||||
},
|
||||
miningPoolsConfigUrls:[
|
||||
"https://raw.githubusercontent.com/btc21/Bitcoin-Known-Miners/master/miners.json",
|
||||
"https://raw.githubusercontent.com/btccom/Blockchain-Known-Pools/master/pools.json",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue