Merge pull request #3039 from valentinewallace/2024-04-invoice-amt-msats-overflow

Fix overflow in invoice amount setter.
This commit is contained in:
Matt Corallo 2024-05-06 12:20:37 -07:00 committed by GitHub
commit 78ab54ff82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)