Browse Source

Ensure all displayed addresses are imported

Fixes #1143 (and possibly others). Before this commit,
(index plus gap limit) addresses are imported on sync,
and addresses used by maker/taker in coinjoin are imported,
but when a deposit occurred, bumping the index, further
addresses were not imported. The effect was that it was
possible, if doing a series of deposits to multiple
external addresses in a Qt session, to end up depositing
to an address that was not yet imported. And this results
in the user needing to rescan for Core+JM to recognize the
coins.
After this commit, we ensure all 'gap limit forwards'
addresses, which are displayed as potential deposit addresses
in Joinmarket-Qt, are imported before the display.
master
Adam Gibson 4 years ago
parent
commit
ac8b173508
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 16
      jmclient/jmclient/wallet_service.py
  2. 12
      jmclient/jmclient/wallet_utils.py
  3. 2
      test/ygrunner.py

16
jmclient/jmclient/wallet_service.py

@ -887,11 +887,13 @@ class WalletService(Service):
include_disabled=include_disabled,
maxheight=maxheight)
def get_internal_addr(self, mixdepth):
def import_addr(self, addr):
if self.bci is not None and hasattr(self.bci, 'import_addresses'):
addr = self.wallet.get_internal_addr(mixdepth)
self.bci.import_addresses([addr],
self.wallet.get_wallet_name())
self.bci.import_addresses([addr], self.wallet.get_wallet_name())
def get_internal_addr(self, mixdepth):
addr = self.wallet.get_internal_addr(mixdepth)
self.import_addr(addr)
return addr
def collect_addresses_init(self):
@ -944,10 +946,8 @@ class WalletService(Service):
return addresses
def get_external_addr(self, mixdepth):
if self.bci is not None and hasattr(self.bci, 'import_addresses'):
addr = self.wallet.get_external_addr(mixdepth)
self.bci.import_addresses([addr],
self.wallet.get_wallet_name())
addr = self.wallet.get_external_addr(mixdepth)
self.import_addr(addr)
return addr
def __getattr__(self, attr):

12
jmclient/jmclient/wallet_utils.py

@ -494,9 +494,12 @@ def wallet_display(wallet_service, showprivkey, displayall=False,
xpub_key = ""
unused_index = wallet_service.get_next_unused_index(m, address_type)
gap_addrs = []
for k in range(unused_index + wallet_service.gap_limit):
path = wallet_service.get_path(m, address_type, k)
addr = wallet_service.get_address_from_path(path)
if k >= unused_index:
gap_addrs.append(addr)
label = wallet_service.get_address_label(addr)
balance, status = get_addr_status(
path, utxos[m], k >= unused_index, address_type)
@ -509,6 +512,15 @@ def wallet_display(wallet_service, showprivkey, displayall=False,
entrylist.append(WalletViewEntry(
wallet_service.get_path_repr(path), m, address_type, k, addr,
[balance, balance], priv=privkey, status=status, label=label))
# ensure that we never display un-imported addresses (this will generally duplicate
# the import of each new address gap limit times, but one importmulti call
# per mixdepth is cheap enough.
# This only applies to the external branch, because it only applies to addresses
# displayed for user deposit.
# It also does not apply to fidelity bond addresses which are created manually.
if address_type == BaseWallet.ADDRESS_TYPE_EXTERNAL:
wallet_service.bci.import_addresses(gap_addrs,
wallet_service.get_wallet_name())
wallet_service.set_next_index(m, address_type, unused_index)
path = wallet_service.get_path_repr(wallet_service.get_path(m, address_type))
branchlist.append(WalletViewBranch(path, m, address_type, entrylist,

2
test/ygrunner.py

@ -217,7 +217,7 @@ def get_addr_and_fund(yg):
return
if yg.wallet_service.timelock_funded:
return
addr = wallet_gettimelockaddress(yg.wallet_service.wallet, "2021-11")
addr = wallet_gettimelockaddress(yg.wallet_service.wallet, "2023-11")
print("Got timelockaddress: {}".format(addr))
# pay into it; amount is randomized for now.

Loading…
Cancel
Save