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

More federation metadata parsing #1168

Merged
merged 1 commit into from
May 7, 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
90 changes: 79 additions & 11 deletions mutiny-core/src/federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@ pub struct FederationIdentity {
pub federation_expiry_timestamp: Option<String>,
pub welcome_message: Option<String>,
pub gateway_fees: Option<GatewayFees>,
// undocumented parameters that fedi uses: https://meta.dev.fedibtc.com/meta.json
pub default_currency: Option<String>,
pub federation_icon_url: Option<String>,
pub max_balance_msats: Option<u32>,
pub max_invoice_msats: Option<u32>,
pub meta_external_url: Option<String>,
pub onchain_deposits_disabled: Option<bool>,
pub preview_message: Option<String>,
pub sites: Option<Site>,
pub public: Option<bool>,
pub tos_url: Option<String>,
pub popup_end_timestamp: Option<u32>,
pub popup_countdown_message: Option<String>,
pub invite_codes_disabled: Option<bool>,
pub stability_pool_disabled: Option<bool>,
pub social_recovery_disabled: Option<bool>,
}

#[derive(Default, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Site {
pub id: Option<String>,
pub url: Option<String>,
pub title: Option<String>,
pub image_url: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Default)]
Expand Down Expand Up @@ -658,18 +682,12 @@ impl<S: MutinyStorage> FederationClient<S> {

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(),
invite_code: self.invite_code.clone(),
federation_name: self.fedimint_client.get_meta("federation_name"),
federation_expiry_timestamp: self
.fedimint_client
.get_meta("federation_expiry_timestamp"),
welcome_message: self.fedimint_client.get_meta("welcome_message"),
get_federation_identity(
self.uuid.clone(),
self.fedimint_client.clone(),
self.invite_code.clone(),
gateway_fees,
}
)
}

// delete_fedimint_storage is not suggested at the moment due to the lack of easy restores
Expand All @@ -679,6 +697,56 @@ impl<S: MutinyStorage> FederationClient<S> {
}
}

pub(crate) fn get_federation_identity(
uuid: String,
fedimint_client: ClientHandleArc,
invite_code: InviteCode,
gateway_fees: Option<GatewayFees>,
) -> FederationIdentity {
FederationIdentity {
uuid: uuid.clone(),
federation_id: fedimint_client.federation_id(),
invite_code: invite_code.clone(),
federation_name: fedimint_client.get_meta("federation_name"),
federation_expiry_timestamp: fedimint_client.get_meta("federation_expiry_timestamp"),
welcome_message: fedimint_client.get_meta("welcome_message"),
gateway_fees,
default_currency: fedimint_client.get_meta("default_currency"),
federation_icon_url: fedimint_client.get_meta("federation_icon_url"),
max_balance_msats: fedimint_client
.get_meta("max_balance_msats")
.map(|v| v.parse().unwrap_or(0)),
max_invoice_msats: fedimint_client
.get_meta("max_invoice_msats")
.map(|v| v.parse().unwrap_or(0)),
meta_external_url: fedimint_client.get_meta("meta_external_url"),
onchain_deposits_disabled: fedimint_client
.get_meta("onchain_deposits_disabled")
.map(|v| v.parse().unwrap_or(false)),
preview_message: fedimint_client.get_meta("preview_message"),
sites: fedimint_client
.get_meta("sites")
.map(|v| serde_json::from_str(&v).unwrap_or_default()),
public: fedimint_client
.get_meta("public")
.map(|v| v.parse().unwrap_or(false)),
tos_url: fedimint_client.get_meta("tos_url"),
popup_end_timestamp: fedimint_client
.get_meta("popup_end_timestamp")
.map(|v| v.parse().unwrap_or(0)),
popup_countdown_message: fedimint_client.get_meta("popup_countdown_message"),
invite_codes_disabled: fedimint_client
.get_meta("invite_codes_disabled")
.map(|v| v.parse().unwrap_or(false)),
stability_pool_disabled: fedimint_client
.get_meta("stability_pool_disabled")
.map(|v| v.parse().unwrap_or(false)),
social_recovery_disabled: fedimint_client
.get_meta("social_recovery_disabled")
.map(|v| v.parse().unwrap_or(false)),
}
}

fn subscribe_operation_ext<S: MutinyStorage>(
entry: OperationLogEntry,
hash: [u8; 32],
Expand Down
37 changes: 16 additions & 21 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ mod test_utils;
pub use crate::gossip::{GOSSIP_SYNC_TIME_KEY, NETWORK_GRAPH_KEY, PROB_SCORER_KEY};
pub use crate::keymanager::generate_seed;
pub use crate::ldkstorage::{CHANNEL_CLOSURE_PREFIX, CHANNEL_MANAGER_KEY, MONITORS_PREFIX_KEY};
use crate::storage::{
get_payment_hash_from_key, list_payment_info, persist_payment_info, update_nostr_contact_list,
IndexItem, MutinyStorage, DEVICE_ID_KEY, EXPECTED_NETWORK_KEY, NEED_FULL_SYNC_KEY,
ONCHAIN_PREFIX, PAYMENT_INBOUND_PREFIX_KEY, PAYMENT_OUTBOUND_PREFIX_KEY,
SUBSCRIPTION_TIMESTAMP,
};
use crate::utils::spawn;
use crate::{auth::MutinyAuthClient, hermes::HermesClient, logging::MutinyLogger};
use crate::{blindauth::BlindAuthClient, cashu::CashuHttpClient};
Expand All @@ -60,6 +54,15 @@ use crate::{
event::{HTLCStatus, MillisatAmount, PaymentInfo},
onchain::FULL_SYNC_STOP_GAP,
};
use crate::{
federation::get_federation_identity,
storage::{
get_payment_hash_from_key, list_payment_info, persist_payment_info,
update_nostr_contact_list, IndexItem, MutinyStorage, DEVICE_ID_KEY, EXPECTED_NETWORK_KEY,
NEED_FULL_SYNC_KEY, ONCHAIN_PREFIX, PAYMENT_INBOUND_PREFIX_KEY,
PAYMENT_OUTBOUND_PREFIX_KEY, SUBSCRIPTION_TIMESTAMP,
},
};
use crate::{
federation::{
FederationClient, FederationIdentity, FederationIndex, FederationStorage, GatewayFees,
Expand Down Expand Up @@ -3191,28 +3194,20 @@ pub(crate) async fn create_new_federation<S: MutinyStorage>(
storage.insert_federations(federation_mutex.clone()).await?;

let federation_id = new_federation.fedimint_client.federation_id();
let federation_name = new_federation.fedimint_client.get_meta("federation_name");
let federation_expiry_timestamp = new_federation
.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();

let new_federation_identity = get_federation_identity(
next_federation_uuid.clone(),
new_federation.fedimint_client.clone(),
federation_code.clone(),
gateway_fees,
);

federations
.write()
.await
.insert(federation_id, Arc::new(new_federation));

let new_federation_identity = FederationIdentity {
uuid: next_federation_uuid.clone(),
federation_id,
invite_code: federation_code,
federation_name,
federation_expiry_timestamp,
welcome_message,
gateway_fees,
};

// change the federation with hermes, if available
if let Some(h) = hermes_client {
match h
Expand Down
Loading