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