|
|
@ -931,6 +931,36 @@ class MySqlDbWrapper { |
|
|
|
return ret |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the number of indices derived in an interval for a HD chain |
|
|
|
* @param {string} xpub - xpub |
|
|
|
* @param {integer} chain - HD chain (0 or 1) |
|
|
|
* @param {integer} minIdx - min index of derivation |
|
|
|
* @param {integer} maxIdx - max index of derivation |
|
|
|
* @returns {integer[]} returns an array of number of derived indices |
|
|
|
*/ |
|
|
|
async getHDAccountNbDerivedIndices(xpub, chain, minIdx, maxIdx) { |
|
|
|
const sqlQuery = 'SELECT \ |
|
|
|
COUNT(`hd_addresses`.`hdAddrIndex`) AS `nbDerivedIndices` \ |
|
|
|
FROM `hd_addresses` \ |
|
|
|
INNER JOIN `hd` ON `hd_addresses`.`hdID` = `hd`.`hdID` \ |
|
|
|
WHERE `hd`.`hdXpub` = ? \ |
|
|
|
AND `hd_addresses`.`hdAddrChain` = ? \ |
|
|
|
AND `hd_addresses`.`hdAddrIndex` >= ? \ |
|
|
|
AND `hd_addresses`.`hdAddrIndex` <= ?' |
|
|
|
|
|
|
|
const params = [xpub, chain, minIdx, maxIdx] |
|
|
|
const query = mysql.format(sqlQuery, params) |
|
|
|
const results = await this._query(query) |
|
|
|
|
|
|
|
if (results.length == 1) { |
|
|
|
const nbDerivedIndices = results[0].nbDerivedIndices |
|
|
|
return (nbDerivedIndices == null) ? 0 : nbDerivedIndices |
|
|
|
} |
|
|
|
|
|
|
|
return 0 |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the number of transactions for an HD account |
|
|
|
* @param {string} xpub - xpub |
|
|
|