From 8210ec48e84e20169c76000e88c4bc96047b080a Mon Sep 17 00:00:00 2001 From: Lucas Sunsi Abreu Date: Tue, 5 Dec 2023 06:44:34 -0300 Subject: [PATCH] chore: rename, reorganize, simplify, evolve --- src/client.rs | 58 +++--- src/core.rs | 26 +-- src/core/{channel_request.rs => channel.rs} | 25 ++- src/core/{pay_request.rs => pay.rs} | 29 ++- src/core/{withdraw_request.rs => withdraw.rs} | 23 ++- src/server.rs | 169 +++++++++--------- tests/lud02.rs | 18 +- tests/lud03.rs | 12 +- tests/lud06.rs | 6 +- tests/lud09.rs | 15 +- tests/lud11.rs | 6 +- tests/lud12.rs | 6 +- 12 files changed, 192 insertions(+), 201 deletions(-) rename src/core/{channel_request.rs => channel.rs} (87%) rename src/core/{pay_request.rs => pay.rs} (93%) rename src/core/{withdraw_request.rs => withdraw.rs} (87%) diff --git a/src/client.rs b/src/client.rs index 116076d..c7deecb 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,5 +1,3 @@ -use crate::core; - #[derive(Clone, Default)] pub struct Client(reqwest::Client); @@ -8,52 +6,48 @@ impl Client { /// /// Returns errors on network or deserialization failures. pub async fn query(&self, s: &str) -> Result { - let url = core::resolve(s)?; + let url = crate::core::resolve(s)?; let client = &self.0; let response = client.get(url).send().await.map_err(|_| "request failed")?; let text = response.text().await.map_err(|_| "body failed")?; - text.parse::() + text.parse::() .map_err(|_| "parse failed") .map(|query| match query { - core::Query::ChannelRequest(core) => { - Query::ChannelRequest(ChannelRequest { client, core }) - } - core::Query::WithdrawRequest(core) => { - Query::WithdrawRequest(WithdrawRequest { client, core }) - } - core::Query::PayRequest(core) => Query::PayRequest(PayRequest { client, core }), + crate::core::Query::Channel(core) => Query::Channel(Channel { client, core }), + crate::core::Query::Pay(core) => Query::Pay(Pay { client, core }), + crate::core::Query::Withdraw(core) => Query::Withdraw(Withdraw { client, core }), }) } } #[derive(Clone, Debug)] pub enum Query<'a> { - ChannelRequest(ChannelRequest<'a>), - WithdrawRequest(WithdrawRequest<'a>), - PayRequest(PayRequest<'a>), + Channel(Channel<'a>), + Pay(Pay<'a>), + Withdraw(Withdraw<'a>), } #[derive(Clone, Debug)] -pub struct ChannelRequest<'a> { +pub struct Channel<'a> { client: &'a reqwest::Client, - pub core: core::channel_request::ChannelRequest, + pub core: crate::core::channel::Query, } #[derive(Clone, Debug)] -pub struct WithdrawRequest<'a> { +pub struct Pay<'a> { client: &'a reqwest::Client, - pub core: core::withdraw_request::WithdrawRequest, + pub core: crate::core::pay::Query, } #[derive(Clone, Debug)] -pub struct PayRequest<'a> { +pub struct Withdraw<'a> { client: &'a reqwest::Client, - pub core: core::pay_request::PayRequest, + pub core: crate::core::withdraw::Query, } -impl ChannelRequest<'_> { +impl Channel<'_> { /// # Errors /// /// Returns errors on network or deserialization failures. @@ -61,7 +55,7 @@ impl ChannelRequest<'_> { self, remoteid: &str, private: bool, - ) -> Result { + ) -> Result { let callback = self.core.callback_accept(remoteid, private); let response = self @@ -81,7 +75,7 @@ impl ChannelRequest<'_> { pub async fn callback_cancel( self, remoteid: &str, - ) -> Result { + ) -> Result { let callback = self.core.callback_cancel(remoteid); let response = self @@ -96,15 +90,16 @@ impl ChannelRequest<'_> { } } -impl WithdrawRequest<'_> { +impl Pay<'_> { /// # Errors /// /// Returns errors on network or deserialization failures. pub async fn callback( self, - pr: &str, - ) -> Result { - let callback = self.core.callback(pr); + comment: &str, + millisatoshis: u64, + ) -> Result { + let callback = self.core.callback(comment, millisatoshis); let response = self .client @@ -118,16 +113,15 @@ impl WithdrawRequest<'_> { } } -impl PayRequest<'_> { +impl Withdraw<'_> { /// # Errors /// /// Returns errors on network or deserialization failures. pub async fn callback( self, - comment: &str, - millisatoshis: u64, - ) -> Result { - let callback = self.core.callback(comment, millisatoshis); + pr: &str, + ) -> Result { + let callback = self.core.callback(pr); let response = self .client diff --git a/src/core.rs b/src/core.rs index abafa0f..a67c8f7 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,6 +1,6 @@ -pub mod channel_request; -pub mod pay_request; -pub mod withdraw_request; +pub mod channel; +pub mod pay; +pub mod withdraw; /// # Errors /// @@ -70,9 +70,9 @@ fn resolve_address(s: &str) -> Result { #[derive(Debug)] pub enum Query { - PayRequest(pay_request::PayRequest), - ChannelRequest(channel_request::ChannelRequest), - WithdrawRequest(withdraw_request::WithdrawRequest), + Channel(channel::Query), + Pay(pay::Query), + Withdraw(withdraw::Query), } impl std::str::FromStr for Query { @@ -86,15 +86,15 @@ impl std::str::FromStr for Query { let tag = miniserde::json::from_str::(s).map_err(|_| "deserialize tag failed")?; - if tag.tag == channel_request::TAG { + if tag.tag == channel::TAG { let cr = s.parse().map_err(|_| "deserialize data failed")?; - Ok(Query::ChannelRequest(cr)) - } else if tag.tag == withdraw_request::TAG { - let wr = s.parse().map_err(|_| "deserialize data failed")?; - Ok(Query::WithdrawRequest(wr)) - } else if tag.tag == pay_request::TAG { + Ok(Query::Channel(cr)) + } else if tag.tag == pay::TAG { let pr = s.parse().map_err(|_| "deserialize data failed")?; - Ok(Query::PayRequest(pr)) + Ok(Query::Pay(pr)) + } else if tag.tag == withdraw::TAG { + let wr = s.parse().map_err(|_| "deserialize data failed")?; + Ok(Query::Withdraw(wr)) } else { Err("unknown tag") } diff --git a/src/core/channel_request.rs b/src/core/channel.rs similarity index 87% rename from src/core/channel_request.rs rename to src/core/channel.rs index d6e1968..33d60d3 100644 --- a/src/core/channel_request.rs +++ b/src/core/channel.rs @@ -1,20 +1,19 @@ pub const TAG: &str = "channelRequest"; #[derive(Clone, Debug)] -pub struct ChannelRequest { +pub struct Query { pub callback: url::Url, pub uri: String, pub k1: String, } -impl std::str::FromStr for ChannelRequest { +impl std::str::FromStr for Query { type Err = &'static str; fn from_str(s: &str) -> Result { - let d: de::QueryResponse = - miniserde::json::from_str(s).map_err(|_| "deserialize failed")?; + let d: de::Query = miniserde::json::from_str(s).map_err(|_| "deserialize failed")?; - Ok(ChannelRequest { + Ok(Query { callback: d.callback.0, uri: d.uri, k1: d.k1, @@ -22,9 +21,9 @@ impl std::str::FromStr for ChannelRequest { } } -impl std::fmt::Display for ChannelRequest { +impl std::fmt::Display for Query { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&miniserde::json::to_string(&ser::QueryResponse { + f.write_str(&miniserde::json::to_string(&ser::Query { tag: TAG, callback: crate::serde::Url(self.callback.clone()), uri: &self.uri, @@ -33,7 +32,7 @@ impl std::fmt::Display for ChannelRequest { } } -impl ChannelRequest { +impl Query { /// # Errors /// /// Returns errors on network or deserialization failures. @@ -115,7 +114,7 @@ mod ser { use miniserde::Serialize; #[derive(Serialize)] - pub(super) struct QueryResponse<'a> { + pub(super) struct Query<'a> { pub tag: &'static str, pub callback: Url, pub uri: &'a str, @@ -128,7 +127,7 @@ mod de { use miniserde::Deserialize; #[derive(Deserialize)] - pub(super) struct QueryResponse { + pub(super) struct Query { pub callback: Url, pub uri: String, pub k1: String, @@ -147,7 +146,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); assert_eq!(parsed.callback.to_string(), "https://yuri/?o=callback"); assert_eq!(parsed.uri, "noh@ipe:porta"); @@ -164,7 +163,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); let url = parsed.clone().callback_accept("idremoto", true); assert_eq!( @@ -190,7 +189,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); let url = parsed.callback_cancel("idremoto"); assert_eq!( diff --git a/src/core/pay_request.rs b/src/core/pay.rs similarity index 93% rename from src/core/pay_request.rs rename to src/core/pay.rs index 01f5299..89af8f2 100644 --- a/src/core/pay_request.rs +++ b/src/core/pay.rs @@ -1,7 +1,7 @@ pub const TAG: &str = "payRequest"; #[derive(Clone, Debug)] -pub struct PayRequest { +pub struct Query { pub callback: url::Url, pub short_description: String, pub long_description: Option, @@ -12,15 +12,14 @@ pub struct PayRequest { pub max: u64, } -impl std::str::FromStr for PayRequest { +impl std::str::FromStr for Query { type Err = &'static str; fn from_str(s: &str) -> Result { use base64::{prelude::BASE64_STANDARD, Engine}; use miniserde::json::Value; - let p: de::QueryResponse = - miniserde::json::from_str(s).map_err(|_| "deserialize failed")?; + let p: de::Query = miniserde::json::from_str(s).map_err(|_| "deserialize failed")?; let comment_size = p.comment_allowed.unwrap_or(0); @@ -60,7 +59,7 @@ impl std::str::FromStr for PayRequest { _ => None, }); - Ok(PayRequest { + Ok(Query { callback: p.callback.0, min: p.min_sendable, max: p.max_sendable, @@ -73,7 +72,7 @@ impl std::str::FromStr for PayRequest { } } -impl std::fmt::Display for PayRequest { +impl std::fmt::Display for Query { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use base64::{prelude::BASE64_STANDARD, Engine}; @@ -95,7 +94,7 @@ impl std::fmt::Display for PayRequest { .collect::>(), ); - f.write_str(&miniserde::json::to_string(&ser::QueryResponse { + f.write_str(&miniserde::json::to_string(&ser::Query { tag: TAG, metadata, callback: &crate::serde::Url(self.callback.clone()), @@ -106,7 +105,7 @@ impl std::fmt::Display for PayRequest { } } -impl PayRequest { +impl Query { /// # Errors /// /// Returns errors on network or deserialization failures. @@ -200,7 +199,7 @@ mod ser { use std::collections::BTreeMap; #[derive(Serialize)] - pub(super) struct QueryResponse<'a> { + pub(super) struct Query<'a> { pub tag: &'static str, pub metadata: String, pub callback: &'a Url, @@ -227,7 +226,7 @@ mod de { use std::collections::BTreeMap; #[derive(Deserialize)] - pub(super) struct QueryResponse { + pub(super) struct Query { pub metadata: String, pub callback: Url, #[serde(rename = "minSendable")] @@ -260,7 +259,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); assert_eq!(parsed.callback.to_string(), "https://yuri/?o=callback"); assert_eq!(parsed.short_description, "boneco do steve magal"); @@ -285,7 +284,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); assert_eq!(parsed.comment_size, 140); } @@ -300,7 +299,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); assert_eq!( parsed.long_description.unwrap(), "mochila a jato brutal incluida" @@ -318,7 +317,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); assert_eq!(parsed.jpeg.unwrap(), b"imagembrutal"); assert_eq!(parsed.png.unwrap(), b"fotobrutal"); } @@ -334,7 +333,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); assert_eq!( parsed.clone().callback("comentario", 314).to_string(), diff --git a/src/core/withdraw_request.rs b/src/core/withdraw.rs similarity index 87% rename from src/core/withdraw_request.rs rename to src/core/withdraw.rs index 9bdf01d..b640a76 100644 --- a/src/core/withdraw_request.rs +++ b/src/core/withdraw.rs @@ -1,7 +1,7 @@ pub const TAG: &str = "withdrawRequest"; #[derive(Clone, Debug)] -pub struct WithdrawRequest { +pub struct Query { pub k1: String, pub callback: url::Url, pub description: String, @@ -9,14 +9,13 @@ pub struct WithdrawRequest { pub max: u64, } -impl std::str::FromStr for WithdrawRequest { +impl std::str::FromStr for Query { type Err = &'static str; fn from_str(s: &str) -> Result { - let d: de::QueryResponse = - miniserde::json::from_str(s).map_err(|_| "deserialize failed")?; + let d: de::Query = miniserde::json::from_str(s).map_err(|_| "deserialize failed")?; - Ok(WithdrawRequest { + Ok(Query { k1: d.k1, callback: d.callback.0, description: d.default_description, @@ -26,9 +25,9 @@ impl std::str::FromStr for WithdrawRequest { } } -impl std::fmt::Display for WithdrawRequest { +impl std::fmt::Display for Query { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&miniserde::json::to_string(&ser::QueryResponse { + f.write_str(&miniserde::json::to_string(&ser::Query { tag: TAG, callback: crate::serde::Url(self.callback.clone()), default_description: &self.description, @@ -39,7 +38,7 @@ impl std::fmt::Display for WithdrawRequest { } } -impl WithdrawRequest { +impl Query { /// # Errors /// /// Returns errors on network or deserialization failures. @@ -99,7 +98,7 @@ mod ser { use miniserde::Serialize; #[derive(Serialize)] - pub(super) struct QueryResponse<'a> { + pub(super) struct Query<'a> { pub tag: &'static str, pub k1: &'a str, pub callback: Url, @@ -117,7 +116,7 @@ mod de { use miniserde::Deserialize; #[derive(Deserialize)] - pub(super) struct QueryResponse { + pub(super) struct Query { pub k1: String, pub callback: Url, #[serde(rename = "defaultDescription")] @@ -143,7 +142,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); assert_eq!(parsed.callback.to_string(), "https://yuri/?o=callback"); assert_eq!(parsed.description, "verde com bolinhas"); @@ -164,7 +163,7 @@ mod tests { } "#; - let parsed = input.parse::().expect("parse"); + let parsed = input.parse::().expect("parse"); assert_eq!( parsed.callback("pierre").to_string(), diff --git a/src/server.rs b/src/server.rs index 5697084..b8c4338 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,47 +1,51 @@ -use crate::core; use axum::{extract::RawQuery, http::StatusCode, routing::get, Router}; use std::future::Future; -pub struct Server { +pub struct Server { channel_query: CQ, channel_callback: CC, - withdraw_query: WQ, - withdraw_callback: WC, pay_query: PQ, pay_callback: PC, + withdraw_query: WQ, + withdraw_callback: WC, } impl Default for Server< - unimplemented::Handler0, - unimplemented::Handler1< - (String, String, core::channel_request::CallbackAction), - core::channel_request::CallbackResponse, + // Channel Request + unimplemented::Query, + unimplemented::Callback< + (String, String, crate::core::channel::CallbackAction), + crate::core::channel::CallbackResponse, >, - unimplemented::Handler0, - unimplemented::Handler1<(String, String), core::withdraw_request::CallbackResponse>, - unimplemented::Handler0, - unimplemented::Handler1<(u64, Option), core::pay_request::CallbackResponse>, + // Pay Request + unimplemented::Query, + unimplemented::Callback<(u64, Option), crate::core::pay::CallbackResponse>, + // Withdraw Request + unimplemented::Query, + unimplemented::Callback<(String, String), crate::core::withdraw::CallbackResponse>, > { fn default() -> Self { Server { - channel_query: unimplemented::handler0, - channel_callback: unimplemented::handler1, - withdraw_query: unimplemented::handler0, - withdraw_callback: unimplemented::handler1, - pay_query: unimplemented::handler0, - pay_callback: unimplemented::handler1, + channel_query: unimplemented::query, + channel_callback: unimplemented::callback, + + pay_query: unimplemented::query, + pay_callback: unimplemented::callback, + + withdraw_query: unimplemented::query, + withdraw_callback: unimplemented::callback, } } } -impl Server { +impl Server { pub fn channel_request( self, channel_query: CQ2, channel_callback: CC2, - ) -> Server { + ) -> Server { Server { channel_query, channel_callback, @@ -52,26 +56,11 @@ impl Server { } } - pub fn withdraw_request( - self, - withdraw_query: WQ2, - withdraw_callback: WC2, - ) -> Server { - Server { - channel_query: self.channel_query, - channel_callback: self.channel_callback, - pay_query: self.pay_query, - pay_callback: self.pay_callback, - withdraw_query, - withdraw_callback, - } - } - pub fn pay_request( self, pay_query: PQ2, pay_callback: PC2, - ) -> Server { + ) -> Server { Server { channel_query: self.channel_query, channel_callback: self.channel_callback, @@ -81,31 +70,46 @@ impl Server { withdraw_callback: self.withdraw_callback, } } + + pub fn withdraw_request( + self, + withdraw_query: WQ2, + withdraw_callback: WC2, + ) -> Server { + Server { + channel_query: self.channel_query, + channel_callback: self.channel_callback, + pay_query: self.pay_query, + pay_callback: self.pay_callback, + withdraw_query, + withdraw_callback, + } + } } -impl - Server +impl + Server where CQ: 'static + Send + Clone + Fn() -> CQFut, - CQFut: Send + Future>, + CQFut: Send + Future>, CC: 'static + Send + Clone - + Fn((String, String, core::channel_request::CallbackAction)) -> CCFut, - CCFut: Send + Future>, - - WQ: 'static + Send + Clone + Fn() -> WQFut, - WQFut: Send + Future>, - - WC: 'static + Send + Clone + Fn((String, String)) -> WCFut, - WCFut: Send + Future>, + + Fn((String, String, crate::core::channel::CallbackAction)) -> CCFut, + CCFut: Send + Future>, PQ: 'static + Send + Clone + Fn() -> PQFut, - PQFut: Send + Future>, + PQFut: Send + Future>, PC: 'static + Send + Clone + Fn((u64, Option)) -> PCFut, - PCFut: Send + Future>, + PCFut: Send + Future>, + + WQ: 'static + Send + Clone + Fn() -> WQFut, + WQFut: Send + Future>, + + WC: 'static + Send + Clone + Fn((String, String)) -> WCFut, + WCFut: Send + Future>, { pub fn build(self) -> Router<()> { Router::new() @@ -132,13 +136,13 @@ where let action = qs .get("cancel") .filter(|v| **v == "1") - .map(|_| core::channel_request::CallbackAction::Cancel) + .map(|_| crate::core::channel::CallbackAction::Cancel) .or_else(|| { qs.get("private").and_then(|v| match *v { - "0" => Some(core::channel_request::CallbackAction::Accept { + "0" => Some(crate::core::channel::CallbackAction::Accept { private: false, }), - "1" => Some(core::channel_request::CallbackAction::Accept { + "1" => Some(crate::core::channel::CallbackAction::Accept { private: true, }), _ => None, @@ -152,16 +156,16 @@ where }), ) .route( - "/lnurlw", + "/lnurlp", get(move || { - let wq = self.withdraw_query.clone(); - async move { wq().await.map(|a| a.to_string()) } + let pq = self.pay_query.clone(); + async move { pq().await.map(|a| a.to_string()) } }), ) .route( - "/lnurlw/callback", + "/lnurlp/callback", get(move |RawQuery(q): RawQuery| { - let wc = self.withdraw_callback.clone(); + let pc = self.pay_callback.clone(); async move { let q = q.ok_or(StatusCode::BAD_REQUEST)?; let qs = q @@ -169,25 +173,28 @@ where .filter_map(|s| s.split_once('=')) .collect::>(); - let k1 = qs.get("k1").ok_or(StatusCode::BAD_REQUEST)?; - let pr = qs.get("pr").ok_or(StatusCode::BAD_REQUEST)?; + let amount = qs + .get("amount") + .and_then(|s| s.parse().ok()) + .ok_or(StatusCode::BAD_REQUEST)?; - let param = (String::from(*k1), String::from(*pr)); - wc(param).await.map(|a| a.to_string()) + let comment = qs.get("comment").map(|c| String::from(*c)); + + pc((amount, comment)).await.map(|a| a.to_string()) } }), ) .route( - "/lnurlp", + "/lnurlw", get(move || { - let pq = self.pay_query.clone(); - async move { pq().await.map(|a| a.to_string()) } + let wq = self.withdraw_query.clone(); + async move { wq().await.map(|a| a.to_string()) } }), ) .route( - "/lnurlp/callback", + "/lnurlw/callback", get(move |RawQuery(q): RawQuery| { - let pc = self.pay_callback.clone(); + let wc = self.withdraw_callback.clone(); async move { let q = q.ok_or(StatusCode::BAD_REQUEST)?; let qs = q @@ -195,14 +202,11 @@ where .filter_map(|s| s.split_once('=')) .collect::>(); - let amount = qs - .get("amount") - .and_then(|s| s.parse().ok()) - .ok_or(StatusCode::BAD_REQUEST)?; - - let comment = qs.get("comment").map(|c| String::from(*c)); + let k1 = qs.get("k1").ok_or(StatusCode::BAD_REQUEST)?; + let pr = qs.get("pr").ok_or(StatusCode::BAD_REQUEST)?; - pc((amount, comment)).await.map(|a| a.to_string()) + let param = (String::from(*k1), String::from(*pr)); + wc(param).await.map(|a| a.to_string()) } }), ) @@ -218,8 +222,15 @@ mod unimplemented { task::{Context, Poll}, }; - pub(super) type Handler0 = fn() -> Unimplemented; - pub(super) type Handler1 = fn(T1) -> Unimplemented; + pub(super) type Query = fn() -> Unimplemented; + pub(super) fn query() -> Unimplemented { + Unimplemented(PhantomData) + } + + pub(super) type Callback = fn(Param) -> Unimplemented; + pub(super) fn callback(_: T1) -> Unimplemented { + Unimplemented(PhantomData) + } pub struct Unimplemented(PhantomData); @@ -230,14 +241,6 @@ mod unimplemented { Poll::Ready(Err(StatusCode::NOT_IMPLEMENTED)) } } - - pub(super) fn handler0() -> Unimplemented { - Unimplemented(PhantomData) - } - - pub(super) fn handler1(_: T1) -> Unimplemented { - Unimplemented(PhantomData) - } } #[cfg(test)] diff --git a/tests/lud02.rs b/tests/lud02.rs index b53a608..85fe116 100644 --- a/tests/lud02.rs +++ b/tests/lud02.rs @@ -14,7 +14,7 @@ async fn test() { move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::channel_request::ChannelRequest { + Ok(lnurlkit::core::channel::Query { uri: String::from("u@r:i"), k1: String::from("caum"), callback, @@ -23,11 +23,9 @@ async fn test() { }, |(k1, remoteid, action)| async move { Ok(if remoteid == "idremoto" { - lnurlkit::core::channel_request::CallbackResponse::Ok + lnurlkit::core::channel::CallbackResponse::Ok } else { - lnurlkit::core::channel_request::CallbackResponse::Error(format!( - "{k1}/{action:?}" - )) + lnurlkit::core::channel::CallbackResponse::Error(format!("{k1}/{action:?}")) }) }, ) @@ -47,7 +45,7 @@ async fn test() { .expect("lnurl"); let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Query::ChannelRequest(cr) = queried else { + let lnurlkit::client::Query::Channel(cr) = queried else { panic!("not pay request"); }; @@ -61,7 +59,7 @@ async fn test() { assert!(matches!( response, - lnurlkit::core::channel_request::CallbackResponse::Ok + lnurlkit::core::channel::CallbackResponse::Ok )); let response = cr @@ -72,7 +70,7 @@ async fn test() { assert!(matches!( response, - lnurlkit::core::channel_request::CallbackResponse::Error(r) if r == "caum/Cancel" + lnurlkit::core::channel::CallbackResponse::Error(r) if r == "caum/Cancel" )); let response = cr @@ -83,7 +81,7 @@ async fn test() { assert!(matches!( response, - lnurlkit::core::channel_request::CallbackResponse::Error(r) if r == "caum/Accept { private: true }" + lnurlkit::core::channel::CallbackResponse::Error(r) if r == "caum/Accept { private: true }" )); let response = cr @@ -93,6 +91,6 @@ async fn test() { assert!(matches!( response, - lnurlkit::core::channel_request::CallbackResponse::Error(r) if r == "caum/Accept { private: false }" + lnurlkit::core::channel::CallbackResponse::Error(r) if r == "caum/Accept { private: false }" )); } diff --git a/tests/lud03.rs b/tests/lud03.rs index ddaddc5..703d2df 100644 --- a/tests/lud03.rs +++ b/tests/lud03.rs @@ -14,7 +14,7 @@ async fn test() { move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::withdraw_request::WithdrawRequest { + Ok(lnurlkit::core::withdraw::Query { description: String::from("descricao"), k1: String::from("caum"), callback, @@ -25,9 +25,9 @@ async fn test() { }, |(k1, pr)| async move { Ok(if pr == "pierre" { - lnurlkit::core::withdraw_request::CallbackResponse::Ok + lnurlkit::core::withdraw::CallbackResponse::Ok } else { - lnurlkit::core::withdraw_request::CallbackResponse::Error(k1) + lnurlkit::core::withdraw::CallbackResponse::Error(k1) }) }, ) @@ -47,7 +47,7 @@ async fn test() { .expect("lnurl"); let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Query::WithdrawRequest(wr) = queried else { + let lnurlkit::client::Query::Withdraw(wr) = queried else { panic!("not pay request"); }; @@ -58,12 +58,12 @@ async fn test() { let response = wr.clone().callback("pierre").await.expect("callback"); assert!(matches!( response, - lnurlkit::core::withdraw_request::CallbackResponse::Ok + lnurlkit::core::withdraw::CallbackResponse::Ok )); let response = wr.callback("pierrado").await.expect("callback"); assert!(matches!( response, - lnurlkit::core::withdraw_request::CallbackResponse::Error(r) if r == "caum" + lnurlkit::core::withdraw::CallbackResponse::Error(r) if r == "caum" )); } diff --git a/tests/lud06.rs b/tests/lud06.rs index e0d750e..ccb21a4 100644 --- a/tests/lud06.rs +++ b/tests/lud06.rs @@ -14,7 +14,7 @@ async fn test() { move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::pay_request::PayRequest { + Ok(lnurlkit::core::pay::Query { callback, short_description: String::from("today i become death"), long_description: Some(String::from("the destroyer of worlds")), @@ -27,7 +27,7 @@ async fn test() { } }, |(amount, _)| async move { - Ok(lnurlkit::core::pay_request::CallbackResponse { + Ok(lnurlkit::core::pay::CallbackResponse { pr: format!("pierre:{amount}"), disposable: false, success_action: None, @@ -50,7 +50,7 @@ async fn test() { .expect("lnurl"); let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Query::PayRequest(pr) = queried else { + let lnurlkit::client::Query::Pay(pr) = queried else { panic!("not pay request"); }; diff --git a/tests/lud09.rs b/tests/lud09.rs index ff96f89..b1f748f 100644 --- a/tests/lud09.rs +++ b/tests/lud09.rs @@ -14,7 +14,7 @@ async fn test() { move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::pay_request::PayRequest { + Ok(lnurlkit::core::pay::Query { callback, short_description: String::new(), long_description: None, @@ -27,17 +27,17 @@ async fn test() { } }, |(amount, comment): (u64, Option)| async move { - Ok(lnurlkit::core::pay_request::CallbackResponse { + Ok(lnurlkit::core::pay::CallbackResponse { pr: String::new(), disposable: false, success_action: if amount == 0 { None } else if amount == 1 { - Some(lnurlkit::core::pay_request::SuccessAction::Message( + Some(lnurlkit::core::pay::SuccessAction::Message( comment.unwrap_or_default(), )) } else { - Some(lnurlkit::core::pay_request::SuccessAction::Url( + Some(lnurlkit::core::pay::SuccessAction::Url( url::Url::parse("http://u.rl").expect("url"), comment.unwrap_or_default(), )) @@ -61,7 +61,7 @@ async fn test() { .expect("lnurl"); let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Query::PayRequest(pr) = queried else { + let lnurlkit::client::Query::Pay(pr) = queried else { panic!("not pay request"); }; @@ -70,8 +70,7 @@ async fn test() { let invoice = pr.clone().callback("mensagem", 1).await.expect("callback"); - let Some(lnurlkit::core::pay_request::SuccessAction::Message(m)) = invoice.success_action - else { + let Some(lnurlkit::core::pay::SuccessAction::Message(m)) = invoice.success_action else { panic!("bad success action"); }; @@ -79,7 +78,7 @@ async fn test() { let invoice = pr.callback("descricao", 2).await.expect("callback"); - let Some(lnurlkit::core::pay_request::SuccessAction::Url(u, d)) = invoice.success_action else { + let Some(lnurlkit::core::pay::SuccessAction::Url(u, d)) = invoice.success_action else { panic!("bad success action"); }; diff --git a/tests/lud11.rs b/tests/lud11.rs index 28c05de..24d151d 100644 --- a/tests/lud11.rs +++ b/tests/lud11.rs @@ -14,7 +14,7 @@ async fn test() { move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::pay_request::PayRequest { + Ok(lnurlkit::core::pay::Query { callback, short_description: String::new(), long_description: None, @@ -27,7 +27,7 @@ async fn test() { } }, |(amount, _)| async move { - Ok(lnurlkit::core::pay_request::CallbackResponse { + Ok(lnurlkit::core::pay::CallbackResponse { pr: String::new(), disposable: amount % 2 == 0, success_action: None, @@ -50,7 +50,7 @@ async fn test() { .expect("lnurl"); let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Query::PayRequest(pr) = queried else { + let lnurlkit::client::Query::Pay(pr) = queried else { panic!("not pay request"); }; diff --git a/tests/lud12.rs b/tests/lud12.rs index da375de..becf6f6 100644 --- a/tests/lud12.rs +++ b/tests/lud12.rs @@ -14,7 +14,7 @@ async fn test() { move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::pay_request::PayRequest { + Ok(lnurlkit::core::pay::Query { callback, short_description: String::new(), long_description: None, @@ -27,7 +27,7 @@ async fn test() { } }, |(_, comment)| async move { - Ok(lnurlkit::core::pay_request::CallbackResponse { + Ok(lnurlkit::core::pay::CallbackResponse { pr: format!("pierre:{comment:?}"), disposable: false, success_action: None, @@ -50,7 +50,7 @@ async fn test() { .expect("lnurl"); let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Query::PayRequest(pr) = queried else { + let lnurlkit::client::Query::Pay(pr) = queried else { panic!("not pay request"); };