Skip to content

Commit

Permalink
Merge pull request fedimint#37 from fedimint/stateless-router-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow authored May 4, 2024
2 parents 20615bd + 3bd12ca commit 168f2c6
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion clientd-stateless/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "clientd-statless"
name = "clientd-stateless"
version = "0.3.3"
edition = "2021"
description = "A stateless fedimint client daemon"
Expand Down
1 change: 0 additions & 1 deletion clientd-stateless/examples/cashu_encoding.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use base64::Engine;
use bitcoin::secp256k1::{Secp256k1, SecretKey};
use bitcoin::KeyPair;
use fedimint_core::api::InviteCode;
use fedimint_core::config::FederationIdPrefix;
use fedimint_core::config::{FederationId, FederationIdPrefix};
use fedimint_core::db::DatabaseValue;
use fedimint_core::module::registry::ModuleDecoderRegistry;
use fedimint_core::{Amount, TieredMulti};
Expand All @@ -16,14 +16,6 @@ use serde::de::Error;
use serde::{Deserialize, Serialize};
use tbs::Signature;

pub mod check;
pub mod info;
pub mod keys;
pub mod keysets;
pub mod melt;
pub mod mint;
pub mod swap;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Proof {
// Amount unassociated with the unit
Expand Down Expand Up @@ -156,7 +148,7 @@ impl fmt::Display for TokenV3 {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Unit {
Msat,
Expand All @@ -169,3 +161,22 @@ pub enum Method {
Bolt11,
Onchain,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub struct Keyset {
id: String,
unit: Unit,
active: bool,
}

impl From<FederationId> for Keyset {
fn from(federation_id: FederationId) -> Self {
let as_str = format!("00{}", federation_id.to_string());
Keyset {
id: as_str,
unit: Unit::Msat,
active: true,
}
}
}
38 changes: 15 additions & 23 deletions clientd-stateless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use std::str::FromStr;
use anyhow::Result;
use axum::http::Method;
use fedimint_core::api::InviteCode;
use router::handlers;
use router::{check, info, keys, keysets, melt, mint, swap};
use tower_http::cors::{Any, CorsLayer};
use tower_http::trace::TraceLayer;
use tracing::info;

mod cashu;
mod error;
mod router;
pub mod router;
mod state;
mod utils;

Expand Down Expand Up @@ -156,31 +157,22 @@ async fn main() -> Result<()> {
/// - DLEQ in BlindedSignature for Mint to User
fn cashu_v1_rest() -> Router<AppState> {
Router::new()
.route("/keys", get(handlers::keys::handle_keys))
.route(
"/keys/:keyset_id",
get(handlers::keys::handle_keys_keyset_id),
)
.route("/keysets", get(handlers::keysets::handle_keysets))
.route("/swap", post(handlers::swap::handle_swap))
.route(
"/mint/quote/:method",
get(handlers::mint::quote::handle_method),
)
.route("/keys", get(keys::handle_keys))
.route("/keys/:keyset_id", get(keys::handle_keys_keyset_id))
.route("/keysets", get(keysets::handle_keysets))
.route("/swap", post(swap::handle_swap))
.route("/mint/quote/:method", get(mint::quote::handle_method))
.route(
"/mint/quote/:method/:quote_id",
get(handlers::mint::quote::handle_method_quote_id),
)
.route("/mint/:method", post(handlers::mint::method::handle_method))
.route(
"/melt/quote/:method",
get(handlers::melt::quote::handle_method),
get(mint::quote::handle_method_quote_id),
)
.route("/mint/:method", post(mint::method::handle_method))
.route("/melt/quote/:method", get(melt::quote::handle_method))
.route(
"/melt/quote/:method/:quote_id",
get(handlers::melt::quote::handle_method_quote_id),
get(melt::quote::handle_method_quote_id),
)
.route("/melt/:method", post(handlers::melt::method::handle_method))
.route("/info", get(handlers::info::handle_info))
.route("/check", post(handlers::check::handle_check))
.route("/melt/:method", post(melt::method::handle_method))
.route("/info", get(info::handle_info))
.route("/check", post(check::handle_check))
}
File renamed without changes.
10 changes: 0 additions & 10 deletions clientd-stateless/src/router/handlers/keysets.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions clientd-stateless/src/router/keysets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use axum::extract::State;
use axum::Json;
use serde::Serialize;

use crate::cashu::Keyset;
use crate::error::AppError;
use crate::state::AppState;

#[derive(Serialize)]
#[serde(rename_all = "lowercase")]
pub struct KeysetsResponse {
keysets: Vec<Keyset>,
}

#[axum_macros::debug_handler]
pub async fn handle_keysets(
State(state): State<AppState>,
) -> Result<Json<KeysetsResponse>, AppError> {
let mut keysets = Vec::<Keyset>::new();
let ids = state.multimint.ids().await;
for id in ids {
keysets.push(Keyset::from(id))
}

Ok(Json(KeysetsResponse { keysets }))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use lightning_invoice::Bolt11Invoice;
use serde::{Deserialize, Serialize};
use tracing::{error, info};

use crate::cashu::{Method, Unit};
use crate::error::AppError;
use crate::router::handlers::{Method, Unit};
use crate::state::AppState;

#[derive(Debug, Deserialize)]
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use lightning_invoice::{Bolt11InvoiceDescription, Description};
use serde::{Deserialize, Serialize};
use tracing::error;

use crate::cashu::{Method, Unit};
use crate::error::AppError;
use crate::router::handlers::{Method, Unit};
use crate::state::AppState;

#[derive(Debug, Deserialize)]
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 7 additions & 1 deletion clientd-stateless/src/router/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
pub mod handlers;
pub mod check;
pub mod info;
pub mod keys;
pub mod keysets;
pub mod melt;
pub mod mint;
pub mod swap;
File renamed without changes.
2 changes: 1 addition & 1 deletion multimint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "multimint"
version = "0.3.3"
version = "0.3.4"
edition = "2021"
description = "A library for managing fedimint clients across multiple federations"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions multimint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ use fedimint_wallet_client::WalletClientModule;
use tokio::sync::Mutex;
use tracing::warn;
use types::InfoResponse;
pub use {fedimint_core, fedimint_ln_client, fedimint_mint_client, fedimint_wallet_client};

pub mod client;
pub mod db;
Expand Down

0 comments on commit 168f2c6

Please sign in to comment.