projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #3039 from valentinewallace/2024-04-invoice-amt-msats-overflow
[rust-lightning]
/
lightning-invoice
/
src
/
lib.rs
diff --git
a/lightning-invoice/src/lib.rs
b/lightning-invoice/src/lib.rs
index a029c5f3dad5bdf76fe8df4439380fb52846f5f4..fb34240bee1b32ee397f9acce1de769db65bf9a7 100644
(file)
--- a/
lightning-invoice/src/lib.rs
+++ b/
lightning-invoice/src/lib.rs
@@
-31,7
+31,6
@@
pub mod utils;
extern crate bech32;
#[macro_use] extern crate lightning;
extern crate bech32;
#[macro_use] extern crate lightning;
-extern crate num_traits;
extern crate secp256k1;
extern crate alloc;
#[cfg(any(test, feature = "std"))]
extern crate secp256k1;
extern crate alloc;
#[cfg(any(test, feature = "std"))]
@@
-66,7
+65,7
@@
use core::str;
use serde::{Deserialize, Deserializer,Serialize, Serializer, de::Error};
#[doc(no_inline)]
use serde::{Deserialize, Deserializer,Serialize, Serializer, de::Error};
#[doc(no_inline)]
-pub use lightning::ln::PaymentSecret;
+pub use lightning::ln::
types::
PaymentSecret;
#[doc(no_inline)]
pub use lightning::routing::router::{RouteHint, RouteHintHop};
#[doc(no_inline)]
#[doc(no_inline)]
pub use lightning::routing::router::{RouteHint, RouteHintHop};
#[doc(no_inline)]
@@
-163,7
+162,7
@@
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
/// use secp256k1::Secp256k1;
/// use secp256k1::SecretKey;
///
/// use secp256k1::Secp256k1;
/// use secp256k1::SecretKey;
///
-/// use lightning::ln::PaymentSecret;
+/// use lightning::ln::
types::
PaymentSecret;
///
/// use lightning_invoice::{Currency, InvoiceBuilder};
///
///
/// use lightning_invoice::{Currency, InvoiceBuilder};
///
@@
-578,7
+577,13
@@
impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Boo
/// Sets the amount in millisatoshis. The optimal SI prefix is chosen automatically.
pub fn amount_milli_satoshis(mut self, amount_msat: u64) -> Self {
/// Sets the amount in millisatoshis. The optimal SI prefix is chosen automatically.
pub fn amount_milli_satoshis(mut self, amount_msat: u64) -> Self {
- let amount = amount_msat * 10; // Invoices are denominated in "pico BTC"
+ let amount = match amount_msat.checked_mul(10) { // Invoices are denominated in "pico BTC"
+ Some(amt) => amt,
+ None => {
+ self.error = Some(CreationError::InvalidAmount);
+ return self
+ }
+ };
let biggest_possible_si_prefix = SiPrefix::values_desc()
.iter()
.find(|prefix| amount % prefix.multiplier() == 0)
let biggest_possible_si_prefix = SiPrefix::values_desc()
.iter()
.find(|prefix| amount % prefix.multiplier() == 0)
@@
-1069,9
+1074,10
@@
impl RawBolt11Invoice {
find_all_extract!(self.known_tagged_fields(), TaggedField::PrivateRoute(ref x), x).collect()
}
find_all_extract!(self.known_tagged_fields(), TaggedField::PrivateRoute(ref x), x).collect()
}
+ /// Returns `None` if no amount is set or on overflow.
pub fn amount_pico_btc(&self) -> Option<u64> {
pub fn amount_pico_btc(&self) -> Option<u64> {
- self.hrp.raw_amount.
map
(|v| {
- v
* self.hrp.si_prefix.as_ref().map_or(1_000_000_000_000, |si| { si.multiplier() }
)
+ self.hrp.raw_amount.
and_then
(|v| {
+ v
.checked_mul(self.hrp.si_prefix.as_ref().map_or(1_000_000_000_000, |si| { si.multiplier() })
)
})
}
})
}
@@
-1877,7
+1883,7
@@
mod test {
Bolt11SemanticError};
let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
Bolt11SemanticError};
let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
- let payment_secret = lightning::ln::PaymentSecret([21; 32]);
+ let payment_secret = lightning::ln::
types::
PaymentSecret([21; 32]);
let invoice_template = RawBolt11Invoice {
hrp: RawHrp {
currency: Currency::Bitcoin,
let invoice_template = RawBolt11Invoice {
hrp: RawHrp {
currency: Currency::Bitcoin,