Skip to content

Commit

Permalink
bip39_recovery: also scan change addresses
Browse files Browse the repository at this point in the history
fixes #7804
  • Loading branch information
SomberNight committed May 7, 2022
1 parent dd43ccf commit 9e0a0af
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions electrum/bip39_recovery.py
Expand Up @@ -3,6 +3,7 @@
# file LICENCE or http://www.opensource.org/licenses/mit-license.php

from typing import TYPE_CHECKING
import itertools

from . import bitcoin
from .constants import BIP39_WALLET_FORMATS
Expand Down Expand Up @@ -44,11 +45,15 @@ async def scan_for_active_accounts(network: 'Network', get_account_xpub, wallet_


async def account_has_history(network: 'Network', account_node: BIP32Node, script_type: str) -> bool:
gap_limit = 20
# note: scan both receiving and change addresses. some wallets send change across accounts.
path_suffixes = itertools.chain(
itertools.product((0,), range(20)), # ad-hoc gap limits
itertools.product((1,), range(10)),
)
async with OldTaskGroup() as group:
get_history_tasks = []
for address_index in range(gap_limit):
address_node = account_node.subkey_at_public_derivation("0/" + str(address_index))
for path_suffix in path_suffixes:
address_node = account_node.subkey_at_public_derivation(path_suffix)
pubkey = address_node.eckey.get_public_key_hex()
address = bitcoin.pubkey_to_address(script_type, pubkey)
script = bitcoin.address_to_script(address)
Expand Down

0 comments on commit 9e0a0af

Please sign in to comment.