-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
563 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
let client = lnurlkit::Lnurl::default(); | ||
let client = lnurlkit::client::Client::default(); | ||
|
||
let pr = client.address("kenu@bipa.app").await.expect("address"); | ||
let queried = client.query("kenu@bipa.app").await.expect("address"); | ||
|
||
println!("{pr:?}"); | ||
println!("{queried:?}"); | ||
|
||
let invoice = pr | ||
.generate_invoice("comment", 123000) | ||
.await | ||
.expect("callback"); | ||
let lnurlkit::client::Query::PayRequest(pr) = queried else { | ||
panic!("not pay request"); | ||
}; | ||
|
||
let invoice = pr.callback("comment", 123000).await.expect("callback"); | ||
|
||
println!("{invoice:?}"); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#[derive(Clone, Default)] | ||
pub struct Client(reqwest::Client); | ||
|
||
impl Client { | ||
/// # Errors | ||
/// | ||
/// Returns errors on network or deserialization failures. | ||
pub async fn query(&self, s: &str) -> Result<Query, &'static str> { | ||
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::<crate::core::Query>() | ||
.map_err(|_| "parse failed") | ||
.map(|query| match query { | ||
crate::core::Query::PayRequest(core) => { | ||
Query::PayRequest(PayRequest { client, core }) | ||
} | ||
crate::core::Query::ChannelRequest(core) => { | ||
Query::ChannelRequest(ChannelRequest { client, core }) | ||
} | ||
crate::core::Query::WithdrawalRequest(core) => { | ||
Query::WithdrawalRequest(WithdrawalRequest { client, core }) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Query<'a> { | ||
PayRequest(PayRequest<'a>), | ||
ChannelRequest(ChannelRequest<'a>), | ||
WithdrawalRequest(WithdrawalRequest<'a>), | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct PayRequest<'a> { | ||
client: &'a reqwest::Client, | ||
core: crate::core::pay_request::PayRequest, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ChannelRequest<'a> { | ||
client: &'a reqwest::Client, | ||
core: crate::core::channel_request::ChannelRequest, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct WithdrawalRequest<'a> { | ||
client: &'a reqwest::Client, | ||
core: crate::core::withdrawal_request::WithdrawalRequest, | ||
} | ||
|
||
impl PayRequest<'_> { | ||
/// # Errors | ||
/// | ||
/// Returns errors on network or deserialization failures. | ||
pub async fn callback( | ||
self, | ||
comment: &str, | ||
millisatoshis: u64, | ||
) -> Result<crate::core::pay_request::CallbackResponse, &'static str> { | ||
let callback = self.core.callback(comment, millisatoshis); | ||
|
||
let response = self | ||
.client | ||
.get(callback) | ||
.send() | ||
.await | ||
.map_err(|_| "request failed")?; | ||
|
||
let text = response.text().await.map_err(|_| "body failed")?; | ||
|
||
text.parse().map_err(|_| "parse failed") | ||
} | ||
} | ||
|
||
impl ChannelRequest<'_> { | ||
/// # Errors | ||
/// | ||
/// Returns errors on network or deserialization failures. | ||
pub async fn callback_accept(self, remoteid: &str, private: bool) -> Result<(), &'static str> { | ||
let callback = self.core.callback_accept(remoteid, private); | ||
|
||
self.client | ||
.get(callback) | ||
.send() | ||
.await | ||
.map_err(|_| "request failed")?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// # Errors | ||
/// | ||
/// Returns errors on network or deserialization failures. | ||
pub async fn callback_cancel(self, remoteid: &str) -> Result<(), &'static str> { | ||
let callback = self.core.callback_cancel(remoteid); | ||
|
||
self.client | ||
.get(callback) | ||
.send() | ||
.await | ||
.map_err(|_| "request failed")?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl WithdrawalRequest<'_> { | ||
/// # Errors | ||
/// | ||
/// Returns errors on network or deserialization failures. | ||
pub async fn callback(self, pr: &str) -> Result<(), &'static str> { | ||
let callback = self.core.callback(pr); | ||
|
||
self.client | ||
.get(callback) | ||
.send() | ||
.await | ||
.map_err(|_| "request failed")?; | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.