@@ -887,7 +887,8 @@ impl VerifiedInvoiceRequest {
887
887
amount_msats : * amount_msats,
888
888
features : features. clone ( ) ,
889
889
quantity : * quantity,
890
- payer_note : payer_note. clone ( ) . map ( |mut s| { s. truncate ( 512 ) ; UntrustedString ( s) } ) ,
890
+ payer_note_truncated : payer_note. clone ( )
891
+ . map ( |mut s| { s. truncate ( PAYER_NOTE_LIMIT ) ; UntrustedString ( s) } ) ,
891
892
}
892
893
}
893
894
}
@@ -1142,10 +1143,13 @@ pub struct InvoiceRequestFields {
1142
1143
pub quantity : Option < u64 > ,
1143
1144
1144
1145
/// A payer-provided note which will be seen by the recipient and reflected back in the invoice
1145
- /// response.
1146
- pub payer_note : Option < UntrustedString > ,
1146
+ /// response. Truncated to [`PAYER_NOTE_LIMIT`] characters.
1147
+ pub payer_note_truncated : Option < UntrustedString > ,
1147
1148
}
1148
1149
1150
+ /// The maximum number of characters included in [`InvoiceRequestFields::payer_note_truncated`].
1151
+ pub const PAYER_NOTE_LIMIT : usize = 512 ;
1152
+
1149
1153
impl Writeable for InvoiceRequestFields {
1150
1154
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
1151
1155
write_tlv_fields ! ( writer, {
@@ -1154,7 +1158,7 @@ impl Writeable for InvoiceRequestFields {
1154
1158
( 4 , self . amount_msats, option) ,
1155
1159
( 6 , WithoutLength ( & self . features) , required) ,
1156
1160
( 8 , self . quantity, option) ,
1157
- ( 10 , self . payer_note , option) ,
1161
+ ( 10 , self . payer_note_truncated , option) ,
1158
1162
} ) ;
1159
1163
Ok ( ( ) )
1160
1164
}
@@ -1168,19 +1172,20 @@ impl Readable for InvoiceRequestFields {
1168
1172
( 4 , amount_msats, option) ,
1169
1173
( 6 , features, ( option, encoding: ( InvoiceRequestFeatures , WithoutLength ) ) ) ,
1170
1174
( 8 , quantity, option) ,
1171
- ( 10 , payer_note , option) ,
1175
+ ( 10 , payer_note_truncated , option) ,
1172
1176
} ) ;
1173
1177
let features = features. unwrap_or ( InvoiceRequestFeatures :: empty ( ) ) ;
1174
1178
1175
1179
Ok ( InvoiceRequestFields {
1176
- payer_id : payer_id. 0 . unwrap ( ) , chain, amount_msats, features, quantity, payer_note
1180
+ payer_id : payer_id. 0 . unwrap ( ) , chain, amount_msats, features, quantity,
1181
+ payer_note_truncated,
1177
1182
} )
1178
1183
}
1179
1184
}
1180
1185
1181
1186
#[ cfg( test) ]
1182
1187
mod tests {
1183
- use super :: { InvoiceRequest , InvoiceRequestFields , InvoiceRequestTlvStreamRef , SIGNATURE_TAG , UnsignedInvoiceRequest } ;
1188
+ use super :: { InvoiceRequest , InvoiceRequestFields , InvoiceRequestTlvStreamRef , PAYER_NOTE_LIMIT , SIGNATURE_TAG , UnsignedInvoiceRequest } ;
1184
1189
1185
1190
use bitcoin:: blockdata:: constants:: ChainHash ;
1186
1191
use bitcoin:: network:: constants:: Network ;
@@ -2267,7 +2272,7 @@ mod tests {
2267
2272
. chain ( Network :: Testnet ) . unwrap ( )
2268
2273
. amount_msats ( 1001 ) . unwrap ( )
2269
2274
. quantity ( 1 ) . unwrap ( )
2270
- . payer_note ( "0" . repeat ( 1024 ) )
2275
+ . payer_note ( "0" . repeat ( PAYER_NOTE_LIMIT * 2 ) )
2271
2276
. build ( ) . unwrap ( )
2272
2277
. sign ( payer_sign) . unwrap ( ) ;
2273
2278
match invoice_request. verify ( & expanded_key, & secp_ctx) {
@@ -2281,7 +2286,7 @@ mod tests {
2281
2286
amount_msats: Some ( 1001 ) ,
2282
2287
features: InvoiceRequestFeatures :: empty( ) ,
2283
2288
quantity: Some ( 1 ) ,
2284
- payer_note : Some ( UntrustedString ( "0" . repeat( 512 ) ) ) ,
2289
+ payer_note_truncated : Some ( UntrustedString ( "0" . repeat( PAYER_NOTE_LIMIT ) ) ) ,
2285
2290
}
2286
2291
) ;
2287
2292
} ,
0 commit comments