Skip to content

Commit

Permalink
Merge pull request #24 from G8XSU/ldk-server-rename
Browse files Browse the repository at this point in the history
Rename to LdkServer.
  • Loading branch information
G8XSU authored Nov 25, 2024
2 parents f2c5baf + 144d732 commit a5178ec
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

8 changes: 4 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::client::LdkServerClient;
use client::error::LdkServerError;
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
Expand Down Expand Up @@ -78,7 +78,7 @@ enum Commands {
#[tokio::main]
async fn main() {
let cli = Cli::parse();
let client = LdkNodeServerClient::new(cli.base_url);
let client = LdkServerClient::new(cli.base_url);

match cli.command {
Commands::OnchainReceive => {
Expand Down Expand Up @@ -141,7 +141,7 @@ async fn main() {
}
}

fn handle_response<Rs: ::prost::Message>(response: Result<Rs, LdkNodeServerError>) {
fn handle_response<Rs: ::prost::Message>(response: Result<Rs, LdkServerError>) {
match response {
Ok(response) => {
println!("{:?}", response);
Expand Down
34 changes: 17 additions & 17 deletions client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use crate::error::LdkServerError;
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
Expand All @@ -23,15 +23,15 @@ const OPEN_CHANNEL_PATH: &str = "OpenChannel";
const CLOSE_CHANNEL_PATH: &str = "CloseChannel";
const LIST_CHANNELS_PATH: &str = "ListChannels";

/// Client to access a hosted instance of LDK Node Server.
/// Client to access a hosted instance of LDK Server.
#[derive(Clone)]
pub struct LdkNodeServerClient {
pub struct LdkServerClient {
base_url: String,
client: Client,
}

impl LdkNodeServerClient {
/// Constructs a [`LdkNodeServerClient`] using `base_url` as the server endpoint.
impl LdkServerClient {
/// Constructs a [`LdkServerClient`] using `base_url` as the server endpoint.
pub fn new(base_url: String) -> Self {
Self { base_url, client: Client::new() }
}
Expand All @@ -40,7 +40,7 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`OnchainReceiveRequest`] and [`OnchainReceiveResponse`].
pub async fn onchain_receive(
&self, request: OnchainReceiveRequest,
) -> Result<OnchainReceiveResponse, LdkNodeServerError> {
) -> Result<OnchainReceiveResponse, LdkServerError> {
let url = format!("http://{}/{ONCHAIN_RECEIVE_PATH}", self.base_url);
self.post_request(&request, &url).await
}
Expand All @@ -49,7 +49,7 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`OnchainSendRequest`] and [`OnchainSendResponse`].
pub async fn onchain_send(
&self, request: OnchainSendRequest,
) -> Result<OnchainSendResponse, LdkNodeServerError> {
) -> Result<OnchainSendResponse, LdkServerError> {
let url = format!("http://{}/{ONCHAIN_SEND_PATH}", self.base_url);
self.post_request(&request, &url).await
}
Expand All @@ -58,7 +58,7 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`Bolt11ReceiveRequest`] and [`Bolt11ReceiveResponse`].
pub async fn bolt11_receive(
&self, request: Bolt11ReceiveRequest,
) -> Result<Bolt11ReceiveResponse, LdkNodeServerError> {
) -> Result<Bolt11ReceiveResponse, LdkServerError> {
let url = format!("http://{}/{BOLT11_RECEIVE_PATH}", self.base_url);
self.post_request(&request, &url).await
}
Expand All @@ -67,7 +67,7 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`Bolt11SendRequest`] and [`Bolt11SendResponse`].
pub async fn bolt11_send(
&self, request: Bolt11SendRequest,
) -> Result<Bolt11SendResponse, LdkNodeServerError> {
) -> Result<Bolt11SendResponse, LdkServerError> {
let url = format!("http://{}/{BOLT11_SEND_PATH}", self.base_url);
self.post_request(&request, &url).await
}
Expand All @@ -76,7 +76,7 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`Bolt12ReceiveRequest`] and [`Bolt12ReceiveResponse`].
pub async fn bolt12_receive(
&self, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, LdkNodeServerError> {
) -> Result<Bolt12ReceiveResponse, LdkServerError> {
let url = format!("http://{}/{BOLT12_RECEIVE_PATH}", self.base_url);
self.post_request(&request, &url).await
}
Expand All @@ -85,7 +85,7 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`Bolt12SendRequest`] and [`Bolt12SendResponse`].
pub async fn bolt12_send(
&self, request: Bolt12SendRequest,
) -> Result<Bolt12SendResponse, LdkNodeServerError> {
) -> Result<Bolt12SendResponse, LdkServerError> {
let url = format!("http://{}/{BOLT12_SEND_PATH}", self.base_url);
self.post_request(&request, &url).await
}
Expand All @@ -94,7 +94,7 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`OpenChannelRequest`] and [`OpenChannelResponse`].
pub async fn open_channel(
&self, request: OpenChannelRequest,
) -> Result<OpenChannelResponse, LdkNodeServerError> {
) -> Result<OpenChannelResponse, LdkServerError> {
let url = format!("http://{}/{OPEN_CHANNEL_PATH}", self.base_url);
self.post_request(&request, &url).await
}
Expand All @@ -103,7 +103,7 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`CloseChannelRequest`] and [`CloseChannelResponse`].
pub async fn close_channel(
&self, request: CloseChannelRequest,
) -> Result<CloseChannelResponse, LdkNodeServerError> {
) -> Result<CloseChannelResponse, LdkServerError> {
let url = format!("http://{}/{CLOSE_CHANNEL_PATH}", self.base_url);
self.post_request(&request, &url).await
}
Expand All @@ -112,14 +112,14 @@ impl LdkNodeServerClient {
/// For API contract/usage, refer to docs for [`ListChannelsRequest`] and [`ListChannelsResponse`].
pub async fn list_channels(
&self, request: ListChannelsRequest,
) -> Result<ListChannelsResponse, LdkNodeServerError> {
) -> Result<ListChannelsResponse, LdkServerError> {
let url = format!("http://{}/{LIST_CHANNELS_PATH}", self.base_url);
self.post_request(&request, &url).await
}

async fn post_request<Rq: Message, Rs: Message + Default>(
&self, request: &Rq, url: &str,
) -> Result<Rs, LdkNodeServerError> {
) -> Result<Rs, LdkServerError> {
let request_body = request.encode_to_vec();
let response_raw = match self
.client
Expand All @@ -131,7 +131,7 @@ impl LdkNodeServerClient {
{
Ok(response) => response,
Err(e) => {
return Err(LdkNodeServerError::InternalError(e.to_string()));
return Err(LdkServerError::InternalError(e.to_string()));
},
};
let status = response_raw.status();
Expand All @@ -141,7 +141,7 @@ impl LdkNodeServerClient {
Ok(Rs::decode(&payload[..])?)
} else {
//TODO: Error handling and error response parsing.
Err(LdkNodeServerError::InternalError("Unknown Error".to_string()))
Err(LdkServerError::InternalError("Unknown Error".to_string()))
}
}
}
12 changes: 6 additions & 6 deletions client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use prost::DecodeError;

/// When there is an error in request to LDK Node Server, the response contains a relevant error code.
/// When there is an error in request to LDK Server, the response contains a relevant error code.
#[derive(Debug)]
pub enum LdkNodeServerError {
pub enum LdkServerError {
/// There is an unknown error. (Placeholder until error handling is done.)
InternalError(String),
}

impl From<DecodeError> for LdkNodeServerError {
impl From<DecodeError> for LdkServerError {
fn from(err: DecodeError) -> Self {
LdkNodeServerError::InternalError(err.to_string())
LdkServerError::InternalError(err.to_string())
}
}

impl From<reqwest::Error> for LdkNodeServerError {
impl From<reqwest::Error> for LdkServerError {
fn from(err: reqwest::Error) -> Self {
LdkNodeServerError::InternalError(err.to_string())
LdkServerError::InternalError(err.to_string())
}
}
6 changes: 3 additions & 3 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Client-side library to interact with LDK Node Server.
//! Client-side library to interact with LDK Server.
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(rustdoc::private_intra_doc_links)]
#![deny(missing_docs)]

/// Implements a client ([`client::LdkNodeServerClient`]) to access a hosted instance of LDK Node Server.
/// Implements a client ([`client::LdkServerClient`]) to access a hosted instance of LDK Server.
pub mod client;

/// Implements the error type ([`error::LdkNodeServerError`]) returned on interacting with [`client::LdkNodeServerClient`]
/// Implements the error type ([`error::LdkServerError`]) returned on interacting with [`client::LdkServerClient`]
pub mod error;

/// Request/Response structs required for interacting with the client.
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ldk-node-server"
name = "ldk-server"
version = "0.1.0"
edition = "2021"

Expand Down

0 comments on commit a5178ec

Please sign in to comment.