Skip to content

Commit

Permalink
refactor: split client/server structs inside core
Browse files Browse the repository at this point in the history
  • Loading branch information
lsunsi committed Dec 9, 2023
1 parent 1e12919 commit 1063847
Show file tree
Hide file tree
Showing 20 changed files with 1,573 additions and 1,387 deletions.
46 changes: 23 additions & 23 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,35 @@ pub enum Query<'a> {
#[derive(Clone, Debug)]
pub struct Channel<'a> {
client: &'a reqwest::Client,
pub core: crate::channel::Query,
pub core: crate::channel::client::Query,
}

#[derive(Clone, Debug)]
pub struct Pay<'a> {
client: &'a reqwest::Client,
pub core: crate::pay::Query,
pub core: crate::pay::client::Query,
}

#[derive(Clone, Debug)]
pub struct Withdraw<'a> {
client: &'a reqwest::Client,
pub core: crate::withdraw::Query,
pub core: crate::withdraw::client::Query,
}

impl Channel<'_> {
/// # Errors
///
/// Returns errors on network or deserialization failures.
pub async fn callback_accept(
self,
remoteid: String,
&self,
remoteid: &str,
private: bool,
) -> Result<crate::channel::CallbackResponse, &'static str> {
let callback = self.core.callback_accept(remoteid, private).url();
) -> Result<crate::channel::client::CallbackResponse, &'static str> {
let callback = self.core.callback_accept(remoteid, private);

let response = self
.client
.get(callback)
.get(callback.to_string())
.send()
.await
.map_err(|_| "request failed")?;
Expand All @@ -73,14 +73,14 @@ impl Channel<'_> {
///
/// Returns errors on network or deserialization failures.
pub async fn callback_cancel(
self,
remoteid: String,
) -> Result<crate::channel::CallbackResponse, &'static str> {
let callback = self.core.callback_cancel(remoteid).url();
&self,
remoteid: &str,
) -> Result<crate::channel::client::CallbackResponse, &'static str> {
let callback = self.core.callback_cancel(remoteid);

let response = self
.client
.get(callback)
.get(callback.to_string())
.send()
.await
.map_err(|_| "request failed")?;
Expand All @@ -95,15 +95,15 @@ impl Pay<'_> {
///
/// Returns errors on network or deserialization failures.
pub async fn callback(
self,
&self,
millisatoshis: u64,
comment: String,
) -> Result<crate::pay::CallbackResponse, &'static str> {
let callback = self.core.callback(millisatoshis, comment).url();
comment: &str,
) -> Result<crate::pay::client::CallbackResponse, &'static str> {
let callback = self.core.callback(millisatoshis, comment);

let response = self
.client
.get(callback)
.get(callback.to_string())
.send()
.await
.map_err(|_| "request failed")?;
Expand All @@ -118,14 +118,14 @@ impl Withdraw<'_> {
///
/// Returns errors on network or deserialization failures.
pub async fn callback(
self,
pr: String,
) -> Result<crate::withdraw::CallbackResponse, &'static str> {
let callback = self.core.callback(pr).url();
&self,
pr: &str,
) -> Result<crate::withdraw::client::CallbackResponse, &'static str> {
let callback = self.core.callback(pr);

let response = self
.client
.get(callback)
.get(callback.to_string())
.send()
.await
.map_err(|_| "request failed")?;
Expand Down
6 changes: 3 additions & 3 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ fn resolve_address(s: &str) -> Result<url::Url, &'static str> {

#[derive(Debug)]
pub enum Query {
Channel(channel::Query),
Pay(pay::Query),
Withdraw(withdraw::Query),
Channel(channel::client::Query),
Pay(pay::client::Query),
Withdraw(withdraw::client::Query),
}

impl std::str::FromStr for Query {
Expand Down
Loading

0 comments on commit 1063847

Please sign in to comment.