From 588d7eb281833618eab5f4b9995312755553612b Mon Sep 17 00:00:00 2001 From: Lucas Sunsi Abreu Date: Tue, 5 Dec 2023 07:06:23 -0300 Subject: [PATCH] refactor: add re-exports top level for ease of use --- src/lib.rs | 10 +++++++++- tests/lud02.rs | 21 +++++++++------------ tests/lud03.rs | 17 +++++++---------- tests/lud06.rs | 8 ++++---- tests/lud09.rs | 16 ++++++++-------- tests/lud11.rs | 8 ++++---- tests/lud12.rs | 8 ++++---- 7 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 37c661c..ff0ebf0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ #![cfg_attr(all(doc, docsrs), feature(doc_auto_cfg))] -pub mod core; +mod core; mod serde; #[cfg(feature = "server")] @@ -8,3 +8,11 @@ pub mod server; #[cfg(feature = "client")] pub mod client; + +pub use core::{channel, pay, resolve, withdraw, Query}; + +#[cfg(feature = "server")] +pub use server::Server; + +#[cfg(feature = "client")] +pub use client::Client; diff --git a/tests/lud02.rs b/tests/lud02.rs index 85fe116..ed542a9 100644 --- a/tests/lud02.rs +++ b/tests/lud02.rs @@ -9,12 +9,12 @@ async fn test() { let query_url = format!("http://{addr}/lnurlc"); let callback_url = url::Url::parse(&format!("http://{addr}/lnurlc/callback")).expect("url"); - let router = lnurlkit::server::Server::default() + let router = lnurlkit::Server::default() .channel_request( move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::channel::Query { + Ok(lnurlkit::channel::Query { uri: String::from("u@r:i"), k1: String::from("caum"), callback, @@ -23,9 +23,9 @@ async fn test() { }, |(k1, remoteid, action)| async move { Ok(if remoteid == "idremoto" { - lnurlkit::core::channel::CallbackResponse::Ok + lnurlkit::channel::CallbackResponse::Ok } else { - lnurlkit::core::channel::CallbackResponse::Error(format!("{k1}/{action:?}")) + lnurlkit::channel::CallbackResponse::Error(format!("{k1}/{action:?}")) }) }, ) @@ -35,7 +35,7 @@ async fn test() { axum::serve(listener, router).await.expect("serve"); }); - let client = lnurlkit::client::Client::default(); + let client = lnurlkit::Client::default(); let lnurl = bech32::encode( "lnurl", @@ -57,10 +57,7 @@ async fn test() { .await .expect("callback"); - assert!(matches!( - response, - lnurlkit::core::channel::CallbackResponse::Ok - )); + assert!(matches!(response, lnurlkit::channel::CallbackResponse::Ok)); let response = cr .clone() @@ -70,7 +67,7 @@ async fn test() { assert!(matches!( response, - lnurlkit::core::channel::CallbackResponse::Error(r) if r == "caum/Cancel" + lnurlkit::channel::CallbackResponse::Error(r) if r == "caum/Cancel" )); let response = cr @@ -81,7 +78,7 @@ async fn test() { assert!(matches!( response, - lnurlkit::core::channel::CallbackResponse::Error(r) if r == "caum/Accept { private: true }" + lnurlkit::channel::CallbackResponse::Error(r) if r == "caum/Accept { private: true }" )); let response = cr @@ -91,6 +88,6 @@ async fn test() { assert!(matches!( response, - lnurlkit::core::channel::CallbackResponse::Error(r) if r == "caum/Accept { private: false }" + lnurlkit::channel::CallbackResponse::Error(r) if r == "caum/Accept { private: false }" )); } diff --git a/tests/lud03.rs b/tests/lud03.rs index 703d2df..63a0381 100644 --- a/tests/lud03.rs +++ b/tests/lud03.rs @@ -9,12 +9,12 @@ async fn test() { let query_url = format!("http://{addr}/lnurlw"); let callback_url = url::Url::parse(&format!("http://{addr}/lnurlw/callback")).expect("url"); - let router = lnurlkit::server::Server::default() + let router = lnurlkit::Server::default() .withdraw_request( move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::withdraw::Query { + Ok(lnurlkit::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::CallbackResponse::Ok + lnurlkit::withdraw::CallbackResponse::Ok } else { - lnurlkit::core::withdraw::CallbackResponse::Error(k1) + lnurlkit::withdraw::CallbackResponse::Error(k1) }) }, ) @@ -37,7 +37,7 @@ async fn test() { axum::serve(listener, router).await.expect("serve"); }); - let client = lnurlkit::client::Client::default(); + let client = lnurlkit::Client::default(); let lnurl = bech32::encode( "lnurl", @@ -56,14 +56,11 @@ async fn test() { assert_eq!(wr.core.description, "descricao"); let response = wr.clone().callback("pierre").await.expect("callback"); - assert!(matches!( - response, - lnurlkit::core::withdraw::CallbackResponse::Ok - )); + assert!(matches!(response, lnurlkit::withdraw::CallbackResponse::Ok)); let response = wr.callback("pierrado").await.expect("callback"); assert!(matches!( response, - lnurlkit::core::withdraw::CallbackResponse::Error(r) if r == "caum" + lnurlkit::withdraw::CallbackResponse::Error(r) if r == "caum" )); } diff --git a/tests/lud06.rs b/tests/lud06.rs index ccb21a4..565093f 100644 --- a/tests/lud06.rs +++ b/tests/lud06.rs @@ -9,12 +9,12 @@ async fn test() { let query_url = format!("http://{addr}/lnurlp"); let callback_url = url::Url::parse(&format!("http://{addr}/lnurlp/callback")).expect("url"); - let router = lnurlkit::server::Server::default() + let router = lnurlkit::Server::default() .pay_request( move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::pay::Query { + Ok(lnurlkit::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::CallbackResponse { + Ok(lnurlkit::pay::CallbackResponse { pr: format!("pierre:{amount}"), disposable: false, success_action: None, @@ -40,7 +40,7 @@ async fn test() { axum::serve(listener, router).await.expect("serve"); }); - let client = lnurlkit::client::Client::default(); + let client = lnurlkit::Client::default(); let lnurl = bech32::encode( "lnurl", diff --git a/tests/lud09.rs b/tests/lud09.rs index b1f748f..9c3ca5c 100644 --- a/tests/lud09.rs +++ b/tests/lud09.rs @@ -9,12 +9,12 @@ async fn test() { let query_url = format!("http://{addr}/lnurlp"); let callback_url = url::Url::parse(&format!("http://{addr}/lnurlp/callback")).expect("url"); - let router = lnurlkit::server::Server::default() + let router = lnurlkit::Server::default() .pay_request( move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::pay::Query { + Ok(lnurlkit::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::CallbackResponse { + Ok(lnurlkit::pay::CallbackResponse { pr: String::new(), disposable: false, success_action: if amount == 0 { None } else if amount == 1 { - Some(lnurlkit::core::pay::SuccessAction::Message( + Some(lnurlkit::pay::SuccessAction::Message( comment.unwrap_or_default(), )) } else { - Some(lnurlkit::core::pay::SuccessAction::Url( + Some(lnurlkit::pay::SuccessAction::Url( url::Url::parse("http://u.rl").expect("url"), comment.unwrap_or_default(), )) @@ -51,7 +51,7 @@ async fn test() { axum::serve(listener, router).await.expect("serve"); }); - let client = lnurlkit::client::Client::default(); + let client = lnurlkit::Client::default(); let lnurl = bech32::encode( "lnurl", @@ -70,7 +70,7 @@ async fn test() { let invoice = pr.clone().callback("mensagem", 1).await.expect("callback"); - let Some(lnurlkit::core::pay::SuccessAction::Message(m)) = invoice.success_action else { + let Some(lnurlkit::pay::SuccessAction::Message(m)) = invoice.success_action else { panic!("bad success action"); }; @@ -78,7 +78,7 @@ async fn test() { let invoice = pr.callback("descricao", 2).await.expect("callback"); - let Some(lnurlkit::core::pay::SuccessAction::Url(u, d)) = invoice.success_action else { + let Some(lnurlkit::pay::SuccessAction::Url(u, d)) = invoice.success_action else { panic!("bad success action"); }; diff --git a/tests/lud11.rs b/tests/lud11.rs index 24d151d..2d328ba 100644 --- a/tests/lud11.rs +++ b/tests/lud11.rs @@ -9,12 +9,12 @@ async fn test() { let query_url = format!("http://{addr}/lnurlp"); let callback_url = url::Url::parse(&format!("http://{addr}/lnurlp/callback")).expect("url"); - let router = lnurlkit::server::Server::default() + let router = lnurlkit::Server::default() .pay_request( move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::pay::Query { + Ok(lnurlkit::pay::Query { callback, short_description: String::new(), long_description: None, @@ -27,7 +27,7 @@ async fn test() { } }, |(amount, _)| async move { - Ok(lnurlkit::core::pay::CallbackResponse { + Ok(lnurlkit::pay::CallbackResponse { pr: String::new(), disposable: amount % 2 == 0, success_action: None, @@ -40,7 +40,7 @@ async fn test() { axum::serve(listener, router).await.expect("serve"); }); - let client = lnurlkit::client::Client::default(); + let client = lnurlkit::Client::default(); let lnurl = bech32::encode( "lnurl", diff --git a/tests/lud12.rs b/tests/lud12.rs index becf6f6..4a916c4 100644 --- a/tests/lud12.rs +++ b/tests/lud12.rs @@ -9,12 +9,12 @@ async fn test() { let query_url = format!("http://{addr}/lnurlp"); let callback_url = url::Url::parse(&format!("http://{addr}/lnurlp/callback")).expect("url"); - let router = lnurlkit::server::Server::default() + let router = lnurlkit::Server::default() .pay_request( move || { let callback = callback_url.clone(); async { - Ok(lnurlkit::core::pay::Query { + Ok(lnurlkit::pay::Query { callback, short_description: String::new(), long_description: None, @@ -27,7 +27,7 @@ async fn test() { } }, |(_, comment)| async move { - Ok(lnurlkit::core::pay::CallbackResponse { + Ok(lnurlkit::pay::CallbackResponse { pr: format!("pierre:{comment:?}"), disposable: false, success_action: None, @@ -40,7 +40,7 @@ async fn test() { axum::serve(listener, router).await.expect("serve"); }); - let client = lnurlkit::client::Client::default(); + let client = lnurlkit::Client::default(); let lnurl = bech32::encode( "lnurl",