|
|
@ -25,7 +25,7 @@ if (network.key == 'bitcoin') { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* A singleton providing tools |
|
|
|
* A singleton providing tools |
|
|
|
* for importing HD and loose addresses from remote sources |
|
|
|
*/ |
|
|
|
class RemoteImporter { |
|
|
@ -81,7 +81,7 @@ class RemoteImporter { |
|
|
|
|
|
|
|
if (!txParents[txid]) |
|
|
|
txParents[txid] = [] |
|
|
|
|
|
|
|
|
|
|
|
for (let i in tx.inputs) { |
|
|
|
const input = tx.inputs[i] |
|
|
|
let prev = input.outpoint.txid |
|
|
@ -109,13 +109,13 @@ class RemoteImporter { |
|
|
|
* Import a list of transactions associated to a list of addresses |
|
|
|
* @param {object[]} addresses - array of addresses objects |
|
|
|
* @param {object[]} txns - array of transaction objects |
|
|
|
* @returns {Promise} |
|
|
|
* @returns {Promise} |
|
|
|
*/ |
|
|
|
async _importTransactions(addresses, txns) { |
|
|
|
const addrIdMap = await db.getAddressesIds(addresses) |
|
|
|
|
|
|
|
// The transactions array must be topologically ordered, such that
|
|
|
|
// entries earlier in the array MUST NOT depend upon any entry later
|
|
|
|
// The transactions array must be topologically ordered, such that
|
|
|
|
// entries earlier in the array MUST NOT depend upon any entry later
|
|
|
|
// in the array.
|
|
|
|
const txMaps = this._processTxsRelations(txns) |
|
|
|
const txOrdered = util.topologicalOrdering(txMaps.txParents, txMaps.txChildren) |
|
|
@ -161,7 +161,7 @@ class RemoteImporter { |
|
|
|
if (gapLimit |
|
|
|
&& ((keys.indexer.active == 'local_bitcoind') |
|
|
|
|| (keys.indexer.active == 'local_indexer')) |
|
|
|
) { |
|
|
|
) { |
|
|
|
gaps = [gapLimit, gapLimit] |
|
|
|
} |
|
|
|
|
|
|
@ -212,12 +212,12 @@ class RemoteImporter { |
|
|
|
* 4. Set u = highest chain index of used address, go to 1 |
|
|
|
* 5. Store all in database |
|
|
|
* |
|
|
|
* @returns {object} returns |
|
|
|
* @returns {object} returns |
|
|
|
* { |
|
|
|
* addresses: [{address, chain, index}], |
|
|
|
* transactions: [{ |
|
|
|
* txid, |
|
|
|
* version, |
|
|
|
* txid, |
|
|
|
* version, |
|
|
|
* locktime, |
|
|
|
* created, // if known
|
|
|
|
* block: 'abcdef', // if confirmed
|
|
|
@ -331,7 +331,7 @@ class RemoteImporter { |
|
|
|
return true |
|
|
|
|
|
|
|
Logger.info(`Importer : Importing ${addresses.join(',')}`) |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
const scanTx = [] |
|
|
|
const results = await this.sources.getAddresses(addresses, filterAddr) |
|
|
@ -373,7 +373,7 @@ class RemoteImporter { |
|
|
|
|
|
|
|
if (N > 0) |
|
|
|
Logger.info(`Importer : Imported ${N} addresses in ${ts}s (${(dt/N).toFixed(0)} ms/addr)`) |
|
|
|
|
|
|
|
|
|
|
|
for (let address of addresses) |
|
|
|
delete this.importing[address] |
|
|
|
|
|
|
@ -405,7 +405,7 @@ class RemoteImporter { |
|
|
|
const filteredTxs = txs.filter(tx => (tx.block && tx.block.hash == block.blockHash)) |
|
|
|
if (filteredTxs.length > 0) { |
|
|
|
const txids = filteredTxs.map(tx => tx.txid) |
|
|
|
// Asynchronous confirmations
|
|
|
|
// Asynchronous confirmations
|
|
|
|
db.confirmTransactions(txids, block.blockID) |
|
|
|
} |
|
|
|
} |
|
|
@ -430,12 +430,12 @@ class RemoteImporter { |
|
|
|
} |
|
|
|
} |
|
|
|
await db.addOutputs(outputs) |
|
|
|
|
|
|
|
|
|
|
|
// Store the inputs in db
|
|
|
|
const inputs = [] |
|
|
|
const spent = {} |
|
|
|
|
|
|
|
// Get any outputs spent by the inputs of this transaction,
|
|
|
|
// Get any outputs spent by the inputs of this transaction,
|
|
|
|
// add those database outIDs to the corresponding inputs, and store.
|
|
|
|
let outpoints = [] |
|
|
|
for (let tx of txs) |
|
|
@ -465,6 +465,15 @@ class RemoteImporter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retrieve the height of the chaintip for the remote source |
|
|
|
* @returns {Promise} returns an object |
|
|
|
* {chainTipHeight: <chaintip_height>} |
|
|
|
*/ |
|
|
|
async getChainTipHeight() { |
|
|
|
return this.sources.getChainTipHeight() |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
module.exports = new RemoteImporter() |
|
|
|