tshow address on trezor for multisig (#3823) - electrum - Electrum Bitcoin wallet
 (HTM) git clone https://git.parazyd.org/electrum
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
       ---
 (DIR) commit 37904bc1109564e481253f656ef00f5bd9a44771
 (DIR) parent ea2a2aaf09011fe98c22268f640ddecad246dfa5
 (HTM) Author: Wampum <farmerwampum@protonmail.com>
       Date:   Sun,  4 Feb 2018 05:21:25 +0000
       
       show address on trezor for multisig (#3823)
       
       * show address on trezor for multisig
       
       * Show menu option properly.
       
       * remove useless line
       
       Diffstat:
         M plugins/trezor/plugin.py            |      38 ++++++++++++++++++++++---------
         M plugins/trezor/qt_generic.py        |      13 +++++++------
       
       2 files changed, 34 insertions(+), 17 deletions(-)
       ---
 (DIR) diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py
       t@@ -243,23 +243,39 @@ class TrezorCompatiblePlugin(HW_PluginBase):
                raw = bh2u(signed_tx)
                tx.update_signatures(raw)
        
       -    def show_address(self, wallet, address):
       -        client = self.get_client(wallet.keystore)
       +    def show_address(self, wallet, keystore, address):
       +        client = self.get_client(keystore)
                if not client.atleast_version(1, 3):
       -            wallet.keystore.handler.show_error(_("Your device firmware is too old"))
       +            keystore.handler.show_error(_("Your device firmware is too old"))
                    return
                change, index = wallet.get_address_index(address)
       -        derivation = wallet.keystore.derivation
       +        derivation = keystore.derivation
                address_path = "%s/%d/%d"%(derivation, change, index)
                address_n = client.expand_path(address_path)
       -        script_gen = wallet.keystore.get_script_gen()
       -        if script_gen == SCRIPT_GEN_NATIVE_SEGWIT:
       -            script_type = self.types.InputScriptType.SPENDWITNESS
       -        elif script_gen == SCRIPT_GEN_P2SH_SEGWIT:
       -            script_type = self.types.InputScriptType.SPENDP2SHWITNESS
       +        xpubs = wallet.get_master_public_keys()
       +        if len(xpubs) == 1:
       +            script_gen = keystore.get_script_gen()
       +            if script_gen == SCRIPT_GEN_NATIVE_SEGWIT:
       +                script_type = self.types.InputScriptType.SPENDWITNESS
       +            elif script_gen == SCRIPT_GEN_P2SH_SEGWIT:
       +                script_type = self.types.InputScriptType.SPENDP2SHWITNESS
       +            else:
       +                script_type = self.types.InputScriptType.SPENDADDRESS
       +            client.get_address(self.get_coin_name(), address_n, True, script_type=script_type)
                else:
       -            script_type = self.types.InputScriptType.SPENDADDRESS
       -        client.get_address(self.get_coin_name(), address_n, True, script_type=script_type)
       +            def f(xpub):
       +                node = self.ckd_public.deserialize(xpub)
       +                return self.types.HDNodePathType(node=node, address_n=[change, index])
       +            pubkeys = wallet.get_public_keys(address)
       +            # sort xpubs using the order of pubkeys
       +            sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs)))
       +            pubkeys = list(map(f, sorted_xpubs))
       +            multisig = self.types.MultisigRedeemScriptType(
       +               pubkeys=pubkeys,
       +               signatures=[b''] * wallet.n,
       +               m=wallet.m,
       +            )
       +            client.get_address(self.get_coin_name(), address_n, True, multisig=multisig)
        
            def tx_inputs(self, tx, for_sig=False, script_gen=SCRIPT_GEN_LEGACY):
                inputs = []
 (DIR) diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py
       t@@ -188,13 +188,14 @@ class QtPlugin(QtPluginBase):
        
            @hook
            def receive_menu(self, menu, addrs, wallet):
       -        if type(wallet) is not Standard_Wallet:
       +        if len(addrs) != 1:
                    return
       -        keystore = wallet.get_keystore()
       -        if type(keystore) == self.keystore_class and len(addrs) == 1:
       -            def show_address():
       -                keystore.thread.add(partial(self.show_address, wallet, addrs[0]))
       -            menu.addAction(_("Show on %s") % self.device, show_address)
       +        for keystore in wallet.get_keystores():
       +            if type(keystore) == self.keystore_class:
       +                def show_address():
       +                    keystore.thread.add(partial(self.show_address, wallet, keystore, addrs[0]))
       +                menu.addAction(_("Show on %s") % self.device, show_address)
       +                break
        
            def show_settings_dialog(self, window, keystore):
                device_id = self.choose_device(window, keystore)