From: Wilmer Paulino Date: Wed, 2 Nov 2022 23:29:00 +0000 (-0700) Subject: Drop DecoratingEventHandler in favor of inline closure X-Git-Tag: v0.0.113~45^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=9787b28e89d9d988a5c2cc7593a6dde58b00227a;p=rust-lightning Drop DecoratingEventHandler in favor of inline closure --- diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 9e2c7203e..ec7d29256 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -202,39 +202,6 @@ fn handle_network_graph_update( } } -/// Decorates an [`EventHandler`] with common functionality provided by standard [`EventHandler`]s. -struct DecoratingEventHandler< - 'a, - E: EventHandler, - PGS: Deref>, - RGS: Deref>, - G: Deref>, - A: Deref, - L: Deref, -> -where A::Target: chain::Access, L::Target: Logger { - event_handler: E, - gossip_sync: &'a GossipSync, -} - -impl< - 'a, - E: EventHandler, - PGS: Deref>, - RGS: Deref>, - G: Deref>, - A: Deref, - L: Deref, -> EventHandler for DecoratingEventHandler<'a, E, PGS, RGS, G, A, L> -where A::Target: chain::Access, L::Target: Logger { - fn handle_event(&self, event: Event) { - if let Some(network_graph) = self.gossip_sync.network_graph() { - handle_network_graph_update(network_graph, &event) - } - self.event_handler.handle_event(event); - } -} - macro_rules! define_run_body { ($persister: ident, $chain_monitor: ident, $process_chain_monitor_events: expr, $channel_manager: ident, $process_channel_manager_events: expr, @@ -536,9 +503,12 @@ impl BackgroundProcessor { let stop_thread = Arc::new(AtomicBool::new(false)); let stop_thread_clone = stop_thread.clone(); let handle = thread::spawn(move || -> Result<(), std::io::Error> { - let event_handler = DecoratingEventHandler { - event_handler, - gossip_sync: &gossip_sync, + let event_handler = |event| { + let network_graph = gossip_sync.network_graph(); + if let Some(network_graph) = network_graph { + handle_network_graph_update(network_graph, &event) + } + event_handler.handle_event(event); }; define_run_body!(persister, chain_monitor, chain_monitor.process_pending_events(&event_handler), channel_manager, channel_manager.process_pending_events(&event_handler),