|
47 | 47 | //! .issuer("Foo Bar".to_string())
|
48 | 48 | //! .path(create_blinded_path())
|
49 | 49 | //! .path(create_another_blinded_path())
|
50 |
| -//! .build() |
51 |
| -//! .unwrap(); |
| 50 | +//! .build()?; |
52 | 51 | //!
|
53 | 52 | //! // Encode as a bech32 string for use in a QR code.
|
54 | 53 | //! let encoded_offer = offer.to_string();
|
@@ -218,15 +217,15 @@ impl OfferBuilder {
|
218 | 217 | }
|
219 | 218 |
|
220 | 219 | /// Builds an [`Offer`] from the builder's settings.
|
221 |
| - pub fn build(self) -> Result<Offer, ()> { |
| 220 | + pub fn build(self) -> Result<Offer, SemanticError> { |
222 | 221 | // TODO: Also check for Amount::Currency
|
223 | 222 | if let Some(Amount::Currency { .. }) = self.offer.amount {
|
224 | 223 | } else if self.offer.amount_msats() > MAX_VALUE_MSAT {
|
225 |
| - return Err(()); |
| 224 | + return Err(SemanticError::InvalidAmount); |
226 | 225 | }
|
227 | 226 |
|
228 | 227 | if self.offer.quantity_min() > self.offer.quantity_max() {
|
229 |
| - return Err(()); |
| 228 | + return Err(SemanticError::InvalidQuantity); |
230 | 229 | }
|
231 | 230 |
|
232 | 231 | let mut bytes = Vec::new();
|
@@ -554,6 +553,7 @@ mod tests {
|
554 | 553 | use core::time::Duration;
|
555 | 554 | use ln::features::OfferFeatures;
|
556 | 555 | use ln::msgs::MAX_VALUE_MSAT;
|
| 556 | + use offers::parse::SemanticError; |
557 | 557 | use onion_message::{BlindedHop, BlindedPath};
|
558 | 558 | use util::ser::Writeable;
|
559 | 559 |
|
@@ -687,7 +687,7 @@ mod tests {
|
687 | 687 | let invalid_amount = Amount::Bitcoin { amount_msats: MAX_VALUE_MSAT + 1 };
|
688 | 688 | match OfferBuilder::new("foo".into(), pubkey(42)).amount(invalid_amount).build() {
|
689 | 689 | Ok(_) => panic!("expected error"),
|
690 |
| - Err(e) => assert_eq!(e, ()), |
| 690 | + Err(e) => assert_eq!(e, SemanticError::InvalidAmount), |
691 | 691 | }
|
692 | 692 | }
|
693 | 693 |
|
@@ -913,11 +913,10 @@ mod tests {
|
913 | 913 | assert_eq!(tlv_stream.quantity_min, None);
|
914 | 914 | assert_eq!(tlv_stream.quantity_max, Some(9));
|
915 | 915 |
|
916 |
| - assert!(OfferBuilder::new("foo".into(), pubkey(42)) |
917 |
| - .quantity_range(ten..five) |
918 |
| - .build() |
919 |
| - .is_err() |
920 |
| - ); |
| 916 | + match OfferBuilder::new("foo".into(), pubkey(42)).quantity_range(ten..five).build() { |
| 917 | + Ok(_) => panic!("expected error"), |
| 918 | + Err(e) => assert_eq!(e, SemanticError::InvalidQuantity), |
| 919 | + } |
921 | 920 | }
|
922 | 921 | }
|
923 | 922 |
|
|
0 commit comments