Add UserConfig::manually_handle_bolt12_invoices
[rust-lightning] / lightning-custom-message / src / lib.rs
index a0a70c9de03ff26dfd499bb7b8cb1dc6eeee8dbe..a0948f23b5fb383d0b82c5156346e5822baa4fdc 100644 (file)
@@ -12,6 +12,7 @@
 //! `Foo` and `Bar` messages, and further composing it with a handler for `Baz` messages.
 //!
 //!```
+//! # fn main() {} // Avoid #[macro_export] generating an in-function warning
 //! # extern crate bitcoin;
 //! extern crate lightning;
 //! #[macro_use]
@@ -19,7 +20,7 @@
 //!
 //! # use bitcoin::secp256k1::PublicKey;
 //! # use lightning::io;
-//! # use lightning::ln::msgs::{DecodeError, LightningError};
+//! # use lightning::ln::msgs::{DecodeError, Init, LightningError};
 //! # use lightning::ln::features::{InitFeatures, NodeFeatures};
 //! use lightning::ln::peer_handler::CustomMessageHandler;
 //! use lightning::ln::wire::{CustomMessageReader, self};
 //! #     fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> {
 //! #         unimplemented!()
 //! #     }
+//! #     fn peer_disconnected(&self, _their_node_id: &PublicKey) {
+//! #         unimplemented!()
+//! #     }
+//! #     fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> {
+//! #         unimplemented!()
+//! #     }
 //! #     fn provided_node_features(&self) -> NodeFeatures {
 //! #         unimplemented!()
 //! #     }
 //! #     fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> {
 //! #         unimplemented!()
 //! #     }
+//! #     fn peer_disconnected(&self, _their_node_id: &PublicKey) {
+//! #         unimplemented!()
+//! #     }
+//! #     fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> {
+//! #         unimplemented!()
+//! #     }
 //! #     fn provided_node_features(&self) -> NodeFeatures {
 //! #         unimplemented!()
 //! #     }
 //! #     fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> {
 //! #         unimplemented!()
 //! #     }
+//! #     fn peer_disconnected(&self, _their_node_id: &PublicKey) {
+//! #         unimplemented!()
+//! #     }
+//! #     fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> {
+//! #         unimplemented!()
+//! #     }
 //! #     fn provided_node_features(&self) -> NodeFeatures {
 //! #         unimplemented!()
 //! #     }
 //! #     }
 //! }
 //!
-//! # fn main() {
 //! // The first crate may define a handler composing `FooHandler` and `BarHandler` and export the
 //! // corresponding message type ids as a macro to use in further composition.
 //!
 //! macro_rules! foo_bar_baz_type_ids {
 //!     () => { foo_bar_type_ids!() | baz_type_id!() }
 //! }
-//! # }
 //!```
 //!
 //! [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
@@ -288,6 +305,22 @@ macro_rules! composite_custom_message_handler {
                                        .collect()
                        }
 
+                       fn peer_disconnected(&self, their_node_id: &$crate::bitcoin::secp256k1::PublicKey) {
+                               $(
+                                       self.$field.peer_disconnected(their_node_id);
+                               )*
+                       }
+
+                       fn peer_connected(&self, their_node_id: &$crate::bitcoin::secp256k1::PublicKey, msg: &$crate::lightning::ln::msgs::Init, inbound: bool) -> Result<(), ()> {
+                               let mut result = Ok(());
+                               $(
+                                       if let Err(e) = self.$field.peer_connected(their_node_id, msg, inbound) {
+                                               result = Err(e);
+                                       }
+                               )*
+                               result
+                       }
+
                        fn provided_node_features(&self) -> $crate::lightning::ln::features::NodeFeatures {
                                $crate::lightning::ln::features::NodeFeatures::empty()
                                        $(