From 859f06c79826ca7e6e1e50c314db29280cddf37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0ev=C4=8D=C3=ADk?= Date: Mon, 16 Aug 2021 17:17:08 +0200 Subject: [PATCH] Look back when importing postmix like-type change addresses --- lib/bitcoin/hd-accounts-service.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bitcoin/hd-accounts-service.js b/lib/bitcoin/hd-accounts-service.js index 3de162c..5503fdd 100644 --- a/lib/bitcoin/hd-accounts-service.js +++ b/lib/bitcoin/hd-accounts-service.js @@ -4,7 +4,7 @@ */ 'use strict' -const _ = require('lodash') +const util = require('../util') const errors = require('../errors') const Logger = require('../logger') const db = require('../db/mysql-db-wrapper') @@ -141,10 +141,10 @@ class HDAccountsService { Logger.info(`HdAccountsService : Created HD Account: ${xpub}${segwit}`) - const externalPrm = hdaHelper.deriveAddresses(xpub, 0, _.range(gap.external), scheme) - const internalPrm = hdaHelper.deriveAddresses(xpub, 1, _.range(gap.internal), scheme) + const externalPrm = hdaHelper.deriveAddresses(xpub, 0, util.range(0, gap.external), scheme) + const internalPrm = hdaHelper.deriveAddresses(xpub, 1, util.range(0, gap.internal), scheme) - const addresses = _.flatten(await Promise.all([externalPrm, internalPrm])) + const addresses = (await Promise.all([externalPrm, internalPrm])).flat() return db.addAddressesToHDAccount(xpub, addresses) } @@ -269,7 +269,7 @@ class HDAccountsService { const postmixNode = hdaHelper.getNode(postmixAcct) const [externalUnused, internalUnused] = await db.getHDAccountNextUnusedIndices(postmixAcct) - const deriveRange = Array.from({ length: gap.internal }, (_, i) => i + internalUnused) + const deriveRange = util.range(Math.max(0, internalUnused - 50), internalUnused + gap.internal) const likeTypeChangeAddresses = await Promise.all(deriveRange.map((index) => { return [