Skip to content

Commit

Permalink
feat: impl keysets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Apr 30, 2024
1 parent e910ae2 commit 0fb92a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
4 changes: 0 additions & 4 deletions clientd-stateless/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ repository = "https://github.com/fedimint/fedimint-clientd"
keywords = ["fedimint", "bitcoin", "lightning", "ecash"]
license = "MIT"

[[example]]
name = "cashu_encoding"
path = "examples/cashu_encoding.rs"

[dependencies]
anyhow = "1.0.75"
axum = { version = "0.7.1", features = ["json", "ws"] }
Expand Down
23 changes: 21 additions & 2 deletions clientd-stateless/src/cashu.rs
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 Down Expand Up @@ -148,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 @@ -161,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,
}
}
}
22 changes: 19 additions & 3 deletions clientd-stateless/src/router/keysets.rs
Original file line number Diff line number Diff line change
@@ -1,10 +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<(), AppError> {
// TODO: Implement this function
Ok(())
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 }))
}

0 comments on commit 0fb92a6

Please sign in to comment.