electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 9425319dcd4c16a63ee3559bde433472b44ec165
parent 24af61816414927392142ec6f28e7c7e859b500f
Author: ThomasV <thomasv@electrum.org>
Date:   Fri, 24 Nov 2017 10:26:08 +0100

Merge pull request #3367 from SomberNight/tx_size_est_uncompressed_pk

tx size estimation: handle uncompressed pubkeys
Diffstat:
Mlib/transaction.py | 29++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/lib/transaction.py b/lib/transaction.py @@ -613,13 +613,40 @@ class Transaction: raise TypeError('Unknown output type') @classmethod + def estimate_pubkey_size_from_x_pubkey(cls, x_pubkey): + try: + if x_pubkey[0:2] in ['02', '03']: # compressed pubkey + return 0x21 + elif x_pubkey[0:2] == '04': # uncompressed pubkey + return 0x41 + elif x_pubkey[0:2] == 'ff': # bip32 extended pubkey + return 0x21 + elif x_pubkey[0:2] == 'fe': # old electrum extended pubkey + return 0x41 + except Exception as e: + pass + return 0x21 # just guess it is compressed + + @classmethod + def estimate_pubkey_size_for_txin(cls, txin): + pubkeys = txin.get('pubkeys', []) + x_pubkeys = txin.get('x_pubkeys', []) + if len(pubkeys) > 0: + return cls.estimate_pubkey_size_from_x_pubkey(pubkeys[0]) + elif len(x_pubkeys) > 0: + return cls.estimate_pubkey_size_from_x_pubkey(x_pubkeys[0]) + else: + return 0x21 # just guess it is compressed + + @classmethod def get_siglist(self, txin, estimate_size=False): # if we have enough signatures, we use the actual pubkeys # otherwise, use extended pubkeys (with bip32 derivation) num_sig = txin.get('num_sig', 1) if estimate_size: + pubkey_size = self.estimate_pubkey_size_for_txin(txin) + pk_list = ["00" * pubkey_size] * num_sig # we assume that signature will be 0x48 bytes long - pk_list = [ "00" * 0x21 ] * num_sig sig_list = [ "00" * 0x48 ] * num_sig else: pubkeys, x_pubkeys = self.get_sorted_pubkeys(txin)