Skip to content

Commit

Permalink
Merge pull request #50 from fedimint/v0.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow authored Oct 9, 2024
2 parents 0747ec6 + ca34571 commit 62823ea
Show file tree
Hide file tree
Showing 33 changed files with 690 additions and 682 deletions.
1,122 changes: 572 additions & 550 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["multimint", "fedimint-clientd", "fedimint-nwc"]
resolver = "2"

[workspace.package]
version = "0.3.7"
version = "0.4.0"
edition = "2021"
repository = "https://github.com/fedimint/fedimint-clientd"
keywords = ["fedimint", "bitcoin", "lightning", "ecash"]
Expand All @@ -12,13 +12,14 @@ readme = "README.md"
authors = ["The Fedimint Developers"]

[workspace.dependencies]
fedimint-client = "0.3.3"
fedimint-core = "0.3.3"
fedimint-wallet-client = "0.3.3"
fedimint-mint-client = "0.3.3"
fedimint-ln-client = "0.3.3"
fedimint-ln-common = "0.3.3"
fedimint-rocksdb = "0.3.3"
fedimint-api-client = "0.4.2"
fedimint-client = "0.4.2"
fedimint-core = "0.4.2"
fedimint-wallet-client = "0.4.2"
fedimint-mint-client = "0.4.2"
fedimint-ln-client = "0.4.2"
fedimint-ln-common = "0.4.2"
fedimint-rocksdb = "0.4.2"

# Config for 'cargo dist'
[workspace.metadata.dist]
Expand Down
6 changes: 2 additions & 4 deletions fedimint-clientd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ url = "2.5.0"
lazy_static = "1.4.0"
async-utility = "0.2.0"
tower-http = { version = "0.5.2", features = ["cors", "auth", "trace"] }
bitcoin = "0.29.2"
itertools = "0.12.0"
lnurl-rs = { version = "0.5.0", features = ["async"], default-features = false }
reqwest = { version = "0.12.3", features = [
"json",
"rustls-tls",
], default-features = false }
lightning-invoice = { version = "0.26.0", features = ["serde"] }
bitcoin_hashes = "0.13.0"
bitcoin = "0.30.2"
time = { version = "0.3.25", features = ["formatting"] }
chrono = "0.4.31"
futures-util = "0.3.30"
clap = { version = "3", features = ["derive", "env"] }
multimint = { version = "0.3.8" }
multimint = { version = "0.4.0" }
# multimint = { path = "../multimint" }
hex = "0.4.3"

Expand Down
2 changes: 1 addition & 1 deletion fedimint-clientd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use axum::response::IntoResponse;
use futures::future::TryFutureExt;
use futures::try_join;
use metrics_exporter_prometheus::{Matcher, PrometheusBuilder, PrometheusHandle};
use multimint::fedimint_core::api::InviteCode;
use multimint::fedimint_core::invite_code::InviteCode;
use router::handlers::{admin, ln, mint, onchain};
use router::ws::websocket_handler;
use tower_http::cors::{Any, CorsLayer};
Expand Down
2 changes: 1 addition & 1 deletion fedimint-clientd/src/router/handlers/admin/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::state::AppState;
async fn _config(multimint: MultiMint) -> Result<Value, AppError> {
let mut config = HashMap::new();
for (id, client) in multimint.clients.lock().await.iter() {
config.insert(*id, client.get_config_json());
config.insert(*id, client.config().await.to_json());
}
Ok(serde_json::to_value(config)
.map_err(|e| anyhow::anyhow!("Client config is serializable: {e}"))?)
Expand Down
31 changes: 6 additions & 25 deletions fedimint-clientd/src/router/handlers/admin/discover_version.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,32 @@
use std::collections::HashMap;

use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use multimint::MultiMint;
use serde::Deserialize;
use serde_json::{json, Value};

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

#[derive(Debug, Clone, Deserialize)]
pub struct DiscoverVersionRequest {
threshold: Option<usize>,
}

async fn _discover_version(
multimint: MultiMint,
threshold: Option<usize>,
) -> Result<Value, AppError> {
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(threshold).await?}),
json!({"version" : client.load_and_refresh_common_api_version().await?}),
);
}
Ok(json!(api_versions))
}

pub async fn handle_ws(state: AppState, v: Value) -> Result<Value, AppError> {
let v = serde_json::from_value::<DiscoverVersionRequest>(v).map_err(|e| {
AppError::new(
StatusCode::BAD_REQUEST,
anyhow::anyhow!("Invalid request: {}", e),
)
})?;
let version = _discover_version(state.multimint, v.threshold).await?;
pub async fn handle_ws(state: AppState) -> Result<Value, AppError> {
let version = _discover_version(state.multimint).await?;
let version_json = json!(version);
Ok(version_json)
}

#[axum_macros::debug_handler]
pub async fn handle_rest(
State(state): State<AppState>,
Json(req): Json<DiscoverVersionRequest>,
) -> Result<Json<Value>, AppError> {
let version = _discover_version(state.multimint, req.threshold).await?;
pub async fn handle_rest(State(state): State<AppState>) -> Result<Json<Value>, AppError> {
let version = _discover_version(state.multimint).await?;
Ok(Json(version))
}
6 changes: 3 additions & 3 deletions fedimint-clientd/src/router/handlers/admin/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Error;
use axum::extract::State;
use axum::Json;
use multimint::fedimint_core::config::FederationId;
use multimint::fedimint_core::{Amount, TieredSummary};
use multimint::fedimint_core::{Amount, TieredCounts};
use multimint::fedimint_mint_client::MintClientModule;
use multimint::fedimint_wallet_client::WalletClientModule;
use multimint::MultiMint;
Expand All @@ -21,7 +21,7 @@ pub struct InfoResponse {
pub meta: BTreeMap<String, String>,
pub total_amount_msat: Amount,
pub total_num_notes: usize,
pub denominations_msat: TieredSummary,
pub denominations_msat: TieredCounts,
}

async fn _info(multimint: MultiMint) -> Result<HashMap<FederationId, InfoResponse>, Error> {
Expand All @@ -44,7 +44,7 @@ async fn _info(multimint: MultiMint) -> Result<HashMap<FederationId, InfoRespons
*id,
InfoResponse {
network: wallet_client.get_network().to_string(),
meta: client.get_config().global.meta.clone(),
meta: client.config().await.global.meta.clone(),
total_amount_msat: summary.total_amount(),
total_num_notes: summary.count_items(),
denominations_msat: summary,
Expand Down
2 changes: 1 addition & 1 deletion fedimint-clientd/src/router/handlers/admin/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anyhow::{anyhow, Error};
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use multimint::fedimint_core::api::InviteCode;
use multimint::fedimint_core::config::FederationId;
use multimint::fedimint_core::invite_code::InviteCode;
use multimint::MultiMint;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
Expand Down
2 changes: 1 addition & 1 deletion fedimint-clientd/src/router/handlers/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn _get_note_summary(client: &ClientHandleArc) -> anyhow::Result<InfoR
.await;
Ok(InfoResponse {
network: wallet_client.get_network().to_string(),
meta: client.get_config().global.meta.clone(),
meta: client.config().await.global.meta.clone(),
total_amount_msat: summary.total_amount(),
total_num_notes: summary.count_items(),
denominations_msat: summary,
Expand Down
2 changes: 1 addition & 1 deletion fedimint-clientd/src/router/handlers/ln/await_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn _await_invoice(
.await?
.into_stream();
info!(
"Created await invoice stream for operation id: {}",
"Created await invoice stream for operation id: {:?}",
req.operation_id
);
while let Some(update) = updates.next().await {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use anyhow::anyhow;
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use bitcoin::secp256k1::{Secp256k1, SecretKey};
use bitcoin::util::key::KeyPair;
use futures_util::StreamExt;
use multimint::fedimint_client::ClientHandleArc;
use multimint::fedimint_core::config::FederationId;
use multimint::fedimint_core::secp256k1::{KeyPair, Secp256k1, SecretKey};
use multimint::fedimint_ln_client::{LightningClientModule, LnReceiveState};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
Expand Down Expand Up @@ -46,7 +45,7 @@ async fn _await_claim_external_receive_tweaked(
.await?
.into_stream();
info!(
"Created claim external receive tweaked stream for operation id: {}",
"Created claim external receive tweaked stream for operation id: {:?}",
operation_id
);
while let Some(update) = updates.next().await {
Expand Down
4 changes: 2 additions & 2 deletions fedimint-clientd/src/router/handlers/ln/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use anyhow::anyhow;
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use bitcoin::secp256k1::PublicKey;
use lightning_invoice::{Bolt11InvoiceDescription, Description};
use multimint::fedimint_client::ClientHandleArc;
use multimint::fedimint_core::config::FederationId;
use multimint::fedimint_core::core::OperationId;
use multimint::fedimint_core::secp256k1::PublicKey;
use multimint::fedimint_core::Amount;
use multimint::fedimint_ln_client::LightningClientModule;
use multimint::fedimint_ln_common::lightning_invoice::{Bolt11InvoiceDescription, Description};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use tracing::error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use anyhow::anyhow;
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use bitcoin::secp256k1::PublicKey;
use lightning_invoice::{Bolt11InvoiceDescription, Description};
use multimint::fedimint_client::ClientHandleArc;
use multimint::fedimint_core::config::FederationId;
use multimint::fedimint_core::core::OperationId;
use multimint::fedimint_core::secp256k1::PublicKey;
use multimint::fedimint_core::Amount;
use multimint::fedimint_ln_client::LightningClientModule;
use multimint::fedimint_ln_common::lightning_invoice::{Bolt11InvoiceDescription, Description};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use tracing::error;
Expand Down
8 changes: 4 additions & 4 deletions fedimint-clientd/src/router/handlers/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::str::FromStr;

use anyhow::{bail, Context};
use futures_util::StreamExt;
use lightning_invoice::Bolt11Invoice;
use multimint::fedimint_client::ClientHandleArc;
use multimint::fedimint_core::Amount;
use multimint::fedimint_ln_client::{InternalPayState, LightningClientModule, LnPayState, PayType};
use multimint::fedimint_ln_common::lightning_invoice::Bolt11Invoice;
use tracing::{debug, info};

use self::pay::{LnPayRequest, LnPayResponse};
Expand Down Expand Up @@ -137,11 +137,11 @@ pub async fn wait_for_ln_payment(
LnPayState::Canceled => {
Err(anyhow::anyhow!("Payment was canceled"))?;
}
LnPayState::Funded { block_height: _ } if return_on_funding => return Ok(None),
LnPayState::Created
| LnPayState::AwaitingChange
| LnPayState::WaitingForRefund { .. } => {}
LnPayState::Funded if return_on_funding => return Ok(None),
LnPayState::Funded => {}
| LnPayState::WaitingForRefund { .. }
| LnPayState::Funded { block_height: _ } => {}
LnPayState::UnexpectedError { error_message } => {
bail!("UnexpectedError: {error_message}")
}
Expand Down
4 changes: 2 additions & 2 deletions fedimint-clientd/src/router/handlers/ln/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use anyhow::anyhow;
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use bitcoin::secp256k1::PublicKey;
use multimint::fedimint_client::ClientHandleArc;
use multimint::fedimint_core::config::FederationId;
use multimint::fedimint_core::core::OperationId;
use multimint::fedimint_core::secp256k1::PublicKey;
use multimint::fedimint_core::Amount;
use multimint::fedimint_ln_client::{LightningClientModule, OutgoingLightningPayment, PayType};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -59,7 +59,7 @@ async fn _pay(client: ClientHandleArc, req: LnPayRequest) -> Result<LnPayRespons
.pay_bolt11_invoice(Some(gateway), bolt11, ())
.await?;
let operation_id = payment_type.operation_id();
info!("Gateway fee: {fee}, payment operation id: {operation_id}");
info!("Gateway fee: {fee}, payment operation id: {operation_id:?}");

wait_for_ln_payment(&client, payment_type, contract_id.to_string(), false)
.await?
Expand Down
2 changes: 1 addition & 1 deletion fedimint-clientd/src/router/handlers/mint/spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn _spend(client: ClientHandleArc, req: SpendRequest) -> Result<SpendRespo
)
.await?
};
info!("Spend e-cash operation: {operation}");
info!("Spend e-cash operation: {:?}", operation);
Ok(SpendResponse { operation, notes })
}

Expand Down
3 changes: 1 addition & 2 deletions fedimint-clientd/src/router/handlers/mint/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ async fn _validate(
) -> Result<ValidateResponse, AppError> {
let amount_msat = client
.get_first_module::<MintClientModule>()
.validate_notes(req.notes)
.await?;
.validate_notes(&req.notes)?;

Ok(ValidateResponse { amount_msat })
}
Expand Down
28 changes: 20 additions & 8 deletions fedimint-clientd/src/router/handlers/onchain/await_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use futures_util::StreamExt;
use multimint::fedimint_client::ClientHandleArc;
use multimint::fedimint_core::config::FederationId;
use multimint::fedimint_core::core::OperationId;
use multimint::fedimint_wallet_client::{DepositState, WalletClientModule};
use multimint::fedimint_wallet_client::{DepositStateV2, WalletClientModule};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};

Expand All @@ -23,7 +23,7 @@ pub struct AwaitDepositRequest {
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AwaitDepositResponse {
pub status: DepositState,
pub status: DepositStateV2,
}

async fn _await_deposit(
Expand All @@ -32,23 +32,35 @@ async fn _await_deposit(
) -> Result<AwaitDepositResponse, AppError> {
let mut updates = client
.get_first_module::<WalletClientModule>()
.subscribe_deposit_updates(req.operation_id)
.subscribe_deposit(req.operation_id)
.await?
.into_stream();

while let Some(update) = updates.next().await {
match update {
DepositState::Confirmed(tx) => {
DepositStateV2::Confirmed {
btc_deposited,
btc_out_point,
} => {
return Ok(AwaitDepositResponse {
status: DepositState::Confirmed(tx),
status: DepositStateV2::Confirmed {
btc_deposited,
btc_out_point,
},
})
}
DepositState::Claimed(tx) => {
DepositStateV2::Claimed {
btc_deposited,
btc_out_point,
} => {
return Ok(AwaitDepositResponse {
status: DepositState::Claimed(tx),
status: DepositStateV2::Claimed {
btc_deposited,
btc_out_point,
},
})
}
DepositState::Failed(reason) => {
DepositStateV2::Failed(reason) => {
return Err(AppError::new(
StatusCode::INTERNAL_SERVER_ERROR,
anyhow!(reason),
Expand Down
Loading

0 comments on commit 62823ea

Please sign in to comment.