Skip to content

Commit

Permalink
fix: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Feb 19, 2024
1 parent 37a8f80 commit fa7047e
Show file tree
Hide file tree
Showing 39 changed files with 249 additions and 147 deletions.
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
let
pkgs = import nixpkgs { inherit system; };
flakeboxLib = flakebox.lib.${system} { };
toolchainsStd = flakeboxLib.mkStdFenixToolchains;
rustSrc = flakeboxLib.filterSubPaths {
root = builtins.path {
name = "fedimint-http";
Expand All @@ -35,7 +36,6 @@
workspaceDeps = craneLib.buildWorkspaceDepsOnly { };
workspaceBuild =
craneLib.buildWorkspace { cargoArtifacts = workspaceDeps; };
bullpen = craneLib.buildPackage { };
});
in {
legacyPackages = outputs;
Expand All @@ -49,6 +49,7 @@
];
shellHook = ''
eval "$(starship init bash)"
export RUSTFLAGS="--cfg tokio_unstable"
'';
};
});
Expand Down
10 changes: 6 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
// let port = env::var("PORT").unwrap_or("3000".to_string());
// let port = u16::from_str(&port).expect("Invalid port");

// let fm_db_path = env::var("FM_DB_PATH").expect("FM_DB_PATH must be set");
// let fm_db_path = PathBuf::from_str(&fm_db_path).expect("Invalid fm db path");
// let fm_db_path = env::var("FM_DB_PATH").expect("FM_DB_PATH must be
// set"); let fm_db_path =
// PathBuf::from_str(&fm_db_path).expect("Invalid fm db path");

// let invite_code =
// env::var("FEDERATION_INVITE_CODE").expect("FEDERATION_INVITE_CODE must be set");
// let invite_code = InviteCode::from_str(&invite_code).expect("Invalid invite code");
// env::var("FEDERATION_INVITE_CODE").expect("FEDERATION_INVITE_CODE
// must be set"); let invite_code =
// InviteCode::from_str(&invite_code).expect("Invalid invite code");

// let secret = env::var("SECRET_KEY").expect("SECRET_KEY must be set");
// let root_secret = create_root_secret(secret);
Expand Down
6 changes: 2 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::fmt;

use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use serde_json::json;

pub struct AppError {
Expand Down
45 changes: 28 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::path::PathBuf;
use std::str::FromStr;

use anyhow::Result;
use fedimint_core::api::InviteCode;
use router::ws::websocket_handler;
use std::str::FromStr;
use tracing::info;

mod config;
Expand All @@ -15,9 +15,8 @@ mod utils;
use axum::routing::{get, post};
use axum::Router;
use clap::{Parser, Subcommand, ValueEnum};
use state::AppState;

use router::handlers::*;
use state::AppState;
// use tower_http::cors::{Any, CorsLayer};
use tower_http::validate_request::ValidateRequestHeaderLayer;

Expand Down Expand Up @@ -122,8 +121,8 @@ async fn main() -> Result<()> {
}

pub async fn create_default_router(state: AppState, password: &str) -> Result<Router> {
// TODO: Allow CORS? Probably not, since this should just interact with the local machine.
// let cors = CorsLayer::new()
// TODO: Allow CORS? Probably not, since this should just interact with the
// local machine. let cors = CorsLayer::new()
// .allow_methods([Method::GET, Method::POST])
// .allow_origin(Any);

Expand All @@ -140,33 +139,44 @@ pub async fn create_default_router(state: AppState, password: &str) -> Result<Ro
}

/// Implements Fedimint V0.2 API Route matching against CLI commands:
/// - `/fedimint/v2/admin/backup`: Upload the (encrypted) snapshot of mint notes to federation.
/// - `/fedimint/v2/admin/discover-version`: Discover the common api version to use to communicate with the federation.
/// - `/fedimint/v2/admin/backup`: Upload the (encrypted) snapshot of mint notes
/// to federation.
/// - `/fedimint/v2/admin/discover-version`: Discover the common api version to
/// use to communicate with the federation.
/// - `/fedimint/v2/admin/info`: Display wallet info (holdings, tiers).
/// - `/fedimint/v2/admin/join`: Join a federation with an invite code.
/// - `/fedimint/v2/admin/restore`: Restore the previously created backup of mint notes (with `backup` command).
/// - `/fedimint/v2/admin/restore`: Restore the previously created backup of
/// mint notes (with `backup` command).
/// - `/fedimint/v2/admin/list-operations`: List operations.
/// - `/fedimint/v2/admin/module`: Call a module subcommand.
/// - `/fedimint/v2/admin/config`: Returns the client config.
///
/// Mint related commands:
/// - `/fedimint/v2/mint/reissue`: Reissue notes received from a third party to avoid double spends.
/// - `/fedimint/v2/mint/spend`: Prepare notes to send to a third party as a payment.
/// - `/fedimint/v2/mint/validate`: Verifies the signatures of e-cash notes, but *not* if they have been spent already.
/// - `/fedimint/v2/mint/split`: Splits a string containing multiple e-cash notes (e.g. from the `spend` command) into ones that contain exactly one.
/// - `/fedimint/v2/mint/combine`: Combines two or more serialized e-cash notes strings.
/// - `/fedimint/v2/mint/reissue`: Reissue notes received from a third party to
/// avoid double spends.
/// - `/fedimint/v2/mint/spend`: Prepare notes to send to a third party as a
/// payment.
/// - `/fedimint/v2/mint/validate`: Verifies the signatures of e-cash notes, but
/// *not* if they have been spent already.
/// - `/fedimint/v2/mint/split`: Splits a string containing multiple e-cash
/// notes (e.g. from the `spend` command) into ones that contain exactly one.
/// - `/fedimint/v2/mint/combine`: Combines two or more serialized e-cash notes
/// strings.
///
/// Lightning network related commands:
/// - `/fedimint/v2/ln/invoice`: Create a lightning invoice to receive payment via gateway.
/// - `/fedimint/v2/ln/invoice`: Create a lightning invoice to receive payment
/// via gateway.
/// - `/fedimint/v2/ln/await-invoice`: Wait for incoming invoice to be paid.
/// - `/fedimint/v2/ln/pay`: Pay a lightning invoice or lnurl via a gateway.
/// - `/fedimint/v2/ln/await-pay`: Wait for a lightning payment to complete.
/// - `/fedimint/v2/ln/list-gateways`: List registered gateways.
/// - `/fedimint/v2/ln/switch-gateway`: Switch active gateway.
///
/// Onchain related commands:
/// - `/fedimint/v2/onchain/deposit-address`: Generate a new deposit address, funds sent to it can later be claimed.
/// - `/fedimint/v2/onchain/await-deposit`: Wait for deposit on previously generated address.
/// - `/fedimint/v2/onchain/deposit-address`: Generate a new deposit address,
/// funds sent to it can later be claimed.
/// - `/fedimint/v2/onchain/await-deposit`: Wait for deposit on previously
/// generated address.
/// - `/fedimint/v2/onchain/withdraw`: Withdraw funds from the federation.
fn fedimint_v2_rest() -> Router<AppState> {
let mint_router = Router::new()
Expand Down Expand Up @@ -217,7 +227,8 @@ fn fedimint_v2_rest() -> Router<AppState> {
.route("/info", get(fedimint::admin::info::handle_rest))
.route("/join", post(fedimint::admin::join::handle_rest))
.route("/restore", post(fedimint::admin::restore::handle_rest))
// .route("/printsecret", get(fedimint::handle_printsecret)) TODO: should I expose this under admin?
// .route("/printsecret", get(fedimint::handle_printsecret)) TODO: should I expose this
// under admin?
.route(
"/list-operations",
post(fedimint::admin::list_operations::handle_rest),
Expand Down
6 changes: 4 additions & 2 deletions src/router/handlers/cashu/check.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use axum::{extract::State, Json};
use axum::extract::State;
use axum::Json;
use fedimint_core::Amount;
use fedimint_mint_client::{MintClientModule, OOBNotes};
use serde::{Deserialize, Serialize};

use crate::{error::AppError, state::AppState};
use crate::error::AppError;
use crate::state::AppState;

#[derive(Debug, Deserialize)]
pub struct CheckRequest {
Expand Down
7 changes: 5 additions & 2 deletions src/router/handlers/cashu/info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::collections::BTreeMap;

use axum::{extract::State, http::StatusCode, Json};
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use serde::Serialize;

use crate::{error::AppError, state::AppState};
use crate::error::AppError;
use crate::state::AppState;

#[derive(Debug, Serialize)]
pub struct Contact {
Expand Down
4 changes: 3 additions & 1 deletion src/router/handlers/cashu/keys.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{error::AppError, state::AppState};
use anyhow::Result;
use axum::extract::State;

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

#[axum_macros::debug_handler]
pub async fn handle_keys(State(_state): State<AppState>) -> Result<(), AppError> {
// TODO: Implement this function
Expand Down
3 changes: 2 additions & 1 deletion src/router/handlers/cashu/keysets.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use axum::extract::State;

use crate::{error::AppError, state::AppState};
use crate::error::AppError;
use crate::state::AppState;

#[axum_macros::debug_handler]
pub async fn handle_keysets(State(_state): State<AppState>) -> Result<(), AppError> {
Expand Down
20 changes: 9 additions & 11 deletions src/router/handlers/cashu/melt/method.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
use std::str::FromStr;

use crate::{
error::AppError,
router::handlers::cashu::{Method, Unit},
state::AppState,
};
use anyhow::anyhow;
use axum::{
extract::{Path, State},
http::StatusCode,
Json,
};
use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::Json;
use fedimint_client::ClientArc;
use fedimint_core::{config::FederationId, Amount};
use fedimint_core::config::FederationId;
use fedimint_core::Amount;
use fedimint_ln_client::{LightningClientModule, OutgoingLightningPayment};
use fedimint_wallet_client::{WalletClientModule, WithdrawState};
use futures_util::StreamExt;
use lightning_invoice::Bolt11Invoice;
use serde::{Deserialize, Serialize};
use tracing::info;

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

#[derive(Debug, Deserialize)]
pub struct PostMeltQuoteMethodRequest {
pub request: String,
Expand Down
3 changes: 2 additions & 1 deletion src/router/handlers/cashu/melt/quote.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use axum::extract::State;

use crate::{error::AppError, state::AppState};
use crate::error::AppError;
use crate::state::AppState;

#[axum_macros::debug_handler]
pub async fn handle_method(State(_state): State<AppState>) -> Result<(), AppError> {
Expand Down
21 changes: 10 additions & 11 deletions src/router/handlers/cashu/mint/method.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use std::time::Duration;

use crate::{
error::AppError,
router::handlers::cashu::{Method, Unit},
state::AppState,
};
use anyhow::anyhow;
use axum::{
extract::{Path, State},
http::StatusCode,
Json,
};
use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::Json;
use fedimint_client::ClientArc;
use fedimint_core::{config::FederationId, time::now, Amount};
use fedimint_core::config::FederationId;
use fedimint_core::time::now;
use fedimint_core::Amount;
use fedimint_ln_client::LightningClientModule;
use fedimint_wallet_client::WalletClientModule;
use serde::{Deserialize, Serialize};

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

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PostMintQuoteMethodRequest {
Expand Down
3 changes: 2 additions & 1 deletion src/router/handlers/cashu/mint/quote.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use axum::extract::State;

use crate::{error::AppError, state::AppState};
use crate::error::AppError;
use crate::state::AppState;

#[axum_macros::debug_handler]
pub async fn handle_method(State(_state): State<AppState>) -> Result<(), AppError> {
Expand Down
11 changes: 8 additions & 3 deletions src/router/handlers/cashu/swap.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::{error::AppError, state::AppState};
use anyhow::anyhow;
use axum::{extract::State, http::StatusCode, Json};
use fedimint_core::{config::FederationId, Amount};
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use fedimint_core::config::FederationId;
use fedimint_core::Amount;
use fedimint_mint_client::{MintClientModule, OOBNotes};
use futures_util::StreamExt;
use serde::{Deserialize, Serialize};
use tracing::info;

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

#[derive(Debug, Deserialize)]
pub struct SwapRequest {
pub notes: OOBNotes,
Expand Down
14 changes: 10 additions & 4 deletions src/router/handlers/fedimint/admin/backup.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use crate::{error::AppError, state::AppState};
use std::collections::BTreeMap;

use anyhow::anyhow;
use axum::{extract::State, http::StatusCode, Json};
use fedimint_client::{backup::Metadata, ClientArc};
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use fedimint_client::backup::Metadata;
use fedimint_client::ClientArc;
use fedimint_core::config::FederationId;
use serde::Deserialize;
use serde_json::{json, Value};
use std::collections::BTreeMap;

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

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
6 changes: 4 additions & 2 deletions src/router/handlers/fedimint/admin/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::collections::HashMap;

use axum::{extract::State, Json};
use axum::extract::State;
use axum::Json;
use multimint::MultiMint;
use serde_json::{json, Value};

use crate::{error::AppError, state::AppState};
use crate::error::AppError;
use crate::state::AppState;

async fn _config(multimint: MultiMint) -> Result<Value, AppError> {
let mut config = HashMap::new();
Expand Down
11 changes: 8 additions & 3 deletions src/router/handlers/fedimint/admin/discover_version.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use std::collections::HashMap;

use axum::{extract::State, Json};
use axum::extract::State;
use axum::Json;
use multimint::MultiMint;
use serde_json::{json, Value};

use crate::{error::AppError, state::AppState};
use crate::error::AppError;
use crate::state::AppState;

async fn _discover_version(multimint: MultiMint) -> Result<Value, AppError> {
let mut api_versions = HashMap::new();
for (id, client) in multimint.clients.lock().await.iter() {
api_versions.insert(*id, json!({"version" : client.discover_common_api_version().await?}));
api_versions.insert(
*id,
json!({"version" : client.discover_common_api_version().await?}),
);
}
Ok(json!(api_versions))
}
Expand Down
6 changes: 4 additions & 2 deletions src/router/handlers/fedimint/admin/federation_ids.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use anyhow::Error;
use axum::{extract::State, Json};
use axum::extract::State;
use axum::Json;
use fedimint_core::config::FederationId;
use multimint::MultiMint;
use serde::Serialize;
use serde_json::{json, Value};

use crate::{error::AppError, state::AppState};
use crate::error::AppError;
use crate::state::AppState;

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down
Loading

0 comments on commit fa7047e

Please sign in to comment.