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