@@ -263,20 +263,22 @@ pub struct ChainMonitor<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F
263
263
264
264
/// A synchronous wrapper around [`ChainMonitor`].
265
265
pub struct ChainMonitorSync<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, FS: FutureSpawner>
266
- (ChainMonitor<ChannelSigner, C, T, F, L, P , FS>) where C::Target: chain::Filter,
266
+ (ChainMonitor<ChannelSigner, C, T, F, L, PersistSyncWrapper<P> , FS>) where C::Target: chain::Filter,
267
267
T::Target: BroadcasterInterface,
268
268
F::Target: FeeEstimator,
269
269
L::Target: Logger,
270
- P::Target: Persist <ChannelSigner>;
270
+ P::Target: PersistSync <ChannelSigner>;
271
271
272
272
impl<ChannelSigner: EcdsaChannelSigner + 'static, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, FS: FutureSpawner> ChainMonitorSync<ChannelSigner, C, T, F, L, P, FS>
273
273
where C::Target: chain::Filter,
274
274
T::Target: BroadcasterInterface,
275
275
F::Target: FeeEstimator,
276
276
L::Target: Logger,
277
- P::Target: Persist <ChannelSigner> {
277
+ P::Target: PersistSync <ChannelSigner> {
278
278
279
279
fn new(chain_source: Option<C>, broadcaster: T, logger: L, feeest: F, persister: P, future_spawner: FS) -> Self {
280
+ let persister = PersistSyncWrapper(persister);
281
+
280
282
Self(ChainMonitor::new(chain_source, broadcaster, logger, feeest, persister, future_spawner))
281
283
}
282
284
}
@@ -1022,6 +1024,48 @@ impl<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref,
1022
1024
}
1023
1025
}
1024
1026
1027
+ /// A synchronous version of [`Persist`].
1028
+ pub trait PersistSync<ChannelSigner: EcdsaChannelSigner> {
1029
+ /// A synchronous version of [`Persist::persist_new_channel`].
1030
+ fn persist_new_channel(&self, monitor_name: MonitorName, monitor: &ChannelMonitor<ChannelSigner>) -> Result<(), ()>;
1031
+
1032
+ /// A synchronous version of [`Persist::update_persisted_channel`].
1033
+ fn update_persisted_channel(&self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>, monitor: &ChannelMonitor<ChannelSigner>) -> Result<(), ()>;
1034
+
1035
+ /// A synchronous version of [`Persist::archive_persisted_channel`].
1036
+ fn archive_persisted_channel(&self, monitor_name: MonitorName);
1037
+ }
1038
+
1039
+ struct PersistSyncWrapper<P: Deref>(P);
1040
+
1041
+ impl<T: Deref> Deref for PersistSyncWrapper<T> {
1042
+ type Target = Self;
1043
+ fn deref(&self) -> &Self { self }
1044
+ }
1045
+
1046
+ impl<ChannelSigner: EcdsaChannelSigner, P: Deref> Persist<ChannelSigner> for PersistSyncWrapper<P> where P::Target: PersistSync<ChannelSigner> {
1047
+ fn persist_new_channel(&self, monitor_name: MonitorName, monitor: &ChannelMonitor<ChannelSigner>) -> AsyncResult<'static, ()> {
1048
+ let res = self.0.persist_new_channel(monitor_name, monitor);
1049
+
1050
+ Box::pin(async move {
1051
+ res
1052
+ })
1053
+ }
1054
+
1055
+ fn update_persisted_channel(&self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>, monitor: &ChannelMonitor<ChannelSigner>)-> AsyncResult<'static, ()>{
1056
+ let res = self.0.update_persisted_channel(monitor_name, monitor_update, monitor);
1057
+ Box::pin(async move {
1058
+ res
1059
+ })
1060
+ }
1061
+
1062
+ fn archive_persisted_channel(&self, monitor_name: MonitorName) -> AsyncVoid {
1063
+ self.0.archive_persisted_channel(monitor_name);
1064
+
1065
+ Box::pin(async move {})
1066
+ }
1067
+ }
1068
+
1025
1069
#[cfg(test)]
1026
1070
mod tests {
1027
1071
use crate::{check_added_monitors, check_closed_event};
0 commit comments