@bitcoinerlab/discovery
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -111,3 +111,3 @@ "use strict"; | ||
const canonicalInput = (0, deriveData_1.canonicalize)(descriptorOrDescriptors, network); | ||
let nextPromise; | ||
let nextPromise = undefined; | ||
let usedOutput = false; | ||
@@ -119,3 +119,3 @@ let usedOutputNotified = false; | ||
const networkId = (0, networks_1.getNetworkId)(network); | ||
for (const descriptor of descriptorArray) { | ||
const descriptorFetchPromises = descriptorArray.map(async (descriptor) => { | ||
__classPrivateFieldSet(this, _Discovery_discoveryData, (0, immer_1.produce)(__classPrivateFieldGet(this, _Discovery_discoveryData, "f"), discoveryData => { | ||
@@ -159,3 +159,3 @@ const descriptorInfo = discoveryData[networkId].descriptorMap[descriptor]; | ||
if (onUsed && usedOutputNotified === false) { | ||
onUsed(descriptor); | ||
onUsed(descriptorOrDescriptors); | ||
usedOutputNotified = true; | ||
@@ -178,3 +178,4 @@ } | ||
}), "f"); | ||
} | ||
}); | ||
await Promise.all(descriptorFetchPromises); | ||
const promises = []; | ||
@@ -603,2 +604,3 @@ if (usedOutput) | ||
const networkId = (0, networks_1.getNetworkId)(network); | ||
//console.log(`Fetching ${descriptor}, ${internalIndex}`); | ||
const scriptPubKey = __classPrivateFieldGet(this, _Discovery_derivers, "f").deriveScriptPubKey(networkId, (0, deriveData_1.canonicalize)(descriptor, network), internalIndex); | ||
@@ -661,5 +663,6 @@ //https://electrumx.readthedocs.io/en/latest/protocol-basics.html#script-hashes | ||
async function _Discovery_fetchTxs() { | ||
const txHexRecords = {}; | ||
const networkId = (0, networks_1.getNetworkId)(network); | ||
const networkData = __classPrivateFieldGet(this, _Discovery_discoveryData, "f")[networkId]; | ||
const fetchTxPromises = []; | ||
const txIdsToFetch = new Set(); | ||
for (const descriptor in networkData.descriptorMap) { | ||
@@ -670,12 +673,15 @@ const range = networkData.descriptorMap[descriptor]?.range || []; | ||
if (!txIds) | ||
throw new Error(`Error: cannot retrieve txs for nonexising scriptPubKey: ${networkId}, ${descriptor}, ${index}`); | ||
for (const txId of txIds) | ||
if (!networkData.txMap[txId]?.txHex) | ||
txHexRecords[txId] = await explorer.fetchTx(txId); | ||
throw new Error(`Error: cannot retrieve txs for nonexisting scriptPubKey: ${networkId}, ${descriptor}, ${index}`); | ||
for (const txId of txIds) { | ||
if (!networkData.txMap[txId]?.txHex && !txIdsToFetch.has(txId)) { | ||
txIdsToFetch.add(txId); | ||
fetchTxPromises.push(explorer.fetchTx(txId).then(txHex => ({ txId, txHex }))); | ||
} | ||
} | ||
} | ||
} | ||
if (Object.keys(txHexRecords).length) { | ||
const txHexResults = await Promise.all(fetchTxPromises); | ||
if (txHexResults.length) { | ||
__classPrivateFieldSet(this, _Discovery_discoveryData, (0, immer_1.produce)(__classPrivateFieldGet(this, _Discovery_discoveryData, "f"), discoveryData => { | ||
for (const txId in txHexRecords) { | ||
const txHex = txHexRecords[txId]; | ||
txHexResults.forEach(({ txId, txHex }) => { | ||
if (!txHex) | ||
@@ -687,3 +693,3 @@ throw new Error(`txHex not retrieved for ${txId}`); | ||
txData.txHex = txHex; | ||
} | ||
}); | ||
}), "f"); | ||
@@ -690,0 +696,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/bitcoinerlab/discovery", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": "Jose-Luis Landabaso", | ||
@@ -48,3 +48,3 @@ "license": "MIT", | ||
"@bitcoinerlab/descriptors": "^2.0.1", | ||
"@bitcoinerlab/explorer": "^0.1.1", | ||
"@bitcoinerlab/explorer": "^0.1.2", | ||
"@bitcoinerlab/secp256k1": "^1.0.5", | ||
@@ -51,0 +51,0 @@ "@types/memoizee": "^0.4.8", |
113759
1883