@@ -75,6 +75,7 @@ use crate::offers::offer::{EXPERIMENTAL_OFFER_TYPES, ExperimentalOfferTlvStream,
7575use crate :: offers:: parse:: { Bolt12ParseError , ParsedMessage , Bolt12SemanticError } ;
7676use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
7777use crate :: offers:: signer:: { Metadata , MetadataMaterial } ;
78+ use crate :: onion_message:: dns_resolution:: HumanReadableName ;
7879use crate :: util:: ser:: { CursorReadable , HighZeroBytesDroppedBigSize , Readable , WithoutLength , Writeable , Writer } ;
7980use crate :: util:: string:: { PrintableString , UntrustedString } ;
8081
@@ -241,6 +242,7 @@ macro_rules! invoice_request_builder_methods { (
241242 InvoiceRequestContentsWithoutPayerSigningPubkey {
242243 payer: PayerContents ( metadata) , offer, chain: None , amount_msats: None ,
243244 features: InvoiceRequestFeatures :: empty( ) , quantity: None , payer_note: None ,
245+ offer_from_hrn: None ,
244246 #[ cfg( test) ]
245247 experimental_bar: None ,
246248 }
@@ -301,6 +303,14 @@ macro_rules! invoice_request_builder_methods { (
301303 $return_value
302304 }
303305
306+ /// Sets the [`InvoiceRequest::offer_from_hrn`].
307+ ///
308+ /// Successive calls to this method will override the previous setting.
309+ pub fn sourced_from_human_readable_name( $( $self_mut) * $self: $self_type, hrn: HumanReadableName ) -> $return_type {
310+ $self. invoice_request. offer_from_hrn = Some ( hrn) ;
311+ $return_value
312+ }
313+
304314 fn build_with_checks( $( $self_mut) * $self: $self_type) -> Result <
305315 ( UnsignedInvoiceRequest , Option <Keypair >, Option <& ' b Secp256k1 <$secp_context>>) ,
306316 Bolt12SemanticError
@@ -699,6 +709,7 @@ pub(super) struct InvoiceRequestContentsWithoutPayerSigningPubkey {
699709 features : InvoiceRequestFeatures ,
700710 quantity : Option < u64 > ,
701711 payer_note : Option < String > ,
712+ offer_from_hrn : Option < HumanReadableName > ,
702713 #[ cfg( test) ]
703714 experimental_bar : Option < u64 > ,
704715}
@@ -745,6 +756,12 @@ macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
745756 pub fn payer_note( & $self) -> Option <PrintableString > {
746757 $contents. payer_note( )
747758 }
759+
760+ /// If the [`Offer`] was sourced from a BIP 353 Human Readable Name, this should be set by the
761+ /// builder to indicate the original [`HumanReadableName`] which was resolved.
762+ pub fn offer_from_hrn( & $self) -> & Option <HumanReadableName > {
763+ $contents. offer_from_hrn( )
764+ }
748765} }
749766
750767impl UnsignedInvoiceRequest {
@@ -1004,9 +1021,7 @@ impl VerifiedInvoiceRequest {
10041021 let InvoiceRequestContents {
10051022 payer_signing_pubkey,
10061023 inner : InvoiceRequestContentsWithoutPayerSigningPubkey {
1007- payer : _, offer : _, chain : _, amount_msats : _, features : _, quantity, payer_note,
1008- #[ cfg( test) ]
1009- experimental_bar : _,
1024+ quantity, payer_note, ..
10101025 } ,
10111026 } = & self . inner . contents ;
10121027
@@ -1049,6 +1064,10 @@ impl InvoiceRequestContents {
10491064 . map ( |payer_note| PrintableString ( payer_note. as_str ( ) ) )
10501065 }
10511066
1067+ pub ( super ) fn offer_from_hrn ( & self ) -> & Option < HumanReadableName > {
1068+ & self . inner . offer_from_hrn
1069+ }
1070+
10521071 pub ( super ) fn as_tlv_stream ( & self ) -> PartialInvoiceRequestTlvStreamRef {
10531072 let ( payer, offer, mut invoice_request, experimental_offer, experimental_invoice_request) =
10541073 self . inner . as_tlv_stream ( ) ;
@@ -1085,6 +1104,7 @@ impl InvoiceRequestContentsWithoutPayerSigningPubkey {
10851104 quantity : self . quantity ,
10861105 payer_id : None ,
10871106 payer_note : self . payer_note . as_ref ( ) ,
1107+ offer_from_hrn : self . offer_from_hrn . as_ref ( ) ,
10881108 paths : None ,
10891109 } ;
10901110
@@ -1142,6 +1162,7 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef<'a>, INVOICE_REQ
11421162 ( 89 , payer_note: ( String , WithoutLength ) ) ,
11431163 // Only used for Refund since the onion message of an InvoiceRequest has a reply path.
11441164 ( 90 , paths: ( Vec <BlindedMessagePath >, WithoutLength ) ) ,
1165+ ( 91 , offer_from_hrn: HumanReadableName ) ,
11451166} ) ;
11461167
11471168/// Valid type range for experimental invoice_request TLV records.
@@ -1266,6 +1287,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
12661287 offer_tlv_stream,
12671288 InvoiceRequestTlvStream {
12681289 chain, amount, features, quantity, payer_id, payer_note, paths,
1290+ offer_from_hrn,
12691291 } ,
12701292 experimental_offer_tlv_stream,
12711293 ExperimentalInvoiceRequestTlvStream {
@@ -1305,6 +1327,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
13051327 Ok ( InvoiceRequestContents {
13061328 inner : InvoiceRequestContentsWithoutPayerSigningPubkey {
13071329 payer, offer, chain, amount_msats : amount, features, quantity, payer_note,
1330+ offer_from_hrn,
13081331 #[ cfg( test) ]
13091332 experimental_bar,
13101333 } ,
@@ -1484,6 +1507,7 @@ mod tests {
14841507 payer_id: Some ( & payer_pubkey( ) ) ,
14851508 payer_note: None ,
14861509 paths: None ,
1510+ offer_from_hrn: None ,
14871511 } ,
14881512 SignatureTlvStreamRef { signature: Some ( & invoice_request. signature( ) ) } ,
14891513 ExperimentalOfferTlvStreamRef {
0 commit comments