|
49 | 49 | //! .issuer("Foo Bar".to_string())
|
50 | 50 | //! .path(create_blinded_path())
|
51 | 51 | //! .path(create_another_blinded_path())
|
52 |
| -//! .build() |
53 |
| -//! .unwrap(); |
| 52 | +//! .build()?; |
54 | 53 | //!
|
55 | 54 | //! // Encode as a bech32 string for use in a QR code.
|
56 | 55 | //! let encoded_offer = offer.to_string();
|
@@ -228,15 +227,15 @@ impl OfferBuilder {
|
228 | 227 | }
|
229 | 228 |
|
230 | 229 | /// Builds an [`Offer`] from the builder's settings.
|
231 |
| - pub fn build(self) -> Result<Offer, ()> { |
| 230 | + pub fn build(self) -> Result<Offer, SemanticError> { |
232 | 231 | // TODO: Also check for Amount::Currency
|
233 | 232 | if let Some(Amount::Currency { .. }) = self.offer.amount {
|
234 | 233 | } else if self.offer.amount_msats() > MAX_VALUE_MSAT {
|
235 |
| - return Err(()); |
| 234 | + return Err(SemanticError::InvalidAmount); |
236 | 235 | }
|
237 | 236 |
|
238 | 237 | if self.offer.quantity_min() > self.offer.quantity_max() {
|
239 |
| - return Err(()); |
| 238 | + return Err(SemanticError::InvalidQuantity); |
240 | 239 | }
|
241 | 240 |
|
242 | 241 | let mut bytes = Vec::new();
|
@@ -589,6 +588,7 @@ mod tests {
|
589 | 588 | use core::time::Duration;
|
590 | 589 | use ln::features::OfferFeatures;
|
591 | 590 | use ln::msgs::MAX_VALUE_MSAT;
|
| 591 | + use offers::parse::SemanticError; |
592 | 592 | use onion_message::{BlindedHop, BlindedPath};
|
593 | 593 | use util::ser::Writeable;
|
594 | 594 | use util::string::PrintableString;
|
@@ -727,7 +727,7 @@ mod tests {
|
727 | 727 | let invalid_amount = Amount::Bitcoin { amount_msats: MAX_VALUE_MSAT + 1 };
|
728 | 728 | match OfferBuilder::new("foo".into(), pubkey(42)).amount(invalid_amount).build() {
|
729 | 729 | Ok(_) => panic!("expected error"),
|
730 |
| - Err(e) => assert_eq!(e, ()), |
| 730 | + Err(e) => assert_eq!(e, SemanticError::InvalidAmount), |
731 | 731 | }
|
732 | 732 | }
|
733 | 733 |
|
@@ -953,11 +953,10 @@ mod tests {
|
953 | 953 | assert_eq!(tlv_stream.quantity_min, None);
|
954 | 954 | assert_eq!(tlv_stream.quantity_max, Some(9));
|
955 | 955 |
|
956 |
| - assert!(OfferBuilder::new("foo".into(), pubkey(42)) |
957 |
| - .quantity_range(ten..five) |
958 |
| - .build() |
959 |
| - .is_err() |
960 |
| - ); |
| 956 | + match OfferBuilder::new("foo".into(), pubkey(42)).quantity_range(ten..five).build() { |
| 957 | + Ok(_) => panic!("expected error"), |
| 958 | + Err(e) => assert_eq!(e, SemanticError::InvalidQuantity), |
| 959 | + } |
961 | 960 | }
|
962 | 961 | }
|
963 | 962 |
|
|
0 commit comments