Skip to content

Commit

Permalink
Merge pull request #3032 from valentinewallace/2024-04-pico-btc-overflow
Browse files Browse the repository at this point in the history
Fix overflow in lightning-invoice `amount_pico_btc`
  • Loading branch information
TheBlueMatt committed May 1, 2024
2 parents c903698 + c6ae928 commit b403411
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 b403411

Please sign in to comment.