1
0

cli: add command to export preimage

..also export preimage in check_hold_invoice return value if available.

I intentionally did not return the preimage in the returned dict of
wallet.export_requests as this seems risky to do considering some users
of the cli might forward the response to a payer and the payserver
exposes it too.

Closes https://github.com/spesmilo/electrum/issues/10176
This commit is contained in:
f321x
2025-09-29 18:06:12 +02:00
parent 3d27992fb7
commit b57f867c2f
3 changed files with 34 additions and 2 deletions

View File

@@ -572,6 +572,7 @@ class TestCommandsTestnet(ElectrumTestCase):
assert settled_status['status'] == 'settled'
assert settled_status['received_amount_sat'] == 10000
assert settled_status['invoice_amount_sat'] == 10000
assert settled_status['preimage'] == preimage.hex()
with self.assertRaises(AssertionError):
# cancelling a settled invoice should raise
@@ -723,3 +724,19 @@ class TestCommandsTestnet(ElectrumTestCase):
}
}
self.assertEqual(result, expected_result)
@mock.patch.object(wallet.Abstract_Wallet, 'save_db')
async def test_export_lightning_preimage(self, *mock_args):
w = restore_wallet_from_text__for_unittest(
'disagree rug lemon bean unaware square alone beach tennis exhibit fix mimic',
path='if_this_exists_mocking_failed_648151893',
config=self.config)['wallet']
cmds = Commands(config=self.config)
preimage = os.urandom(32)
payment_hash = sha256(preimage)
w.lnworker.save_preimage(payment_hash, preimage)
assert await cmds.export_lightning_preimage(payment_hash=payment_hash.hex(), wallet=w) == preimage.hex()
assert await cmds.export_lightning_preimage(payment_hash=os.urandom(32).hex(), wallet=w) is None