From f85e8d496cf740e0edfa57ab02d6d0f30026263d Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Mon, 6 May 2024 23:38:43 -0500 Subject: [PATCH] More federation metadata parsing --- mutiny-core/src/federation.rs | 90 ++++++++++++++++++++++++++++++----- mutiny-core/src/lib.rs | 37 +++++++------- 2 files changed, 95 insertions(+), 32 deletions(-) diff --git a/mutiny-core/src/federation.rs b/mutiny-core/src/federation.rs index fb4be88ea..0398df691 100644 --- a/mutiny-core/src/federation.rs +++ b/mutiny-core/src/federation.rs @@ -144,6 +144,30 @@ pub struct FederationIdentity { pub federation_expiry_timestamp: Option, pub welcome_message: Option, pub gateway_fees: Option, + // undocumented parameters that fedi uses: https://meta.dev.fedibtc.com/meta.json + pub default_currency: Option, + pub federation_icon_url: Option, + pub max_balance_msats: Option, + pub max_invoice_msats: Option, + pub meta_external_url: Option, + pub onchain_deposits_disabled: Option, + pub preview_message: Option, + pub sites: Option, + pub public: Option, + pub tos_url: Option, + pub popup_end_timestamp: Option, + pub popup_countdown_message: Option, + pub invite_codes_disabled: Option, + pub stability_pool_disabled: Option, + pub social_recovery_disabled: Option, +} + +#[derive(Default, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct Site { + pub id: Option, + pub url: Option, + pub title: Option, + pub image_url: Option, } #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Default)] @@ -658,18 +682,12 @@ impl FederationClient { 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 @@ -679,6 +697,56 @@ impl FederationClient { } } +pub(crate) fn get_federation_identity( + uuid: String, + fedimint_client: ClientHandleArc, + invite_code: InviteCode, + gateway_fees: Option, +) -> 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( entry: OperationLogEntry, hash: [u8; 32], diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 54155f6b5..52a209518 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -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}; @@ -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, @@ -3191,28 +3194,20 @@ pub(crate) async fn create_new_federation( 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