Skip to content
Merged
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
20 changes: 6 additions & 14 deletions ldk-server-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,18 @@ use ldk_server_protos::api::{
OnchainReceiveRequest, OnchainReceiveResponse, OnchainSendRequest, OnchainSendResponse,
OpenChannelRequest, OpenChannelResponse,
};
use ldk_server_protos::endpoints::{
BOLT11_RECEIVE_PATH, BOLT11_SEND_PATH, BOLT12_RECEIVE_PATH, BOLT12_SEND_PATH,
CLOSE_CHANNEL_PATH, FORCE_CLOSE_CHANNEL_PATH, GET_BALANCES_PATH, GET_NODE_INFO_PATH,
LIST_CHANNELS_PATH, LIST_PAYMENTS_PATH, ONCHAIN_RECEIVE_PATH, ONCHAIN_SEND_PATH,
OPEN_CHANNEL_PATH,
};
use ldk_server_protos::error::{ErrorCode, ErrorResponse};
use reqwest::header::CONTENT_TYPE;
use reqwest::Client;

const APPLICATION_OCTET_STREAM: &str = "application/octet-stream";

const GET_NODE_INFO_PATH: &str = "GetNodeInfo";
const GET_BALANCES_PATH: &str = "GetBalances";
const ONCHAIN_RECEIVE_PATH: &str = "OnchainReceive";
const ONCHAIN_SEND_PATH: &str = "OnchainSend";
const BOLT11_RECEIVE_PATH: &str = "Bolt11Receive";
const BOLT11_SEND_PATH: &str = "Bolt11Send";
const BOLT12_RECEIVE_PATH: &str = "Bolt12Receive";
const BOLT12_SEND_PATH: &str = "Bolt12Send";
const OPEN_CHANNEL_PATH: &str = "OpenChannel";
const CLOSE_CHANNEL_PATH: &str = "CloseChannel";
const FORCE_CLOSE_CHANNEL_PATH: &str = "ForceCloseChannel";
const LIST_CHANNELS_PATH: &str = "ListChannels";
const LIST_PAYMENTS_PATH: &str = "ListPayments";

/// Client to access a hosted instance of LDK Server.
#[derive(Clone)]
pub struct LdkServerClient {
Expand Down
16 changes: 16 additions & 0 deletions ldk-server-protos/src/endpoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pub const GET_NODE_INFO_PATH: &str = "GetNodeInfo";
pub const GET_BALANCES_PATH: &str = "GetBalances";
pub const ONCHAIN_RECEIVE_PATH: &str = "OnchainReceive";
pub const ONCHAIN_SEND_PATH: &str = "OnchainSend";
pub const BOLT11_RECEIVE_PATH: &str = "Bolt11Receive";
pub const BOLT11_SEND_PATH: &str = "Bolt11Send";
pub const BOLT12_RECEIVE_PATH: &str = "Bolt12Receive";
pub const BOLT12_SEND_PATH: &str = "Bolt12Send";
pub const OPEN_CHANNEL_PATH: &str = "OpenChannel";
pub const CLOSE_CHANNEL_PATH: &str = "CloseChannel";
pub const FORCE_CLOSE_CHANNEL_PATH: &str = "ForceCloseChannel";
pub const LIST_CHANNELS_PATH: &str = "ListChannels";
pub const LIST_PAYMENTS_PATH: &str = "ListPayments";
pub const LIST_FORWARDED_PAYMENTS_PATH: &str = "ListForwardedPayments";
pub const UPDATE_CHANNEL_CONFIG_PATH: &str = "UpdateChannelConfig";
pub const GET_PAYMENT_DETAILS_PATH: &str = "GetPaymentDetails";
1 change: 1 addition & 0 deletions ldk-server-protos/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod api;
pub mod endpoints;
pub mod error;
pub mod events;
pub mod types;
2 changes: 0 additions & 2 deletions ldk-server/src/api/bolt11_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::service::Context;
use crate::util::proto_adapter::proto_to_bolt11_description;
use ldk_server_protos::api::{Bolt11ReceiveRequest, Bolt11ReceiveResponse};

pub(crate) const BOLT11_RECEIVE_PATH: &str = "Bolt11Receive";

pub(crate) fn handle_bolt11_receive_request(
context: Context, request: Bolt11ReceiveRequest,
) -> Result<Bolt11ReceiveResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/bolt11_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use ldk_node::lightning_invoice::Bolt11Invoice;
use ldk_server_protos::api::{Bolt11SendRequest, Bolt11SendResponse};
use std::str::FromStr;

pub(crate) const BOLT11_SEND_PATH: &str = "Bolt11Send";

pub(crate) fn handle_bolt11_send_request(
context: Context, request: Bolt11SendRequest,
) -> Result<Bolt11SendResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/bolt12_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::api::error::LdkServerError;
use crate::service::Context;
use ldk_server_protos::api::{Bolt12ReceiveRequest, Bolt12ReceiveResponse};

pub(crate) const BOLT12_RECEIVE_PATH: &str = "Bolt12Receive";

pub(crate) fn handle_bolt12_receive_request(
context: Context, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/bolt12_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use ldk_node::lightning::offers::offer::Offer;
use ldk_server_protos::api::{Bolt12SendRequest, Bolt12SendResponse};
use std::str::FromStr;

pub(crate) const BOLT12_SEND_PATH: &str = "Bolt12Send";

pub(crate) fn handle_bolt12_send_request(
context: Context, request: Bolt12SendRequest,
) -> Result<Bolt12SendResponse, LdkServerError> {
Expand Down
4 changes: 0 additions & 4 deletions ldk-server/src/api/close_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use ldk_server_protos::api::{
};
use std::str::FromStr;

pub(crate) const CLOSE_CHANNEL_PATH: &str = "CloseChannel";

pub(crate) fn handle_close_channel_request(
context: Context, request: CloseChannelRequest,
) -> Result<CloseChannelResponse, LdkServerError> {
Expand All @@ -21,8 +19,6 @@ pub(crate) fn handle_close_channel_request(
Ok(CloseChannelResponse {})
}

pub(crate) const FORCE_CLOSE_CHANNEL_PATH: &str = "ForceCloseChannel";

pub(crate) fn handle_force_close_channel_request(
context: Context, request: ForceCloseChannelRequest,
) -> Result<ForceCloseChannelResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/get_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::service::Context;
use crate::util::proto_adapter::{lightning_balance_to_proto, pending_sweep_balance_to_proto};
use ldk_server_protos::api::{GetBalancesRequest, GetBalancesResponse};

pub(crate) const GET_BALANCES: &str = "GetBalances";

pub(crate) fn handle_get_balances_request(
context: Context, _request: GetBalancesRequest,
) -> Result<GetBalancesResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/get_node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::service::Context;
use ldk_server_protos::api::{GetNodeInfoRequest, GetNodeInfoResponse};
use ldk_server_protos::types::BestBlock;

pub(crate) const GET_NODE_INFO: &str = "GetNodeInfo";

pub(crate) fn handle_get_node_info_request(
context: Context, _request: GetNodeInfoRequest,
) -> Result<GetNodeInfoResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/get_payment_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use hex::FromHex;
use ldk_node::lightning::ln::channelmanager::PaymentId;
use ldk_server_protos::api::{GetPaymentDetailsRequest, GetPaymentDetailsResponse};

pub(crate) const GET_PAYMENT_DETAILS_PATH: &str = "GetPaymentDetails";

pub(crate) fn handle_get_payment_details_request(
context: Context, request: GetPaymentDetailsRequest,
) -> Result<GetPaymentDetailsResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/list_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::service::Context;
use crate::util::proto_adapter::channel_to_proto;
use ldk_server_protos::api::{ListChannelsRequest, ListChannelsResponse};

pub(crate) const LIST_CHANNELS_PATH: &str = "ListChannels";

pub(crate) fn handle_list_channels_request(
context: Context, _request: ListChannelsRequest,
) -> Result<ListChannelsResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/list_forwarded_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use ldk_server_protos::api::{ListForwardedPaymentsRequest, ListForwardedPayments
use ldk_server_protos::types::{ForwardedPayment, PageToken};
use prost::Message;

pub(crate) const LIST_FORWARDED_PAYMENTS_PATH: &str = "ListForwardedPayments";

pub(crate) fn handle_list_forwarded_payments_request(
context: Context, request: ListForwardedPaymentsRequest,
) -> Result<ListForwardedPaymentsResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/list_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use ldk_server_protos::api::{ListPaymentsRequest, ListPaymentsResponse};
use ldk_server_protos::types::{PageToken, Payment};
use prost::Message;

pub(crate) const LIST_PAYMENTS_PATH: &str = "ListPayments";

pub(crate) fn handle_list_payments_request(
context: Context, request: ListPaymentsRequest,
) -> Result<ListPaymentsResponse, LdkServerError> {
Expand Down
1 change: 0 additions & 1 deletion ldk-server/src/api/onchain_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::api::error::LdkServerError;
use crate::service::Context;
use ldk_server_protos::api::{OnchainReceiveRequest, OnchainReceiveResponse};

pub(crate) const ONCHAIN_RECEIVE_PATH: &str = "OnchainReceive";
pub(crate) fn handle_onchain_receive_request(
context: Context, _request: OnchainReceiveRequest,
) -> Result<OnchainReceiveResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/onchain_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use ldk_node::bitcoin::{Address, FeeRate};
use ldk_server_protos::api::{OnchainSendRequest, OnchainSendResponse};
use std::str::FromStr;

pub(crate) const ONCHAIN_SEND_PATH: &str = "OnchainSend";

pub(crate) fn handle_onchain_send_request(
context: Context, request: OnchainSendRequest,
) -> Result<OnchainSendResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/open_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_server_protos::api::{OpenChannelRequest, OpenChannelResponse};
use std::str::FromStr;

pub(crate) const OPEN_CHANNEL_PATH: &str = "OpenChannel";

pub(crate) fn handle_open_channel(
context: Context, request: OpenChannelRequest,
) -> Result<OpenChannelResponse, LdkServerError> {
Expand Down
2 changes: 0 additions & 2 deletions ldk-server/src/api/update_channel_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use ldk_server_protos::api::{UpdateChannelConfigRequest, UpdateChannelConfigResp
use ldk_server_protos::types::channel_config::MaxDustHtlcExposure;
use std::str::FromStr;

pub(crate) const UPDATE_CHANNEL_CONFIG_PATH: &str = "UpdateChannelConfig";

pub(crate) fn handle_update_channel_config_request(
context: Context, request: UpdateChannelConfigRequest,
) -> Result<UpdateChannelConfigResponse, LdkServerError> {
Expand Down
54 changes: 28 additions & 26 deletions ldk-server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,32 @@ use hyper::body::{Bytes, Incoming};
use hyper::service::Service;
use hyper::{Request, Response, StatusCode};

use ldk_server_protos::endpoints::{
BOLT11_RECEIVE_PATH, BOLT11_SEND_PATH, BOLT12_RECEIVE_PATH, BOLT12_SEND_PATH,
CLOSE_CHANNEL_PATH, FORCE_CLOSE_CHANNEL_PATH, GET_BALANCES_PATH, GET_NODE_INFO_PATH,
GET_PAYMENT_DETAILS_PATH, LIST_CHANNELS_PATH, LIST_FORWARDED_PAYMENTS_PATH, LIST_PAYMENTS_PATH,
ONCHAIN_RECEIVE_PATH, ONCHAIN_SEND_PATH, OPEN_CHANNEL_PATH, UPDATE_CHANNEL_CONFIG_PATH,
};

use prost::Message;

use crate::api::bolt11_receive::{handle_bolt11_receive_request, BOLT11_RECEIVE_PATH};
use crate::api::bolt11_send::{handle_bolt11_send_request, BOLT11_SEND_PATH};
use crate::api::bolt12_receive::{handle_bolt12_receive_request, BOLT12_RECEIVE_PATH};
use crate::api::bolt12_send::{handle_bolt12_send_request, BOLT12_SEND_PATH};
use crate::api::close_channel::{
handle_close_channel_request, handle_force_close_channel_request, CLOSE_CHANNEL_PATH,
FORCE_CLOSE_CHANNEL_PATH,
};
use crate::api::bolt11_receive::handle_bolt11_receive_request;
use crate::api::bolt11_send::handle_bolt11_send_request;
use crate::api::bolt12_receive::handle_bolt12_receive_request;
use crate::api::bolt12_send::handle_bolt12_send_request;
use crate::api::close_channel::{handle_close_channel_request, handle_force_close_channel_request};
use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::api::get_balances::{handle_get_balances_request, GET_BALANCES};
use crate::api::get_node_info::{handle_get_node_info_request, GET_NODE_INFO};
use crate::api::get_payment_details::{
handle_get_payment_details_request, GET_PAYMENT_DETAILS_PATH,
};
use crate::api::list_channels::{handle_list_channels_request, LIST_CHANNELS_PATH};
use crate::api::list_forwarded_payments::{
handle_list_forwarded_payments_request, LIST_FORWARDED_PAYMENTS_PATH,
};
use crate::api::list_payments::{handle_list_payments_request, LIST_PAYMENTS_PATH};
use crate::api::onchain_receive::{handle_onchain_receive_request, ONCHAIN_RECEIVE_PATH};
use crate::api::onchain_send::{handle_onchain_send_request, ONCHAIN_SEND_PATH};
use crate::api::open_channel::{handle_open_channel, OPEN_CHANNEL_PATH};
use crate::api::update_channel_config::{
handle_update_channel_config_request, UPDATE_CHANNEL_CONFIG_PATH,
};
use crate::api::get_balances::handle_get_balances_request;
use crate::api::get_node_info::handle_get_node_info_request;
use crate::api::get_payment_details::handle_get_payment_details_request;
use crate::api::list_channels::handle_list_channels_request;
use crate::api::list_forwarded_payments::handle_list_forwarded_payments_request;
use crate::api::list_payments::handle_list_payments_request;
use crate::api::onchain_receive::handle_onchain_receive_request;
use crate::api::onchain_send::handle_onchain_send_request;
use crate::api::open_channel::handle_open_channel;
use crate::api::update_channel_config::handle_update_channel_config_request;
use crate::io::persist::paginated_kv_store::PaginatedKVStore;
use crate::util::proto_adapter::to_error_response;
use std::future::Future;
Expand Down Expand Up @@ -68,8 +66,12 @@ impl Service<Request<Incoming>> for NodeService {
};
// Exclude '/' from path pattern matching.
match &req.uri().path()[1..] {
GET_NODE_INFO => Box::pin(handle_request(context, req, handle_get_node_info_request)),
GET_BALANCES => Box::pin(handle_request(context, req, handle_get_balances_request)),
GET_NODE_INFO_PATH => {
Box::pin(handle_request(context, req, handle_get_node_info_request))
},
GET_BALANCES_PATH => {
Box::pin(handle_request(context, req, handle_get_balances_request))
},
ONCHAIN_RECEIVE_PATH => {
Box::pin(handle_request(context, req, handle_onchain_receive_request))
},
Expand Down