1
0

wallet: sweep_preparations to raise UserFacingException on p2sh/etc

closes https://github.com/spesmilo/electrum/issues/10145
This commit is contained in:
SomberNight
2025-08-18 17:02:34 +00:00
parent e7c8377808
commit 74d2c6386a
3 changed files with 13 additions and 3 deletions

View File

@@ -1031,6 +1031,9 @@ def parse_descriptor(desc: str) -> 'Descriptor':
#####
class NotLegacySinglesigScriptType(Exception): pass
def get_singlesig_descriptor_from_legacy_leaf(*, pubkey: str, script_type: str) -> Optional[Descriptor]:
pubkey = PubkeyProvider.parse(pubkey)
if script_type == 'p2pk':
@@ -1043,7 +1046,7 @@ def get_singlesig_descriptor_from_legacy_leaf(*, pubkey: str, script_type: str)
wpkh = WPKHDescriptor(pubkey=pubkey)
return SHDescriptor(subdescriptor=wpkh)
else:
raise NotImplementedError(f"unexpected {script_type=}")
raise NotLegacySinglesigScriptType(f"unexpected {script_type=}")
def create_dummy_descriptor_from_address(addr: Optional[str]) -> 'Descriptor':

View File

@@ -999,6 +999,7 @@ class QETxSweepFinalizer(QETxFinalizer):
def make_sweep_tx(self):
address = self._wallet.wallet.get_receiving_address()
assert self._wallet.wallet.is_mine(address)
assert self._txins is not None
coins, keypairs = copy.deepcopy(self._txins)
outputs = [PartialTxOutput.from_address_and_value(address, value='!')]
@@ -1033,6 +1034,9 @@ class QETxSweepFinalizer(QETxFinalizer):
if not self._private_keys:
self._logger.debug('private keys not set, ignoring update()')
return
if self._txins is None:
self._logger.debug('txins not set, ignoring update()')
return
try:
# make unsigned transaction

View File

@@ -137,7 +137,10 @@ async def sweep_preparations(
async def find_utxos_for_privkey(txin_type: str, privkey: bytes, compressed: bool):
pubkey = ecc.ECPrivkey(privkey).get_public_key_bytes(compressed=compressed)
desc = descriptor.get_singlesig_descriptor_from_legacy_leaf(pubkey=pubkey.hex(), script_type=txin_type)
try:
desc = descriptor.get_singlesig_descriptor_from_legacy_leaf(pubkey=pubkey.hex(), script_type=txin_type)
except descriptor.NotLegacySinglesigScriptType:
raise UserFacingException(_("Unsupported script-type ({}) for sweeping.").format(txin_type)) from None
await _append_utxos_to_inputs(
inputs=inputs,
network=network,
@@ -3710,7 +3713,7 @@ class Imported_Wallet(Simple_Wallet):
for txin_type in bitcoin.WIF_SCRIPT_TYPES.keys():
try:
addr2 = bitcoin.pubkey_to_address(txin_type, pubkey)
except NotImplementedError:
except descriptor.NotLegacySinglesigScriptType:
pass
else:
if self.db.has_imported_address(addr2):