@@ -641,6 +641,56 @@ impl TryFrom<OfferTlvStream> for OfferContents {
641
641
}
642
642
}
643
643
644
+ /// [`OfferContents`] used with a "send invoice" offer (i.e., a published [`InvoiceRequest`]).
645
+ ///
646
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
647
+ pub ( super ) struct SendInvoiceOfferContents ( pub OfferContents ) ;
648
+
649
+ impl TryFrom < OfferTlvStream > for SendInvoiceOfferContents {
650
+ type Error = SemanticError ;
651
+
652
+ fn try_from ( tlv_stream : OfferTlvStream ) -> Result < Self , Self :: Error > {
653
+ let OfferTlvStream {
654
+ chains, metadata, currency, amount, description, features, absolute_expiry, paths,
655
+ issuer, quantity_min, quantity_max, node_id,
656
+ } = tlv_stream;
657
+ assert ! ( node_id. is_none( ) ) ;
658
+
659
+ if chains. is_some ( ) {
660
+ return Err ( SemanticError :: UnexpectedChain ) ;
661
+ }
662
+
663
+ if currency. is_some ( ) || amount. is_some ( ) {
664
+ return Err ( SemanticError :: UnexpectedAmount ) ;
665
+ }
666
+
667
+ let description = match description {
668
+ None => return Err ( SemanticError :: MissingDescription ) ,
669
+ Some ( description) => description,
670
+ } ;
671
+
672
+ if features. is_some ( ) {
673
+ return Err ( SemanticError :: UnexpectedFeatures ) ;
674
+ }
675
+
676
+ let absolute_expiry = absolute_expiry. map ( Duration :: from_secs) ;
677
+
678
+ let paths = match paths {
679
+ Some ( paths) if paths. is_empty ( ) => return Err ( SemanticError :: MissingPaths ) ,
680
+ paths => paths,
681
+ } ;
682
+
683
+ if quantity_min. is_some ( ) || quantity_max. is_some ( ) {
684
+ return Err ( SemanticError :: UnexpectedQuantity ) ;
685
+ }
686
+
687
+ Ok ( SendInvoiceOfferContents ( OfferContents {
688
+ chains : None , metadata, amount : None , description, features : None , absolute_expiry,
689
+ issuer, paths, quantity_min : None , quantity_max : None , signing_pubkey : None ,
690
+ } ) )
691
+ }
692
+ }
693
+
644
694
impl core:: fmt:: Display for Offer {
645
695
fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
646
696
self . fmt_bech32_str ( f)
0 commit comments