Fix overflow in lightning-invoice amount_pico_btc.

This commit is contained in:
Valentine Wallace 2024-04-30 10:05:35 -04:00
parent 2b14cc40a6
commit c6ae9288b9
No known key found for this signature in database
GPG key ID: FD3E106A2CE099B4

View file

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