Browse Source

Restore account support in wallet_service, needed for pre-0.17 Bitcoin Core

master
Kristaps Kaupe 6 years ago
parent
commit
cf19df2de1
No known key found for this signature in database
GPG Key ID: D47B1B4232B55437
  1. 11
      jmclient/jmclient/blockchaininterface.py
  2. 10
      jmclient/jmclient/wallet_service.py

11
jmclient/jmclient/blockchaininterface.py

@ -31,6 +31,10 @@ class BlockchainInterface(object):
except JsonRpcError:
return len(self.rpc('getaddressinfo', [addr])['labels']) > 0
@abc.abstractmethod
def is_address_labeled(self, utxo, walletname):
"""checks that UTXO belongs to the JM wallet"""
@abc.abstractmethod
def pushtx(self, txhex):
"""pushes tx to the network, returns False if failed"""
@ -182,6 +186,13 @@ class BitcoinCoreInterface(BlockchainInterface):
res = self.jsonRpc.call(method, args)
return res
def is_address_labeled(self, utxo, walletname):
# Bitcoin Core before 0.17 used accounts, new versions has labels
return (
("label" in utxo and utxo["label"] == walletname) or
("account" in utxo and utxo["account"] == walletname)
)
def import_addresses(self, addr_list, wallet_name, restart_cb=None):
"""Imports addresses in a batch during initial sync.
Refuses to proceed if keys are found to be under control

10
jmclient/jmclient/wallet_service.py

@ -225,8 +225,8 @@ class WalletService(Service):
# transaction pertains to anything known (but must
# have correct label per above); filter on this Joinmarket wallet label,
# or the external monitoring label:
if "label" in tx and tx["label"] in [
self.EXTERNAL_WALLET_LABEL, self.get_wallet_name()]:
if (self.bci.is_address_labeled(tx, self.get_wallet_name()) or
self.bci.is_address_labeled(tx, self.EXTERNAL_WALLET_LABEL)):
for f in self.callbacks["all"]:
# note we need no return value as we will never
# remove these from the list
@ -491,13 +491,13 @@ class WalletService(Service):
'POLICY', 'listunspent_args'))
unspent_list = self.bci.rpc('listunspent', listunspent_args)
unspent_list = [x for x in unspent_list if "label" in x]
# filter on label, but note (a) in certain circumstances (in-
# wallet transfer) it is possible for the utxo to be labeled
# with the external label, and (b) the wallet will know if it
# belongs or not anyway (is_known_addr):
our_unspent_list = [x for x in unspent_list if x["label"] in [
wallet_name, self.EXTERNAL_WALLET_LABEL]]
our_unspent_list = [x for x in unspent_list if (
self.bci.is_address_labeled(x, wallet_name) or
self.bci.is_address_labeled(x, self.EXTERNAL_WALLET_LABEL))]
for u in our_unspent_list:
if not self.is_known_addr(u['address']):
continue

Loading…
Cancel
Save