mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 09:45:18 +00:00
Merge pull request #3367 from SomberNight/tx_size_est_uncompressed_pk
tx size estimation: handle uncompressed pubkeys
This commit is contained in:
commit
9425319dcd
1 changed files with 28 additions and 1 deletions
|
@ -612,14 +612,41 @@ class Transaction:
|
||||||
else:
|
else:
|
||||||
raise TypeError('Unknown output type')
|
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
|
@classmethod
|
||||||
def get_siglist(self, txin, estimate_size=False):
|
def get_siglist(self, txin, estimate_size=False):
|
||||||
# if we have enough signatures, we use the actual pubkeys
|
# if we have enough signatures, we use the actual pubkeys
|
||||||
# otherwise, use extended pubkeys (with bip32 derivation)
|
# otherwise, use extended pubkeys (with bip32 derivation)
|
||||||
num_sig = txin.get('num_sig', 1)
|
num_sig = txin.get('num_sig', 1)
|
||||||
if estimate_size:
|
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
|
# we assume that signature will be 0x48 bytes long
|
||||||
pk_list = [ "00" * 0x21 ] * num_sig
|
|
||||||
sig_list = [ "00" * 0x48 ] * num_sig
|
sig_list = [ "00" * 0x48 ] * num_sig
|
||||||
else:
|
else:
|
||||||
pubkeys, x_pubkeys = self.get_sorted_pubkeys(txin)
|
pubkeys, x_pubkeys = self.get_sorted_pubkeys(txin)
|
||||||
|
|
Loading…
Add table
Reference in a new issue