Use utility methods to construct `HashMap`s and `HashSet`s
[rust-lightning] / lightning / src / onion_message / messenger.rs
index 812429f907d133b8ac67b7602e0cc9a8ba6e37f2..65b8110fb046995ed304261d4d90c9246a67eefe 100644 (file)
@@ -20,8 +20,6 @@ use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, ReceiveTlvs
 use crate::blinded_path::utils;
 use crate::events::{Event, EventHandler, EventsProvider};
 use crate::sign::{EntropySource, NodeSigner, Recipient};
-#[cfg(not(c_bindings))]
-use crate::ln::channelmanager::{SimpleArcChannelManager, SimpleRefChannelManager};
 use crate::ln::features::{InitFeatures, NodeFeatures};
 use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress};
 use crate::ln::onion_utils;
@@ -42,6 +40,7 @@ use crate::prelude::*;
 #[cfg(not(c_bindings))]
 use {
        crate::sign::KeysManager,
+       crate::ln::channelmanager::{SimpleArcChannelManager, SimpleRefChannelManager},
        crate::ln::peer_handler::IgnoringMessageHandler,
        crate::sync::Arc,
 };
@@ -705,7 +704,7 @@ where
                OnionMessenger {
                        entropy_source,
                        node_signer,
-                       message_recipients: Mutex::new(HashMap::new()),
+                       message_recipients: Mutex::new(new_hash_map()),
                        secp_ctx,
                        logger,
                        message_router,
@@ -714,6 +713,11 @@ where
                }
        }
 
+       #[cfg(test)]
+       pub(crate) fn set_offers_handler(&mut self, offers_handler: OMH) {
+               self.offers_handler = offers_handler;
+       }
+
        /// Sends an [`OnionMessage`] with the given `contents` to `destination`.
        ///
        /// See [`OnionMessenger`] for example usage.
@@ -842,7 +846,7 @@ where
        #[cfg(test)]
        pub(super) fn release_pending_msgs(&self) -> HashMap<PublicKey, VecDeque<OnionMessage>> {
                let mut message_recipients = self.message_recipients.lock().unwrap();
-               let mut msgs = HashMap::new();
+               let mut msgs = new_hash_map();
                // We don't want to disconnect the peers by removing them entirely from the original map, so we
                // release the pending message buffers individually.
                for (node_id, recipient) in &mut *message_recipients {