@@ -506,7 +506,9 @@ impl UnsignedBolt12Invoice {
506
506
record. write ( & mut bytes) . unwrap ( ) ;
507
507
}
508
508
509
- let ( _, _, _, invoice_tlv_stream, _, _) = contents. as_tlv_stream ( ) ;
509
+ let ( _, _, _, invoice_tlv_stream, _, _, experimental_invoice_tlv_stream) =
510
+ contents. as_tlv_stream ( ) ;
511
+
510
512
invoice_tlv_stream. write ( & mut bytes) . unwrap ( ) ;
511
513
512
514
let mut experimental_bytes = Vec :: new ( ) ;
@@ -515,6 +517,8 @@ impl UnsignedBolt12Invoice {
515
517
record. write ( & mut experimental_bytes) . unwrap ( ) ;
516
518
}
517
519
520
+ experimental_invoice_tlv_stream. write ( & mut experimental_bytes) . unwrap ( ) ;
521
+
518
522
let tlv_stream = TlvStream :: new ( & bytes) . chain ( TlvStream :: new ( & experimental_bytes) ) ;
519
523
let tagged_hash = TaggedHash :: from_tlv_stream ( SIGNATURE_TAG , tlv_stream) ;
520
524
@@ -872,14 +876,15 @@ impl Bolt12Invoice {
872
876
let (
873
877
payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
874
878
experimental_offer_tlv_stream, experimental_invoice_request_tlv_stream,
879
+ experimental_invoice_tlv_stream,
875
880
) = self . contents . as_tlv_stream ( ) ;
876
881
let signature_tlv_stream = SignatureTlvStreamRef {
877
882
signature : Some ( & self . signature ) ,
878
883
} ;
879
884
(
880
885
payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
881
886
signature_tlv_stream, experimental_offer_tlv_stream,
882
- experimental_invoice_request_tlv_stream,
887
+ experimental_invoice_request_tlv_stream, experimental_invoice_tlv_stream ,
883
888
)
884
889
}
885
890
@@ -1140,9 +1145,12 @@ impl InvoiceContents {
1140
1145
InvoiceContents :: ForOffer { invoice_request, .. } => invoice_request. as_tlv_stream ( ) ,
1141
1146
InvoiceContents :: ForRefund { refund, .. } => refund. as_tlv_stream ( ) ,
1142
1147
} ;
1143
- let invoice = self . fields ( ) . as_tlv_stream ( ) ;
1148
+ let ( invoice, experimental_invoice ) = self . fields ( ) . as_tlv_stream ( ) ;
1144
1149
1145
- ( payer, offer, invoice_request, invoice, experimental_offer, experimental_invoice_request)
1150
+ (
1151
+ payer, offer, invoice_request, invoice, experimental_offer,
1152
+ experimental_invoice_request, experimental_invoice,
1153
+ )
1146
1154
}
1147
1155
}
1148
1156
@@ -1190,24 +1198,27 @@ pub(super) fn filter_fallbacks(
1190
1198
}
1191
1199
1192
1200
impl InvoiceFields {
1193
- fn as_tlv_stream ( & self ) -> InvoiceTlvStreamRef {
1201
+ fn as_tlv_stream ( & self ) -> ( InvoiceTlvStreamRef , ExperimentalInvoiceTlvStreamRef ) {
1194
1202
let features = {
1195
1203
if self . features == Bolt12InvoiceFeatures :: empty ( ) { None }
1196
1204
else { Some ( & self . features ) }
1197
1205
} ;
1198
1206
1199
- InvoiceTlvStreamRef {
1200
- paths : Some ( Iterable ( self . payment_paths . iter ( ) . map ( |path| path. inner_blinded_path ( ) ) ) ) ,
1201
- blindedpay : Some ( Iterable ( self . payment_paths . iter ( ) . map ( |path| & path. payinfo ) ) ) ,
1202
- created_at : Some ( self . created_at . as_secs ( ) ) ,
1203
- relative_expiry : self . relative_expiry . map ( |duration| duration. as_secs ( ) as u32 ) ,
1204
- payment_hash : Some ( & self . payment_hash ) ,
1205
- amount : Some ( self . amount_msats ) ,
1206
- fallbacks : self . fallbacks . as_ref ( ) ,
1207
- features,
1208
- node_id : Some ( & self . signing_pubkey ) ,
1209
- message_paths : None ,
1210
- }
1207
+ (
1208
+ InvoiceTlvStreamRef {
1209
+ paths : Some ( Iterable ( self . payment_paths . iter ( ) . map ( |path| path. inner_blinded_path ( ) ) ) ) ,
1210
+ blindedpay : Some ( Iterable ( self . payment_paths . iter ( ) . map ( |path| & path. payinfo ) ) ) ,
1211
+ created_at : Some ( self . created_at . as_secs ( ) ) ,
1212
+ relative_expiry : self . relative_expiry . map ( |duration| duration. as_secs ( ) as u32 ) ,
1213
+ payment_hash : Some ( & self . payment_hash ) ,
1214
+ amount : Some ( self . amount_msats ) ,
1215
+ fallbacks : self . fallbacks . as_ref ( ) ,
1216
+ features,
1217
+ node_id : Some ( & self . signing_pubkey ) ,
1218
+ message_paths : None ,
1219
+ } ,
1220
+ ExperimentalInvoiceTlvStreamRef { } ,
1221
+ )
1211
1222
}
1212
1223
}
1213
1224
@@ -1282,6 +1293,13 @@ tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef<'a>, INVOICE_TYPES, {
1282
1293
( 236 , message_paths: ( Vec <BlindedMessagePath >, WithoutLength ) ) ,
1283
1294
} ) ;
1284
1295
1296
+ /// Valid type range for experimental invoice TLV records.
1297
+ const EXPERIMENTAL_INVOICE_TYPES : core:: ops:: RangeFrom < u64 > = 3_000_000_000 ..;
1298
+
1299
+ tlv_stream ! (
1300
+ ExperimentalInvoiceTlvStream , ExperimentalInvoiceTlvStreamRef , EXPERIMENTAL_INVOICE_TYPES , { }
1301
+ ) ;
1302
+
1285
1303
pub ( super ) type BlindedPathIter < ' a > = core:: iter:: Map <
1286
1304
core:: slice:: Iter < ' a , BlindedPaymentPath > ,
1287
1305
for <' r > fn ( & ' r BlindedPaymentPath ) -> & ' r BlindedPath ,
@@ -1303,7 +1321,7 @@ impl_writeable!(FallbackAddress, { version, program });
1303
1321
1304
1322
type FullInvoiceTlvStream =(
1305
1323
PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream , InvoiceTlvStream , SignatureTlvStream ,
1306
- ExperimentalOfferTlvStream , ExperimentalInvoiceRequestTlvStream ,
1324
+ ExperimentalOfferTlvStream , ExperimentalInvoiceRequestTlvStream , ExperimentalInvoiceTlvStream ,
1307
1325
) ;
1308
1326
1309
1327
type FullInvoiceTlvStreamRef < ' a > = (
@@ -1314,6 +1332,7 @@ type FullInvoiceTlvStreamRef<'a> = (
1314
1332
SignatureTlvStreamRef < ' a > ,
1315
1333
ExperimentalOfferTlvStreamRef ,
1316
1334
ExperimentalInvoiceRequestTlvStreamRef ,
1335
+ ExperimentalInvoiceTlvStreamRef ,
1317
1336
) ;
1318
1337
1319
1338
impl CursorReadable for FullInvoiceTlvStream {
@@ -1325,19 +1344,20 @@ impl CursorReadable for FullInvoiceTlvStream {
1325
1344
let signature = CursorReadable :: read ( r) ?;
1326
1345
let experimental_offer = CursorReadable :: read ( r) ?;
1327
1346
let experimental_invoice_request = CursorReadable :: read ( r) ?;
1347
+ let experimental_invoice = CursorReadable :: read ( r) ?;
1328
1348
1329
1349
Ok (
1330
1350
(
1331
1351
payer, offer, invoice_request, invoice, signature, experimental_offer,
1332
- experimental_invoice_request,
1352
+ experimental_invoice_request, experimental_invoice ,
1333
1353
)
1334
1354
)
1335
1355
}
1336
1356
}
1337
1357
1338
1358
type PartialInvoiceTlvStream = (
1339
1359
PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream , InvoiceTlvStream ,
1340
- ExperimentalOfferTlvStream , ExperimentalInvoiceRequestTlvStream ,
1360
+ ExperimentalOfferTlvStream , ExperimentalInvoiceRequestTlvStream , ExperimentalInvoiceTlvStream ,
1341
1361
) ;
1342
1362
1343
1363
type PartialInvoiceTlvStreamRef < ' a > = (
@@ -1347,6 +1367,7 @@ type PartialInvoiceTlvStreamRef<'a> = (
1347
1367
InvoiceTlvStreamRef < ' a > ,
1348
1368
ExperimentalOfferTlvStreamRef ,
1349
1369
ExperimentalInvoiceRequestTlvStreamRef ,
1370
+ ExperimentalInvoiceTlvStreamRef ,
1350
1371
) ;
1351
1372
1352
1373
impl CursorReadable for PartialInvoiceTlvStream {
@@ -1357,11 +1378,12 @@ impl CursorReadable for PartialInvoiceTlvStream {
1357
1378
let invoice = CursorReadable :: read ( r) ?;
1358
1379
let experimental_offer = CursorReadable :: read ( r) ?;
1359
1380
let experimental_invoice_request = CursorReadable :: read ( r) ?;
1381
+ let experimental_invoice = CursorReadable :: read ( r) ?;
1360
1382
1361
1383
Ok (
1362
1384
(
1363
1385
payer, offer, invoice_request, invoice, experimental_offer,
1364
- experimental_invoice_request,
1386
+ experimental_invoice_request, experimental_invoice ,
1365
1387
)
1366
1388
)
1367
1389
}
@@ -1377,11 +1399,13 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
1377
1399
SignatureTlvStream { signature } ,
1378
1400
experimental_offer_tlv_stream,
1379
1401
experimental_invoice_request_tlv_stream,
1402
+ experimental_invoice_tlv_stream,
1380
1403
) = tlv_stream;
1381
1404
let contents = InvoiceContents :: try_from (
1382
1405
(
1383
1406
payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
1384
1407
experimental_offer_tlv_stream, experimental_invoice_request_tlv_stream,
1408
+ experimental_invoice_tlv_stream,
1385
1409
)
1386
1410
) ?;
1387
1411
@@ -1410,6 +1434,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
1410
1434
} ,
1411
1435
experimental_offer_tlv_stream,
1412
1436
experimental_invoice_request_tlv_stream,
1437
+ ExperimentalInvoiceTlvStream { } ,
1413
1438
) = tlv_stream;
1414
1439
1415
1440
if message_paths. is_some ( ) { return Err ( Bolt12SemanticError :: UnexpectedPaths ) }
@@ -1506,7 +1531,7 @@ pub(super) fn check_invoice_signing_pubkey(
1506
1531
1507
1532
#[ cfg( test) ]
1508
1533
mod tests {
1509
- use super :: { Bolt12Invoice , DEFAULT_RELATIVE_EXPIRY , FallbackAddress , FullInvoiceTlvStreamRef , INVOICE_TYPES , InvoiceTlvStreamRef , SIGNATURE_TAG , UnsignedBolt12Invoice } ;
1534
+ use super :: { Bolt12Invoice , DEFAULT_RELATIVE_EXPIRY , ExperimentalInvoiceTlvStreamRef , FallbackAddress , FullInvoiceTlvStreamRef , INVOICE_TYPES , InvoiceTlvStreamRef , SIGNATURE_TAG , UnsignedBolt12Invoice } ;
1510
1535
1511
1536
use bitcoin:: { CompressedPublicKey , WitnessProgram , WitnessVersion } ;
1512
1537
use bitcoin:: constants:: ChainHash ;
@@ -1702,6 +1727,7 @@ mod tests {
1702
1727
ExperimentalInvoiceRequestTlvStreamRef {
1703
1728
experimental_bar: None ,
1704
1729
} ,
1730
+ ExperimentalInvoiceTlvStreamRef { } ,
1705
1731
) ,
1706
1732
) ;
1707
1733
@@ -1801,6 +1827,7 @@ mod tests {
1801
1827
ExperimentalInvoiceRequestTlvStreamRef {
1802
1828
experimental_bar: None ,
1803
1829
} ,
1830
+ ExperimentalInvoiceTlvStreamRef { } ,
1804
1831
) ,
1805
1832
) ;
1806
1833
@@ -1997,7 +2024,7 @@ mod tests {
1997
2024
. relative_expiry ( one_hour. as_secs ( ) as u32 )
1998
2025
. build ( ) . unwrap ( )
1999
2026
. sign ( recipient_sign) . unwrap ( ) ;
2000
- let ( _, _, _, tlv_stream, _, _, _) = invoice. as_tlv_stream ( ) ;
2027
+ let ( _, _, _, tlv_stream, _, _, _, _ ) = invoice. as_tlv_stream ( ) ;
2001
2028
#[ cfg( feature = "std" ) ]
2002
2029
assert ! ( !invoice. is_expired( ) ) ;
2003
2030
assert_eq ! ( invoice. relative_expiry( ) , one_hour) ;
@@ -2013,7 +2040,7 @@ mod tests {
2013
2040
. relative_expiry ( one_hour. as_secs ( ) as u32 - 1 )
2014
2041
. build ( ) . unwrap ( )
2015
2042
. sign ( recipient_sign) . unwrap ( ) ;
2016
- let ( _, _, _, tlv_stream, _, _, _) = invoice. as_tlv_stream ( ) ;
2043
+ let ( _, _, _, tlv_stream, _, _, _, _ ) = invoice. as_tlv_stream ( ) ;
2017
2044
#[ cfg( feature = "std" ) ]
2018
2045
assert ! ( invoice. is_expired( ) ) ;
2019
2046
assert_eq ! ( invoice. relative_expiry( ) , one_hour - Duration :: from_secs( 1 ) ) ;
@@ -2032,7 +2059,7 @@ mod tests {
2032
2059
. respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
2033
2060
. build ( ) . unwrap ( )
2034
2061
. sign ( recipient_sign) . unwrap ( ) ;
2035
- let ( _, _, _, tlv_stream, _, _, _) = invoice. as_tlv_stream ( ) ;
2062
+ let ( _, _, _, tlv_stream, _, _, _, _ ) = invoice. as_tlv_stream ( ) ;
2036
2063
assert_eq ! ( invoice. amount_msats( ) , 1001 ) ;
2037
2064
assert_eq ! ( tlv_stream. amount, Some ( 1001 ) ) ;
2038
2065
}
@@ -2050,7 +2077,7 @@ mod tests {
2050
2077
. respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
2051
2078
. build ( ) . unwrap ( )
2052
2079
. sign ( recipient_sign) . unwrap ( ) ;
2053
- let ( _, _, _, tlv_stream, _, _, _) = invoice. as_tlv_stream ( ) ;
2080
+ let ( _, _, _, tlv_stream, _, _, _, _ ) = invoice. as_tlv_stream ( ) ;
2054
2081
assert_eq ! ( invoice. amount_msats( ) , 2000 ) ;
2055
2082
assert_eq ! ( tlv_stream. amount, Some ( 2000 ) ) ;
2056
2083
@@ -2088,7 +2115,7 @@ mod tests {
2088
2115
. fallback_v1_p2tr_tweaked ( & tweaked_pubkey)
2089
2116
. build ( ) . unwrap ( )
2090
2117
. sign ( recipient_sign) . unwrap ( ) ;
2091
- let ( _, _, _, tlv_stream, _, _, _) = invoice. as_tlv_stream ( ) ;
2118
+ let ( _, _, _, tlv_stream, _, _, _, _ ) = invoice. as_tlv_stream ( ) ;
2092
2119
assert_eq ! (
2093
2120
invoice. fallbacks( ) ,
2094
2121
vec![
@@ -2131,7 +2158,7 @@ mod tests {
2131
2158
. allow_mpp ( )
2132
2159
. build ( ) . unwrap ( )
2133
2160
. sign ( recipient_sign) . unwrap ( ) ;
2134
- let ( _, _, _, tlv_stream, _, _, _) = invoice. as_tlv_stream ( ) ;
2161
+ let ( _, _, _, tlv_stream, _, _, _, _ ) = invoice. as_tlv_stream ( ) ;
2135
2162
assert_eq ! ( invoice. invoice_features( ) , & features) ;
2136
2163
assert_eq ! ( tlv_stream. features, Some ( & features) ) ;
2137
2164
}
0 commit comments