1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 //! High level lightning structs and impls live here.
12 //! You probably want to create a channelmanager::ChannelManager, and a routing::NetGraphMsgHandler first.
13 //! Then, you probably want to pass them both on to a peer_handler::PeerManager and use that to
14 //! create/manage connections and call get_and_clear_pending_events after each action, handling
15 //! them appropriately.
17 //! When you want to open/close a channel or send a payment, call into your ChannelManager and when
18 //! you want to learn things about the network topology (eg get a route for sending a payment),
19 //! call into your NetGraphMsgHandler.
21 #[cfg(any(test, feature = "_test_utils"))]
23 pub mod functional_test_utils;
25 pub mod channelmanager;
26 pub mod inbound_payment;
34 pub mod peer_channel_encryptor;
36 pub(crate) mod peer_channel_encryptor;
41 pub(crate) mod channel;
46 // Older rustc (which we support) refuses to let us call the get_payment_preimage_hash!() macro
47 // without the node parameter being mut. This is incorrect, and thus newer rustcs will complain
48 // about an unnecessary mut. Thus, we silence the unused_mut warning in two test modules below.
58 mod priv_short_conf_tests;
61 mod chanmon_update_fail_tests;
67 mod onion_route_tests;
75 pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
77 /// payment_hash type, use to cross-lock hop
78 /// (C-not exported) as we just use [u8; 32] directly
79 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
80 pub struct PaymentHash(pub [u8;32]);
81 /// payment_preimage type, use to route payment between hop
82 /// (C-not exported) as we just use [u8; 32] directly
83 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
84 pub struct PaymentPreimage(pub [u8;32]);
85 /// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
86 /// (C-not exported) as we just use [u8; 32] directly
87 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
88 pub struct PaymentSecret(pub [u8;32]);
92 use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5};
94 impl FromBase32 for PaymentSecret {
95 type Err = bech32::Error;
97 fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, bech32::Error> {
98 if field_data.len() != 52 {
99 return Err(bech32::Error::InvalidLength)
101 let data_bytes = Vec::<u8>::from_base32(field_data)?;
102 let mut payment_secret = [0; 32];
103 payment_secret.copy_from_slice(&data_bytes);
104 Ok(PaymentSecret(payment_secret))
109 impl ToBase32 for PaymentSecret {
110 fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
111 (&self.0[..]).write_base32(writer)
115 impl Base32Len for PaymentSecret {
116 fn base32_len(&self) -> usize {