Skip to content

Commit

Permalink
refactor(devimint): run DKG using the apis
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmoon authored and douglaz committed Jul 27, 2023
1 parent 0db6b13 commit c459126
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 109 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions devimint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ tower-http = { version = "0.3.5", features = ["cors", "auth"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
serde = "1.0.159"
url = "2.3.1"
18 changes: 15 additions & 3 deletions devimint/src/bin/faucet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::PathBuf;
use std::sync::Arc;

use anyhow::Context;
use axum::extract::State;
use axum::http::StatusCode;
use axum::routing::{get, post};
Expand All @@ -20,7 +22,7 @@ struct Cmd {
#[clap(long, env = "FM_CLN_SOCKET")]
cln_socket: String,
#[clap(long, env = "FM_CONNECT_STRING")]
connect_string: String,
connect_string: Option<String>,
}

#[derive(Clone)]
Expand All @@ -35,7 +37,11 @@ impl Faucet {
let url = cmd.bitcoind_rpc.parse()?;
let (host, auth) = fedimint_bitcoind::bitcoincore::from_url_to_url_auth(&url)?;
let bitcoin = Arc::new(bitcoincore_rpc::Client::new(&host, auth)?);
let ln_rpc = Arc::new(Mutex::new(ClnRpc::new(&cmd.cln_socket).await?));
let ln_rpc = Arc::new(Mutex::new(
ClnRpc::new(&cmd.cln_socket)
.await
.with_context(|| format!("couldn't open CLN socket {}", &cmd.cln_socket))?,
));
Ok(Faucet { bitcoin, ln_rpc })
}

Expand Down Expand Up @@ -97,7 +103,13 @@ async fn main() -> anyhow::Result<()> {
let router = Router::new()
.route(
"/connect-string",
get(|| async move { cmd.connect_string.clone() }),
get(|| async move {
cmd.connect_string.unwrap_or_else(|| {
// return error if not set
let data_dir = std::env::var("FM_DATA_DIR").unwrap();
std::fs::read_to_string(PathBuf::from(data_dir).join("client-connect")).unwrap()
})
}),
)
.route(
"/pay",
Expand Down
Loading

0 comments on commit c459126

Please sign in to comment.