@@ -112,7 +112,7 @@ use crate::ln::msgs::DecodeError;
112
112
use crate :: offers:: invoice_request:: { INVOICE_REQUEST_PAYER_ID_TYPE , INVOICE_REQUEST_TYPES , IV_BYTES as INVOICE_REQUEST_IV_BYTES , InvoiceRequest , InvoiceRequestContents , InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef } ;
113
113
use crate :: offers:: merkle:: { SignError , SignatureTlvStream , SignatureTlvStreamRef , TlvStream , WithoutSignatures , self } ;
114
114
use crate :: offers:: offer:: { Amount , OFFER_TYPES , OfferTlvStream , OfferTlvStreamRef } ;
115
- use crate :: offers:: parse:: { Bolt12ParseError , ParsedMessage , SemanticError } ;
115
+ use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
116
116
use crate :: offers:: payer:: { PAYER_METADATA_TYPE , PayerTlvStream , PayerTlvStreamRef } ;
117
117
use crate :: offers:: refund:: { IV_BYTES as REFUND_IV_BYTES , Refund , RefundContents } ;
118
118
use crate :: offers:: signer;
@@ -168,7 +168,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
168
168
pub ( super ) fn for_offer (
169
169
invoice_request : & ' a InvoiceRequest , payment_paths : Vec < ( BlindedPayInfo , BlindedPath ) > ,
170
170
created_at : Duration , payment_hash : PaymentHash
171
- ) -> Result < Self , SemanticError > {
171
+ ) -> Result < Self , Bolt12SemanticError > {
172
172
let amount_msats = Self :: check_amount_msats ( invoice_request) ?;
173
173
let signing_pubkey = invoice_request. contents . inner . offer . signing_pubkey ( ) ;
174
174
let contents = InvoiceContents :: ForOffer {
@@ -184,7 +184,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
184
184
pub ( super ) fn for_refund (
185
185
refund : & ' a Refund , payment_paths : Vec < ( BlindedPayInfo , BlindedPath ) > , created_at : Duration ,
186
186
payment_hash : PaymentHash , signing_pubkey : PublicKey
187
- ) -> Result < Self , SemanticError > {
187
+ ) -> Result < Self , Bolt12SemanticError > {
188
188
let amount_msats = refund. amount_msats ( ) ;
189
189
let contents = InvoiceContents :: ForRefund {
190
190
refund : refund. contents . clone ( ) ,
@@ -201,7 +201,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
201
201
pub ( super ) fn for_offer_using_keys (
202
202
invoice_request : & ' a InvoiceRequest , payment_paths : Vec < ( BlindedPayInfo , BlindedPath ) > ,
203
203
created_at : Duration , payment_hash : PaymentHash , keys : KeyPair
204
- ) -> Result < Self , SemanticError > {
204
+ ) -> Result < Self , Bolt12SemanticError > {
205
205
let amount_msats = Self :: check_amount_msats ( invoice_request) ?;
206
206
let signing_pubkey = invoice_request. contents . inner . offer . signing_pubkey ( ) ;
207
207
let contents = InvoiceContents :: ForOffer {
@@ -217,7 +217,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
217
217
pub ( super ) fn for_refund_using_keys (
218
218
refund : & ' a Refund , payment_paths : Vec < ( BlindedPayInfo , BlindedPath ) > , created_at : Duration ,
219
219
payment_hash : PaymentHash , keys : KeyPair ,
220
- ) -> Result < Self , SemanticError > {
220
+ ) -> Result < Self , Bolt12SemanticError > {
221
221
let amount_msats = refund. amount_msats ( ) ;
222
222
let signing_pubkey = keys. public_key ( ) ;
223
223
let contents = InvoiceContents :: ForRefund {
@@ -232,16 +232,16 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
232
232
}
233
233
234
234
impl < ' a , S : SigningPubkeyStrategy > InvoiceBuilder < ' a , S > {
235
- fn check_amount_msats ( invoice_request : & InvoiceRequest ) -> Result < u64 , SemanticError > {
235
+ fn check_amount_msats ( invoice_request : & InvoiceRequest ) -> Result < u64 , Bolt12SemanticError > {
236
236
match invoice_request. amount_msats ( ) {
237
237
Some ( amount_msats) => Ok ( amount_msats) ,
238
238
None => match invoice_request. contents . inner . offer . amount ( ) {
239
239
Some ( Amount :: Bitcoin { amount_msats } ) => {
240
240
amount_msats. checked_mul ( invoice_request. quantity ( ) . unwrap_or ( 1 ) )
241
- . ok_or ( SemanticError :: InvalidAmount )
241
+ . ok_or ( Bolt12SemanticError :: InvalidAmount )
242
242
} ,
243
- Some ( Amount :: Currency { .. } ) => Err ( SemanticError :: UnsupportedCurrency ) ,
244
- None => Err ( SemanticError :: MissingAmount ) ,
243
+ Some ( Amount :: Currency { .. } ) => Err ( Bolt12SemanticError :: UnsupportedCurrency ) ,
244
+ None => Err ( Bolt12SemanticError :: MissingAmount ) ,
245
245
} ,
246
246
}
247
247
}
@@ -258,9 +258,9 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
258
258
259
259
fn new (
260
260
invreq_bytes : & ' a Vec < u8 > , contents : InvoiceContents , keys : Option < KeyPair >
261
- ) -> Result < Self , SemanticError > {
261
+ ) -> Result < Self , Bolt12SemanticError > {
262
262
if contents. fields ( ) . payment_paths . is_empty ( ) {
263
- return Err ( SemanticError :: MissingPaths ) ;
263
+ return Err ( Bolt12SemanticError :: MissingPaths ) ;
264
264
}
265
265
266
266
Ok ( Self {
@@ -331,10 +331,10 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
331
331
impl < ' a > InvoiceBuilder < ' a , ExplicitSigningPubkey > {
332
332
/// Builds an unsigned [`Bolt12Invoice`] after checking for valid semantics. It can be signed by
333
333
/// [`UnsignedBolt12Invoice::sign`].
334
- pub fn build ( self ) -> Result < UnsignedBolt12Invoice < ' a > , SemanticError > {
334
+ pub fn build ( self ) -> Result < UnsignedBolt12Invoice < ' a > , Bolt12SemanticError > {
335
335
#[ cfg( feature = "std" ) ] {
336
336
if self . invoice . is_offer_or_refund_expired ( ) {
337
- return Err ( SemanticError :: AlreadyExpired ) ;
337
+ return Err ( Bolt12SemanticError :: AlreadyExpired ) ;
338
338
}
339
339
}
340
340
@@ -347,10 +347,10 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
347
347
/// Builds a signed [`Bolt12Invoice`] after checking for valid semantics.
348
348
pub fn build_and_sign < T : secp256k1:: Signing > (
349
349
self , secp_ctx : & Secp256k1 < T >
350
- ) -> Result < Bolt12Invoice , SemanticError > {
350
+ ) -> Result < Bolt12Invoice , Bolt12SemanticError > {
351
351
#[ cfg( feature = "std" ) ] {
352
352
if self . invoice . is_offer_or_refund_expired ( ) {
353
- return Err ( SemanticError :: AlreadyExpired ) ;
353
+ return Err ( Bolt12SemanticError :: AlreadyExpired ) ;
354
354
}
355
355
}
356
356
@@ -853,7 +853,7 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
853
853
) ?;
854
854
855
855
let signature = match signature {
856
- None => return Err ( Bolt12ParseError :: InvalidSemantics ( SemanticError :: MissingSignature ) ) ,
856
+ None => return Err ( Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingSignature ) ) ,
857
857
Some ( signature) => signature,
858
858
} ;
859
859
let pubkey = contents. fields ( ) . signing_pubkey ;
@@ -864,7 +864,7 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
864
864
}
865
865
866
866
impl TryFrom < PartialInvoiceTlvStream > for InvoiceContents {
867
- type Error = SemanticError ;
867
+ type Error = Bolt12SemanticError ;
868
868
869
869
fn try_from ( tlv_stream : PartialInvoiceTlvStream ) -> Result < Self , Self :: Error > {
870
870
let (
@@ -878,19 +878,19 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
878
878
) = tlv_stream;
879
879
880
880
let payment_paths = match ( blindedpay, paths) {
881
- ( _, None ) => return Err ( SemanticError :: MissingPaths ) ,
882
- ( None , _) => return Err ( SemanticError :: InvalidPayInfo ) ,
883
- ( _, Some ( paths) ) if paths. is_empty ( ) => return Err ( SemanticError :: MissingPaths ) ,
881
+ ( _, None ) => return Err ( Bolt12SemanticError :: MissingPaths ) ,
882
+ ( None , _) => return Err ( Bolt12SemanticError :: InvalidPayInfo ) ,
883
+ ( _, Some ( paths) ) if paths. is_empty ( ) => return Err ( Bolt12SemanticError :: MissingPaths ) ,
884
884
( Some ( blindedpay) , Some ( paths) ) if paths. len ( ) != blindedpay. len ( ) => {
885
- return Err ( SemanticError :: InvalidPayInfo ) ;
885
+ return Err ( Bolt12SemanticError :: InvalidPayInfo ) ;
886
886
} ,
887
887
( Some ( blindedpay) , Some ( paths) ) => {
888
888
blindedpay. into_iter ( ) . zip ( paths. into_iter ( ) ) . collect :: < Vec < _ > > ( )
889
889
} ,
890
890
} ;
891
891
892
892
let created_at = match created_at {
893
- None => return Err ( SemanticError :: MissingCreationTime ) ,
893
+ None => return Err ( Bolt12SemanticError :: MissingCreationTime ) ,
894
894
Some ( timestamp) => Duration :: from_secs ( timestamp) ,
895
895
} ;
896
896
@@ -899,19 +899,19 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
899
899
. map ( Duration :: from_secs) ;
900
900
901
901
let payment_hash = match payment_hash {
902
- None => return Err ( SemanticError :: MissingPaymentHash ) ,
902
+ None => return Err ( Bolt12SemanticError :: MissingPaymentHash ) ,
903
903
Some ( payment_hash) => payment_hash,
904
904
} ;
905
905
906
906
let amount_msats = match amount {
907
- None => return Err ( SemanticError :: MissingAmount ) ,
907
+ None => return Err ( Bolt12SemanticError :: MissingAmount ) ,
908
908
Some ( amount) => amount,
909
909
} ;
910
910
911
911
let features = features. unwrap_or_else ( Bolt12InvoiceFeatures :: empty) ;
912
912
913
913
let signing_pubkey = match node_id {
914
- None => return Err ( SemanticError :: MissingSigningPubkey ) ,
914
+ None => return Err ( Bolt12SemanticError :: MissingSigningPubkey ) ,
915
915
Some ( node_id) => node_id,
916
916
} ;
917
917
@@ -923,7 +923,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
923
923
match offer_tlv_stream. node_id {
924
924
Some ( expected_signing_pubkey) => {
925
925
if fields. signing_pubkey != expected_signing_pubkey {
926
- return Err ( SemanticError :: InvalidSigningPubkey ) ;
926
+ return Err ( Bolt12SemanticError :: InvalidSigningPubkey ) ;
927
927
}
928
928
929
929
let invoice_request = InvoiceRequestContents :: try_from (
@@ -961,7 +961,7 @@ mod tests {
961
961
use crate :: offers:: invoice_request:: InvoiceRequestTlvStreamRef ;
962
962
use crate :: offers:: merkle:: { SignError , SignatureTlvStreamRef , self } ;
963
963
use crate :: offers:: offer:: { OfferBuilder , OfferTlvStreamRef , Quantity } ;
964
- use crate :: offers:: parse:: { Bolt12ParseError , SemanticError } ;
964
+ use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError } ;
965
965
use crate :: offers:: payer:: PayerTlvStreamRef ;
966
966
use crate :: offers:: refund:: RefundBuilder ;
967
967
use crate :: offers:: test_utils:: * ;
@@ -1180,7 +1180,7 @@ mod tests {
1180
1180
. build ( )
1181
1181
{
1182
1182
Ok ( _) => panic ! ( "expected error" ) ,
1183
- Err ( e) => assert_eq ! ( e, SemanticError :: AlreadyExpired ) ,
1183
+ Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: AlreadyExpired ) ,
1184
1184
}
1185
1185
}
1186
1186
@@ -1208,7 +1208,7 @@ mod tests {
1208
1208
. build ( )
1209
1209
{
1210
1210
Ok ( _) => panic ! ( "expected error" ) ,
1211
- Err ( e) => assert_eq ! ( e, SemanticError :: AlreadyExpired ) ,
1211
+ Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: AlreadyExpired ) ,
1212
1212
}
1213
1213
}
1214
1214
@@ -1253,7 +1253,7 @@ mod tests {
1253
1253
payment_paths ( ) , payment_hash ( ) , now ( ) , & expanded_key, & secp_ctx
1254
1254
) {
1255
1255
Ok ( _) => panic ! ( "expected error" ) ,
1256
- Err ( e) => assert_eq ! ( e, SemanticError :: InvalidMetadata ) ,
1256
+ Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: InvalidMetadata ) ,
1257
1257
}
1258
1258
1259
1259
let desc = "foo" . to_string ( ) ;
@@ -1269,7 +1269,7 @@ mod tests {
1269
1269
payment_paths ( ) , payment_hash ( ) , now ( ) , & expanded_key, & secp_ctx
1270
1270
) {
1271
1271
Ok ( _) => panic ! ( "expected error" ) ,
1272
- Err ( e) => assert_eq ! ( e, SemanticError :: InvalidMetadata ) ,
1272
+ Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: InvalidMetadata ) ,
1273
1273
}
1274
1274
}
1275
1275
@@ -1376,7 +1376,7 @@ mod tests {
1376
1376
. respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) )
1377
1377
{
1378
1378
Ok ( _) => panic ! ( "expected error" ) ,
1379
- Err ( e) => assert_eq ! ( e, SemanticError :: InvalidAmount ) ,
1379
+ Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: InvalidAmount ) ,
1380
1380
}
1381
1381
}
1382
1382
@@ -1502,15 +1502,15 @@ mod tests {
1502
1502
1503
1503
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1504
1504
Ok ( _) => panic ! ( "expected error" ) ,
1505
- Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: MissingPaths ) ) ,
1505
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingPaths ) ) ,
1506
1506
}
1507
1507
1508
1508
let mut tlv_stream = invoice. as_tlv_stream ( ) ;
1509
1509
tlv_stream. 3 . blindedpay = None ;
1510
1510
1511
1511
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1512
1512
Ok ( _) => panic ! ( "expected error" ) ,
1513
- Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: InvalidPayInfo ) ) ,
1513
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: InvalidPayInfo ) ) ,
1514
1514
}
1515
1515
1516
1516
let empty_payment_paths = vec ! [ ] ;
@@ -1519,7 +1519,7 @@ mod tests {
1519
1519
1520
1520
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1521
1521
Ok ( _) => panic ! ( "expected error" ) ,
1522
- Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: MissingPaths ) ) ,
1522
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingPaths ) ) ,
1523
1523
}
1524
1524
1525
1525
let mut payment_paths = payment_paths ( ) ;
@@ -1529,7 +1529,7 @@ mod tests {
1529
1529
1530
1530
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1531
1531
Ok ( _) => panic ! ( "expected error" ) ,
1532
- Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: InvalidPayInfo ) ) ,
1532
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: InvalidPayInfo ) ) ,
1533
1533
}
1534
1534
}
1535
1535
@@ -1558,7 +1558,7 @@ mod tests {
1558
1558
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1559
1559
Ok ( _) => panic ! ( "expected error" ) ,
1560
1560
Err ( e) => {
1561
- assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: MissingCreationTime ) ) ;
1561
+ assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingCreationTime ) ) ;
1562
1562
} ,
1563
1563
}
1564
1564
}
@@ -1610,7 +1610,7 @@ mod tests {
1610
1610
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1611
1611
Ok ( _) => panic ! ( "expected error" ) ,
1612
1612
Err ( e) => {
1613
- assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: MissingPaymentHash ) ) ;
1613
+ assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingPaymentHash ) ) ;
1614
1614
} ,
1615
1615
}
1616
1616
}
@@ -1639,7 +1639,7 @@ mod tests {
1639
1639
1640
1640
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1641
1641
Ok ( _) => panic ! ( "expected error" ) ,
1642
- Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: MissingAmount ) ) ,
1642
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingAmount ) ) ,
1643
1643
}
1644
1644
}
1645
1645
@@ -1758,7 +1758,7 @@ mod tests {
1758
1758
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1759
1759
Ok ( _) => panic ! ( "expected error" ) ,
1760
1760
Err ( e) => {
1761
- assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: MissingSigningPubkey ) ) ;
1761
+ assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingSigningPubkey ) ) ;
1762
1762
} ,
1763
1763
}
1764
1764
@@ -1769,7 +1769,7 @@ mod tests {
1769
1769
match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
1770
1770
Ok ( _) => panic ! ( "expected error" ) ,
1771
1771
Err ( e) => {
1772
- assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: InvalidSigningPubkey ) ) ;
1772
+ assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: InvalidSigningPubkey ) ) ;
1773
1773
} ,
1774
1774
}
1775
1775
}
@@ -1790,7 +1790,7 @@ mod tests {
1790
1790
1791
1791
match Bolt12Invoice :: try_from ( buffer) {
1792
1792
Ok ( _) => panic ! ( "expected error" ) ,
1793
- Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( SemanticError :: MissingSignature ) ) ,
1793
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingSignature ) ) ,
1794
1794
}
1795
1795
}
1796
1796
0 commit comments