47
47
//! .issuer("Foo Bar".to_string())
48
48
//! .path(create_blinded_path())
49
49
//! .path(create_another_blinded_path())
50
- //! .build()
51
- //! .unwrap();
50
+ //! .build()?;
52
51
//!
53
52
//! // Encode as a bech32 string for use in a QR code.
54
53
//! let encoded_offer = offer.to_string();
@@ -213,17 +212,17 @@ impl OfferBuilder {
213
212
}
214
213
215
214
/// Builds an [`Offer`] from the builder's settings.
216
- pub fn build ( self ) -> Result < Offer , ( ) > {
215
+ pub fn build ( self ) -> Result < Offer , SemanticError > {
217
216
if let Some ( Amount :: Currency { .. } ) = self . offer . amount {
218
- return Err ( ( ) ) ;
217
+ return Err ( SemanticError :: UnsupportedCurrency ) ;
219
218
}
220
219
221
220
if self . offer . amount_msats ( ) > MAX_VALUE_MSAT {
222
- return Err ( ( ) ) ;
221
+ return Err ( SemanticError :: InvalidAmount ) ;
223
222
}
224
223
225
224
if self . offer . quantity_min ( ) > self . offer . quantity_max ( ) {
226
- return Err ( ( ) ) ;
225
+ return Err ( SemanticError :: InvalidQuantity ) ;
227
226
}
228
227
229
228
let mut bytes = Vec :: new ( ) ;
@@ -559,6 +558,7 @@ mod tests {
559
558
use core:: time:: Duration ;
560
559
use ln:: features:: OfferFeatures ;
561
560
use ln:: msgs:: MAX_VALUE_MSAT ;
561
+ use offers:: parse:: SemanticError ;
562
562
use onion_message:: { BlindedHop , BlindedPath } ;
563
563
use util:: ser:: Writeable ;
564
564
@@ -679,7 +679,7 @@ mod tests {
679
679
assert_eq ! ( tlv_stream. currency, Some ( b"USD" ) ) ;
680
680
match builder. build ( ) {
681
681
Ok ( _) => panic ! ( "expected error" ) ,
682
- Err ( e) => assert_eq ! ( e, ( ) ) ,
682
+ Err ( e) => assert_eq ! ( e, SemanticError :: UnsupportedCurrency ) ,
683
683
}
684
684
685
685
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
@@ -694,7 +694,7 @@ mod tests {
694
694
let invalid_amount = Amount :: Bitcoin { amount_msats : MAX_VALUE_MSAT + 1 } ;
695
695
match OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) ) . amount ( invalid_amount) . build ( ) {
696
696
Ok ( _) => panic ! ( "expected error" ) ,
697
- Err ( e) => assert_eq ! ( e, ( ) ) ,
697
+ Err ( e) => assert_eq ! ( e, SemanticError :: InvalidAmount ) ,
698
698
}
699
699
}
700
700
@@ -920,11 +920,10 @@ mod tests {
920
920
assert_eq ! ( tlv_stream. quantity_min, None ) ;
921
921
assert_eq ! ( tlv_stream. quantity_max, Some ( 9 ) ) ;
922
922
923
- assert ! ( OfferBuilder :: new( "foo" . into( ) , pubkey( 42 ) )
924
- . quantity_range( ten..five)
925
- . build( )
926
- . is_err( )
927
- ) ;
923
+ match OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) ) . quantity_range ( ten..five) . build ( ) {
924
+ Ok ( _) => panic ! ( "expected error" ) ,
925
+ Err ( e) => assert_eq ! ( e, SemanticError :: InvalidQuantity ) ,
926
+ }
928
927
}
929
928
}
930
929
0 commit comments