Skip to content

Commit

Permalink
Merge pull request #3039 from valentinewallace/2024-04-invoice-amt-ms…
Browse files Browse the repository at this point in the history
…ats-overflow

Fix overflow in invoice amount setter.
  • Loading branch information
TheBlueMatt authored May 6, 2024
2 parents b8d4ac1 + 0ea58d0 commit 78ab54f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lightning-invoice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,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 {
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)
Expand Down

0 comments on commit 78ab54f

Please sign in to comment.