}
}
+#[derive(Debug)]
struct TestCustomMessage {}
const CUSTOM_MESSAGE_TYPE: u64 = 4242;
{
let log_entries = logger.lines.lock().unwrap();
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
- "Received an onion message with path_id None and a reply_path".to_string())), Some(&1));
+ "Received an onion message with path_id None and a reply_path: Custom(TestCustomMessage)"
+ .to_string())), Some(&1));
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
- "Sending onion message when responding to Custom onion message with path_id None".to_string())), Some(&1));
+ "Sending onion message: TestCustomMessage".to_string())), Some(&1));
}
let two_unblinded_hops_om = "\
self.contents.verify(TlvStream::new(&self.bytes), key, secp_ctx)
}
- #[cfg(test)]
- pub(super) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
+ pub(crate) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
let (payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream) =
self.contents.as_tlv_stream();
let signature_tlv_stream = SignatureTlvStreamRef {
type FullInvoiceTlvStream =
(PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, InvoiceTlvStream, SignatureTlvStream);
-#[cfg(test)]
type FullInvoiceTlvStreamRef<'a> = (
PayerTlvStreamRef<'a>,
OfferTlvStreamRef<'a>,
})
}
- #[cfg(test)]
- fn as_tlv_stream(&self) -> FullInvoiceRequestTlvStreamRef {
+ pub(crate) fn as_tlv_stream(&self) -> FullInvoiceRequestTlvStreamRef {
let (payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream) =
self.contents.as_tlv_stream();
let signature_tlv_stream = SignatureTlvStreamRef {
type FullInvoiceRequestTlvStream =
(PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, SignatureTlvStream);
-#[cfg(test)]
type FullInvoiceRequestTlvStreamRef<'a> = (
PayerTlvStreamRef<'a>,
OfferTlvStreamRef<'a>,
fn invalid_custom_message_type() {
let nodes = create_nodes(2);
+ #[derive(Debug)]
struct InvalidCustomMessage{}
impl OnionMessageContents for InvalidCustomMessage {
fn tlv_type(&self) -> u64 {
/// # use std::sync::Arc;
/// # struct FakeLogger;
/// # impl Logger for FakeLogger {
-/// # fn log(&self, record: Record) { unimplemented!() }
+/// # fn log(&self, record: Record) { println!("{:?}" , record); }
/// # }
/// # struct FakeMessageRouter {}
/// # impl MessageRouter for FakeMessageRouter {
/// &keys_manager, &keys_manager, logger, message_router, &offers_message_handler,
/// &custom_message_handler
/// );
-///
+
+/// # #[derive(Debug)]
/// # struct YourCustomMessage {}
/// impl Writeable for YourCustomMessage {
/// fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
pub fn send_onion_message<T: OnionMessageContents>(
&self, path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>
) -> Result<(), SendError> {
+
+ log_trace!(self.logger, "Sending onion message: {:?}", contents);
+
let (first_node_id, onion_msg) = create_onion_message(
&self.entropy_source, &self.node_signer, &self.secp_ctx, path, contents, reply_path
)?;
},
};
- log_trace!(self.logger, "Sending onion message {}", log_suffix);
+ log_trace!(self.logger, "Sending onion message {}: {:?}", log_suffix, contents);
if let Err(e) = self.send_onion_message(path, contents, reply_path) {
log_trace!(self.logger, "Failed sending onion message {}: {:?}", log_suffix, e);
msg, &self.secp_ctx, &*self.node_signer, &*self.logger, &*self.custom_handler
) {
Ok(PeeledOnion::Receive(message, path_id, reply_path)) => {
- log_trace!(self.logger,
- "Received an onion message with path_id {:02x?} and {} reply_path",
- path_id, if reply_path.is_some() { "a" } else { "no" });
+ log_trace!(
+ self.logger,
+ "Received an onion message with path_id {:02x?} and {} reply_path: {:?}",
+ path_id, if reply_path.is_some() { "a" } else { "no" }, message);
match message {
ParsedOnionMessageContents::Offers(msg) => {
//! Message handling for BOLT 12 Offers.
use core::convert::TryFrom;
+use core::fmt;
use crate::io::{self, Read};
use crate::ln::msgs::DecodeError;
use crate::offers::invoice_error::InvoiceError;
/// Possible BOLT 12 Offers messages sent and received via an [`OnionMessage`].
///
/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
-#[derive(Clone, Debug)]
+#[derive(Clone)]
pub enum OffersMessage {
/// A request for a [`Bolt12Invoice`] for a particular [`Offer`].
///
}
}
+impl fmt::Debug for OffersMessage {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ OffersMessage::InvoiceRequest(message) => {
+ write!(f, "{:?}", message.as_tlv_stream())
+ }
+ OffersMessage::Invoice(message) => {
+ write!(f, "{:?}", message.as_tlv_stream())
+ }
+ OffersMessage::InvoiceError(message) => {
+ write!(f, "{:?}", message)
+ }
+ }
+ }
+}
+
impl OnionMessageContents for OffersMessage {
fn tlv_type(&self) -> u64 {
match self {
}
/// The contents of an onion message.
-pub trait OnionMessageContents: Writeable {
+pub trait OnionMessageContents: Writeable + core::fmt::Debug {
/// Returns the TLV type identifying the message contents. MUST be >= 64.
fn tlv_type(&self) -> u64;
}
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
- pub(super) struct $nameref<'a> {
+ pub(crate) struct $nameref<'a> {
$(
pub(super) $field: Option<tlv_record_ref_type!($fieldty)>,
)*