Skip to content

Commit

Permalink
Merge pull request lightningdevkit#3032 from valentinewallace/2024-04…
Browse files Browse the repository at this point in the history
…-pico-btc-overflow

Fix overflow in lightning-invoice `amount_pico_btc`
  • Loading branch information
TheBlueMatt committed May 6, 2024
2 parents ff1827a + c6ae928 commit 1b33b36
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lightning-invoice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,9 +1068,10 @@ impl RawBolt11Invoice {
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> {
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() }))
})
}

Expand Down

0 comments on commit 1b33b36

Please sign in to comment.