Browse Source

optimize requests sent by RemoteImporter with batch rpc calls

umbrel
kenshin-samourai 5 years ago
parent
commit
901ade3e30
  1. 33
      lib/remote-importer/remote-importer.js

33
lib/remote-importer/remote-importer.js

@ -260,19 +260,21 @@ class RemoteImporter {
Logger.info(` Got ${scanTx.length} transactions`) Logger.info(` Got ${scanTx.length} transactions`)
await util.seriesCall(scanTx, async txid => { // Retrieve the transactions by batches of 100 transactions
const txsChunks = util.splitList(scanTx, 100)
try { try {
const tx = await rpcTxns.getTransaction(txid, false) for (let txsChunk of txsChunks) {
if (tx == null) { const txs = await rpcTxns.getTransactions(txsChunk, false)
Logger.info(` got null for ${txid}`) for (let tx of txs) {
return null if (tx != null) {
}
ret.transactions.push(tx) ret.transactions.push(tx)
txids[tx.txid] = true txids[tx.txid] = true
}
}
}
} catch(e) { } catch(e) {
Logger.error(e, `RemoteImporter.xpubScan() : rawTransaction error, txid ${txid}`) Logger.error(e, `RemoteImporter.xpubScan() : getTransactions error`)
} }
})
if (gotTransactions) { if (gotTransactions) {
// We must go deeper // We must go deeper
@ -335,15 +337,14 @@ class RemoteImporter {
Logger.info(` Got ${scanTx.length} transactions`) Logger.info(` Got ${scanTx.length} transactions`)
// Get transaction s data from bitcoind // Retrieve the transactions by batches of 100 transactions
await util.seriesCall(scanTx, async txid => { const txsChunks = util.splitList(scanTx, 100)
const tx = await rpcTxns.getTransaction(txid, false) for (let txsChunk of txsChunks) {
if (tx == null) { const txs = await rpcTxns.getTransactions(txsChunk, false)
Logger.info(` got null for ${txid}`) for (let tx of txs)
return null if (tx != null)
}
txns.push(tx) txns.push(tx)
}) }
// Import addresses and transactions into the database // Import addresses and transactions into the database
await db.addAddresses(imported) await db.addAddresses(imported)

Loading…
Cancel
Save