@@ -38,6 +38,7 @@ use crate::sync::{Arc, Mutex, RwLock};
38
38
use crate :: utils:: time:: DefaultTimeProvider ;
39
39
use crate :: utils:: time:: TimeProvider ;
40
40
41
+ use lightning:: chain:: chaininterface:: BroadcasterInterface ;
41
42
use lightning:: chain:: { self , BestBlock , Confirm , Filter , Listen } ;
42
43
use lightning:: ln:: channelmanager:: { AChannelManager , ChainParameters } ;
43
44
use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
@@ -112,8 +113,13 @@ pub trait ALiquidityManager {
112
113
type TimeProvider : TimeProvider + ?Sized ;
113
114
/// A type that may be dereferenced to [`Self::TimeProvider`].
114
115
type TP : Deref < Target = Self :: TimeProvider > + Clone ;
116
+ /// A type implementing [`BroadcasterInterface`].
117
+ type BroadcasterInterface : BroadcasterInterface + ?Sized ;
118
+ /// A type that may be dereferenced to [`Self::BroadcasterInterface`].
119
+ type T : Deref < Target = Self :: BroadcasterInterface > + Clone ;
115
120
/// Returns a reference to the actual [`LiquidityManager`] object.
116
- fn get_lm ( & self ) -> & LiquidityManager < Self :: ES , Self :: NS , Self :: CM , Self :: C , Self :: TP > ;
121
+ fn get_lm ( & self )
122
+ -> & LiquidityManager < Self :: ES , Self :: NS , Self :: CM , Self :: C , Self :: TP , Self :: T > ;
117
123
}
118
124
119
125
impl <
@@ -122,13 +128,15 @@ impl<
122
128
CM : Deref + Clone ,
123
129
C : Deref + Clone ,
124
130
TP : Deref + Clone ,
125
- > ALiquidityManager for LiquidityManager < ES , NS , CM , C , TP >
131
+ T : Deref + Clone ,
132
+ > ALiquidityManager for LiquidityManager < ES , NS , CM , C , TP , T >
126
133
where
127
134
ES :: Target : EntropySource ,
128
135
NS :: Target : NodeSigner ,
129
136
CM :: Target : AChannelManager ,
130
137
C :: Target : Filter ,
131
138
TP :: Target : TimeProvider ,
139
+ T :: Target : BroadcasterInterface ,
132
140
{
133
141
type EntropySource = ES :: Target ;
134
142
type ES = ES ;
@@ -140,7 +148,9 @@ where
140
148
type C = C ;
141
149
type TimeProvider = TP :: Target ;
142
150
type TP = TP ;
143
- fn get_lm ( & self ) -> & LiquidityManager < ES , NS , CM , C , TP > {
151
+ type BroadcasterInterface = T :: Target ;
152
+ type T = T ;
153
+ fn get_lm ( & self ) -> & LiquidityManager < ES , NS , CM , C , TP , T > {
144
154
self
145
155
}
146
156
}
@@ -170,12 +180,14 @@ pub struct LiquidityManager<
170
180
CM : Deref + Clone ,
171
181
C : Deref + Clone ,
172
182
TP : Deref + Clone ,
183
+ T : Deref + Clone ,
173
184
> where
174
185
ES :: Target : EntropySource ,
175
186
NS :: Target : NodeSigner ,
176
187
CM :: Target : AChannelManager ,
177
188
C :: Target : Filter ,
178
189
TP :: Target : TimeProvider ,
190
+ T :: Target : BroadcasterInterface ,
179
191
{
180
192
pending_messages : Arc < MessageQueue > ,
181
193
pending_events : Arc < EventQueue > ,
@@ -187,7 +199,7 @@ pub struct LiquidityManager<
187
199
#[ cfg( lsps1_service) ]
188
200
lsps1_service_handler : Option < LSPS1ServiceHandler < ES , CM , C > > ,
189
201
lsps1_client_handler : Option < LSPS1ClientHandler < ES > > ,
190
- lsps2_service_handler : Option < LSPS2ServiceHandler < CM > > ,
202
+ lsps2_service_handler : Option < LSPS2ServiceHandler < CM , T > > ,
191
203
lsps2_client_handler : Option < LSPS2ClientHandler < ES > > ,
192
204
lsps5_service_handler : Option < LSPS5ServiceHandler < CM , NS , TP > > ,
193
205
lsps5_client_handler : Option < LSPS5ClientHandler < ES > > ,
@@ -198,25 +210,33 @@ pub struct LiquidityManager<
198
210
}
199
211
200
212
#[ cfg( feature = "time" ) ]
201
- impl < ES : Deref + Clone , NS : Deref + Clone , CM : Deref + Clone , C : Deref + Clone >
202
- LiquidityManager < ES , NS , CM , C , Arc < DefaultTimeProvider > >
213
+ impl <
214
+ ES : Deref + Clone ,
215
+ NS : Deref + Clone ,
216
+ CM : Deref + Clone ,
217
+ C : Deref + Clone ,
218
+ T : Deref + Clone ,
219
+ > LiquidityManager < ES , NS , CM , C , Arc < DefaultTimeProvider > , T >
203
220
where
204
221
ES :: Target : EntropySource ,
205
222
NS :: Target : NodeSigner ,
206
223
CM :: Target : AChannelManager ,
207
224
C :: Target : Filter ,
225
+ T :: Target : BroadcasterInterface ,
208
226
{
209
227
/// Constructor for the [`LiquidityManager`] using the default system clock
210
228
pub fn new (
211
229
entropy_source : ES , node_signer : NS , channel_manager : CM , chain_source : Option < C > ,
212
- chain_params : Option < ChainParameters > , service_config : Option < LiquidityServiceConfig > ,
230
+ transaction_broadcaster : T , chain_params : Option < ChainParameters > ,
231
+ service_config : Option < LiquidityServiceConfig > ,
213
232
client_config : Option < LiquidityClientConfig > ,
214
233
) -> Self {
215
234
let time_provider = Arc :: new ( DefaultTimeProvider ) ;
216
235
Self :: new_with_custom_time_provider (
217
236
entropy_source,
218
237
node_signer,
219
238
channel_manager,
239
+ transaction_broadcaster,
220
240
chain_source,
221
241
chain_params,
222
242
service_config,
@@ -232,13 +252,15 @@ impl<
232
252
CM : Deref + Clone ,
233
253
C : Deref + Clone ,
234
254
TP : Deref + Clone ,
235
- > LiquidityManager < ES , NS , CM , C , TP >
255
+ T : Deref + Clone ,
256
+ > LiquidityManager < ES , NS , CM , C , TP , T >
236
257
where
237
258
ES :: Target : EntropySource ,
238
259
NS :: Target : NodeSigner ,
239
260
CM :: Target : AChannelManager ,
240
261
C :: Target : Filter ,
241
262
TP :: Target : TimeProvider ,
263
+ T :: Target : BroadcasterInterface ,
242
264
{
243
265
/// Constructor for the [`LiquidityManager`] with a custom time provider.
244
266
///
@@ -247,8 +269,9 @@ where
247
269
/// Sets up the required protocol message handlers based on the given
248
270
/// [`LiquidityClientConfig`] and [`LiquidityServiceConfig`].
249
271
pub fn new_with_custom_time_provider (
250
- entropy_source : ES , node_signer : NS , channel_manager : CM , chain_source : Option < C > ,
251
- chain_params : Option < ChainParameters > , service_config : Option < LiquidityServiceConfig > ,
272
+ entropy_source : ES , node_signer : NS , channel_manager : CM , transaction_broadcaster : T ,
273
+ chain_source : Option < C > , chain_params : Option < ChainParameters > ,
274
+ service_config : Option < LiquidityServiceConfig > ,
252
275
client_config : Option < LiquidityClientConfig > , time_provider : TP ,
253
276
) -> Self {
254
277
let pending_messages = Arc :: new ( MessageQueue :: new ( ) ) ;
@@ -270,14 +293,15 @@ where
270
293
let lsps2_service_handler = service_config. as_ref ( ) . and_then ( |config| {
271
294
config. lsps2_service_config . as_ref ( ) . map ( |config| {
272
295
if let Some ( number) =
273
- <LSPS2ServiceHandler < CM > as LSPSProtocolMessageHandler >:: PROTOCOL_NUMBER
296
+ <LSPS2ServiceHandler < CM , T > as LSPSProtocolMessageHandler >:: PROTOCOL_NUMBER
274
297
{
275
298
supported_protocols. push ( number) ;
276
299
}
277
300
LSPS2ServiceHandler :: new (
278
301
Arc :: clone ( & pending_messages) ,
279
302
Arc :: clone ( & pending_events) ,
280
303
channel_manager. clone ( ) ,
304
+ transaction_broadcaster,
281
305
config. clone ( ) ,
282
306
)
283
307
} )
@@ -412,7 +436,7 @@ where
412
436
/// Returns a reference to the LSPS2 server-side handler.
413
437
///
414
438
/// The returned hendler allows to initiate the LSPS2 service-side flow.
415
- pub fn lsps2_service_handler ( & self ) -> Option < & LSPS2ServiceHandler < CM > > {
439
+ pub fn lsps2_service_handler ( & self ) -> Option < & LSPS2ServiceHandler < CM , T > > {
416
440
self . lsps2_service_handler . as_ref ( )
417
441
}
418
442
@@ -586,13 +610,15 @@ impl<
586
610
CM : Deref + Clone ,
587
611
C : Deref + Clone ,
588
612
TP : Deref + Clone ,
589
- > CustomMessageReader for LiquidityManager < ES , NS , CM , C , TP >
613
+ T : Deref + Clone ,
614
+ > CustomMessageReader for LiquidityManager < ES , NS , CM , C , TP , T >
590
615
where
591
616
ES :: Target : EntropySource ,
592
617
NS :: Target : NodeSigner ,
593
618
CM :: Target : AChannelManager ,
594
619
C :: Target : Filter ,
595
620
TP :: Target : TimeProvider ,
621
+ T :: Target : BroadcasterInterface ,
596
622
{
597
623
type CustomMessage = RawLSPSMessage ;
598
624
@@ -614,13 +640,15 @@ impl<
614
640
CM : Deref + Clone ,
615
641
C : Deref + Clone ,
616
642
TP : Deref + Clone ,
617
- > CustomMessageHandler for LiquidityManager < ES , NS , CM , C , TP >
643
+ T : Deref + Clone ,
644
+ > CustomMessageHandler for LiquidityManager < ES , NS , CM , C , TP , T >
618
645
where
619
646
ES :: Target : EntropySource ,
620
647
NS :: Target : NodeSigner ,
621
648
CM :: Target : AChannelManager ,
622
649
C :: Target : Filter ,
623
650
TP :: Target : TimeProvider ,
651
+ T :: Target : BroadcasterInterface ,
624
652
{
625
653
fn handle_custom_message (
626
654
& self , msg : Self :: CustomMessage , sender_node_id : PublicKey ,
@@ -744,13 +772,15 @@ impl<
744
772
CM : Deref + Clone ,
745
773
C : Deref + Clone ,
746
774
TP : Deref + Clone ,
747
- > Listen for LiquidityManager < ES , NS , CM , C , TP >
775
+ T : Deref + Clone ,
776
+ > Listen for LiquidityManager < ES , NS , CM , C , TP , T >
748
777
where
749
778
ES :: Target : EntropySource ,
750
779
NS :: Target : NodeSigner ,
751
780
CM :: Target : AChannelManager ,
752
781
C :: Target : Filter ,
753
782
TP :: Target : TimeProvider ,
783
+ T :: Target : BroadcasterInterface ,
754
784
{
755
785
fn filtered_block_connected (
756
786
& self , header : & bitcoin:: block:: Header , txdata : & chain:: transaction:: TransactionData ,
@@ -789,13 +819,15 @@ impl<
789
819
CM : Deref + Clone ,
790
820
C : Deref + Clone ,
791
821
TP : Deref + Clone ,
792
- > Confirm for LiquidityManager < ES , NS , CM , C , TP >
822
+ T : Deref + Clone ,
823
+ > Confirm for LiquidityManager < ES , NS , CM , C , TP , T >
793
824
where
794
825
ES :: Target : EntropySource ,
795
826
NS :: Target : NodeSigner ,
796
827
CM :: Target : AChannelManager ,
797
828
C :: Target : Filter ,
798
829
TP :: Target : TimeProvider ,
830
+ T :: Target : BroadcasterInterface ,
799
831
{
800
832
fn transactions_confirmed (
801
833
& self , _header : & bitcoin:: block:: Header , _txdata : & chain:: transaction:: TransactionData ,
0 commit comments