@@ -19,8 +19,8 @@ use common::{
19
19
use ldk_node:: config:: EsploraSyncConfig ;
20
20
use ldk_node:: liquidity:: LSPS2ServiceConfig ;
21
21
use ldk_node:: payment:: {
22
- ConfirmationStatus , PaymentDirection , PaymentKind , PaymentStatus , QrPaymentResult ,
23
- SendingParameters ,
22
+ ConfirmationStatus , PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus ,
23
+ QrPaymentResult , SendingParameters ,
24
24
} ;
25
25
use ldk_node:: { Builder , Event , NodeError } ;
26
26
@@ -30,7 +30,11 @@ use lightning::util::persist::KVStore;
30
30
31
31
use lightning_invoice:: { Bolt11InvoiceDescription , Description } ;
32
32
33
+ use ldk_node:: CustomTlvRecord ;
34
+ use lightning_types:: payment:: PaymentPreimage ;
35
+
33
36
use bitcoin:: address:: NetworkUnchecked ;
37
+ use bitcoin:: hashes:: sha256:: Hash as Sha256Hash ;
34
38
use bitcoin:: hashes:: Hash ;
35
39
use bitcoin:: Address ;
36
40
use bitcoin:: Amount ;
@@ -1381,3 +1385,49 @@ fn facade_logging() {
1381
1385
validate_log_entry ( entry) ;
1382
1386
}
1383
1387
}
1388
+
1389
+ #[ test]
1390
+ fn spontaneous_send_with_custom_preimage ( ) {
1391
+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
1392
+ let chain_source = TestChainSource :: Esplora ( & electrsd) ;
1393
+ let ( node_a, node_b) = setup_two_nodes ( & chain_source, false , true , false ) ;
1394
+
1395
+ let address_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
1396
+ let premine_sat = 1_000_000 ;
1397
+ premine_and_distribute_funds (
1398
+ & bitcoind. client ,
1399
+ & electrsd. client ,
1400
+ vec ! [ address_a] ,
1401
+ Amount :: from_sat ( premine_sat) ,
1402
+ ) ;
1403
+ node_a. sync_wallets ( ) . unwrap ( ) ;
1404
+ node_b. sync_wallets ( ) . unwrap ( ) ;
1405
+ open_channel ( & node_a, & node_b, 500_000 , true , & electrsd) ;
1406
+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) ;
1407
+ node_a. sync_wallets ( ) . unwrap ( ) ;
1408
+ node_b. sync_wallets ( ) . unwrap ( ) ;
1409
+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
1410
+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
1411
+
1412
+ let seed = b"test_payment_preimage" ;
1413
+ let bytes: Sha256Hash = Sha256Hash :: hash ( seed) ;
1414
+ let custom_bytes = bytes. to_byte_array ( ) ;
1415
+ let custom_preimage = PaymentPreimage ( custom_bytes) ;
1416
+
1417
+ let amount_msat = 100_000 ;
1418
+ let payment_id = node_a
1419
+ . spontaneous_payment ( )
1420
+ . send_with_preimage ( amount_msat, node_b. node_id ( ) , None , custom_preimage. clone ( ) )
1421
+ . unwrap ( ) ;
1422
+
1423
+ // check payment status and verify stored preimage
1424
+ expect_payment_successful_event ! ( node_a, Some ( payment_id) , None ) ;
1425
+ let details: PaymentDetails =
1426
+ node_a. list_payments_with_filter ( |p| p. id == payment_id) . first ( ) . unwrap ( ) . clone ( ) ;
1427
+ assert_eq ! ( details. status, PaymentStatus :: Succeeded ) ;
1428
+ if let PaymentKind :: Spontaneous { preimage : Some ( pi) , .. } = details. kind {
1429
+ assert_eq ! ( pi. 0 , custom_bytes) ;
1430
+ } else {
1431
+ panic ! ( "Expected a spontaneous PaymentKind with a preimage" ) ;
1432
+ }
1433
+ }
0 commit comments