Skip to content

Commit

Permalink
refactor: add re-exports top level for ease of use
Browse files Browse the repository at this point in the history
  • Loading branch information
lsunsi committed Dec 5, 2023
1 parent 8210ec4 commit 588d7eb
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 43 deletions.
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#![cfg_attr(all(doc, docsrs), feature(doc_auto_cfg))]

pub mod core;
mod core;
mod serde;

#[cfg(feature = "server")]
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;
21 changes: 9 additions & 12 deletions tests/lud02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:?}"))
})
},
)
Expand All @@ -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",
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }"
));
}
17 changes: 7 additions & 10 deletions tests/lud03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
})
},
)
Expand All @@ -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",
Expand All @@ -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"
));
}
8 changes: 4 additions & 4 deletions tests/lud06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand All @@ -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,
Expand All @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions tests/lud09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,17 +27,17 @@ async fn test() {
}
},
|(amount, comment): (u64, Option<String>)| 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(),
))
Expand All @@ -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",
Expand All @@ -70,15 +70,15 @@ 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");
};

assert_eq!(m, "mensagem");

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");
};

Expand Down
8 changes: 4 additions & 4 deletions tests/lud11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions tests/lud12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand Down

0 comments on commit 588d7eb

Please sign in to comment.