48
48
//! .issuer("Foo Bar".to_string())
49
49
//! .path(create_blinded_path())
50
50
//! .path(create_another_blinded_path())
51
- //! .build()
52
- //! .unwrap();
51
+ //! .build()?;
53
52
//!
54
53
//! // Encode as a bech32 string for use in a QR code.
55
54
//! let encoded_offer = offer.to_string();
@@ -195,14 +194,14 @@ impl OfferBuilder {
195
194
}
196
195
197
196
/// Builds an [`Offer`] from the builder's settings.
198
- pub fn build ( mut self ) -> Result < Offer , ( ) > {
197
+ pub fn build ( mut self ) -> Result < Offer , SemanticError > {
199
198
match self . offer . amount {
200
199
Some ( Amount :: Bitcoin { amount_msats } ) => {
201
200
if amount_msats > MAX_VALUE_MSAT {
202
- return Err ( ( ) ) ;
201
+ return Err ( SemanticError :: InvalidAmount ) ;
203
202
}
204
203
} ,
205
- Some ( Amount :: Currency { .. } ) => unreachable ! ( ) ,
204
+ Some ( Amount :: Currency { .. } ) => return Err ( SemanticError :: UnsupportedCurrency ) ,
206
205
None => { } ,
207
206
}
208
207
@@ -562,6 +561,7 @@ mod tests {
562
561
use core:: time:: Duration ;
563
562
use crate :: ln:: features:: OfferFeatures ;
564
563
use crate :: ln:: msgs:: MAX_VALUE_MSAT ;
564
+ use crate :: offers:: parse:: SemanticError ;
565
565
use crate :: onion_message:: { BlindedHop , BlindedPath } ;
566
566
use crate :: util:: ser:: Writeable ;
567
567
use crate :: util:: string:: PrintableString ;
@@ -687,6 +687,10 @@ mod tests {
687
687
assert_eq ! ( builder. offer. amount, Some ( currency_amount. clone( ) ) ) ;
688
688
assert_eq ! ( tlv_stream. amount, Some ( 10 ) ) ;
689
689
assert_eq ! ( tlv_stream. currency, Some ( b"USD" ) ) ;
690
+ match builder. build ( ) {
691
+ Ok ( _) => panic ! ( "expected error" ) ,
692
+ Err ( e) => assert_eq ! ( e, SemanticError :: UnsupportedCurrency ) ,
693
+ }
690
694
691
695
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
692
696
. amount ( currency_amount. clone ( ) )
@@ -700,7 +704,7 @@ mod tests {
700
704
let invalid_amount = Amount :: Bitcoin { amount_msats : MAX_VALUE_MSAT + 1 } ;
701
705
match OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) ) . amount ( invalid_amount) . build ( ) {
702
706
Ok ( _) => panic ! ( "expected error" ) ,
703
- Err ( e) => assert_eq ! ( e, ( ) ) ,
707
+ Err ( e) => assert_eq ! ( e, SemanticError :: InvalidAmount ) ,
704
708
}
705
709
}
706
710
0 commit comments