transaction.py: rm PartialTxInput.{num_sig, script_type}
This commit is contained in:
@@ -43,6 +43,7 @@ from typing import (
|
||||
Tuple,
|
||||
Sequence,
|
||||
Mapping,
|
||||
Set,
|
||||
)
|
||||
|
||||
|
||||
@@ -376,6 +377,22 @@ class Descriptor(object):
|
||||
script_sig=script_sig,
|
||||
)
|
||||
|
||||
def get_satisfaction_progress(
|
||||
self,
|
||||
*,
|
||||
sigdata: Mapping[bytes, bytes] = None, # pubkey -> sig
|
||||
) -> Tuple[int, int]:
|
||||
"""Returns (num_sigs_we_have, num_sigs_required) towards satisfying this script.
|
||||
Besides signatures, later this can also consider hash-preimages.
|
||||
"""
|
||||
assert not self.is_range()
|
||||
nhave, nreq = 0, 0
|
||||
for desc in self.subdescriptors:
|
||||
a, b = desc.get_satisfaction_progress()
|
||||
nhave += a
|
||||
nreq += b
|
||||
return nhave, nreq
|
||||
|
||||
def is_range(self) -> bool:
|
||||
for pubkey in self.pubkeys:
|
||||
if pubkey.is_range():
|
||||
@@ -388,6 +405,47 @@ class Descriptor(object):
|
||||
def is_segwit(self) -> bool:
|
||||
return any([desc.is_segwit() for desc in self.subdescriptors])
|
||||
|
||||
def get_all_pubkeys(self) -> Set[bytes]:
|
||||
"""Returns set of pubkeys that appear at any level in this descriptor."""
|
||||
assert not self.is_range()
|
||||
all_pubkeys = set([p.get_pubkey_bytes() for p in self.pubkeys])
|
||||
for desc in self.subdescriptors:
|
||||
all_pubkeys |= desc.get_all_pubkeys()
|
||||
return all_pubkeys
|
||||
|
||||
def get_simple_singlesig(self) -> Optional['Descriptor']:
|
||||
"""Returns innermost pk/pkh/wpkh descriptor, or None if we are not a simple singlesig.
|
||||
|
||||
note: besides pk,pkh,sh(wpkh),wpkh, overly complicated stuff such as sh(pk),wsh(sh(pkh),etc is also accepted
|
||||
"""
|
||||
if len(self.subdescriptors) == 1:
|
||||
return self.subdescriptors[0].get_simple_singlesig()
|
||||
return None
|
||||
|
||||
def get_simple_multisig(self) -> Optional['MultisigDescriptor']:
|
||||
"""Returns innermost multi descriptor, or None if we are not a simple multisig."""
|
||||
if len(self.subdescriptors) == 1:
|
||||
return self.subdescriptors[0].get_simple_multisig()
|
||||
return None
|
||||
|
||||
def to_legacy_electrum_script_type(self) -> str:
|
||||
if isinstance(self, PKDescriptor):
|
||||
return "p2pk"
|
||||
elif isinstance(self, PKHDescriptor):
|
||||
return "p2pkh"
|
||||
elif isinstance(self, WPKHDescriptor):
|
||||
return "p2wpkh"
|
||||
elif isinstance(self, SHDescriptor) and isinstance(self.subdescriptors[0], WPKHDescriptor):
|
||||
return "p2wpkh-p2sh"
|
||||
elif isinstance(self, SHDescriptor) and isinstance(self.subdescriptors[0], MultisigDescriptor):
|
||||
return "p2sh"
|
||||
elif isinstance(self, WSHDescriptor) and isinstance(self.subdescriptors[0], MultisigDescriptor):
|
||||
return "p2wsh"
|
||||
elif (isinstance(self, SHDescriptor) and isinstance(self.subdescriptors[0], WSHDescriptor)
|
||||
and isinstance(self.subdescriptors[0].subdescriptors[0], MultisigDescriptor)):
|
||||
return "p2wsh-p2sh"
|
||||
return "unknown"
|
||||
|
||||
|
||||
class PKDescriptor(Descriptor):
|
||||
"""
|
||||
@@ -421,6 +479,14 @@ class PKDescriptor(Descriptor):
|
||||
witness_items=(sig,),
|
||||
)
|
||||
|
||||
def get_satisfaction_progress(self, *, sigdata=None) -> Tuple[int, int]:
|
||||
if sigdata is None: sigdata = {}
|
||||
signatures = list(sigdata.values())
|
||||
return len(signatures), 1
|
||||
|
||||
def get_simple_singlesig(self) -> Optional['Descriptor']:
|
||||
return self
|
||||
|
||||
|
||||
class PKHDescriptor(Descriptor):
|
||||
"""
|
||||
@@ -455,6 +521,14 @@ class PKHDescriptor(Descriptor):
|
||||
witness_items=(sig, pubkey),
|
||||
)
|
||||
|
||||
def get_satisfaction_progress(self, *, sigdata=None) -> Tuple[int, int]:
|
||||
if sigdata is None: sigdata = {}
|
||||
signatures = list(sigdata.values())
|
||||
return len(signatures), 1
|
||||
|
||||
def get_simple_singlesig(self) -> Optional['Descriptor']:
|
||||
return self
|
||||
|
||||
|
||||
class WPKHDescriptor(Descriptor):
|
||||
"""
|
||||
@@ -492,9 +566,17 @@ class WPKHDescriptor(Descriptor):
|
||||
witness_items=(sig, pubkey),
|
||||
)
|
||||
|
||||
def get_satisfaction_progress(self, *, sigdata=None) -> Tuple[int, int]:
|
||||
if sigdata is None: sigdata = {}
|
||||
signatures = list(sigdata.values())
|
||||
return len(signatures), 1
|
||||
|
||||
def is_segwit(self) -> bool:
|
||||
return True
|
||||
|
||||
def get_simple_singlesig(self) -> Optional['Descriptor']:
|
||||
return self
|
||||
|
||||
|
||||
class MultisigDescriptor(Descriptor):
|
||||
"""
|
||||
@@ -552,6 +634,14 @@ class MultisigDescriptor(Descriptor):
|
||||
witness_items=(0, *signatures),
|
||||
)
|
||||
|
||||
def get_satisfaction_progress(self, *, sigdata=None) -> Tuple[int, int]:
|
||||
if sigdata is None: sigdata = {}
|
||||
signatures = list(sigdata.values())
|
||||
return len(signatures), self.thresh
|
||||
|
||||
def get_simple_multisig(self) -> Optional['MultisigDescriptor']:
|
||||
return self
|
||||
|
||||
|
||||
class SHDescriptor(Descriptor):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user