Skip to content

Commit c9778d3

Browse files
committed
Use SemanticError in OfferBuilder::build
1 parent bcebc5e commit c9778d3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lightning/src/offers/offer.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848
//! .issuer("Foo Bar".to_string())
4949
//! .path(create_blinded_path())
5050
//! .path(create_another_blinded_path())
51-
//! .build()
52-
//! .unwrap();
51+
//! .build()?;
5352
//!
5453
//! // Encode as a bech32 string for use in a QR code.
5554
//! let encoded_offer = offer.to_string();
@@ -186,11 +185,11 @@ impl OfferBuilder {
186185
}
187186

188187
/// Builds an [`Offer`] from the builder's settings.
189-
pub fn build(self) -> Result<Offer, ()> {
188+
pub fn build(self) -> Result<Offer, SemanticError> {
190189
// TODO: Also check for Amount::Currency
191190
if let Some(Amount::Currency { .. }) = self.offer.amount {
192191
} else if self.offer.amount_msats() > MAX_VALUE_MSAT {
193-
return Err(());
192+
return Err(SemanticError::InvalidAmount);
194193
}
195194

196195
let mut bytes = Vec::new();
@@ -543,6 +542,7 @@ mod tests {
543542
use core::time::Duration;
544543
use ln::features::OfferFeatures;
545544
use ln::msgs::MAX_VALUE_MSAT;
545+
use offers::parse::SemanticError;
546546
use onion_message::{BlindedHop, BlindedPath};
547547
use util::ser::Writeable;
548548
use util::string::PrintableString;
@@ -679,7 +679,7 @@ mod tests {
679679
let invalid_amount = Amount::Bitcoin { amount_msats: MAX_VALUE_MSAT + 1 };
680680
match OfferBuilder::new("foo".into(), pubkey(42)).amount(invalid_amount).build() {
681681
Ok(_) => panic!("expected error"),
682-
Err(e) => assert_eq!(e, ()),
682+
Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
683683
}
684684
}
685685

lightning/src/offers/parse.rs

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub enum ParseError {
7474
pub enum SemanticError {
7575
/// An amount was expected but was missing.
7676
MissingAmount,
77+
/// An amount exceeded the maximum number of bitcoin.
78+
InvalidAmount,
7779
/// A required description was not provided.
7880
MissingDescription,
7981
/// A node id was not provided.

0 commit comments

Comments
 (0)