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 ( self ) -> Result < Offer , ( ) > {
197
+ pub fn build ( 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
@@ -552,6 +551,7 @@ mod tests {
552
551
use core:: time:: Duration ;
553
552
use crate :: ln:: features:: OfferFeatures ;
554
553
use crate :: ln:: msgs:: MAX_VALUE_MSAT ;
554
+ use crate :: offers:: parse:: SemanticError ;
555
555
use crate :: onion_message:: { BlindedHop , BlindedPath } ;
556
556
use crate :: util:: ser:: Writeable ;
557
557
use crate :: util:: string:: PrintableString ;
@@ -673,6 +673,10 @@ mod tests {
673
673
assert_eq ! ( builder. offer. amount, Some ( currency_amount. clone( ) ) ) ;
674
674
assert_eq ! ( tlv_stream. amount, Some ( 10 ) ) ;
675
675
assert_eq ! ( tlv_stream. currency, Some ( b"USD" ) ) ;
676
+ match builder. build ( ) {
677
+ Ok ( _) => panic ! ( "expected error" ) ,
678
+ Err ( e) => assert_eq ! ( e, SemanticError :: UnsupportedCurrency ) ,
679
+ }
676
680
677
681
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
678
682
. amount ( currency_amount. clone ( ) )
@@ -686,7 +690,7 @@ mod tests {
686
690
let invalid_amount = Amount :: Bitcoin { amount_msats : MAX_VALUE_MSAT + 1 } ;
687
691
match OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) ) . amount ( invalid_amount) . build ( ) {
688
692
Ok ( _) => panic ! ( "expected error" ) ,
689
- Err ( e) => assert_eq ! ( e, ( ) ) ,
693
+ Err ( e) => assert_eq ! ( e, SemanticError :: InvalidAmount ) ,
690
694
}
691
695
}
692
696
0 commit comments