diff --git a/src/amount.rs b/src/amount.rs index 491b091a..f3959a15 100644 --- a/src/amount.rs +++ b/src/amount.rs @@ -14,10 +14,6 @@ impl Sats { msats: sats * 1000, } } - - pub(crate) fn msats(&self) -> Msats { - Msats { msats: self.msats } - } } pub(crate) struct Msats { @@ -91,6 +87,12 @@ pub struct Amount { pub fiat: Option, } +impl Amount { + pub fn to_msats(&self) -> u64 { + self.sats.as_sats().msats + } +} + pub(crate) trait ToAmount { fn to_amount_up(self, rate: &Option) -> Amount; fn to_amount_down(self, rate: &Option) -> Amount; diff --git a/src/analytics.rs b/src/analytics.rs index 673ad285..f3ea2177 100644 --- a/src/analytics.rs +++ b/src/analytics.rs @@ -1,4 +1,3 @@ -use crate::amount::AsSats; use crate::async_runtime::Handle; use crate::errors::Result; use crate::key_derivation::derive_analytics_key; @@ -68,7 +67,7 @@ impl AnalyticsInterceptor { return; } - let invoice_amount = invoice_details.amount.map(|a| a.sats.as_sats().msats); + let invoice_amount = invoice_details.amount.map(|a| a.to_msats()); let paid_amount_msat = match paid_amount.or(invoice_amount) { Some(a) => a, None => { diff --git a/src/fiat_topup.rs b/src/fiat_topup.rs index 78259707..3d9b0a9b 100644 --- a/src/fiat_topup.rs +++ b/src/fiat_topup.rs @@ -233,13 +233,13 @@ impl FiatTopup { .max_withdrawable; ensure!( - max_withdrawable_msats <= offer.amount.sats.as_sats().msats, + max_withdrawable_msats <= offer.amount.to_msats(), permanent_failure("LNURLw provides more") ); let exchange_rate = self.support.get_exchange_rate(); - Ok((offer.amount.sats.as_sats().msats - max_withdrawable_msats) + Ok((offer.amount.to_msats() - max_withdrawable_msats) .as_msats() .to_amount_up(&exchange_rate)) } diff --git a/src/lightning/mod.rs b/src/lightning/mod.rs index a5fdf841..76bb77f6 100644 --- a/src/lightning/mod.rs +++ b/src/lightning/mod.rs @@ -85,7 +85,7 @@ impl Lightning { MaxRoutingFeeMode::Relative { max_fee_permyriad } => { Permyriad(max_fee_permyriad).of(&amount).msats } - MaxRoutingFeeMode::Absolute { max_fee_amount } => max_fee_amount.sats.as_sats().msats, + MaxRoutingFeeMode::Absolute { max_fee_amount } => max_fee_amount.to_msats(), }; let node_state = self.support.sdk.node_info().map_to_runtime_error( diff --git a/src/onchain/swap.rs b/src/onchain/swap.rs index b10085c2..3be11a66 100644 --- a/src/onchain/swap.rs +++ b/src/onchain/swap.rs @@ -96,7 +96,7 @@ impl Swap { get_onchain_resolving_fees( &self.support, self, - failed_swap_info.amount.sats.as_sats().msats(), + failed_swap_info.amount.to_msats().as_msats(), prepare_onchain_tx, ) }