|
|
@ -34,6 +34,8 @@ class RemoteImporter { |
|
|
|
* Constructor |
|
|
|
*/ |
|
|
|
constructor() { |
|
|
|
this.STATUS_RESCAN = 'rescan' |
|
|
|
this.STATUS_IMPORT = 'import' |
|
|
|
// Guard against overlapping imports
|
|
|
|
this.importing = {} |
|
|
|
this.sources = new Sources() |
|
|
@ -50,12 +52,12 @@ class RemoteImporter { |
|
|
|
|
|
|
|
/** |
|
|
|
* Check if a xpub is currently being imported or rescanned by Dojo |
|
|
|
* Returns true if import/rescan is in progress, otherwise returns false |
|
|
|
* Returns infor about the operation if import/rescan is in progress, otherwise returns null |
|
|
|
* @param {string} xpub - xpub |
|
|
|
* @returns {boolean} |
|
|
|
* @returns {object} |
|
|
|
*/ |
|
|
|
importInProgress(xpub) { |
|
|
|
return this.importing[xpub] ? true : false |
|
|
|
return this.importing[xpub] ? this.importing[xpub] : null |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -147,7 +149,11 @@ class RemoteImporter { |
|
|
|
return Promise.reject(errors.xpub.OVERLAP) |
|
|
|
} |
|
|
|
|
|
|
|
this.importing[xpub] = true |
|
|
|
this.importing[xpub] = { |
|
|
|
'status': this.STATUS_RESCAN, |
|
|
|
'txs_ext': 0, |
|
|
|
'txs_int': 0 |
|
|
|
} |
|
|
|
|
|
|
|
const ts = hdaHelper.typeString(type) |
|
|
|
Logger.info(`Importer : Importing ${xpub} ${ts}`) |
|
|
@ -182,6 +188,11 @@ class RemoteImporter { |
|
|
|
addresses = addresses.concat(result.addresses) |
|
|
|
} |
|
|
|
|
|
|
|
this.importing[xpub] = { |
|
|
|
'status': this.STATUS_IMPORT, |
|
|
|
'txs': txns.length |
|
|
|
} |
|
|
|
|
|
|
|
// Store the hdaccount and the addresses into the database
|
|
|
|
await db.ensureHDAccountId(xpub, type) |
|
|
|
await db.addAddressesToHDAccount(xpub, addresses) |
|
|
@ -290,6 +301,10 @@ class RemoteImporter { |
|
|
|
} |
|
|
|
|
|
|
|
if (gotTransactions) { |
|
|
|
if (c == 0) |
|
|
|
this.importing[xpub]['txs_ext'] = Object.keys(txids).length |
|
|
|
else |
|
|
|
this.importing[xpub]['txs_int'] = Object.keys(txids).length |
|
|
|
// We must go deeper
|
|
|
|
const result = await this.xpubScan(xpub, c, d, u, G, type, txids) |
|
|
|
// Accumulate results from further down the rabbit hole
|
|
|
|