Skip to content

Commit

Permalink
refactor: move
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed May 25, 2024
1 parent dbf5173 commit b4140cf
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions fedimint-nwc/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub async fn init(cli: Cli) -> Result<AppState> {
let manual_secret = AppState::load_manual_secret(&cli).await;
let invite_code = cli.invite_code.clone();
state.init_multimint(&invite_code, manual_secret).await?;

if state.multimint.all().await.is_empty() {
return Err(anyhow::anyhow!(
"No multimint clients found, must have at least one client to start the server."
Expand Down Expand Up @@ -69,6 +68,27 @@ impl AppState {
})
}

pub async fn init_multimint(
&mut self,
invite_code: &str,
manual_secret: Option<String>,
) -> Result<()> {
match InviteCode::from_str(invite_code) {
Ok(invite_code) => {
let federation_id = self
.multimint
.register_new(invite_code, manual_secret)
.await?;
info!("Created client for federation id: {:?}", federation_id);
Ok(())
}
Err(e) => {
error!("Invalid federation invite code: {}", e);
Err(e.into())
}
}
}

async fn init_multimint_clients(fm_db_path: PathBuf) -> Result<MultiMint> {
let clients = MultiMint::new(fm_db_path).await?;
clients.update_gateway_caches().await?;
Expand Down Expand Up @@ -106,27 +126,6 @@ impl AppState {
.or_else(|| std::env::var("FEDIMINT_CLIENTD_MANUAL_SECRET").ok())
}

pub async fn init_multimint(
&mut self,
invite_code: &str,
manual_secret: Option<String>,
) -> Result<()> {
match InviteCode::from_str(invite_code) {
Ok(invite_code) => {
let federation_id = self
.multimint
.register_new(invite_code, manual_secret)
.await?;
info!("Created client for federation id: {:?}", federation_id);
Ok(())
}
Err(e) => {
error!("Invalid federation invite code: {}", e);
Err(e.into())
}
}
}

pub async fn wait_for_active_requests(&self) {
let requests = self.active_requests.lock().await;
loop {
Expand Down

0 comments on commit b4140cf

Please sign in to comment.