/// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
ExpiryTimeOutOfBounds,
+
+ /// The supplied millisatoshi amount was greater than the total bitcoin supply.
+ InvalidAmount,
}
impl Display for CreationError {
CreationError::RouteTooLong => f.write_str("The specified route has too many hops and can't be encoded"),
CreationError::TimestampOutOfBounds => f.write_str("The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`"),
CreationError::ExpiryTimeOutOfBounds => f.write_str("The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`"),
+ CreationError::InvalidAmount => f.write_str("The supplied millisatoshi amount was greater than the total bitcoin supply"),
}
}
}
//! Convenient utilities to create an invoice.
-use {Currency, DEFAULT_EXPIRY_TIME, Invoice, InvoiceBuilder, SignOrCreationError, RawInvoice};
+use {CreationError, Currency, DEFAULT_EXPIRY_TIME, Invoice, InvoiceBuilder, SignOrCreationError, RawInvoice};
use payment::{Payer, Router};
use bech32::ToBase32;
}]));
}
+ // `create_inbound_payment` only returns an error if the amount is greater than the total bitcoin
+ // supply.
let (payment_hash, payment_secret) = channelmanager.create_inbound_payment(
- amt_msat,
- DEFAULT_EXPIRY_TIME.try_into().unwrap(),
- ).unwrap();
+ amt_msat, DEFAULT_EXPIRY_TIME.try_into().unwrap())
+ .map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
let our_node_pubkey = channelmanager.get_our_node_id();
let mut invoice = InvoiceBuilder::new(network)
.description(description)