URI: 
       twallet.add_hw_info: also store "is_change" in output_info - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit ab76a1fe5bf7360d93e2a00621f58ce08165d9db
   DIR parent ac329797e0f6b433686a917f9c642e597759009e
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Tue,  3 Sep 2019 14:34:10 +0200
       
       wallet.add_hw_info: also store "is_change" in output_info
       
       as it seems every consumer wants to know this and has its own hacks to
       figure it out
       
       Diffstat:
         M electrum/address_synchronizer.py    |       2 +-
         M electrum/plugins/hw_wallet/plugin.… |       5 ++---
         M electrum/plugins/keepkey/keepkey.py |       5 ++---
         M electrum/plugins/ledger/ledger.py   |       5 ++---
         M electrum/plugins/safe_t/safe_t.py   |       5 ++---
         M electrum/plugins/trezor/trezor.py   |       5 ++---
         M electrum/transaction.py             |       3 ++-
         M electrum/wallet.py                  |      13 +++++++++----
       
       8 files changed, 22 insertions(+), 21 deletions(-)
       ---
   DIR diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
       t@@ -99,7 +99,7 @@ class AddressSynchronizer(Logger):
            def synchronize(self):
                pass
        
       -    def is_mine(self, address):
       +    def is_mine(self, address) -> bool:
                return self.db.is_addr_in_history(address)
        
            def get_addresses(self):
   DIR diff --git a/electrum/plugins/hw_wallet/plugin.py b/electrum/plugins/hw_wallet/plugin.py
       t@@ -132,14 +132,13 @@ class HW_PluginBase(BasePlugin):
                return self._ignore_outdated_fw
        
        
       -def is_any_tx_output_on_change_branch(tx: Transaction):
       +def is_any_tx_output_on_change_branch(tx: Transaction) -> bool:
            if not tx.output_info:
                return False
            for o in tx.outputs():
                info = tx.output_info.get(o.address)
                if info is not None:
       -            if info.address_index[0] == 1:
       -                return True
       +            return info.is_change
            return False
        
        
   DIR diff --git a/electrum/plugins/keepkey/keepkey.py b/electrum/plugins/keepkey/keepkey.py
       t@@ -407,7 +407,7 @@ class KeepKeyPlugin(HW_PluginBase):
        
                return inputs
        
       -    def tx_outputs(self, derivation, tx):
       +    def tx_outputs(self, derivation, tx: Transaction):
        
                def create_output_by_derivation():
                    script_type = self.get_keepkey_output_script_type(info.script_type)
       t@@ -454,10 +454,9 @@ class KeepKeyPlugin(HW_PluginBase):
                    info = tx.output_info.get(address)
                    if info is not None and not has_change:
                        index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
       -                on_change_branch = index[0] == 1
                        # prioritise hiding outputs on the 'change' branch from user
                        # because no more than one change address allowed
       -                if on_change_branch == any_output_on_change_branch:
       +                if info.is_change == any_output_on_change_branch:
                            use_create_by_derivation = True
                            has_change = True
        
   DIR diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py
       t@@ -318,7 +318,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
        
            @test_pin_unlocked
            @set_and_unset_signing
       -    def sign_transaction(self, tx, password):
       +    def sign_transaction(self, tx: Transaction, password):
                if tx.is_complete():
                    return
                client = self.get_client()
       t@@ -409,10 +409,9 @@ class Ledger_KeyStore(Hardware_KeyStore):
                        if (info is not None) and len(tx.outputs()) > 1 \
                                and not has_change:
                            index = info.address_index
       -                    on_change_branch = index[0] == 1
                            # prioritise hiding outputs on the 'change' branch from user
                            # because no more than one change address allowed
       -                    if on_change_branch == any_output_on_change_branch:
       +                    if info.is_change == any_output_on_change_branch:
                                changePath = self.get_derivation()[2:] + "/%d/%d"%index
                                has_change = True
                            else:
   DIR diff --git a/electrum/plugins/safe_t/safe_t.py b/electrum/plugins/safe_t/safe_t.py
       t@@ -403,7 +403,7 @@ class SafeTPlugin(HW_PluginBase):
        
                return inputs
        
       -    def tx_outputs(self, derivation, tx):
       +    def tx_outputs(self, derivation, tx: Transaction):
        
                def create_output_by_derivation():
                    script_type = self.get_safet_output_script_type(info.script_type)
       t@@ -450,12 +450,11 @@ class SafeTPlugin(HW_PluginBase):
                    info = tx.output_info.get(address)
                    if info is not None and not has_change:
                        index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
       -                on_change_branch = index[0] == 1
                        # prioritise hiding outputs on the 'change' branch from user
                        # because no more than one change address allowed
                        # note: ^ restriction can be removed once we require fw
                        # that has https://github.com/trezor/trezor-mcu/pull/306
       -                if on_change_branch == any_output_on_change_branch:
       +                if info.is_change == any_output_on_change_branch:
                            use_create_by_derivation = True
                            has_change = True
        
   DIR diff --git a/electrum/plugins/trezor/trezor.py b/electrum/plugins/trezor/trezor.py
       t@@ -420,7 +420,7 @@ class TrezorPlugin(HW_PluginBase):
                    signatures=signatures,
                    m=m)
        
       -    def tx_outputs(self, derivation, tx):
       +    def tx_outputs(self, derivation, tx: Transaction):
        
                def create_output_by_derivation():
                    script_type = self.get_trezor_output_script_type(info.script_type)
       t@@ -455,12 +455,11 @@ class TrezorPlugin(HW_PluginBase):
                    info = tx.output_info.get(address)
                    if info is not None and not has_change:
                        index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
       -                on_change_branch = index[0] == 1
                        # prioritise hiding outputs on the 'change' branch from user
                        # because no more than one change address allowed
                        # note: ^ restriction can be removed once we require fw
                        # that has https://github.com/trezor/trezor-mcu/pull/306
       -                if on_change_branch == any_output_on_change_branch:
       +                if info.is_change == any_output_on_change_branch:
                            use_create_by_derivation = True
                            has_change = True
        
   DIR diff --git a/electrum/transaction.py b/electrum/transaction.py
       t@@ -81,9 +81,10 @@ class TxOutputForUI(NamedTuple):
        
        class TxOutputHwInfo(NamedTuple):
            address_index: Tuple
       -    sorted_xpubs: Iterable[str]
       +    sorted_xpubs: Sequence[str]
            num_sig: Optional[int]
            script_type: str
       +    is_change: bool  # whether the wallet considers the output to be change
        
        
        class BIP143SharedTxDigestFields(NamedTuple):
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -351,10 +351,10 @@ class Abstract_Wallet(AddressSynchronizer):
                except:
                    return
        
       -    def is_mine(self, address):
       +    def is_mine(self, address) -> bool:
                return bool(self.get_address_index(address))
        
       -    def is_change(self, address):
       +    def is_change(self, address) -> bool:
                if not self.is_mine(address):
                    return False
                return self.get_address_index(address)[0]
       t@@ -1182,7 +1182,12 @@ class Abstract_Wallet(AddressSynchronizer):
                        # sort xpubs using the order of pubkeys
                        sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs)))
                        num_sig = self.m if isinstance(self, Multisig_Wallet) else None
       -                info[o.address] = TxOutputHwInfo(index, sorted_xpubs, num_sig, self.txin_type)
       +                is_change = self.is_change(o.address)
       +                info[o.address] = TxOutputHwInfo(address_index=index,
       +                                                 sorted_xpubs=sorted_xpubs,
       +                                                 num_sig=num_sig,
       +                                                 script_type=self.txin_type,
       +                                                 is_change=is_change)
                tx.output_info = info
        
            def sign_transaction(self, tx, password):
       t@@ -1738,7 +1743,7 @@ class Imported_Wallet(Simple_Wallet):
                        self.save_keystore()
                self.storage.write()
        
       -    def is_mine(self, address):
       +    def is_mine(self, address) -> bool:
                return self.db.has_imported_address(address)
        
            def get_address_index(self, address):