transaction.py: set txio.{witness,redeem}|script based on descriptor
This commit is contained in:
@@ -1186,7 +1186,7 @@ class PartialTxInput(TxInput, PSBTSection):
|
||||
self.witness_script = None # type: Optional[bytes]
|
||||
self._unknown = {} # type: Dict[bytes, bytes]
|
||||
|
||||
self.script_descriptor = None # type: Optional[Descriptor]
|
||||
self._script_descriptor = None # type: Optional[Descriptor]
|
||||
self._trusted_value_sats = None # type: Optional[int]
|
||||
self._trusted_address = None # type: Optional[str]
|
||||
self._is_p2sh_segwit = None # type: Optional[bool] # None means unknown
|
||||
@@ -1225,6 +1225,19 @@ class PartialTxInput(TxInput, PSBTSection):
|
||||
return desc.get_all_pubkeys()
|
||||
return set()
|
||||
|
||||
@property
|
||||
def script_descriptor(self):
|
||||
return self._script_descriptor
|
||||
|
||||
@script_descriptor.setter
|
||||
def script_descriptor(self, desc: Optional[Descriptor]):
|
||||
self._script_descriptor = desc
|
||||
if desc:
|
||||
if self.redeem_script is None:
|
||||
self.redeem_script = desc.expand().redeem_script
|
||||
if self.witness_script is None:
|
||||
self.witness_script = desc.expand().witness_script
|
||||
|
||||
def to_json(self):
|
||||
d = super().to_json()
|
||||
d.update({
|
||||
@@ -1537,7 +1550,7 @@ class PartialTxOutput(TxOutput, PSBTSection):
|
||||
self.bip32_paths = {} # type: Dict[bytes, Tuple[bytes, Sequence[int]]] # pubkey -> (xpub_fingerprint, path)
|
||||
self._unknown = {} # type: Dict[bytes, bytes]
|
||||
|
||||
self.script_descriptor = None # type: Optional[Descriptor]
|
||||
self._script_descriptor = None # type: Optional[Descriptor]
|
||||
self.is_mine = False # type: bool # whether the wallet considers the output to be ismine
|
||||
self.is_change = False # type: bool # whether the wallet considers the output to be change
|
||||
|
||||
@@ -1547,6 +1560,19 @@ class PartialTxOutput(TxOutput, PSBTSection):
|
||||
return desc.get_all_pubkeys()
|
||||
return set()
|
||||
|
||||
@property
|
||||
def script_descriptor(self):
|
||||
return self._script_descriptor
|
||||
|
||||
@script_descriptor.setter
|
||||
def script_descriptor(self, desc: Optional[Descriptor]):
|
||||
self._script_descriptor = desc
|
||||
if desc:
|
||||
if self.redeem_script is None:
|
||||
self.redeem_script = desc.expand().redeem_script
|
||||
if self.witness_script is None:
|
||||
self.witness_script = desc.expand().witness_script
|
||||
|
||||
def to_json(self):
|
||||
d = super().to_json()
|
||||
d.update({
|
||||
|
||||
@@ -2197,18 +2197,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
||||
self.lnworker.swap_manager.add_txin_info(txin)
|
||||
return
|
||||
txin.script_descriptor = self._get_script_descriptor_for_address(address)
|
||||
if txin.redeem_script is None: # FIXME should be set in transaction.py instead, based on the script desc
|
||||
try:
|
||||
redeem_script_hex = self.get_redeem_script(address)
|
||||
txin.redeem_script = bfh(redeem_script_hex) if redeem_script_hex else None
|
||||
except UnknownTxinType:
|
||||
pass
|
||||
if txin.witness_script is None: # FIXME should be set in transaction.py instead, based on the script desc
|
||||
try:
|
||||
witness_script_hex = self.get_witness_script(address)
|
||||
txin.witness_script = bfh(witness_script_hex) if witness_script_hex else None
|
||||
except UnknownTxinType:
|
||||
pass
|
||||
self._add_txinout_derivation_info(txin, address, only_der_suffix=only_der_suffix)
|
||||
txin.block_height = self.adb.get_tx_height(txin.prevout.txid.hex()).height
|
||||
|
||||
@@ -2295,18 +2283,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
||||
txout.is_mine = True
|
||||
txout.is_change = self.is_change(address)
|
||||
self._add_txinout_derivation_info(txout, address, only_der_suffix=only_der_suffix)
|
||||
if txout.redeem_script is None: # FIXME should be set in transaction.py instead, based on the script desc
|
||||
try:
|
||||
redeem_script_hex = self.get_redeem_script(address)
|
||||
txout.redeem_script = bfh(redeem_script_hex) if redeem_script_hex else None
|
||||
except UnknownTxinType:
|
||||
pass
|
||||
if txout.witness_script is None: # FIXME should be set in transaction.py instead, based on the script desc
|
||||
try:
|
||||
witness_script_hex = self.get_witness_script(address)
|
||||
txout.witness_script = bfh(witness_script_hex) if witness_script_hex else None
|
||||
except UnknownTxinType:
|
||||
pass
|
||||
|
||||
def sign_transaction(self, tx: Transaction, password) -> Optional[PartialTransaction]:
|
||||
if self.is_watching_only():
|
||||
|
||||
Reference in New Issue
Block a user