@@ -75,6 +75,7 @@ use crate::offers::offer::{Offer, OfferContents, OfferId, OfferTlvStream, OfferT
75
75
use crate :: offers:: parse:: { Bolt12ParseError , ParsedMessage , Bolt12SemanticError } ;
76
76
use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
77
77
use crate :: offers:: signer:: { Metadata , MetadataMaterial } ;
78
+ use crate :: onion_message:: dns_resolution:: HumanReadableName ;
78
79
use crate :: util:: ser:: { CursorReadable , HighZeroBytesDroppedBigSize , Readable , WithoutLength , Writeable , Writer } ;
79
80
use crate :: util:: string:: { PrintableString , UntrustedString } ;
80
81
@@ -241,6 +242,7 @@ macro_rules! invoice_request_builder_methods { (
241
242
InvoiceRequestContentsWithoutPayerId {
242
243
payer: PayerContents ( metadata) , offer, chain: None , amount_msats: None ,
243
244
features: InvoiceRequestFeatures :: empty( ) , quantity: None , payer_note: None ,
245
+ source_human_readable_name: None ,
244
246
}
245
247
}
246
248
@@ -299,6 +301,14 @@ macro_rules! invoice_request_builder_methods { (
299
301
$return_value
300
302
}
301
303
304
+ /// Sets the [`InvoiceRequest::source_human_readable_name`].
305
+ ///
306
+ /// Successive calls to this method will override the previous setting.
307
+ pub fn sourced_from_human_readable_name( $( $self_mut) * $self: $self_type, hrn: HumanReadableName ) -> $return_type {
308
+ $self. invoice_request. source_human_readable_name = Some ( hrn) ;
309
+ $return_value
310
+ }
311
+
302
312
fn build_with_checks( $( $self_mut) * $self: $self_type) -> Result <
303
313
( UnsignedInvoiceRequest , Option <Keypair >, Option <& ' b Secp256k1 <$secp_context>>) ,
304
314
Bolt12SemanticError
@@ -644,6 +654,7 @@ pub(super) struct InvoiceRequestContentsWithoutPayerId {
644
654
features : InvoiceRequestFeatures ,
645
655
quantity : Option < u64 > ,
646
656
payer_note : Option < String > ,
657
+ source_human_readable_name : Option < HumanReadableName > ,
647
658
}
648
659
649
660
macro_rules! invoice_request_accessors { ( $self: ident, $contents: expr) => {
@@ -688,6 +699,12 @@ macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
688
699
pub fn payer_note( & $self) -> Option <PrintableString > {
689
700
$contents. payer_note( )
690
701
}
702
+
703
+ /// If the [`Offer`] was sourced from a BIP 353 Human Readable Name, this should be set by the
704
+ /// builder to indicate the original [`HumanReadableName`] which was resolved.
705
+ pub fn source_human_readable_name( & $self) -> & Option <HumanReadableName > {
706
+ $contents. source_human_readable_name( )
707
+ }
691
708
} }
692
709
693
710
impl UnsignedInvoiceRequest {
@@ -936,7 +953,7 @@ impl VerifiedInvoiceRequest {
936
953
let InvoiceRequestContents {
937
954
payer_id,
938
955
inner : InvoiceRequestContentsWithoutPayerId {
939
- payer : _ , offer : _ , chain : _ , amount_msats : _ , features : _ , quantity, payer_note
956
+ quantity, payer_note, ..
940
957
} ,
941
958
} = & self . inner . contents ;
942
959
@@ -979,6 +996,10 @@ impl InvoiceRequestContents {
979
996
. map ( |payer_note| PrintableString ( payer_note. as_str ( ) ) )
980
997
}
981
998
999
+ pub ( super ) fn source_human_readable_name ( & self ) -> & Option < HumanReadableName > {
1000
+ & self . inner . source_human_readable_name
1001
+ }
1002
+
982
1003
pub ( super ) fn as_tlv_stream ( & self ) -> PartialInvoiceRequestTlvStreamRef {
983
1004
let ( payer, offer, mut invoice_request) = self . inner . as_tlv_stream ( ) ;
984
1005
invoice_request. payer_id = Some ( & self . payer_id ) ;
@@ -1014,6 +1035,7 @@ impl InvoiceRequestContentsWithoutPayerId {
1014
1035
quantity : self . quantity ,
1015
1036
payer_id : None ,
1016
1037
payer_note : self . payer_note . as_ref ( ) ,
1038
+ source_human_readable_name : self . source_human_readable_name . as_ref ( ) ,
1017
1039
paths : None ,
1018
1040
} ;
1019
1041
@@ -1058,6 +1080,7 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, INVOICE_REQUEST
1058
1080
( 89 , payer_note: ( String , WithoutLength ) ) ,
1059
1081
// Only used for Refund since the onion message of an InvoiceRequest has a reply path.
1060
1082
( 90 , paths: ( Vec <BlindedMessagePath >, WithoutLength ) ) ,
1083
+ ( 91 , source_human_readable_name: HumanReadableName ) ,
1061
1084
} ) ;
1062
1085
1063
1086
type FullInvoiceRequestTlvStream =
@@ -1142,6 +1165,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
1142
1165
offer_tlv_stream,
1143
1166
InvoiceRequestTlvStream {
1144
1167
chain, amount, features, quantity, payer_id, payer_note, paths,
1168
+ source_human_readable_name,
1145
1169
} ,
1146
1170
) = tlv_stream;
1147
1171
@@ -1176,6 +1200,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
1176
1200
Ok ( InvoiceRequestContents {
1177
1201
inner : InvoiceRequestContentsWithoutPayerId {
1178
1202
payer, offer, chain, amount_msats : amount, features, quantity, payer_note,
1203
+ source_human_readable_name,
1179
1204
} ,
1180
1205
payer_id,
1181
1206
} )
@@ -1353,6 +1378,7 @@ mod tests {
1353
1378
payer_id: Some ( & payer_pubkey( ) ) ,
1354
1379
payer_note: None ,
1355
1380
paths: None ,
1381
+ source_human_readable_name: None ,
1356
1382
} ,
1357
1383
SignatureTlvStreamRef { signature: Some ( & invoice_request. signature( ) ) } ,
1358
1384
) ,
0 commit comments