URI: 
       tupdate unsigned tx format, so that imported wallets can sign all address types - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 0dbb976baf773b09637792c4d59f27151f26703c
   DIR parent d472156dcd3b0807d9ceaaac227dd0660e4cc7f3
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Sat, 14 Oct 2017 15:47:36 +0200
       
       update unsigned tx format, so that imported wallets can sign all address types
       
       Diffstat:
         M lib/bitcoin.py                      |       5 +++++
         M lib/keystore.py                     |      13 ++++---------
         M lib/wallet.py                       |       6 ++++--
       
       3 files changed, 13 insertions(+), 11 deletions(-)
       ---
   DIR diff --git a/lib/bitcoin.py b/lib/bitcoin.py
       t@@ -363,6 +363,11 @@ def redeem_script_to_address(txin_type, redeem_script):
                raise NotImplementedError(txin_type)
        
        
       +def script_to_address(script):
       +    from .transaction import get_address_from_output_script
       +    t, addr = get_address_from_output_script(bfh(script))
       +    assert t == TYPE_ADDRESS
       +    return addr
        
        def address_to_script(addr):
            witver, witprog = segwit_addr.decode(SEGWIT_HRP, addr)
   DIR diff --git a/lib/keystore.py b/lib/keystore.py
       t@@ -162,11 +162,9 @@ class Imported_KeyStore(Software_KeyStore):
                    if x_pubkey in self.keypairs.keys():
                        return x_pubkey
                elif x_pubkey[0:2] == 'fd':
       -            # fixme: this assumes p2pkh
       -            _, addr = xpubkey_to_address(x_pubkey)
       -            for pubkey in self.keypairs.keys():
       -                if public_key_to_p2pkh(bfh(pubkey)) == addr:
       -                    return pubkey
       +            addr = bitcoin.script_to_address(x_pubkey[2:])
       +            if addr in self.addresses:
       +                return self.addresses[addr].get('pubkey')
        
            def update_password(self, old_password, new_password):
                self.check_password(old_password)
       t@@ -594,10 +592,7 @@ def parse_xpubkey(x_pubkey):
        
        def xpubkey_to_address(x_pubkey):
            if x_pubkey[0:2] == 'fd':
       -        # TODO: check that ord() is OK here
       -        addrtype = ord(bfh(x_pubkey[2:4]))
       -        hash160 = bfh(x_pubkey[4:])
       -        address = bitcoin.hash160_to_b58_address(hash160, addrtype)
       +        address = bitcoin.script_to_address(x_pubkey[2:])
                return x_pubkey, address
            if x_pubkey[0:2] in ['02', '03', '04']:
                pubkey = x_pubkey
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -1364,6 +1364,9 @@ class Imported_Wallet(Abstract_Wallet):
        
            def load_addresses(self):
                self.addresses = self.storage.get('addresses', {})
       +        # fixme: a reference to addresses is needed
       +        if self.keystore:
       +            self.keystore.addresses = self.addresses
        
            def save_addresses(self):
                self.storage.put('addresses', self.addresses)
       t@@ -1467,8 +1470,7 @@ class Imported_Wallet(Abstract_Wallet):
        
            def add_input_sig_info(self, txin, address):
                if self.is_watching_only():
       -            addrtype, hash160 = b58_address_to_hash160(address)
       -            x_pubkey = 'fd' + bh2u(bytes([addrtype]) + hash160)
       +            x_pubkey = 'fd' + address_to_script(address)
                    txin['x_pubkeys'] = [x_pubkey]
                    txin['signatures'] = [None]
                    return