Skip to content

Commit fd03e49

Browse files
committed
Make OnionMessageContents private for now
This doesn't change the API expressibility as its currently the only type of message that can be sent, but avoids a generation failure as we can't call `&self` methods on complex enums unless we can `clone` all the inner fields. The correct solution to this is to simply not expose those methods (which sucks, but at least for `OnionMessageContents` they don't really matter), but that doesn't have to come now.
1 parent 46a1a8e commit fd03e49

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lightning/src/onion_message/messenger.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,22 @@ impl<Signer: Sign, K: Deref, L: Deref, CMH: Deref> OnionMessenger<Signer, K, L,
198198
}
199199
}
200200

201+
#[cfg(not(c_bindings))]
201202
/// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
202203
/// 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> {
204+
pub fn send_onion_message<T: CustomOnionMessageContents>(&self, intermediate_nodes: &[PublicKey], destination: Destination, msg: OnionMessageContents<T>, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
205+
let OnionMessageContents::Custom(message) = msg;
206+
self.send_custom_onion_message(intermediate_nodes, destination, message, reply_path)
207+
}
208+
209+
/// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
210+
/// See [`OnionMessenger`] for example usage.
211+
pub fn send_custom_onion_message<T: CustomOnionMessageContents>(&self, intermediate_nodes: &[PublicKey], destination: Destination, msg: T, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
204212
if let Destination::BlindedRoute(BlindedRoute { ref blinded_hops, .. }) = destination {
205213
if blinded_hops.len() < 2 {
206214
return Err(SendError::TooFewBlindedHops);
207215
}
208216
}
209-
let OnionMessageContents::Custom(ref msg) = message;
210217
if msg.tlv_type() < 64 { return Err(SendError::InvalidMessage) }
211218

212219
let blinding_secret_bytes = self.keys_manager.get_secure_random_bytes();
@@ -221,7 +228,7 @@ impl<Signer: Sign, K: Deref, L: Deref, CMH: Deref> OnionMessenger<Signer, K, L,
221228
}
222229
};
223230
let (packet_payloads, packet_keys) = packet_payloads_and_keys(
224-
&self.secp_ctx, intermediate_nodes, destination, message, reply_path, &blinding_secret)
231+
&self.secp_ctx, intermediate_nodes, destination, OnionMessageContents::Custom(msg), reply_path, &blinding_secret)
225232
.map_err(|e| SendError::Secp256k1(e))?;
226233

227234
let prng_seed = self.keys_manager.get_secure_random_bytes();

lightning/src/onion_message/packet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub(super) enum Payload<T: CustomOnionMessageContents> {
107107
#[derive(Debug)]
108108
/// The contents of an onion message. In the context of offers, this would be the invoice, invoice
109109
/// request, or invoice error.
110-
pub enum OnionMessageContents<T: CustomOnionMessageContents> {
110+
pub(crate) enum OnionMessageContents<T: CustomOnionMessageContents> {
111111
// Coming soon:
112112
// Invoice,
113113
// InvoiceRequest,

0 commit comments

Comments
 (0)