11//! A dummy implementation of `TrustedWalletInterface` for testing purposes.
22
3+ use crate :: EventQueue ;
34use crate :: bitcoin:: hashes:: Hash ;
4- use crate :: store:: TxStatus ;
5+ use crate :: store:: { PaymentId , TxStatus } ;
56use crate :: trusted_wallet:: { Payment , TrustedError , TrustedWalletInterface } ;
67use bitcoin_payment_instructions:: PaymentMethod ;
78use bitcoin_payment_instructions:: amount:: Amount ;
@@ -44,7 +45,9 @@ pub struct DummyTrustedWalletExtraConfig {
4445
4546impl DummyTrustedWallet {
4647 /// Creates a new `DummyTrustedWallet` instance.
47- pub ( crate ) async fn new ( uuid : Uuid , lsp : & Node , bitcoind : & Bitcoind , rt : Arc < Runtime > ) -> Self {
48+ pub ( crate ) async fn new (
49+ uuid : Uuid , lsp : & Node , bitcoind : & Bitcoind , event_queue : Arc < EventQueue > , rt : Arc < Runtime > ,
50+ ) -> Self {
4851 let mut builder = ldk_node:: Builder :: new ( ) ;
4952 builder. set_network ( Network :: Regtest ) ;
5053 let mut seed: [ u8 ; 64 ] = [ 0 ; 64 ] ;
@@ -105,7 +108,7 @@ impl DummyTrustedWallet {
105108 bal. fetch_sub ( payment. amount . milli_sats ( ) , Ordering :: SeqCst ) ;
106109 }
107110 } ,
108- Event :: PaymentReceived { payment_id, amount_msat, .. } => {
111+ Event :: PaymentReceived { payment_id, amount_msat, payment_hash , .. } => {
109112 // convert id
110113 let id = payment_id. unwrap ( ) . 0 ;
111114
@@ -128,6 +131,17 @@ impl DummyTrustedWallet {
128131 } ;
129132 payments. push ( new) ;
130133 bal. fetch_add ( amount_msat, Ordering :: SeqCst ) ;
134+
135+ // Send a PaymentReceived event
136+ event_queue
137+ . add_event ( crate :: Event :: PaymentReceived {
138+ payment_id : PaymentId :: Trusted ( id) ,
139+ payment_hash,
140+ amount_msat,
141+ custom_records : vec ! [ ] ,
142+ lsp_fee_msats : None ,
143+ } )
144+ . unwrap ( ) ;
131145 } ,
132146 Event :: PaymentForwarded { .. } => { } ,
133147 Event :: PaymentClaimable { .. } => { } ,
@@ -142,6 +156,14 @@ impl DummyTrustedWallet {
142156 }
143157 } ) ;
144158
159+ // wait for ldk to be ready
160+ for _ in 0 ..10 {
161+ if ldk_node. status ( ) . is_listening {
162+ break ;
163+ }
164+ tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
165+ }
166+
145167 // have LSP open channel to node
146168 lsp. open_channel ( ldk_node. node_id ( ) , socket_addr, 1_000_000 , Some ( 500_000_000 ) , None )
147169 . unwrap ( ) ;
0 commit comments