Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ name = "mdkd"
version = "0.0.1"
edition = "2021"

[lib]
name = "mdk"
path = "src/lib.rs"

[[bin]]
name = "mdkd"
path = "src/main.rs"

[features]
demo = []

Expand All @@ -15,6 +23,7 @@ utoipa = { version = "5.4", features = ["axum_extras"] }
utoipa-axum = "0.2"
utoipa-scalar = { version = "0.3", features = ["axum"] }
tokio = { version = "1", features = ["full"] }
tokio-util = "0.7"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
reqwest = { version = "0.12", features = ["json", "rustls-tls", "socks"], default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion src/api/auth.rs → src/daemon/api/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::Json;
use base64::engine::general_purpose::STANDARD as BASE64;
use base64::Engine;

use crate::types::ApiError;
use crate::daemon::types::ApiError;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccessLevel {
Expand Down
4 changes: 2 additions & 2 deletions src/api/balance.rs → src/daemon/api/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::Arc;
use axum::Json;
use ldk_node::Node;

use crate::api::error::AppError;
use crate::types::GetBalanceResponse;
use crate::daemon::api::error::AppError;
use crate::daemon::types::GetBalanceResponse;

/// Returns the node's Lightning and on-chain balances.
///
Expand Down
4 changes: 2 additions & 2 deletions src/api/channels.rs → src/daemon/api/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use hex::FromHex;
use ldk_node::lightning::ln::types::ChannelId;
use ldk_node::Node;

use crate::api::error::AppError;
use crate::types::{ChannelInfo, CloseChannelRequest};
use crate::daemon::api::error::AppError;
use crate::daemon::types::{ChannelInfo, CloseChannelRequest};

pub async fn handle_list_channels(node: Arc<Node>) -> Result<Json<Vec<ChannelInfo>>, AppError> {
let channels = node.list_channels().iter().map(ChannelInfo::from).collect();
Expand Down
6 changes: 3 additions & 3 deletions src/api/decode.rs → src/daemon/api/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use axum::Json;
use ldk_node::lightning::offers::offer::{Amount, Offer};
use ldk_node::lightning_invoice::Bolt11Invoice;

use crate::api::error::AppError;
use crate::types::{
use crate::daemon::api::error::AppError;
use crate::daemon::types::{
DecodeInvoiceRequest, DecodeInvoiceResponse, DecodeOfferRequest, DecodeOfferResponse,
RoutingHint, RoutingHintHop,
};
Expand Down Expand Up @@ -100,7 +100,7 @@ mod tests {
use ldk_node::bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
use ldk_node::lightning::offers::offer::OfferBuilder;

use crate::types::{DecodeInvoiceRequest, DecodeOfferRequest};
use crate::daemon::types::{DecodeInvoiceRequest, DecodeOfferRequest};

// Signet invoice with LSPS4 JIT route hint (single hop), "1 cup coffee".
// {
Expand Down
16 changes: 15 additions & 1 deletion src/api/error.rs → src/daemon/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::Json;

use crate::types::ApiError;
use mdk::error::MdkError;

use crate::daemon::types::ApiError;

#[derive(Debug)]
pub enum AppError {
Expand All @@ -11,6 +13,18 @@ pub enum AppError {
Internal(String),
}

impl From<MdkError> for AppError {
fn from(e: MdkError) -> Self {
match e {
MdkError::InvalidInput(msg) => AppError::BadRequest(msg),
MdkError::NotFound(msg) => AppError::NotFound(msg),
MdkError::Node(msg) => AppError::Internal(msg),
MdkError::Platform { message, .. } => AppError::Internal(message),
MdkError::Network(msg) => AppError::Internal(msg),
}
}
}

impl IntoResponse for AppError {
fn into_response(self) -> Response {
let (status, code, message) = match self {
Expand Down
4 changes: 2 additions & 2 deletions src/api/info.rs → src/daemon/api/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use axum::Json;
use ldk_node::bitcoin::Network;
use ldk_node::Node;

use crate::api::error::AppError;
use crate::types::{ChannelInfo, GetInfoResponse};
use crate::daemon::api::error::AppError;
use crate::daemon::types::{ChannelInfo, GetInfoResponse};

const VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down
Loading
Loading