@@ -85,16 +85,26 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
85
85
let expanded_key = ExpandedKey :: new ( [ 42 ; 32 ] ) ;
86
86
let entropy_source = Randomness { } ;
87
87
let nonce = Nonce :: from_entropy_source ( & entropy_source) ;
88
+
89
+ let invoice_request_fields =
90
+ if let Ok ( ver) = invoice_request. clone ( ) . verify_using_metadata ( & expanded_key, secp_ctx) {
91
+ // Previously we had a panic where we'd truncate the payer note possibly cutting a
92
+ // Unicode character in two here, so try to fetch fields if we can validate.
93
+ ver. fields ( )
94
+ } else {
95
+ InvoiceRequestFields {
96
+ payer_signing_pubkey : invoice_request. payer_signing_pubkey ( ) ,
97
+ quantity : invoice_request. quantity ( ) ,
98
+ payer_note_truncated : invoice_request
99
+ . payer_note ( )
100
+ . map ( |s| UntrustedString ( s. to_string ( ) ) ) ,
101
+ human_readable_name : None ,
102
+ }
103
+ } ;
104
+
88
105
let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
89
106
offer_id : OfferId ( [ 42 ; 32 ] ) ,
90
- invoice_request : InvoiceRequestFields {
91
- payer_signing_pubkey : invoice_request. payer_signing_pubkey ( ) ,
92
- quantity : invoice_request. quantity ( ) ,
93
- payer_note_truncated : invoice_request
94
- . payer_note ( )
95
- . map ( |s| UntrustedString ( s. to_string ( ) ) ) ,
96
- human_readable_name : None ,
97
- } ,
107
+ invoice_request : invoice_request_fields,
98
108
} ) ;
99
109
let payee_tlvs = UnauthenticatedReceiveTlvs {
100
110
payment_secret : PaymentSecret ( [ 42 ; 32 ] ) ,
@@ -134,12 +144,6 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
134
144
)
135
145
. unwrap ( ) ;
136
146
137
- if let Ok ( verified) = invoice_request. clone ( ) . verify_using_metadata ( & expanded_key, secp_ctx) {
138
- // Previously we had a panic where we'd truncate the payer note possibly cutting a Unicode
139
- // character in two here, so try to fetch fields if we can validate.
140
- let _ = verified. fields ( ) ;
141
- }
142
-
143
147
let payment_hash = PaymentHash ( [ 42 ; 32 ] ) ;
144
148
invoice_request. respond_with ( vec ! [ payment_path] , payment_hash) ?. build ( )
145
149
}
0 commit comments