Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 82fff50

Browse files
Show gateway_fee in FederationIdentity
1 parent 74115d1 commit 82fff50

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

mutiny-core/src/federation.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use hex::FromHex;
5858
use lightning::{
5959
ln::PaymentHash, log_debug, log_error, log_info, log_trace, log_warn, util::logger::Logger,
6060
};
61-
use lightning_invoice::Bolt11Invoice;
61+
use lightning_invoice::{Bolt11Invoice, RoutingFees};
6262
use serde::{de::DeserializeOwned, Deserialize, Serialize};
6363
use std::{collections::HashMap, fmt::Debug, sync::Arc};
6464
use std::{
@@ -143,6 +143,22 @@ pub struct FederationIdentity {
143143
pub federation_name: Option<String>,
144144
pub federation_expiry_timestamp: Option<String>,
145145
pub welcome_message: Option<String>,
146+
pub gateway_fees: Option<GatewayFees>,
147+
}
148+
149+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
150+
pub struct GatewayFees {
151+
pub base_msat: u32,
152+
pub proportional_millionths: u32,
153+
}
154+
155+
impl From<RoutingFees> for GatewayFees {
156+
fn from(val: RoutingFees) -> Self {
157+
GatewayFees {
158+
base_msat: val.base_msat,
159+
proportional_millionths: val.proportional_millionths,
160+
}
161+
}
146162
}
147163

148164
// This is the FederationIndex reference that is saved to the DB
@@ -274,6 +290,15 @@ impl<S: MutinyStorage> FederationClient<S> {
274290
})
275291
}
276292

293+
pub(crate) async fn gateway_fee(&self) -> Result<GatewayFees, MutinyError> {
294+
let lightning_module = self
295+
.fedimint_client
296+
.get_first_module::<LightningClientModule>();
297+
298+
let gw = lightning_module.select_active_gateway().await?;
299+
Ok(gw.fees.into())
300+
}
301+
277302
pub(crate) async fn get_invoice(
278303
&self,
279304
amount: u64,
@@ -559,7 +584,9 @@ impl<S: MutinyStorage> FederationClient<S> {
559584
}
560585
}
561586

562-
pub fn get_mutiny_federation_identity(&self) -> FederationIdentity {
587+
pub async fn get_mutiny_federation_identity(&self) -> FederationIdentity {
588+
let gateway_fees = self.gateway_fee().await.ok();
589+
563590
FederationIdentity {
564591
uuid: self.uuid.clone(),
565592
federation_id: self.fedimint_client.federation_id(),
@@ -568,6 +595,7 @@ impl<S: MutinyStorage> FederationClient<S> {
568595
.fedimint_client
569596
.get_meta("federation_expiry_timestamp"),
570597
welcome_message: self.fedimint_client.get_meta("welcome_message"),
598+
gateway_fees,
571599
}
572600
}
573601

@@ -1049,7 +1077,6 @@ fn fedimint_mnemonic_generation() {
10491077
fn gateway_preference() {
10501078
use fedimint_core::util::SafeUrl;
10511079
use fedimint_ln_common::{LightningGateway, LightningGatewayAnnouncement};
1052-
use lightning_invoice::RoutingFees;
10531080
use std::time::Duration;
10541081

10551082
use super::*;

mutiny-core/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,10 +1667,11 @@ impl<S: MutinyStorage> MutinyWallet<S> {
16671667
/// Lists the federation id's of the federation clients in the manager.
16681668
pub async fn list_federations(&self) -> Result<Vec<FederationIdentity>, MutinyError> {
16691669
let federations = self.federations.read().await;
1670-
let federation_identities = federations
1671-
.iter()
1672-
.map(|(_, n)| n.get_mutiny_federation_identity())
1673-
.collect();
1670+
let mut federation_identities = Vec::new();
1671+
for f in federations.iter() {
1672+
let i = f.1.get_mutiny_federation_identity().await;
1673+
federation_identities.push(i);
1674+
}
16741675
Ok(federation_identities)
16751676
}
16761677

@@ -1757,7 +1758,7 @@ impl<S: MutinyStorage> MutinyWallet<S> {
17571758
let fedimint_client = federation_lock.get(&fed_id).ok_or(MutinyError::NotFound)?;
17581759

17591760
let balance = fedimint_client.get_balance().await?;
1760-
let identity = fedimint_client.get_mutiny_federation_identity();
1761+
let identity = fedimint_client.get_mutiny_federation_identity().await;
17611762

17621763
balances.push(FederationBalance { identity, balance });
17631764
}
@@ -2071,6 +2072,8 @@ pub(crate) async fn create_new_federation<S: MutinyStorage>(
20712072
.fedimint_client
20722073
.get_meta("federation_expiry_timestamp");
20732074
let welcome_message = new_federation.fedimint_client.get_meta("welcome_message");
2075+
let gateway_fees = new_federation.gateway_fee().await.ok();
2076+
20742077
federations
20752078
.write()
20762079
.await
@@ -2082,6 +2085,7 @@ pub(crate) async fn create_new_federation<S: MutinyStorage>(
20822085
federation_name,
20832086
federation_expiry_timestamp,
20842087
welcome_message,
2088+
gateway_fees,
20852089
})
20862090
}
20872091

0 commit comments

Comments
 (0)