Skip to content

Commit

Permalink
Merge pull request #12 from fedimint/gateway-id-for-lightning
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow authored Mar 23, 2024
2 parents 461db57 + 35b9e4c commit de26965
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 87 deletions.
8 changes: 6 additions & 2 deletions fedimint-clientd/src/router/handlers/fedimint/admin/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct JoinRequest {
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct JoinResponse {
pub this_federation_id: FederationId,
pub federation_ids: Vec<FederationId>,
}

Expand All @@ -40,13 +41,16 @@ async fn _join(mut multimint: MultiMint, req: JoinRequest) -> Result<JoinRespons
None
};

let _ = multimint
let this_federation_id = multimint
.register_new(req.invite_code.clone(), manual_secret)
.await?;

let federation_ids = multimint.ids().await.into_iter().collect::<Vec<_>>();

Ok(JoinResponse { federation_ids })
Ok(JoinResponse {
this_federation_id,
federation_ids,
})
}

pub async fn handle_ws(state: AppState, v: Value) -> Result<Value, AppError> {
Expand Down
16 changes: 4 additions & 12 deletions fedimint-clientd/src/router/handlers/fedimint/ln/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::anyhow;
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use bitcoin::secp256k1::PublicKey;
use fedimint_client::ClientHandleArc;
use fedimint_core::config::FederationId;
use fedimint_core::core::OperationId;
Expand All @@ -21,6 +22,7 @@ pub struct LnInvoiceRequest {
pub amount_msat: Amount,
pub description: String,
pub expiry_time: Option<u64>,
pub gateway_id: PublicKey,
pub federation_id: FederationId,
}

Expand All @@ -36,21 +38,11 @@ async fn _invoice(
req: LnInvoiceRequest,
) -> Result<LnInvoiceResponse, AppError> {
let lightning_module = client.get_first_module::<LightningClientModule>();
let gateway_id = match lightning_module.list_gateways().await.first() {
Some(gateway_announcement) => gateway_announcement.info.gateway_id,
None => {
error!("No gateways available");
return Err(AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!("No gateways available"),
));
}
};
let gateway = lightning_module
.select_gateway(&gateway_id)
.select_gateway(&req.gateway_id)
.await
.ok_or_else(|| {
error!("Failed to select gateway");
error!("Failed to select gateway: {}", req.gateway_id);
AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!("Failed to select gateway"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct LnInvoiceExternalPubkeyRequest {
pub description: String,
pub expiry_time: Option<u64>,
pub external_pubkey: PublicKey,
pub gateway_id: PublicKey,
pub federation_id: FederationId,
}

Expand All @@ -38,21 +39,11 @@ async fn _invoice(
req: LnInvoiceExternalPubkeyRequest,
) -> Result<LnInvoiceExternalPubkeyResponse, AppError> {
let lightning_module = client.get_first_module::<LightningClientModule>();
let gateway_id = match lightning_module.list_gateways().await.first() {
Some(gateway_announcement) => gateway_announcement.info.gateway_id,
None => {
error!("No gateways available");
return Err(AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!("No gateways available"),
));
}
};
let gateway = lightning_module
.select_gateway(&gateway_id)
.select_gateway(&req.gateway_id)
.await
.ok_or_else(|| {
error!("Failed to select gateway");
error!("Failed to select gateway: {}", req.gateway_id);
AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!("Failed to select gateway"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct LnInvoiceExternalPubkeyTweakedRequest {
pub expiry_time: Option<u64>,
pub external_pubkey: PublicKey,
pub tweak: u64,
pub gateway_id: PublicKey,
pub federation_id: FederationId,
}

Expand All @@ -39,21 +40,11 @@ async fn _invoice(
req: LnInvoiceExternalPubkeyTweakedRequest,
) -> Result<LnInvoiceExternalPubkeyTweakedResponse, AppError> {
let lightning_module = client.get_first_module::<LightningClientModule>();
let gateway_id = match lightning_module.list_gateways().await.first() {
Some(gateway_announcement) => gateway_announcement.info.gateway_id,
None => {
error!("No gateways available");
return Err(AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!("No gateways available"),
));
}
};
let gateway = lightning_module
.select_gateway(&gateway_id)
.select_gateway(&req.gateway_id)
.await
.ok_or_else(|| {
error!("Failed to select gateway");
error!("Failed to select gateway: {}", req.gateway_id);
AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!("Failed to select gateway"),
Expand Down
16 changes: 4 additions & 12 deletions fedimint-clientd/src/router/handlers/fedimint/ln/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::anyhow;
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use bitcoin::secp256k1::PublicKey;
use fedimint_client::ClientHandleArc;
use fedimint_core::config::FederationId;
use fedimint_core::core::OperationId;
Expand All @@ -21,6 +22,7 @@ pub struct LnPayRequest {
pub payment_info: String,
pub amount_msat: Option<Amount>,
pub lnurl_comment: Option<String>,
pub gateway_id: PublicKey,
pub federation_id: FederationId,
}

Expand All @@ -37,21 +39,11 @@ async fn _pay(client: ClientHandleArc, req: LnPayRequest) -> Result<LnPayRespons
let bolt11 = get_invoice(&req).await?;
info!("Paying invoice: {bolt11}");
let lightning_module = client.get_first_module::<LightningClientModule>();
let gateway_id = match lightning_module.list_gateways().await.first() {
Some(gateway_announcement) => gateway_announcement.info.gateway_id,
None => {
error!("No gateways available");
return Err(AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!("No gateways available"),
));
}
};
let gateway = lightning_module
.select_gateway(&gateway_id)
.select_gateway(&req.gateway_id)
.await
.ok_or_else(|| {
error!("Failed to select gateway");
error!("Failed to select gateway: {}", req.gateway_id);
AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!("Failed to select gateway"),
Expand Down
Loading

0 comments on commit de26965

Please sign in to comment.