Browse Source

optimize requests sent by RemoteImporter with batch rpc calls

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

41
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
try { const txsChunks = util.splitList(scanTx, 100)
const tx = await rpcTxns.getTransaction(txid, false) try {
if (tx == null) { for (let txsChunk of txsChunks) {
Logger.info(` got null for ${txid}`) const txs = await rpcTxns.getTransactions(txsChunk, false)
return null for (let tx of txs) {
if (tx != null) {
ret.transactions.push(tx)
txids[tx.txid] = true
}
} }
ret.transactions.push(tx)
txids[tx.txid] = true
} catch(e) {
Logger.error(e, `RemoteImporter.xpubScan() : rawTransaction error, txid ${txid}`)
} }
}) } catch(e) {
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