mod bolt1;
mod bolt11;
mod bolt2;
mod bolt4;
mod bolt7;
mod bolt9;
mod types;
use std::io;
use std::ops::Deref;
pub use bolt1::*;
pub use bolt11::*;
pub use bolt2::*;
pub use bolt4::*;
pub use bolt7::*;
pub use bolt9::{
ChannelFeatures, Feature, FeatureContext, InitFeatures, UnknownFeatureError,
};
use internet2::{CreateUnmarshaller, Payload, Unmarshall, Unmarshaller};
use lightning_encoding::{self, LightningDecode, LightningEncode};
use once_cell::sync::Lazy;
pub use types::*;
pub const LNP2P_BOLT_PORT: u16 = 9735;
pub static LNP2P_LEGACY_UNMARSHALLER: Lazy<Unmarshaller<Messages>> =
Lazy::new(Messages::create_unmarshaller);
#[derive(Clone, Debug, Display, Api)]
#[cfg_attr(feature = "strict_encoding", derive(NetworkEncode, NetworkDecode))]
#[api(encoding = "lightning")]
#[non_exhaustive]
#[display(inner)]
#[allow(clippy::large_enum_variant)]
pub enum Messages {
#[api(type = 16)]
Init(Init),
#[api(type = 17)]
Error(Error),
#[api(type = 18)]
Ping(Ping),
#[api(type = 19)]
#[display("pong(...)")]
Pong(Vec<u8>),
#[api(type = 32)]
OpenChannel(OpenChannel),
#[api(type = 33)]
AcceptChannel(AcceptChannel),
#[api(type = 34)]
FundingCreated(FundingCreated),
#[api(type = 35)]
FundingSigned(FundingSigned),
#[api(type = 36)]
FundingLocked(FundingLocked),
#[api(type = 38)]
Shutdown(Shutdown),
#[api(type = 39)]
ClosingSigned(ClosingSigned),
#[api(type = 128)]
UpdateAddHtlc(UpdateAddHtlc),
#[api(type = 130)]
UpdateFulfillHtlc(UpdateFulfillHtlc),
#[api(type = 131)]
UpdateFailHtlc(UpdateFailHtlc),
#[api(type = 135)]
UpdateFailMalformedHtlc(UpdateFailMalformedHtlc),
#[api(type = 132)]
CommitmentSigned(CommitmentSigned),
#[api(type = 133)]
RevokeAndAck(RevokeAndAck),
#[api(type = 134)]
UpdateFee(UpdateFee),
#[api(type = 136)]
ChannelReestablish(ChannelReestablish),
#[api(type = 259)]
AnnouncementSignatures(AnnouncementSignatures),
#[api(type = 256)]
ChannelAnnouncement(ChannelAnnouncement),
#[api(type = 257)]
NodeAnnouncements(NodeAnnouncements),
#[api(type = 258)]
ChannelUpdate(ChannelUpdate),
#[api(type = 261)]
QueryShortChannelIds(QueryShortChannelIds),
#[api(type = 262)]
ReplyShortChannelIdsEnd(ReplyShortChannelIdsEnd),
#[api(type = 263)]
QueryChannelRange(QueryChannelRange),
#[api(type = 264)]
ReplyChannelRange(ReplyChannelRange),
#[api(type = 265)]
GossipTimestampFilter(GossipTimestampFilter),
}
impl LightningEncode for Messages {
fn lightning_encode<E: io::Write>(
&self,
e: E,
) -> Result<usize, lightning_encoding::Error> {
Payload::from(self.clone()).lightning_encode(e)
}
}
impl LightningDecode for Messages {
fn lightning_decode<D: io::Read>(
d: D,
) -> Result<Self, lightning_encoding::Error> {
let message =
LNP2P_LEGACY_UNMARSHALLER.unmarshall(d).map_err(|err| {
lightning_encoding::Error::DataIntegrityError(format!(
"can't unmarshall bolt LNP2P message. Details: {}",
err
))
})?;
Ok(message.deref().clone())
}
}