@@ -47,7 +47,7 @@ use crate::prelude::*;
4747/// # use lightning::ln::msgs::DecodeError;
4848/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
4949/// # use lightning::onion_message::messenger::{Destination, OnionMessenger};
50- /// # use lightning::onion_message::packet::{ CustomOnionMessageContents, OnionMessageContents} ;
50+ /// # use lightning::onion_message::packet::CustomOnionMessageContents;
5151/// # use lightning::onion_message::blinded_route::BlindedRoute;
5252/// # use lightning::util::logger::{Logger, Record};
5353/// # use lightning::util::ser::{Writeable, Writer};
@@ -88,8 +88,7 @@ use crate::prelude::*;
8888/// let intermediate_hops = [hop_node_id1, hop_node_id2];
8989/// let reply_path = None;
9090/// # let your_custom_message = YourCustomMessage {};
91- /// let message = OnionMessageContents::Custom(your_custom_message);
92- /// onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id), message, reply_path);
91+ /// onion_messenger.send_custom_onion_message(&intermediate_hops, Destination::Node(destination_node_id), your_custom_message, reply_path);
9392///
9493/// // Create a blinded route to yourself, for someone to send an onion message to.
9594/// # let your_node_id = hop_node_id1;
@@ -100,8 +99,7 @@ use crate::prelude::*;
10099/// # let intermediate_hops = [hop_node_id1, hop_node_id2];
101100/// let reply_path = None;
102101/// # let your_custom_message = YourCustomMessage {};
103- /// let message = OnionMessageContents::Custom(your_custom_message);
104- /// onion_messenger.send_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), message, reply_path);
102+ /// onion_messenger.send_custom_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), your_custom_message, reply_path);
105103/// ```
106104///
107105/// [offers]: <https://github.com/lightning/bolts/pull/798>
@@ -139,7 +137,7 @@ impl Destination {
139137
140138/// Errors that may occur when [sending an onion message].
141139///
142- /// [sending an onion message]: OnionMessenger::send_onion_message
140+ /// [sending an onion message]: OnionMessenger::send_custom_onion_message
143141#[ derive( Debug , PartialEq , Eq ) ]
144142pub enum SendError {
145143 /// Errored computing onion message packet keys.
@@ -200,13 +198,19 @@ impl<Signer: Sign, K: Deref, L: Deref, CMH: Deref> OnionMessenger<Signer, K, L,
200198
201199 /// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
202200 /// See [`OnionMessenger`] for example usage.
203- pub fn send_onion_message < T : CustomOnionMessageContents > ( & self , intermediate_nodes : & [ PublicKey ] , destination : Destination , message : OnionMessageContents < T > , reply_path : Option < BlindedRoute > ) -> Result < ( ) , SendError > {
201+ pub ( crate ) fn send_onion_message < T : CustomOnionMessageContents > ( & self , intermediate_nodes : & [ PublicKey ] , destination : Destination , msg : OnionMessageContents < T > , reply_path : Option < BlindedRoute > ) -> Result < ( ) , SendError > {
202+ let OnionMessageContents :: Custom ( message) = msg;
203+ self . send_custom_onion_message ( intermediate_nodes, destination, message, reply_path)
204+ }
205+
206+ /// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
207+ /// See [`OnionMessenger`] for example usage.
208+ pub fn send_custom_onion_message < T : CustomOnionMessageContents > ( & self , intermediate_nodes : & [ PublicKey ] , destination : Destination , msg : T , reply_path : Option < BlindedRoute > ) -> Result < ( ) , SendError > {
204209 if let Destination :: BlindedRoute ( BlindedRoute { ref blinded_hops, .. } ) = destination {
205210 if blinded_hops. len ( ) < 2 {
206211 return Err ( SendError :: TooFewBlindedHops ) ;
207212 }
208213 }
209- let OnionMessageContents :: Custom ( ref msg) = message;
210214 if msg. tlv_type ( ) < 64 { return Err ( SendError :: InvalidMessage ) }
211215
212216 let blinding_secret_bytes = self . keys_manager . get_secure_random_bytes ( ) ;
@@ -221,7 +225,7 @@ impl<Signer: Sign, K: Deref, L: Deref, CMH: Deref> OnionMessenger<Signer, K, L,
221225 }
222226 } ;
223227 let ( packet_payloads, packet_keys) = packet_payloads_and_keys (
224- & self . secp_ctx , intermediate_nodes, destination, message , reply_path, & blinding_secret)
228+ & self . secp_ctx , intermediate_nodes, destination, OnionMessageContents :: Custom ( msg ) , reply_path, & blinding_secret)
225229 . map_err ( |e| SendError :: Secp256k1 ( e) ) ?;
226230
227231 let prng_seed = self . keys_manager . get_secure_random_bytes ( ) ;
0 commit comments