From 87a64adc95b4658b2c2eece0aa61da2a11453276 Mon Sep 17 00:00:00 2001 From: Lucas Sunsi Abreu Date: Wed, 13 Dec 2023 07:25:49 -0300 Subject: [PATCH] refactor: rename response to entrypoint --- src/client.rs | 38 ++++++++++++----------- src/core.rs | 20 ++++++------- src/core/channel.rs | 2 +- src/core/channel/client.rs | 50 +++++++++++++++---------------- src/core/channel/server.rs | 48 ++++++++++++++--------------- src/core/pay/client.rs | 60 +++++++++++++++++-------------------- src/core/pay/server.rs | 48 ++++++++++++++--------------- src/core/withdraw/client.rs | 40 ++++++++++++------------- src/core/withdraw/server.rs | 28 ++++++++--------- src/lib.rs | 2 +- src/server.rs | 27 ++++++++--------- tests/lud02.rs | 26 +++++++--------- tests/lud03.rs | 12 ++++---- tests/lud06.rs | 10 +++---- tests/lud08.rs | 14 ++++----- tests/lud09.rs | 14 ++++----- tests/lud11.rs | 12 ++++---- tests/lud12.rs | 15 ++++------ tests/lud16.rs | 12 ++++---- tests/real.rs | 12 ++++---- 20 files changed, 238 insertions(+), 252 deletions(-) diff --git a/src/client.rs b/src/client.rs index 6b70c05..28f1b9a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,13 +5,13 @@ impl Client { /// # Errors /// /// Returns errors on network or deserialization failures. - pub async fn query(&self, s: &str) -> Result { + pub async fn entrypoint(&self, s: &str) -> Result { let client = &self.0; let url = match crate::resolve(s)? { crate::Resolved::Url(url) => url, crate::Resolved::Withdraw(_, core) => { - return Ok(Response::Withdraw(Withdraw { client, core })) + return Ok(Entrypoint::Withdraw(Withdraw { client, core })) } }; @@ -21,16 +21,18 @@ impl Client { (&bytes as &[u8]) .try_into() .map_err(|_| "parse failed") - .map(|query: crate::Response| match query { - crate::Response::Channel(core) => Response::Channel(Channel { client, core }), - crate::Response::Pay(core) => Response::Pay(Pay { client, core }), - crate::Response::Withdraw(core) => Response::Withdraw(Withdraw { client, core }), + .map(|query: crate::Entrypoint| match query { + crate::Entrypoint::Channel(core) => Entrypoint::Channel(Channel { client, core }), + crate::Entrypoint::Pay(core) => Entrypoint::Pay(Pay { client, core }), + crate::Entrypoint::Withdraw(core) => { + Entrypoint::Withdraw(Withdraw { client, core }) + } }) } } #[derive(Clone, Debug)] -pub enum Response<'a> { +pub enum Entrypoint<'a> { Channel(Channel<'a>), Pay(Pay<'a>), Withdraw(Withdraw<'a>), @@ -39,31 +41,31 @@ pub enum Response<'a> { #[derive(Clone, Debug)] pub struct Channel<'a> { client: &'a reqwest::Client, - pub core: crate::channel::client::Response, + pub core: crate::channel::client::Entrypoint, } #[derive(Clone, Debug)] pub struct Pay<'a> { client: &'a reqwest::Client, - pub core: crate::pay::client::Response, + pub core: crate::pay::client::Entrypoint, } #[derive(Clone, Debug)] pub struct Withdraw<'a> { client: &'a reqwest::Client, - pub core: crate::withdraw::client::Response, + pub core: crate::withdraw::client::Entrypoint, } impl Channel<'_> { /// # Errors /// /// Returns errors on network or deserialization failures. - pub async fn callback_accept( + pub async fn accept( &self, remoteid: &str, private: bool, ) -> Result { - let callback = self.core.callback_accept(remoteid, private); + let callback = self.core.accept(remoteid, private); let response = self .client @@ -79,11 +81,11 @@ impl Channel<'_> { /// # Errors /// /// Returns errors on network or deserialization failures. - pub async fn callback_cancel( + pub async fn cancel( &self, remoteid: &str, ) -> Result { - let callback = self.core.callback_cancel(remoteid); + let callback = self.core.cancel(remoteid); let response = self .client @@ -101,12 +103,12 @@ impl Pay<'_> { /// # Errors /// /// Returns errors on network or deserialization failures. - pub async fn callback( + pub async fn invoice( &self, millisatoshis: u64, comment: Option<&str>, ) -> Result { - let callback = self.core.callback(millisatoshis, comment); + let callback = self.core.invoice(millisatoshis, comment); let response = self .client @@ -124,11 +126,11 @@ impl Withdraw<'_> { /// # Errors /// /// Returns errors on network or deserialization failures. - pub async fn callback( + pub async fn submit( &self, pr: &str, ) -> Result { - let callback = self.core.callback(pr); + let callback = self.core.submit(pr); let response = self .client diff --git a/src/core.rs b/src/core.rs index c621196..63c88a7 100644 --- a/src/core.rs +++ b/src/core.rs @@ -4,7 +4,7 @@ pub mod withdraw; pub enum Resolved { Url(url::Url), - Withdraw(url::Url, withdraw::client::Response), + Withdraw(url::Url, withdraw::client::Entrypoint), } /// # Errors @@ -26,7 +26,7 @@ pub fn resolve(s: &str) -> Result { .find_map(|(k, v)| (k == "tag").then_some(v)); Ok(match tag.as_deref() { - Some(withdraw::TAG) => match url.as_str().parse::() { + Some(withdraw::TAG) => match url.as_str().parse::() { Ok(w) => Resolved::Withdraw(url, w), Err(_) => Resolved::Url(url), }, @@ -86,13 +86,13 @@ fn resolve_address(s: &str) -> Result { } #[derive(Debug)] -pub enum Response { - Channel(channel::client::Response), - Pay(pay::client::Response), - Withdraw(withdraw::client::Response), +pub enum Entrypoint { + Channel(channel::client::Entrypoint), + Pay(pay::client::Entrypoint), + Withdraw(withdraw::client::Entrypoint), } -impl TryFrom<&[u8]> for Response { +impl TryFrom<&[u8]> for Entrypoint { type Error = &'static str; fn try_from(s: &[u8]) -> Result { @@ -105,13 +105,13 @@ impl TryFrom<&[u8]> for Response { if tag.tag == channel::TAG { let cr = s.try_into().map_err(|_| "deserialize data failed")?; - Ok(Response::Channel(cr)) + Ok(Entrypoint::Channel(cr)) } else if tag.tag == pay::TAG { let pr = s.try_into().map_err(|_| "deserialize data failed")?; - Ok(Response::Pay(pr)) + Ok(Entrypoint::Pay(pr)) } else if tag.tag == withdraw::TAG { let wr = s.try_into().map_err(|_| "deserialize data failed")?; - Ok(Response::Withdraw(wr)) + Ok(Entrypoint::Withdraw(wr)) } else { Err("unknown tag") } diff --git a/src/core/channel.rs b/src/core/channel.rs index 46d6dcc..bb045f1 100644 --- a/src/core/channel.rs +++ b/src/core/channel.rs @@ -7,7 +7,7 @@ mod serde { #[derive(Deserialize, Serialize)] #[serde(untagged)] - pub(super) enum CallbackQuery<'a> { + pub(super) enum Callback<'a> { Accept { k1: &'a str, remoteid: &'a str, diff --git a/src/core/channel/client.rs b/src/core/channel/client.rs index f7738b3..6c307f5 100644 --- a/src/core/channel/client.rs +++ b/src/core/channel/client.rs @@ -1,17 +1,17 @@ #[derive(Clone, Debug)] -pub struct Response { +pub struct Entrypoint { pub callback: url::Url, pub uri: String, pub k1: String, } -impl TryFrom<&[u8]> for Response { +impl TryFrom<&[u8]> for Entrypoint { type Error = &'static str; fn try_from(s: &[u8]) -> Result { - let d: de::Response = serde_json::from_slice(s).map_err(|_| "deserialize failed")?; + let d: de::Entrypoint = serde_json::from_slice(s).map_err(|_| "deserialize failed")?; - Ok(Response { + Ok(Entrypoint { callback: d.callback, uri: d.uri, k1: d.k1, @@ -19,10 +19,10 @@ impl TryFrom<&[u8]> for Response { } } -impl Response { +impl Entrypoint { #[must_use] - pub fn callback_accept<'a>(&'a self, remoteid: &'a str, private: bool) -> CallbackQuery<'a> { - CallbackQuery::Accept { + pub fn accept<'a>(&'a self, remoteid: &'a str, private: bool) -> Callback<'a> { + Callback::Accept { url: &self.callback, k1: &self.k1, remoteid, @@ -31,8 +31,8 @@ impl Response { } #[must_use] - pub fn callback_cancel<'a>(&'a self, remoteid: &'a str) -> CallbackQuery<'a> { - CallbackQuery::Cancel { + pub fn cancel<'a>(&'a self, remoteid: &'a str) -> Callback<'a> { + Callback::Cancel { url: &self.callback, k1: &self.k1, remoteid, @@ -41,7 +41,7 @@ impl Response { } #[derive(Clone, Debug)] -pub enum CallbackQuery<'a> { +pub enum Callback<'a> { Accept { url: &'a url::Url, k1: &'a str, @@ -55,17 +55,17 @@ pub enum CallbackQuery<'a> { }, } -impl std::fmt::Display for CallbackQuery<'_> { +impl std::fmt::Display for Callback<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let (url, query) = match self { - CallbackQuery::Accept { + Callback::Accept { url, k1, remoteid, private, } => ( url, - super::serde::CallbackQuery::Accept { + super::serde::Callback::Accept { k1, remoteid, private: if *private { @@ -75,9 +75,9 @@ impl std::fmt::Display for CallbackQuery<'_> { }, }, ), - CallbackQuery::Cancel { url, k1, remoteid } => ( + Callback::Cancel { url, k1, remoteid } => ( url, - super::serde::CallbackQuery::Cancel { + super::serde::Callback::Cancel { k1, remoteid, cancel: super::serde::OneOnly::One, @@ -120,7 +120,7 @@ mod de { use url::Url; #[derive(Deserialize)] - pub(super) struct Response { + pub(super) struct Entrypoint { pub callback: Url, pub uri: String, pub k1: String, @@ -130,14 +130,14 @@ mod de { #[cfg(test)] mod tests { #[test] - fn response_parse() { + fn entrypoint_parse() { let input = r#"{ "callback": "https://yuri?o=callback", "uri": "noh@ipe:porta", "k1": "caum" }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!(parsed.callback.as_str(), "https://yuri/?o=callback"); assert_eq!(parsed.uri, "noh@ipe:porta"); @@ -145,22 +145,22 @@ mod tests { } #[test] - fn callback_query_accept_render() { + fn callback_accept_render() { let input = r#"{ "callback": "https://yuri?o=callback", "uri": "noh@ipe:porta", "k1": "caum" }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); - let url = parsed.callback_accept("idremoto", true); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); + let url = parsed.accept("idremoto", true); assert_eq!( url.to_string(), "https://yuri/?o=callback&k1=caum&remoteid=idremoto&private=1" ); - let url = parsed.callback_accept("idremoto", false); + let url = parsed.accept("idremoto", false); assert_eq!( url.to_string(), @@ -169,15 +169,15 @@ mod tests { } #[test] - fn callback_query_cancel_render() { + fn callback_cancel_render() { let input = r#"{ "callback": "https://yuri?o=callback", "uri": "noh@ipe:porta", "k1": "caum" }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); - let url = parsed.callback_cancel("idremoto"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); + let url = parsed.cancel("idremoto"); assert_eq!( url.to_string(), diff --git a/src/core/channel/server.rs b/src/core/channel/server.rs index aa80bec..75bd045 100644 --- a/src/core/channel/server.rs +++ b/src/core/channel/server.rs @@ -1,15 +1,15 @@ #[derive(Clone, Debug)] -pub struct Response { +pub struct Entrypoint { pub callback: url::Url, pub uri: String, pub k1: String, } -impl TryFrom for Vec { +impl TryFrom for Vec { type Error = &'static str; - fn try_from(r: Response) -> Result { - serde_json::to_vec(&ser::Response { + fn try_from(r: Entrypoint) -> Result { + serde_json::to_vec(&ser::Entrypoint { tag: super::TAG, callback: &r.callback, uri: &r.uri, @@ -20,7 +20,7 @@ impl TryFrom for Vec { } #[derive(Clone, Debug)] -pub enum CallbackQuery { +pub enum Callback { Accept { k1: String, remoteid: String, @@ -32,18 +32,18 @@ pub enum CallbackQuery { }, } -impl<'a> TryFrom<&'a str> for CallbackQuery { +impl<'a> TryFrom<&'a str> for Callback { type Error = &'static str; fn try_from(s: &'a str) -> Result { - serde_urlencoded::from_str::(s) + serde_urlencoded::from_str::(s) .map_err(|_| "deserialize failed") .map(|query| match query { - super::serde::CallbackQuery::Accept { + super::serde::Callback::Accept { k1, remoteid, private, - } => CallbackQuery::Accept { + } => Callback::Accept { k1: String::from(k1), remoteid: String::from(remoteid), private: match private { @@ -51,11 +51,11 @@ impl<'a> TryFrom<&'a str> for CallbackQuery { super::serde::ZeroOrOne::One => true, }, }, - super::serde::CallbackQuery::Cancel { + super::serde::Callback::Cancel { k1, remoteid, cancel: _, - } => CallbackQuery::Cancel { + } => Callback::Cancel { k1: String::from(k1), remoteid: String::from(remoteid), }, @@ -92,7 +92,7 @@ mod ser { use url::Url; #[derive(Serialize)] - pub(super) struct Response<'a> { + pub(super) struct Entrypoint<'a> { pub tag: &'static str, pub callback: &'a Url, pub uri: &'a str, @@ -103,8 +103,8 @@ mod ser { #[cfg(test)] mod tests { #[test] - fn response_render() { - let query = super::Response { + fn entrypoint_render() { + let query = super::Entrypoint { callback: url::Url::parse("https://yuri/?o=callback").expect("url"), uri: String::from("noh@ipe:porta"), k1: String::from("caum"), @@ -115,11 +115,11 @@ mod tests { } #[test] - fn callback_query_accept_parse() { + fn callback_accept_parse() { let input = "remoteid=idremoto&k1=caum&private=1"; - let parsed: super::CallbackQuery = input.try_into().expect("parse"); + let parsed: super::Callback = input.try_into().expect("parse"); - let super::CallbackQuery::Accept { + let super::Callback::Accept { remoteid, private, k1, @@ -133,9 +133,9 @@ mod tests { assert!(private); let input = "remoteid=idremoto&k1=caum&private=0"; - let parsed: super::CallbackQuery = input.try_into().expect("parse"); + let parsed: super::Callback = input.try_into().expect("parse"); - let super::CallbackQuery::Accept { + let super::Callback::Accept { remoteid, private, k1, @@ -149,16 +149,16 @@ mod tests { assert!(!private); let input = "remoteid=idremoto&k1=caum&private=2"; - let parsed: Result = input.try_into(); + let parsed: Result = input.try_into(); assert!(parsed.is_err()); } #[test] - fn callback_query_cancel_parse() { + fn callback_cancel_parse() { let input = "remoteid=idremoto&k1=caum&cancel=1"; - let parsed: super::CallbackQuery = input.try_into().expect("parse"); + let parsed: super::Callback = input.try_into().expect("parse"); - let super::CallbackQuery::Cancel { remoteid, k1 } = parsed else { + let super::Callback::Cancel { remoteid, k1 } = parsed else { panic!("wrong parsed"); }; @@ -166,7 +166,7 @@ mod tests { assert_eq!(k1, "caum"); let input = "remoteid=idremoto&k1=caum&cancel=0"; - let parsed: Result = input.try_into(); + let parsed: Result = input.try_into(); assert!(parsed.is_err()); } diff --git a/src/core/pay/client.rs b/src/core/pay/client.rs index afa50f5..fcb27b9 100644 --- a/src/core/pay/client.rs +++ b/src/core/pay/client.rs @@ -1,5 +1,5 @@ #[derive(Clone, Debug)] -pub struct Response { +pub struct Entrypoint { pub callback: url::Url, pub metadata_raw: String, pub short_description: String, @@ -13,14 +13,14 @@ pub struct Response { pub max: u64, } -impl TryFrom<&[u8]> for Response { +impl TryFrom<&[u8]> for Entrypoint { type Error = &'static str; fn try_from(s: &[u8]) -> Result { use base64::{prelude::BASE64_STANDARD, Engine}; use serde_json::Value; - let p: de::Response = serde_json::from_slice(s).map_err(|_| "deserialize failed")?; + let p: de::Entrypoint = serde_json::from_slice(s).map_err(|_| "deserialize failed")?; let metadata = serde_json::from_str::>(&p.metadata) .map_err(|_| "deserialize metadata failed")?; @@ -74,7 +74,7 @@ impl TryFrom<&[u8]> for Response { _ => None, }); - Ok(Response { + Ok(Entrypoint { metadata_raw: p.metadata, callback: p.callback, comment_size: p.comment_allowed, @@ -90,14 +90,10 @@ impl TryFrom<&[u8]> for Response { } } -impl Response { +impl Entrypoint { #[must_use] - pub fn callback<'a>( - &'a self, - millisatoshis: u64, - comment: Option<&'a str>, - ) -> CallbackQuery<'a> { - CallbackQuery { + pub fn invoice<'a>(&'a self, millisatoshis: u64, comment: Option<&'a str>) -> Callback<'a> { + Callback { url: &self.callback, millisatoshis, comment, @@ -105,13 +101,13 @@ impl Response { } } -pub struct CallbackQuery<'a> { +pub struct Callback<'a> { pub url: &'a url::Url, pub comment: Option<&'a str>, pub millisatoshis: u64, } -impl std::fmt::Display for CallbackQuery<'_> { +impl std::fmt::Display for Callback<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let query = super::serde::CallbackQuery { comment: self.comment, @@ -169,7 +165,7 @@ mod de { use url::Url; #[derive(Deserialize)] - pub(super) struct Response { + pub(super) struct Entrypoint { pub metadata: String, pub callback: Url, #[serde(rename = "minSendable")] @@ -192,7 +188,7 @@ mod de { #[cfg(test)] mod tests { #[test] - fn response_parse_base() { + fn entrypoint_parse_base() { let input = r#"{ "callback": "https://yuri?o=callback", "metadata": "[[\"text/plain\", \"boneco do steve magal\"],[\"text/crazy\", \"👋🇧🇴💾\"]]", @@ -200,7 +196,7 @@ mod tests { "minSendable": 314 }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!(parsed.callback.to_string(), "https://yuri/?o=callback"); assert_eq!(parsed.short_description, "boneco do steve magal"); @@ -220,7 +216,7 @@ mod tests { } #[test] - fn response_parse_comment_size() { + fn entrypoint_parse_comment_size() { let input = r#"{ "callback": "https://yuri?o=callback", "metadata": "[[\"text/plain\", \"boneco do steve magal\"]]", @@ -229,12 +225,12 @@ mod tests { "minSendable": 314 }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!(parsed.comment_size.unwrap(), 140); } #[test] - fn response_parse_long_description() { + fn entrypoint_parse_long_description() { let input = r#"{ "callback": "https://yuri?o=callback", "metadata": "[[\"text/plain\", \"boneco do steve magal\"],[\"text/long-desc\", \"mochila a jato brutal incluida\"]]", @@ -242,7 +238,7 @@ mod tests { "minSendable": 314 }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!( parsed.long_description.unwrap(), "mochila a jato brutal incluida" @@ -250,7 +246,7 @@ mod tests { } #[test] - fn response_parse_images() { + fn entrypoint_parse_images() { let input = r#"{ "callback": "https://yuri?o=callback", "metadata": "[[\"text/plain\", \"boneco do steve magal\"],[\"image/png;base64\", \"Zm90b2JydXRhbA==\"],[\"image/jpeg;base64\", \"aW1hZ2VtYnJ1dGFs\"]]", @@ -258,13 +254,13 @@ mod tests { "minSendable": 314 }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!(parsed.jpeg.unwrap(), b"imagembrutal"); assert_eq!(parsed.png.unwrap(), b"fotobrutal"); } #[test] - fn response_parse_identifier() { + fn entrypoint_parse_identifier() { let input = r#"{ "callback": "https://yuri?o=callback", "metadata": "[[\"text/plain\", \"boneco do steve magal\"],[\"text/identifier\", \"steve@magal.brutal\"]]", @@ -272,12 +268,12 @@ mod tests { "minSendable": 314 }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!(parsed.identifier.unwrap(), "steve@magal.brutal"); } #[test] - fn response_parse_email() { + fn entrypoint_parse_email() { let input = r#"{ "callback": "https://yuri?o=callback", "metadata": "[[\"text/plain\", \"boneco do steve magal\"],[\"text/email\", \"steve@magal.brutal\"]]", @@ -285,12 +281,12 @@ mod tests { "minSendable": 314 }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!(parsed.email.unwrap(), "steve@magal.brutal"); } #[test] - fn callback_query_render_base() { + fn callback_render_base() { let input = r#"{ "metadata": "[[\"text/plain\", \"boneco do steve magal\"]]", "callback": "https://yuri?o=callback", @@ -298,16 +294,16 @@ mod tests { "minSendable": 314 }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!( - parsed.callback(314, None).to_string(), + parsed.invoice(314, None).to_string(), "https://yuri/?o=callback&amount=314" ); } #[test] - fn callback_query_render_comment() { + fn callback_render_comment() { let input = r#"{ "metadata": "[[\"text/plain\", \"boneco do steve magal\"]]", "callback": "https://yuri?o=callback", @@ -315,10 +311,10 @@ mod tests { "minSendable": 314 }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!( - parsed.callback(314, Some("comentario")).to_string(), + parsed.invoice(314, Some("comentario")).to_string(), "https://yuri/?o=callback&comment=comentario&amount=314" ); } diff --git a/src/core/pay/server.rs b/src/core/pay/server.rs index 3d59f9b..927be65 100644 --- a/src/core/pay/server.rs +++ b/src/core/pay/server.rs @@ -1,5 +1,5 @@ #[derive(Clone, Debug)] -pub struct Response { +pub struct Entrypoint { pub callback: url::Url, pub short_description: String, pub long_description: Option, @@ -12,10 +12,10 @@ pub struct Response { pub max: u64, } -impl TryFrom for Vec { +impl TryFrom for Vec { type Error = &'static str; - fn try_from(r: Response) -> Result { + fn try_from(r: Entrypoint) -> Result { use base64::{prelude::BASE64_STANDARD, Engine}; let metadata = serde_json::to_string( @@ -41,7 +41,7 @@ impl TryFrom for Vec { ) .map_err(|_| "serialize failed")?; - serde_json::to_vec(&ser::Response { + serde_json::to_vec(&ser::Entrypoint { tag: super::TAG, metadata, callback: &r.callback, @@ -53,18 +53,18 @@ impl TryFrom for Vec { } } -pub struct CallbackQuery { +pub struct Callback { pub millisatoshis: u64, pub comment: Option, } -impl<'a> TryFrom<&'a str> for CallbackQuery { +impl<'a> TryFrom<&'a str> for Callback { type Error = &'static str; fn try_from(s: &'a str) -> Result { serde_urlencoded::from_str::(s) .map_err(|_| "deserialize failed") - .map(|query| CallbackQuery { + .map(|query| Callback { millisatoshis: query.amount, comment: query.comment.map(String::from), }) @@ -120,7 +120,7 @@ mod ser { use url::Url; #[derive(Serialize)] - pub(super) struct Response<'a> { + pub(super) struct Entrypoint<'a> { pub tag: &'static str, pub metadata: String, pub callback: &'a Url, @@ -144,8 +144,8 @@ mod ser { #[cfg(test)] mod tests { #[test] - fn response_render_base() { - let query = super::Response { + fn entrypoint_render_base() { + let query = super::Entrypoint { callback: url::Url::parse("https://yuri?o=callback").expect("url"), short_description: String::from("boneco do steve magal"), long_description: None, @@ -165,8 +165,8 @@ mod tests { } #[test] - fn response_render_comment_size() { - let query = super::Response { + fn entrypoint_render_comment_size() { + let query = super::Entrypoint { callback: url::Url::parse("https://yuri?o=callback").expect("url"), short_description: String::from("boneco do steve magal"), long_description: None, @@ -186,8 +186,8 @@ mod tests { } #[test] - fn response_render_long_description() { - let query = super::Response { + fn entrypoint_render_long_description() { + let query = super::Entrypoint { callback: url::Url::parse("https://yuri?o=callback").expect("url"), short_description: String::from("boneco do steve magal"), long_description: Some(String::from("mochila a jato brutal incluida")), @@ -207,8 +207,8 @@ mod tests { } #[test] - fn response_render_images() { - let query = super::Response { + fn entrypoint_render_images() { + let query = super::Entrypoint { callback: url::Url::parse("https://yuri?o=callback").expect("url"), short_description: String::from("boneco do steve magal"), long_description: None, @@ -228,8 +228,8 @@ mod tests { } #[test] - fn response_render_identifier() { - let query = super::Response { + fn entrypoint_render_identifier() { + let query = super::Entrypoint { callback: url::Url::parse("https://yuri?o=callback").expect("url"), short_description: String::from("boneco do steve magal"), long_description: None, @@ -249,8 +249,8 @@ mod tests { } #[test] - fn response_render_email() { - let query = super::Response { + fn entrypoint_render_email() { + let query = super::Entrypoint { callback: url::Url::parse("https://yuri?o=callback").expect("url"), short_description: String::from("boneco do steve magal"), long_description: None, @@ -270,18 +270,18 @@ mod tests { } #[test] - fn callback_query_parse_base() { + fn callback_parse_base() { let input = "amount=314"; - let parsed: super::CallbackQuery = input.try_into().expect("parse"); + let parsed: super::Callback = input.try_into().expect("parse"); assert_eq!(parsed.millisatoshis, 314); assert!(parsed.comment.is_none()); } #[test] - fn callback_query_parse_comment() { + fn callback_parse_comment() { let input = "amount=314&comment=comentario"; - let parsed: super::CallbackQuery = input.try_into().expect("parse"); + let parsed: super::Callback = input.try_into().expect("parse"); assert_eq!(parsed.millisatoshis, 314); assert_eq!(parsed.comment.unwrap(), "comentario"); diff --git a/src/core/withdraw/client.rs b/src/core/withdraw/client.rs index a49f773..245f408 100644 --- a/src/core/withdraw/client.rs +++ b/src/core/withdraw/client.rs @@ -1,5 +1,5 @@ #[derive(Clone, Debug)] -pub struct Response { +pub struct Entrypoint { pub k1: String, pub callback: url::Url, pub description: String, @@ -7,13 +7,13 @@ pub struct Response { pub max: u64, } -impl TryFrom<&[u8]> for Response { +impl TryFrom<&[u8]> for Entrypoint { type Error = &'static str; fn try_from(s: &[u8]) -> Result { - let d: de::Response = serde_json::from_slice(s).map_err(|_| "deserialize failed")?; + let d: de::Entrypoint = serde_json::from_slice(s).map_err(|_| "deserialize failed")?; - Ok(Response { + Ok(Entrypoint { k1: d.k1, callback: d.callback, description: d.default_description, @@ -23,13 +23,13 @@ impl TryFrom<&[u8]> for Response { } } -impl std::str::FromStr for Response { +impl std::str::FromStr for Entrypoint { type Err = &'static str; fn from_str(s: &str) -> Result { - let d: de::Response = serde_urlencoded::from_str(s).map_err(|_| "deserialize failed")?; + let d: de::Entrypoint = serde_urlencoded::from_str(s).map_err(|_| "deserialize failed")?; - Ok(Response { + Ok(Entrypoint { k1: d.k1, callback: d.callback, description: d.default_description, @@ -39,10 +39,10 @@ impl std::str::FromStr for Response { } } -impl Response { +impl Entrypoint { #[must_use] - pub fn callback<'a>(&'a self, pr: &'a str) -> CallbackQuery { - CallbackQuery { + pub fn submit<'a>(&'a self, pr: &'a str) -> Callback { + Callback { url: &self.callback, k1: &self.k1, pr, @@ -51,13 +51,13 @@ impl Response { } #[derive(Clone, Debug)] -pub struct CallbackQuery<'a> { +pub struct Callback<'a> { pub url: &'a url::Url, pub k1: &'a str, pub pr: &'a str, } -impl std::fmt::Display for CallbackQuery<'_> { +impl std::fmt::Display for Callback<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let query = super::serde::CallbackQuery { k1: self.k1, @@ -99,7 +99,7 @@ mod de { use url::Url; #[derive(Deserialize)] - pub(super) struct Response { + pub(super) struct Entrypoint { pub k1: String, pub callback: Url, #[serde(rename = "defaultDescription")] @@ -114,7 +114,7 @@ mod de { #[cfg(test)] mod tests { #[test] - fn response_bytes_parse() { + fn entrypoint_bytes_parse() { let input = r#"{ "callback": "https://yuri?o=callback", "defaultDescription": "verde com bolinhas", @@ -123,7 +123,7 @@ mod tests { "k1": "caum" }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!(parsed.callback.to_string(), "https://yuri/?o=callback"); assert_eq!(parsed.description, "verde com bolinhas"); @@ -133,7 +133,7 @@ mod tests { } #[test] - fn response_string_parse() { + fn entrypoint_string_parse() { let input = "lnurlw://there.is/no\ ?s=poon\ &tag=withdrawRequest\ @@ -143,7 +143,7 @@ mod tests { &defaultDescription=descricao\ &callback=https://call.back"; - let parsed: super::Response = input.parse().expect("parse"); + let parsed: super::Entrypoint = input.parse().expect("parse"); assert_eq!(parsed.callback.to_string(), "https://call.back/"); assert_eq!(parsed.description, "descricao"); @@ -153,7 +153,7 @@ mod tests { } #[test] - fn callback_query_render() { + fn callback_render() { let input = r#"{ "callback": "https://yuri?o=callback", "defaultDescription": "verde com bolinhas", @@ -162,10 +162,10 @@ mod tests { "k1": "caum" }"#; - let parsed: super::Response = input.as_bytes().try_into().expect("parse"); + let parsed: super::Entrypoint = input.as_bytes().try_into().expect("parse"); assert_eq!( - parsed.callback("pierre").to_string(), + parsed.submit("pierre").to_string(), "https://yuri/?o=callback&k1=caum&pr=pierre" ); } diff --git a/src/core/withdraw/server.rs b/src/core/withdraw/server.rs index 5ab0024..80d7742 100644 --- a/src/core/withdraw/server.rs +++ b/src/core/withdraw/server.rs @@ -1,5 +1,5 @@ #[derive(Clone, Debug)] -pub struct Response { +pub struct Entrypoint { pub k1: String, pub callback: url::Url, pub description: String, @@ -7,11 +7,11 @@ pub struct Response { pub max: u64, } -impl TryFrom for Vec { +impl TryFrom for Vec { type Error = &'static str; - fn try_from(r: Response) -> Result { - serde_json::to_vec(&ser::Response { + fn try_from(r: Entrypoint) -> Result { + serde_json::to_vec(&ser::Entrypoint { tag: super::TAG, callback: &r.callback, default_description: &r.description, @@ -23,9 +23,9 @@ impl TryFrom for Vec { } } -impl std::fmt::Display for Response { +impl std::fmt::Display for Entrypoint { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let s = serde_urlencoded::to_string(ser::Response { + let s = serde_urlencoded::to_string(ser::Entrypoint { tag: super::TAG, callback: &self.callback, default_description: &self.description, @@ -38,18 +38,18 @@ impl std::fmt::Display for Response { } } -pub struct CallbackQuery { +pub struct Callback { pub k1: String, pub pr: String, } -impl<'a> TryFrom<&'a str> for CallbackQuery { +impl<'a> TryFrom<&'a str> for Callback { type Error = &'static str; fn try_from(s: &'a str) -> Result { serde_urlencoded::from_str::(s) .map_err(|_| "deserialize failed") - .map(|query| CallbackQuery { + .map(|query| Callback { k1: String::from(query.k1), pr: String::from(query.pr), }) @@ -86,7 +86,7 @@ mod ser { use url::Url; #[derive(Serialize)] - pub(super) struct Response<'a> { + pub(super) struct Entrypoint<'a> { pub tag: &'static str, pub k1: &'a str, pub callback: &'a Url, @@ -102,8 +102,8 @@ mod ser { #[cfg(test)] mod tests { #[test] - fn response_render() { - let query = super::Response { + fn entrypoint_render() { + let query = super::Entrypoint { callback: url::Url::parse("https://yuri?o=callback").expect("url"), description: String::from("verde com bolinhas"), k1: String::from("caum"), @@ -118,9 +118,9 @@ mod tests { } #[test] - fn callback_query_parse() { + fn callback_parse() { let input = "k1=caum&pr=pierre"; - let parsed: super::CallbackQuery = input.try_into().expect("parse"); + let parsed: super::Callback = input.try_into().expect("parse"); assert_eq!(parsed.pr, "pierre"); assert_eq!(parsed.k1, "caum"); diff --git a/src/lib.rs b/src/lib.rs index 5f45892..de1e4df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(all(doc, docsrs), feature(doc_auto_cfg))] mod core; -pub use core::{channel, pay, resolve, withdraw, Resolved, Response}; +pub use core::{channel, pay, resolve, withdraw, Entrypoint, Resolved}; #[cfg(feature = "client")] pub mod client; diff --git a/src/server.rs b/src/server.rs index 6dca165..539ae22 100644 --- a/src/server.rs +++ b/src/server.rs @@ -18,21 +18,18 @@ pub struct Server { impl Default for Server< // Channel Request - unimplemented::Handler<(), crate::channel::server::Response>, + unimplemented::Handler<(), crate::channel::server::Entrypoint>, unimplemented::Handler< - crate::channel::server::CallbackQuery, + crate::channel::server::Callback, crate::channel::server::CallbackResponse, >, // Pay Request - unimplemented::Handler, crate::pay::server::Response>, - unimplemented::Handler< - crate::pay::server::CallbackQuery, - crate::pay::server::CallbackResponse, - >, + unimplemented::Handler, crate::pay::server::Entrypoint>, + unimplemented::Handler, // Withdraw Request - unimplemented::Handler<(), crate::withdraw::server::Response>, + unimplemented::Handler<(), crate::withdraw::server::Entrypoint>, unimplemented::Handler< - crate::withdraw::server::CallbackQuery, + crate::withdraw::server::Callback, crate::withdraw::server::CallbackResponse, >, > @@ -102,21 +99,21 @@ impl Server where CQ: 'static + Send + Clone + Fn(()) -> CQFut, - CQFut: Send + Future>, + CQFut: Send + Future>, - CC: 'static + Send + Clone + Fn(crate::channel::server::CallbackQuery) -> CCFut, + CC: 'static + Send + Clone + Fn(crate::channel::server::Callback) -> CCFut, CCFut: Send + Future>, PQ: 'static + Send + Clone + Fn(Option) -> PQFut, - PQFut: Send + Future>, + PQFut: Send + Future>, - PC: 'static + Send + Clone + Fn(crate::pay::server::CallbackQuery) -> PCFut, + PC: 'static + Send + Clone + Fn(crate::pay::server::Callback) -> PCFut, PCFut: Send + Future>, WQ: 'static + Send + Clone + Fn(()) -> WQFut, - WQFut: Send + Future>, + WQFut: Send + Future>, - WC: 'static + Send + Clone + Fn(crate::withdraw::server::CallbackQuery) -> WCFut, + WC: 'static + Send + Clone + Fn(crate::withdraw::server::Callback) -> WCFut, WCFut: Send + Future>, { #[allow(clippy::too_many_lines)] diff --git a/tests/lud02.rs b/tests/lud02.rs index 4b3d7f0..9ad33f9 100644 --- a/tests/lud02.rs +++ b/tests/lud02.rs @@ -14,16 +14,16 @@ async fn test() { move |()| { let callback = callback_url.clone(); async { - Ok(lnurlkit::channel::server::Response { + Ok(lnurlkit::channel::server::Entrypoint { uri: String::from("u@r:i"), k1: String::from("caum"), callback, }) } }, - |req: lnurlkit::channel::server::CallbackQuery| async move { + |req: lnurlkit::channel::server::Callback| async move { Ok(match req { - lnurlkit::channel::server::CallbackQuery::Cancel { remoteid, k1 } => { + lnurlkit::channel::server::Callback::Cancel { remoteid, k1 } => { if &remoteid as &str == "idremoto" { lnurlkit::channel::server::CallbackResponse::Ok } else { @@ -31,7 +31,7 @@ async fn test() { lnurlkit::channel::server::CallbackResponse::Error { reason } } } - lnurlkit::channel::server::CallbackQuery::Accept { + lnurlkit::channel::server::Callback::Accept { remoteid, private, k1, @@ -57,41 +57,35 @@ async fn test() { ) .expect("lnurl"); - let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Response::Channel(cr) = queried else { + let queried = client.entrypoint(&lnurl).await.expect("query"); + let lnurlkit::client::Entrypoint::Channel(cr) = queried else { panic!("not pay request"); }; assert_eq!(&cr.core.uri as &str, "u@r:i"); - let response = cr.callback_cancel("idremoto").await.expect("callback"); + let response = cr.cancel("idremoto").await.expect("callback"); assert!(matches!( response, lnurlkit::channel::client::CallbackResponse::Ok )); - let response = cr.callback_cancel("iderrado").await.expect("callback"); + let response = cr.cancel("iderrado").await.expect("callback"); assert!(matches!( response, lnurlkit::channel::client::CallbackResponse::Error { reason } if &reason as &str == "Cancel/caum/iderrado" )); - let response = cr - .callback_accept("iderrado", true) - .await - .expect("callback"); + let response = cr.accept("iderrado", true).await.expect("callback"); assert!(matches!( response, lnurlkit::channel::client::CallbackResponse::Error { reason } if &reason as &str == "Accept/caum/iderrado/true" )); - let response = cr - .callback_accept("iderrado", false) - .await - .expect("callback"); + let response = cr.accept("iderrado", false).await.expect("callback"); assert!(matches!( response, diff --git a/tests/lud03.rs b/tests/lud03.rs index f90545b..f679cd4 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::withdraw::server::Response { + Ok(lnurlkit::withdraw::server::Entrypoint { description: String::from("descricao"), k1: String::from("caum"), callback, @@ -23,7 +23,7 @@ async fn test() { }) } }, - |req: lnurlkit::withdraw::server::CallbackQuery| async move { + |req: lnurlkit::withdraw::server::Callback| async move { Ok(if &req.pr as &str == "pierre" { lnurlkit::withdraw::server::CallbackResponse::Ok } else { @@ -48,8 +48,8 @@ async fn test() { ) .expect("lnurl"); - let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Response::Withdraw(wr) = queried else { + let queried = client.entrypoint(&lnurl).await.expect("query"); + let lnurlkit::client::Entrypoint::Withdraw(wr) = queried else { panic!("not pay request"); }; @@ -57,14 +57,14 @@ async fn test() { assert_eq!(wr.core.max, 315); assert_eq!(&wr.core.description as &str, "descricao"); - let response = wr.callback("pierre").await.expect("callback"); + let response = wr.submit("pierre").await.expect("callback"); assert!(matches!( response, lnurlkit::withdraw::client::CallbackResponse::Ok )); - let response = wr.callback("pierrado").await.expect("callback"); + let response = wr.submit("pierrado").await.expect("callback"); assert!(matches!( response, diff --git a/tests/lud06.rs b/tests/lud06.rs index e36ca95..d174446 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::pay::server::Response { + Ok(lnurlkit::pay::server::Entrypoint { callback, short_description: String::from("today i become death"), long_description: Some(String::from("the destroyer of worlds")), @@ -28,7 +28,7 @@ async fn test() { }) } }, - |req: lnurlkit::pay::server::CallbackQuery| async move { + |req: lnurlkit::pay::server::Callback| async move { Ok(lnurlkit::pay::server::CallbackResponse { pr: format!("pierre:{}", req.millisatoshis), disposable: false, @@ -51,8 +51,8 @@ async fn test() { ) .expect("lnurl"); - let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Response::Pay(pr) = queried else { + let queried = client.entrypoint(&lnurl).await.expect("query"); + let lnurlkit::client::Entrypoint::Pay(pr) = queried else { panic!("not pay request"); }; @@ -64,7 +64,7 @@ async fn test() { "the destroyer of worlds" ); - let invoice = pr.callback(314, Some("comment")).await.expect("callback"); + let invoice = pr.invoice(314, Some("comment")).await.expect("callback"); assert_eq!(&invoice.pr as &str, "pierre:314"); } diff --git a/tests/lud08.rs b/tests/lud08.rs index 1b27426..5e6b323 100644 --- a/tests/lud08.rs +++ b/tests/lud08.rs @@ -9,7 +9,7 @@ async fn test() { let callback = url::Url::parse(&format!("http://{addr}/lnurlw/callback")).expect("url"); let callback2 = url::Url::parse(&format!("http://{addr}/lnurlw/callback")).expect("url"); - let w = lnurlkit::withdraw::server::Response { + let w = lnurlkit::withdraw::server::Entrypoint { description: String::from("descricao"), k1: String::from("caum"), callback: callback.clone(), @@ -25,7 +25,7 @@ async fn test() { move |()| { let callback = callback.clone(); async move { - Ok(lnurlkit::withdraw::server::Response { + Ok(lnurlkit::withdraw::server::Entrypoint { description: String::from("outra-descricao"), k1: String::from("cadois"), callback, @@ -34,7 +34,7 @@ async fn test() { }) } }, - |_: lnurlkit::withdraw::server::CallbackQuery| async { unimplemented!() }, + |_: lnurlkit::withdraw::server::Callback| async { unimplemented!() }, ) .build(); @@ -51,8 +51,8 @@ async fn test() { ) .expect("lnurl"); - let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Response::Withdraw(wr) = queried else { + let queried = client.entrypoint(&lnurl).await.expect("query"); + let lnurlkit::client::Entrypoint::Withdraw(wr) = queried else { panic!("not pay request"); }; @@ -68,8 +68,8 @@ async fn test() { ) .expect("lnurl"); - let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Response::Withdraw(wr) = queried else { + let queried = client.entrypoint(&lnurl).await.expect("query"); + let lnurlkit::client::Entrypoint::Withdraw(wr) = queried else { panic!("not pay request"); }; diff --git a/tests/lud09.rs b/tests/lud09.rs index e4e6a46..0b5aaad 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::pay::server::Response { + Ok(lnurlkit::pay::server::Entrypoint { callback, short_description: String::new(), long_description: None, @@ -28,7 +28,7 @@ async fn test() { }) } }, - |req: lnurlkit::pay::server::CallbackQuery| async move { + |req: lnurlkit::pay::server::Callback| async move { Ok(lnurlkit::pay::server::CallbackResponse { pr: String::new(), disposable: false, @@ -62,16 +62,16 @@ async fn test() { ) .expect("lnurl"); - let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Response::Pay(pr) = queried else { + let queried = client.entrypoint(&lnurl).await.expect("query"); + let lnurlkit::client::Entrypoint::Pay(pr) = queried else { panic!("not pay request"); }; - let invoice = pr.callback(0, None).await.expect("callback"); + let invoice = pr.invoice(0, None).await.expect("callback"); assert!(invoice.success_action.is_none()); - let invoice = pr.callback(1, Some("mensagem")).await.expect("callback"); + let invoice = pr.invoice(1, Some("mensagem")).await.expect("callback"); let Some(lnurlkit::pay::client::SuccessAction::Message(m)) = invoice.success_action else { panic!("bad success action"); @@ -79,7 +79,7 @@ async fn test() { assert_eq!(&m as &str, "mensagem"); - let invoice = pr.callback(2, Some("descricao")).await.expect("callback"); + let invoice = pr.invoice(2, Some("descricao")).await.expect("callback"); let Some(lnurlkit::pay::client::SuccessAction::Url(u, d)) = invoice.success_action else { panic!("bad success action"); diff --git a/tests/lud11.rs b/tests/lud11.rs index 32c3531..95997c2 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::pay::server::Response { + Ok(lnurlkit::pay::server::Entrypoint { callback, short_description: String::new(), long_description: None, @@ -28,7 +28,7 @@ async fn test() { }) } }, - |req: lnurlkit::pay::server::CallbackQuery| async move { + |req: lnurlkit::pay::server::Callback| async move { Ok(lnurlkit::pay::server::CallbackResponse { pr: String::new(), disposable: req.millisatoshis % 2 == 0, @@ -51,15 +51,15 @@ async fn test() { ) .expect("lnurl"); - let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Response::Pay(pr) = queried else { + let queried = client.entrypoint(&lnurl).await.expect("query"); + let lnurlkit::client::Entrypoint::Pay(pr) = queried else { panic!("not pay request"); }; - let invoice = pr.callback(314, None).await.expect("callback"); + let invoice = pr.invoice(314, None).await.expect("callback"); assert!(invoice.disposable); - let invoice = pr.callback(315, None).await.expect("callback"); + let invoice = pr.invoice(315, None).await.expect("callback"); assert!(!invoice.disposable); } diff --git a/tests/lud12.rs b/tests/lud12.rs index 68572c1..c4950fd 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::pay::server::Response { + Ok(lnurlkit::pay::server::Entrypoint { callback, short_description: String::new(), long_description: None, @@ -28,7 +28,7 @@ async fn test() { }) } }, - |req: lnurlkit::pay::server::CallbackQuery| async move { + |req: lnurlkit::pay::server::Callback| async move { Ok(lnurlkit::pay::server::CallbackResponse { pr: format!("pierre:{:?}", req.comment), disposable: false, @@ -51,21 +51,18 @@ async fn test() { ) .expect("lnurl"); - let queried = client.query(&lnurl).await.expect("query"); - let lnurlkit::client::Response::Pay(pr) = queried else { + let queried = client.entrypoint(&lnurl).await.expect("query"); + let lnurlkit::client::Entrypoint::Pay(pr) = queried else { panic!("not pay request"); }; assert_eq!(pr.core.comment_size.unwrap(), 140); - let invoice = pr.callback(314, None).await.expect("callback"); + let invoice = pr.invoice(314, None).await.expect("callback"); assert_eq!(&invoice.pr as &str, "pierre:None"); - let invoice = pr - .callback(314, Some("comentario")) - .await - .expect("callback"); + let invoice = pr.invoice(314, Some("comentario")).await.expect("callback"); assert_eq!(&invoice.pr as &str, "pierre:Some(\"comentario\")"); } diff --git a/tests/lud16.rs b/tests/lud16.rs index f7a952c..585d549 100644 --- a/tests/lud16.rs +++ b/tests/lud16.rs @@ -13,7 +13,7 @@ async fn test() { move |identifier: Option| { let callback = callback_url.clone(); async { - Ok(lnurlkit::pay::server::Response { + Ok(lnurlkit::pay::server::Entrypoint { 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() { }) } }, - |req: lnurlkit::pay::server::CallbackQuery| async move { + |req: lnurlkit::pay::server::Callback| async move { Ok(lnurlkit::pay::server::CallbackResponse { pr: format!("pierre:{}", req.millisatoshis), disposable: false, @@ -56,8 +56,8 @@ async fn test() { ) .expect("bech32"); - let queried = client.query(&bech32).await.expect("query"); - let lnurlkit::client::Response::Pay(pr) = queried else { + let queried = client.entrypoint(&bech32).await.expect("query"); + let lnurlkit::client::Entrypoint::Pay(pr) = queried else { panic!("not pay request"); }; @@ -77,8 +77,8 @@ async fn test() { ) .expect("bech32"); - let queried = client.query(&bech32).await.expect("query"); - let lnurlkit::client::Response::Pay(pr) = queried else { + let queried = client.entrypoint(&bech32).await.expect("query"); + let lnurlkit::client::Entrypoint::Pay(pr) = queried else { panic!("not pay request"); }; diff --git a/tests/real.rs b/tests/real.rs index db435fd..795db58 100644 --- a/tests/real.rs +++ b/tests/real.rs @@ -1,7 +1,7 @@ mod pay_request { #[test] fn alby() { - let Ok(lnurlkit::Response::Pay(pr)) = + let Ok(lnurlkit::Entrypoint::Pay(pr)) = (include_bytes!("../fixtures/alby-pay.json") as &[u8]).try_into() else { panic!("parse"); @@ -24,7 +24,7 @@ mod pay_request { #[test] fn blink() { - let Ok(lnurlkit::Response::Pay(pr)) = + let Ok(lnurlkit::Entrypoint::Pay(pr)) = (include_bytes!("../fixtures/blink-pay.json") as &[u8]).try_into() else { panic!("parse"); @@ -47,7 +47,7 @@ mod pay_request { #[test] fn bipa() { - let Ok(lnurlkit::Response::Pay(pr)) = + let Ok(lnurlkit::Entrypoint::Pay(pr)) = (include_bytes!("../fixtures/bipa-pay.json") as &[u8]).try_into() else { panic!("parse"); @@ -70,7 +70,7 @@ mod pay_request { #[test] fn pouch() { - let Ok(lnurlkit::Response::Pay(pr)) = + let Ok(lnurlkit::Entrypoint::Pay(pr)) = (include_bytes!("../fixtures/pouch-pay.json") as &[u8]).try_into() else { panic!("parse"); @@ -93,7 +93,7 @@ mod pay_request { #[test] fn walletofsatoshi() { - let Ok(lnurlkit::Response::Pay(pr)) = + let Ok(lnurlkit::Entrypoint::Pay(pr)) = (include_bytes!("../fixtures/walletofsatoshi-pay.json") as &[u8]).try_into() else { panic!("parse"); @@ -119,7 +119,7 @@ mod pay_request { #[test] fn zebedee() { - let Ok(lnurlkit::Response::Pay(pr)) = + let Ok(lnurlkit::Entrypoint::Pay(pr)) = (include_bytes!("../fixtures/zebedee-pay.json") as &[u8]).try_into() else { panic!("parse");