URI: 
       ttrustedcoin: use psbt format on wire. rm psbt to legacy tx conversion. - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit e6e587b7da58a4fb3da451fef4af8fddd8715d01
   DIR parent 2adbbee5fe2da2bcf753a4ef27ddb4a86cf6dfae
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Fri, 29 May 2020 18:58:30 +0200
       
       ttrustedcoin: use psbt format on wire. rm psbt to legacy tx conversion.
       
       closes #6123
       
       Diffstat:
         D electrum/plugins/trustedcoin/legac… |     106 ------------------------------
         M electrum/plugins/trustedcoin/trust… |       5 ++---
         M electrum/tests/test_transaction.py  |      63 +------------------------------
       
       3 files changed, 3 insertions(+), 171 deletions(-)
       ---
   DIR diff --git a/electrum/plugins/trustedcoin/legacy_tx_format.py b/electrum/plugins/trustedcoin/legacy_tx_format.py
       t@@ -1,106 +0,0 @@
       -# Copyright (C) 2018 The Electrum developers
       -# Distributed under the MIT software license, see the accompanying
       -# file LICENCE or http://www.opensource.org/licenses/mit-license.php
       -
       -import copy
       -from typing import Union
       -
       -from electrum import bitcoin
       -from electrum.bitcoin import push_script, int_to_hex, var_int
       -from electrum.transaction import (Transaction, PartialTransaction, PartialTxInput,
       -                                  multisig_script, construct_witness)
       -from electrum.keystore import BIP32_KeyStore
       -from electrum.wallet import Multisig_Wallet
       -
       -
       -ELECTRUM_PARTIAL_TXN_HEADER_MAGIC = b'EPTF\xff'
       -PARTIAL_FORMAT_VERSION = b'\x00'
       -NO_SIGNATURE = b'\xff'
       -
       -
       -def get_xpubkey(keystore: BIP32_KeyStore, c, i) -> str:
       -    def encode_path_int(path_int) -> str:
       -        if path_int < 0xffff:
       -            hex = bitcoin.int_to_hex(path_int, 2)
       -        else:
       -            hex = 'ffff' + bitcoin.int_to_hex(path_int, 4)
       -        return hex
       -
       -    s = ''.join(map(encode_path_int, (c, i)))
       -    return 'ff' + bitcoin.DecodeBase58Check(keystore.xpub).hex() + s
       -
       -
       -def serialize_tx_in_legacy_format(tx: PartialTransaction, *, wallet: Multisig_Wallet) -> str:
       -    assert isinstance(tx, PartialTransaction)
       -
       -    # copy tx so we don't mutate the input arg
       -    # monkey-patch method of tx instance to change serialization
       -    tx = copy.deepcopy(tx)
       -
       -    def get_siglist(txin: 'PartialTxInput', *, estimate_size=False):
       -        if txin.is_coinbase_input():
       -            return [], []
       -        if estimate_size:
       -            try:
       -                pubkey_size = len(txin.pubkeys[0])
       -            except IndexError:
       -                pubkey_size = 33  # guess it is compressed
       -            num_pubkeys = max(1, len(txin.pubkeys))
       -            pk_list = ["00" * pubkey_size] * num_pubkeys
       -            # we assume that signature will be 0x48 bytes long
       -            num_sig = max(txin.num_sig, num_pubkeys)
       -            sig_list = [ "00" * 0x48 ] * num_sig
       -        else:
       -            pk_list = ["" for pk in txin.pubkeys]
       -            for ks in wallet.get_keystores():
       -                my_pubkey, full_path = ks.find_my_pubkey_in_txinout(txin)
       -                x_pubkey = get_xpubkey(ks, full_path[-2], full_path[-1])
       -                pubkey_index = txin.pubkeys.index(my_pubkey)
       -                pk_list[pubkey_index] = x_pubkey
       -            assert all(pk_list)
       -            sig_list = [txin.part_sigs.get(pubkey, NO_SIGNATURE).hex() for pubkey in txin.pubkeys]
       -        return pk_list, sig_list
       -
       -    def input_script(self, txin: PartialTxInput, *, estimate_size=False) -> str:
       -        assert estimate_size is False
       -        pubkeys, sig_list = get_siglist(txin, estimate_size=estimate_size)
       -        script = ''.join(push_script(x) for x in sig_list)
       -        if txin.script_type == 'p2sh':
       -            # put op_0 before script
       -            script = '00' + script
       -            redeem_script = multisig_script(pubkeys, txin.num_sig)
       -            script += push_script(redeem_script)
       -            return script
       -        elif txin.script_type == 'p2wsh':
       -            return ''
       -        raise Exception(f"unexpected type {txin.script_type}")
       -    tx.input_script = input_script.__get__(tx, PartialTransaction)
       -
       -    def serialize_witness(self, txin: PartialTxInput, *, estimate_size=False):
       -        assert estimate_size is False
       -        if txin.witness is not None:
       -            return txin.witness.hex()
       -        if txin.is_coinbase_input():
       -            return ''
       -        assert isinstance(txin, PartialTxInput)
       -        if not self.is_segwit_input(txin):
       -            return '00'
       -        pubkeys, sig_list = get_siglist(txin, estimate_size=estimate_size)
       -        if txin.script_type == 'p2wsh':
       -            witness_script = multisig_script(pubkeys, txin.num_sig)
       -            witness = construct_witness([0] + sig_list + [witness_script])
       -        else:
       -            raise Exception(f"unexpected type {txin.script_type}")
       -        if txin.is_complete() or estimate_size:
       -            partial_format_witness_prefix = ''
       -        else:
       -            input_value = int_to_hex(txin.value_sats(), 8)
       -            witness_version = int_to_hex(0, 2)
       -            partial_format_witness_prefix = var_int(0xffffffff) + input_value + witness_version
       -        return partial_format_witness_prefix + witness
       -    tx.serialize_witness = serialize_witness.__get__(tx, PartialTransaction)
       -
       -    buf = ELECTRUM_PARTIAL_TXN_HEADER_MAGIC.hex()
       -    buf += PARTIAL_FORMAT_VERSION.hex()
       -    buf += tx.serialize_to_network()
       -    return buf
   DIR diff --git a/electrum/plugins/trustedcoin/trustedcoin.py b/electrum/plugins/trustedcoin/trustedcoin.py
       t@@ -49,8 +49,6 @@ from electrum.network import Network
        from electrum.base_wizard import BaseWizard, WizardWalletPasswordSetting
        from electrum.logging import Logger
        
       -from .legacy_tx_format import serialize_tx_in_legacy_format
       -
        
        def get_signing_xpub(xtype):
            if not constants.net.TESTNET:
       t@@ -345,7 +343,8 @@ class Wallet_2fa(Multisig_Wallet):
                    return
                otp = int(otp)
                long_user_id, short_id = self.get_user_id()
       -        raw_tx = serialize_tx_in_legacy_format(tx, wallet=self)
       +        raw_tx = tx.serialize_as_bytes().hex()
       +        assert raw_tx[:10] == "70736274ff", f"bad magic. {raw_tx[:10]}"
                try:
                    r = server.sign(short_id, raw_tx, otp)
                except TrustedCoinException as e:
   DIR diff --git a/electrum/tests/test_transaction.py b/electrum/tests/test_transaction.py
       t@@ -3,16 +3,8 @@ from typing import NamedTuple, Union
        from electrum import transaction, bitcoin
        from electrum.transaction import convert_raw_tx_to_hex, tx_from_any, Transaction, PartialTransaction
        from electrum.util import bh2u, bfh
       -from electrum import keystore
       -from electrum import bip32
       -from electrum.mnemonic import seed_type
       -from electrum.simple_config import SimpleConfig
        
       -
       -from electrum.plugins.trustedcoin import trustedcoin
       -from electrum.plugins.trustedcoin.legacy_tx_format import serialize_tx_in_legacy_format
       -
       -from . import ElectrumTestCase, TestCaseForTestnet
       +from . import ElectrumTestCase
        
        signed_blob = '01000000012a5c9a94fcde98f5581cd00162c60a13936ceb75389ea65bf38633b424eb4031000000006c493046022100a82bbc57a0136751e5433f41cf000b3f1a99c6744775e76ec764fb78c54ee100022100f9e80b7de89de861dc6fb0c1429d5da72c2b6b2ee2406bc9bfb1beedd729d985012102e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6ffffffff0140420f00000000001976a914230ac37834073a42146f11ef8414ae929feaafc388ac00000000'
        v2_blob = "0200000001191601a44a81e061502b7bfbc6eaa1cef6d1e6af5308ef96c9342f71dbf4b9b5000000006b483045022100a6d44d0a651790a477e75334adfb8aae94d6612d01187b2c02526e340a7fd6c8022028bdf7a64a54906b13b145cd5dab21a26bd4b85d6044e9b97bceab5be44c2a9201210253e8e0254b0c95776786e40984c1aa32a7d03efa6bdacdea5f421b774917d346feffffff026b20fa04000000001976a914024db2e87dd7cfd0e5f266c5f212e21a31d805a588aca0860100000000001976a91421919b94ae5cefcdf0271191459157cdb41c4cbf88aca6240700"
       t@@ -848,56 +840,3 @@ class TestTransaction(ElectrumTestCase):
                self._run_naive_tests_on_tx(raw_tx, txid)
        
        # txns from Bitcoin Core ends <---
       -
       -
       -class TestLegacyPartialTxFormat(TestCaseForTestnet):
       -
       -    def setUp(self):
       -        super().setUp()
       -        self.config = SimpleConfig({'electrum_path': self.electrum_path})
       -
       -    def test_trustedcoin_legacy_2fa_psbt_to_legacy_partial_tx(self):
       -        from .test_wallet_vertical import WalletIntegrityHelper
       -        seed_words = 'kiss live scene rude gate step hip quarter bunker oxygen motor glove'
       -        self.assertEqual(seed_type(seed_words), '2fa')
       -
       -        xprv1, xpub1, xprv2, xpub2 = trustedcoin.TrustedCoinPlugin.xkeys_from_seed(seed_words, '')
       -        ks1 = keystore.from_xprv(xprv1)
       -        ks2 = keystore.from_xprv(xprv2)
       -        long_user_id, short_id = trustedcoin.get_user_id(
       -            {'x1/': {'xpub': xpub1},
       -             'x2/': {'xpub': xpub2}})
       -        xtype = bip32.xpub_type(xpub1)
       -        xpub3 = trustedcoin.make_xpub(trustedcoin.get_signing_xpub(xtype), long_user_id)
       -        ks3 = keystore.from_xpub(xpub3)
       -
       -        wallet = WalletIntegrityHelper.create_multisig_wallet([ks1, ks2, ks3], '2of3', config=self.config)
       -
parazyd.org:70 /git/electrum/commit/e6e587b7da58a4fb3da451fef4af8fddd8715d01.gph:200: line too long