@@ -29,6 +29,7 @@ use crate::error::MutinyError;
29
29
use crate :: fees:: MutinyFeeEstimator ;
30
30
use crate :: labels:: * ;
31
31
use crate :: logging:: MutinyLogger ;
32
+ use crate :: messagehandler:: { CommonLnEvent , CommonLnEventCallback } ;
32
33
use crate :: storage:: {
33
34
IndexItem , MutinyStorage , KEYCHAIN_STORE_KEY , NEED_FULL_SYNC_KEY , ONCHAIN_PREFIX ,
34
35
} ;
@@ -48,9 +49,11 @@ pub struct OnChainWallet<S: MutinyStorage> {
48
49
pub fees : Arc < MutinyFeeEstimator < S > > ,
49
50
pub ( crate ) stop : Arc < AtomicBool > ,
50
51
logger : Arc < MutinyLogger > ,
52
+ ln_event_callback : Option < CommonLnEventCallback > ,
51
53
}
52
54
53
55
impl < S : MutinyStorage > OnChainWallet < S > {
56
+ #[ allow( clippy:: too_many_arguments) ]
54
57
pub fn new (
55
58
xprivkey : Xpriv ,
56
59
db : S ,
@@ -59,6 +62,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
59
62
fees : Arc < MutinyFeeEstimator < S > > ,
60
63
stop : Arc < AtomicBool > ,
61
64
logger : Arc < MutinyLogger > ,
65
+ ln_event_callback : Option < CommonLnEventCallback > ,
62
66
) -> Result < OnChainWallet < S > , MutinyError > {
63
67
let account_number = 0 ;
64
68
let ( receive_descriptor_template, change_descriptor_template) =
@@ -115,6 +119,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
115
119
fees,
116
120
stop,
117
121
logger,
122
+ ln_event_callback,
118
123
} )
119
124
}
120
125
@@ -130,7 +135,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
130
135
) ) ) ;
131
136
} else if let Err ( e) = self
132
137
. insert_tx (
133
- tx,
138
+ tx. clone ( ) ,
134
139
ConfirmationTime :: Unconfirmed {
135
140
last_seen : now ( ) . as_secs ( ) ,
136
141
} ,
@@ -141,6 +146,15 @@ impl<S: MutinyStorage> OnChainWallet<S> {
141
146
log_warn ! ( self . logger, "ERROR: Could not sync broadcasted tx ({txid}), will be synced in next iteration: {e:?}" ) ;
142
147
}
143
148
149
+ if let Some ( cb) = self . ln_event_callback . as_ref ( ) {
150
+ let event = CommonLnEvent :: TxBroadcasted {
151
+ txid : format ! ( "{:x}" , txid) ,
152
+ hex_tx : bitcoin:: consensus:: encode:: serialize_hex ( & tx) ,
153
+ } ;
154
+ cb. trigger ( event) ;
155
+ log_debug ! ( self . logger, "Triggered TxBroadcasted event" ) ;
156
+ }
157
+
144
158
Ok ( ( ) )
145
159
}
146
160
@@ -912,7 +926,17 @@ mod tests {
912
926
let stop = Arc :: new ( AtomicBool :: new ( false ) ) ;
913
927
let xpriv = Xpriv :: new_master ( Network :: Testnet , & mnemonic. to_seed ( "" ) ) . unwrap ( ) ;
914
928
915
- OnChainWallet :: new ( xpriv, db, Network :: Testnet , esplora, fees, stop, logger) . unwrap ( )
929
+ OnChainWallet :: new (
930
+ xpriv,
931
+ db,
932
+ Network :: Testnet ,
933
+ esplora,
934
+ fees,
935
+ stop,
936
+ logger,
937
+ None ,
938
+ )
939
+ . unwrap ( )
916
940
}
917
941
918
942
#[ test]
0 commit comments