@@ -124,7 +124,7 @@ use crate::offers::invoice_macros::invoice_builder_methods_test;
124
124
use crate :: offers:: invoice_request:: { EXPERIMENTAL_INVOICE_REQUEST_TYPES , INVOICE_REQUEST_PAYER_ID_TYPE , INVOICE_REQUEST_TYPES , IV_BYTES as INVOICE_REQUEST_IV_BYTES , InvoiceRequest , InvoiceRequestContents , InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef } ;
125
125
use crate :: offers:: merkle:: { SignError , SignFn , SignatureTlvStream , SignatureTlvStreamRef , TaggedHash , TlvStream , self , SIGNATURE_TLV_RECORD_SIZE } ;
126
126
use crate :: offers:: nonce:: Nonce ;
127
- use crate :: offers:: offer:: { Amount , EXPERIMENTAL_OFFER_TYPES , OFFER_TYPES , OfferTlvStream , OfferTlvStreamRef , Quantity } ;
127
+ use crate :: offers:: offer:: { Amount , EXPERIMENTAL_OFFER_TYPES , ExperimentalOfferTlvStream , ExperimentalOfferTlvStreamRef , OFFER_TYPES , OfferTlvStream , OfferTlvStreamRef , Quantity } ;
128
128
use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
129
129
use crate :: offers:: payer:: { PAYER_METADATA_TYPE , PayerTlvStream , PayerTlvStreamRef } ;
130
130
use crate :: offers:: refund:: { IV_BYTES_WITH_METADATA as REFUND_IV_BYTES_WITH_METADATA , IV_BYTES_WITHOUT_METADATA as REFUND_IV_BYTES_WITHOUT_METADATA , Refund , RefundContents } ;
@@ -497,7 +497,7 @@ impl UnsignedBolt12Invoice {
497
497
const EXPERIMENTAL_TYPES : core:: ops:: Range < u64 > =
498
498
EXPERIMENTAL_OFFER_TYPES . start ..EXPERIMENTAL_INVOICE_REQUEST_TYPES . end ;
499
499
500
- let ( _, _, _, invoice_tlv_stream) = contents. as_tlv_stream ( ) ;
500
+ let ( _, _, _, invoice_tlv_stream, _ ) = contents. as_tlv_stream ( ) ;
501
501
502
502
// Allocate enough space for the invoice, which will include:
503
503
// - all TLV records from `invreq_bytes` except signatures,
@@ -901,13 +901,17 @@ impl Bolt12Invoice {
901
901
}
902
902
903
903
pub ( crate ) fn as_tlv_stream ( & self ) -> FullInvoiceTlvStreamRef {
904
- let ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream) =
905
- self . contents . as_tlv_stream ( ) ;
904
+ let (
905
+ payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
906
+ experimental_offer_tlv_stream,
907
+ ) = self . contents . as_tlv_stream ( ) ;
906
908
let signature_tlv_stream = SignatureTlvStreamRef {
907
909
signature : Some ( & self . signature ) ,
908
910
} ;
909
- ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
910
- signature_tlv_stream)
911
+ (
912
+ payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
913
+ signature_tlv_stream, experimental_offer_tlv_stream,
914
+ )
911
915
}
912
916
913
917
pub ( crate ) fn is_for_refund_without_paths ( & self ) -> bool {
@@ -1145,7 +1149,7 @@ impl InvoiceContents {
1145
1149
1146
1150
fn verify < T : secp256k1:: Signing > (
1147
1151
& self , bytes : & [ u8 ] , metadata : & Metadata , key : & ExpandedKey , iv_bytes : & [ u8 ; IV_LEN ] ,
1148
- secp_ctx : & Secp256k1 < T >
1152
+ secp_ctx : & Secp256k1 < T > ,
1149
1153
) -> Result < PaymentId , ( ) > {
1150
1154
const EXPERIMENTAL_TYPES : core:: ops:: Range < u64 > =
1151
1155
EXPERIMENTAL_OFFER_TYPES . start ..EXPERIMENTAL_INVOICE_REQUEST_TYPES . end ;
@@ -1168,13 +1172,13 @@ impl InvoiceContents {
1168
1172
}
1169
1173
1170
1174
fn as_tlv_stream ( & self ) -> PartialInvoiceTlvStreamRef {
1171
- let ( payer, offer, invoice_request) = match self {
1175
+ let ( payer, offer, invoice_request, experimental_offer ) = match self {
1172
1176
InvoiceContents :: ForOffer { invoice_request, .. } => invoice_request. as_tlv_stream ( ) ,
1173
1177
InvoiceContents :: ForRefund { refund, .. } => refund. as_tlv_stream ( ) ,
1174
1178
} ;
1175
1179
let invoice = self . fields ( ) . as_tlv_stream ( ) ;
1176
1180
1177
- ( payer, offer, invoice_request, invoice)
1181
+ ( payer, offer, invoice_request, invoice, experimental_offer )
1178
1182
}
1179
1183
}
1180
1184
@@ -1333,15 +1337,18 @@ pub(super) struct FallbackAddress {
1333
1337
1334
1338
impl_writeable ! ( FallbackAddress , { version, program } ) ;
1335
1339
1336
- type FullInvoiceTlvStream =
1337
- ( PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream , InvoiceTlvStream , SignatureTlvStream ) ;
1340
+ type FullInvoiceTlvStream =(
1341
+ PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream , InvoiceTlvStream , SignatureTlvStream ,
1342
+ ExperimentalOfferTlvStream ,
1343
+ ) ;
1338
1344
1339
1345
type FullInvoiceTlvStreamRef < ' a > = (
1340
1346
PayerTlvStreamRef < ' a > ,
1341
1347
OfferTlvStreamRef < ' a > ,
1342
1348
InvoiceRequestTlvStreamRef < ' a > ,
1343
1349
InvoiceTlvStreamRef < ' a > ,
1344
1350
SignatureTlvStreamRef < ' a > ,
1351
+ ExperimentalOfferTlvStreamRef ,
1345
1352
) ;
1346
1353
1347
1354
impl CursorReadable for FullInvoiceTlvStream {
@@ -1351,19 +1358,23 @@ impl CursorReadable for FullInvoiceTlvStream {
1351
1358
let invoice_request = CursorReadable :: read ( r) ?;
1352
1359
let invoice = CursorReadable :: read ( r) ?;
1353
1360
let signature = CursorReadable :: read ( r) ?;
1361
+ let experimental_offer = CursorReadable :: read ( r) ?;
1354
1362
1355
- Ok ( ( payer, offer, invoice_request, invoice, signature) )
1363
+ Ok ( ( payer, offer, invoice_request, invoice, signature, experimental_offer ) )
1356
1364
}
1357
1365
}
1358
1366
1359
- type PartialInvoiceTlvStream =
1360
- ( PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream , InvoiceTlvStream ) ;
1367
+ type PartialInvoiceTlvStream = (
1368
+ PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream , InvoiceTlvStream ,
1369
+ ExperimentalOfferTlvStream ,
1370
+ ) ;
1361
1371
1362
1372
type PartialInvoiceTlvStreamRef < ' a > = (
1363
1373
PayerTlvStreamRef < ' a > ,
1364
1374
OfferTlvStreamRef < ' a > ,
1365
1375
InvoiceRequestTlvStreamRef < ' a > ,
1366
1376
InvoiceTlvStreamRef < ' a > ,
1377
+ ExperimentalOfferTlvStreamRef ,
1367
1378
) ;
1368
1379
1369
1380
impl CursorReadable for PartialInvoiceTlvStream {
@@ -1372,8 +1383,9 @@ impl CursorReadable for PartialInvoiceTlvStream {
1372
1383
let offer = CursorReadable :: read ( r) ?;
1373
1384
let invoice_request = CursorReadable :: read ( r) ?;
1374
1385
let invoice = CursorReadable :: read ( r) ?;
1386
+ let experimental_offer = CursorReadable :: read ( r) ?;
1375
1387
1376
- Ok ( ( payer, offer, invoice_request, invoice) )
1388
+ Ok ( ( payer, offer, invoice_request, invoice, experimental_offer ) )
1377
1389
}
1378
1390
}
1379
1391
@@ -1385,9 +1397,13 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
1385
1397
let (
1386
1398
payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
1387
1399
SignatureTlvStream { signature } ,
1400
+ experimental_offer_tlv_stream,
1388
1401
) = tlv_stream;
1389
1402
let contents = InvoiceContents :: try_from (
1390
- ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream)
1403
+ (
1404
+ payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream,
1405
+ experimental_offer_tlv_stream,
1406
+ )
1391
1407
) ?;
1392
1408
1393
1409
let signature = signature. ok_or (
@@ -1413,6 +1429,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
1413
1429
paths, blindedpay, created_at, relative_expiry, payment_hash, amount, fallbacks,
1414
1430
features, node_id, message_paths,
1415
1431
} ,
1432
+ experimental_offer_tlv_stream,
1416
1433
) = tlv_stream;
1417
1434
1418
1435
if message_paths. is_some ( ) { return Err ( Bolt12SemanticError :: UnexpectedPaths ) }
@@ -1445,12 +1462,18 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
1445
1462
1446
1463
if offer_tlv_stream. issuer_id . is_none ( ) && offer_tlv_stream. paths . is_none ( ) {
1447
1464
let refund = RefundContents :: try_from (
1448
- ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
1465
+ (
1466
+ payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream,
1467
+ experimental_offer_tlv_stream,
1468
+ )
1449
1469
) ?;
1450
1470
Ok ( InvoiceContents :: ForRefund { refund, fields } )
1451
1471
} else {
1452
1472
let invoice_request = InvoiceRequestContents :: try_from (
1453
- ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
1473
+ (
1474
+ payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream,
1475
+ experimental_offer_tlv_stream,
1476
+ )
1454
1477
) ?;
1455
1478
Ok ( InvoiceContents :: ForOffer { invoice_request, fields } )
1456
1479
}
@@ -1525,7 +1548,7 @@ mod tests {
1525
1548
use crate :: offers:: invoice_request:: InvoiceRequestTlvStreamRef ;
1526
1549
use crate :: offers:: merkle:: { SignError , SignatureTlvStreamRef , TaggedHash , self } ;
1527
1550
use crate :: offers:: nonce:: Nonce ;
1528
- use crate :: offers:: offer:: { Amount , OfferTlvStreamRef , Quantity } ;
1551
+ use crate :: offers:: offer:: { Amount , ExperimentalOfferTlvStreamRef , OfferTlvStreamRef , Quantity } ;
1529
1552
use crate :: prelude:: * ;
1530
1553
#[ cfg( not( c_bindings) ) ]
1531
1554
use {
@@ -1693,6 +1716,7 @@ mod tests {
1693
1716
message_paths: None ,
1694
1717
} ,
1695
1718
SignatureTlvStreamRef { signature: Some ( & invoice. signature( ) ) } ,
1719
+ ExperimentalOfferTlvStreamRef { } ,
1696
1720
) ,
1697
1721
) ;
1698
1722
@@ -1786,6 +1810,7 @@ mod tests {
1786
1810
message_paths: None ,
1787
1811
} ,
1788
1812
SignatureTlvStreamRef { signature: Some ( & invoice. signature( ) ) } ,
1813
+ ExperimentalOfferTlvStreamRef { } ,
1789
1814
) ,
1790
1815
) ;
1791
1816
@@ -1979,7 +2004,7 @@ mod tests {
1979
2004
. relative_expiry ( one_hour. as_secs ( ) as u32 )
1980
2005
. build ( ) . unwrap ( )
1981
2006
. sign ( recipient_sign) . unwrap ( ) ;
1982
- let ( _, _, _, tlv_stream, _) = invoice. as_tlv_stream ( ) ;
2007
+ let ( _, _, _, tlv_stream, _, _ ) = invoice. as_tlv_stream ( ) ;
1983
2008
#[ cfg( feature = "std" ) ]
1984
2009
assert ! ( !invoice. is_expired( ) ) ;
1985
2010
assert_eq ! ( invoice. relative_expiry( ) , one_hour) ;
@@ -1995,7 +2020,7 @@ mod tests {
1995
2020
. relative_expiry ( one_hour. as_secs ( ) as u32 - 1 )
1996
2021
. build ( ) . unwrap ( )
1997
2022
. sign ( recipient_sign) . unwrap ( ) ;
1998
- let ( _, _, _, tlv_stream, _) = invoice. as_tlv_stream ( ) ;
2023
+ let ( _, _, _, tlv_stream, _, _ ) = invoice. as_tlv_stream ( ) ;
1999
2024
#[ cfg( feature = "std" ) ]
2000
2025
assert ! ( invoice. is_expired( ) ) ;
2001
2026
assert_eq ! ( invoice. relative_expiry( ) , one_hour - Duration :: from_secs( 1 ) ) ;
@@ -2014,7 +2039,7 @@ mod tests {
2014
2039
. respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
2015
2040
. build ( ) . unwrap ( )
2016
2041
. sign ( recipient_sign) . unwrap ( ) ;
2017
- let ( _, _, _, tlv_stream, _) = invoice. as_tlv_stream ( ) ;
2042
+ let ( _, _, _, tlv_stream, _, _ ) = invoice. as_tlv_stream ( ) ;
2018
2043
assert_eq ! ( invoice. amount_msats( ) , 1001 ) ;
2019
2044
assert_eq ! ( tlv_stream. amount, Some ( 1001 ) ) ;
2020
2045
}
@@ -2032,7 +2057,7 @@ mod tests {
2032
2057
. respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
2033
2058
. build ( ) . unwrap ( )
2034
2059
. sign ( recipient_sign) . unwrap ( ) ;
2035
- let ( _, _, _, tlv_stream, _) = invoice. as_tlv_stream ( ) ;
2060
+ let ( _, _, _, tlv_stream, _, _ ) = invoice. as_tlv_stream ( ) ;
2036
2061
assert_eq ! ( invoice. amount_msats( ) , 2000 ) ;
2037
2062
assert_eq ! ( tlv_stream. amount, Some ( 2000 ) ) ;
2038
2063
@@ -2070,7 +2095,7 @@ mod tests {
2070
2095
. fallback_v1_p2tr_tweaked ( & tweaked_pubkey)
2071
2096
. build ( ) . unwrap ( )
2072
2097
. sign ( recipient_sign) . unwrap ( ) ;
2073
- let ( _, _, _, tlv_stream, _) = invoice. as_tlv_stream ( ) ;
2098
+ let ( _, _, _, tlv_stream, _, _ ) = invoice. as_tlv_stream ( ) ;
2074
2099
assert_eq ! (
2075
2100
invoice. fallbacks( ) ,
2076
2101
vec![
@@ -2113,7 +2138,7 @@ mod tests {
2113
2138
. allow_mpp ( )
2114
2139
. build ( ) . unwrap ( )
2115
2140
. sign ( recipient_sign) . unwrap ( ) ;
2116
- let ( _, _, _, tlv_stream, _) = invoice. as_tlv_stream ( ) ;
2141
+ let ( _, _, _, tlv_stream, _, _ ) = invoice. as_tlv_stream ( ) ;
2117
2142
assert_eq ! ( invoice. invoice_features( ) , & features) ;
2118
2143
assert_eq ! ( tlv_stream. features, Some ( & features) ) ;
2119
2144
}
0 commit comments