Merge pull request #3367 from SomberNight/tx_size_est_uncompressed_pk
tx size estimation: handle uncompressed pubkeys
This commit is contained in:
commit
9425319dcd
|
@ -612,14 +612,41 @@ class Transaction:
|
|||
else:
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue