+ fn node_features(&self) -> Option<NodeFeatures> {
+ match self {
+ Self::Clear { features, .. } => features.as_ref().map(|f| f.to_context()),
+ Self::Blinded { features, .. } => features.as_ref().map(|f| f.to_context()),
+ }
+ }
+ fn supports_basic_mpp(&self) -> bool {
+ match self {
+ Self::Clear { features, .. } => features.as_ref().map_or(false, |f| f.supports_basic_mpp()),
+ Self::Blinded { features, .. } => features.as_ref().map_or(false, |f| f.supports_basic_mpp()),
+ }
+ }
+ fn features(&self) -> Option<FeaturesRef> {
+ match self {
+ Self::Clear { features, .. } => features.as_ref().map(|f| FeaturesRef::Bolt11(f)),
+ Self::Blinded { features, .. } => features.as_ref().map(|f| FeaturesRef::Bolt12(f)),
+ }
+ }
+ fn final_cltv_expiry_delta(&self) -> Option<u32> {
+ match self {
+ Self::Clear { final_cltv_expiry_delta, .. } => Some(*final_cltv_expiry_delta),
+ _ => None,
+ }
+ }
+}
+
+enum FeaturesRef<'a> {
+ Bolt11(&'a InvoiceFeatures),
+ Bolt12(&'a Bolt12InvoiceFeatures),
+}
+enum Features {
+ Bolt11(InvoiceFeatures),
+ Bolt12(Bolt12InvoiceFeatures),
+}
+
+impl Features {
+ fn bolt12(self) -> Option<Bolt12InvoiceFeatures> {
+ match self {
+ Self::Bolt12(f) => Some(f),
+ _ => None,
+ }
+ }
+ fn bolt11(self) -> Option<InvoiceFeatures> {
+ match self {
+ Self::Bolt11(f) => Some(f),
+ _ => None,
+ }
+ }
+}
+
+impl<'a> Writeable for FeaturesRef<'a> {
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+ match self {
+ Self::Bolt11(f) => Ok(f.write(w)?),
+ Self::Bolt12(f) => Ok(f.write(w)?),
+ }
+ }
+}
+
+impl ReadableArgs<bool> for Features {
+ fn read<R: io::Read>(reader: &mut R, bolt11: bool) -> Result<Self, DecodeError> {
+ if bolt11 { return Ok(Self::Bolt11(Readable::read(reader)?)) }
+ Ok(Self::Bolt12(Readable::read(reader)?))
+ }