Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience fn to convert Amount into msats #1322

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ impl Sats {
msats: sats * 1000,
}
}

pub(crate) fn msats(&self) -> Msats {
Msats { msats: self.msats }
}
}

pub(crate) struct Msats {
Expand Down Expand Up @@ -91,6 +87,12 @@ pub struct Amount {
pub fiat: Option<FiatValue>,
}

impl Amount {
pub fn to_msats(&self) -> u64 {
self.sats.as_sats().msats
}
}

pub(crate) trait ToAmount {
fn to_amount_up(self, rate: &Option<ExchangeRate>) -> Amount;
fn to_amount_down(self, rate: &Option<ExchangeRate>) -> Amount;
Expand Down
3 changes: 1 addition & 2 deletions src/analytics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::amount::AsSats;
use crate::async_runtime::Handle;
use crate::errors::Result;
use crate::key_derivation::derive_analytics_key;
Expand Down Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions src/fiat_topup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion src/lightning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/onchain/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down
Loading