fedimint_core/
admin_client.rsuse std::collections::BTreeMap;
use std::fmt::Debug;
use fedimint_core::util::SafeUrl;
use serde::{Deserialize, Serialize};
#[cfg(not(target_family = "wasm"))]
use tokio_rustls::rustls::Certificate as RustlsCertificate;
use crate::config::ServerModuleConfigGenParamsRegistry;
use crate::PeerId;
#[derive(Debug, Clone, Default, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ServerStatus {
#[default]
AwaitingPassword,
SharingConfigGenParams,
ReadyForConfigGen,
ConfigGenFailed,
VerifyingConfigs,
VerifiedConfigs,
ConsensusRunning,
SetupRestarted,
}
#[cfg(target_family = "wasm")]
#[derive(Debug, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct RustlsCertificate(pub Vec<u8>);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfigGenConnectionsRequest {
pub our_name: String,
pub leader_api_url: Option<SafeUrl>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct PeerServerParams {
#[serde(with = "serde_tls_cert")]
pub cert: RustlsCertificate,
pub p2p_url: SafeUrl,
pub api_url: SafeUrl,
pub name: String,
pub status: Option<ServerStatus>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct ConfigGenParamsConsensus {
pub peers: BTreeMap<PeerId, PeerServerParams>,
pub meta: BTreeMap<String, String>,
pub modules: ServerModuleConfigGenParamsRegistry,
}
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct ConfigGenParamsResponse {
pub consensus: ConfigGenParamsConsensus,
pub our_current_id: PeerId,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, Eq, PartialEq)]
pub struct ConfigGenParamsRequest {
pub meta: BTreeMap<String, String>,
pub modules: ServerModuleConfigGenParamsRegistry,
}
mod serde_tls_cert {
use std::borrow::Cow;
use hex::{FromHex, ToHex};
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serializer};
use super::RustlsCertificate;
pub fn serialize<S>(certs: &RustlsCertificate, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let hex_str = certs.0.encode_hex::<String>();
serializer.serialize_str(&hex_str)
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<RustlsCertificate, D::Error>
where
D: Deserializer<'de>,
{
let value: Cow<str> = Deserialize::deserialize(deserializer)?;
Ok(RustlsCertificate(
Vec::from_hex(value.as_ref()).map_err(D::Error::custom)?,
))
}
}