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

Commit

Permalink
Show gateway_fee in FederationIdentity
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyRonning committed Jan 31, 2024
1 parent 74115d1 commit 1e751a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
30 changes: 29 additions & 1 deletion mutiny-core/src/federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ pub struct FederationIdentity {
pub federation_name: Option<String>,
pub federation_expiry_timestamp: Option<String>,
pub welcome_message: Option<String>,
pub gateway_fees: Option<GatewayFees>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct GatewayFees {
pub base_msat: u32,
pub proportional_millionths: u32,
}

impl From<RoutingFees> for GatewayFees {
fn from(val: RoutingFees) -> Self {
GatewayFees {
base_msat: val.base_msat,
proportional_millionths: val.proportional_millionths,
}
}
}

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

pub(crate) async fn gateway_fee(&self) -> Result<GatewayFees, MutinyError> {
let lightning_module = self
.fedimint_client
.get_first_module::<LightningClientModule>();

let gw = lightning_module.select_active_gateway().await?;
Ok(gw.fees.into())
}

pub(crate) async fn get_invoice(
&self,
amount: u64,
Expand Down Expand Up @@ -559,7 +584,9 @@ impl<S: MutinyStorage> FederationClient<S> {
}
}

pub fn get_mutiny_federation_identity(&self) -> FederationIdentity {
pub async fn get_mutiny_federation_identity(&self) -> FederationIdentity {
let gateway_fees = self.gateway_fee().await.ok();

FederationIdentity {
uuid: self.uuid.clone(),
federation_id: self.fedimint_client.federation_id(),
Expand All @@ -568,6 +595,7 @@ impl<S: MutinyStorage> FederationClient<S> {
.fedimint_client
.get_meta("federation_expiry_timestamp"),
welcome_message: self.fedimint_client.get_meta("welcome_message"),
gateway_fees,
}
}

Expand Down
14 changes: 9 additions & 5 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,10 +1667,11 @@ impl<S: MutinyStorage> MutinyWallet<S> {
/// Lists the federation id's of the federation clients in the manager.
pub async fn list_federations(&self) -> Result<Vec<FederationIdentity>, MutinyError> {
let federations = self.federations.read().await;
let federation_identities = federations
.iter()
.map(|(_, n)| n.get_mutiny_federation_identity())
.collect();
let mut federation_identities = Vec::new();
for f in federations.iter() {
let i = f.1.get_mutiny_federation_identity().await;
federation_identities.push(i);
}
Ok(federation_identities)
}

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

let balance = fedimint_client.get_balance().await?;
let identity = fedimint_client.get_mutiny_federation_identity();
let identity = fedimint_client.get_mutiny_federation_identity().await;

balances.push(FederationBalance { identity, balance });
}
Expand Down Expand Up @@ -2071,6 +2072,8 @@ pub(crate) async fn create_new_federation<S: MutinyStorage>(
.fedimint_client
.get_meta("federation_expiry_timestamp");
let welcome_message = new_federation.fedimint_client.get_meta("welcome_message");
let gateway_fees = new_federation.gateway_fee().await.ok();

federations
.write()
.await
Expand All @@ -2082,6 +2085,7 @@ pub(crate) async fn create_new_federation<S: MutinyStorage>(
federation_name,
federation_expiry_timestamp,
welcome_message,
gateway_fees,
})
}

Expand Down

0 comments on commit 1e751a3

Please sign in to comment.