diff --git a/libs/Cargo.lock b/libs/Cargo.lock index f814fda70..47becfa14 100644 --- a/libs/Cargo.lock +++ b/libs/Cargo.lock @@ -153,20 +153,6 @@ dependencies = [ "syn 2.0.28", ] -[[package]] -name = "async_executors" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0b2463773401e1f684136f9cdb956cf611f22172472cf3f049e72123f59e359" -dependencies = [ - "blanket", - "futures-core", - "futures-task", - "futures-util", - "pin-project 1.1.0", - "rustc_version", -] - [[package]] name = "atty" version = "0.2.14" @@ -312,17 +298,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "blanket" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b04ce3d2372d05d1ef4ea3fdf427da6ae3c17ca06d688a107b5344836276bc3" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -771,18 +746,6 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" -[[package]] -name = "educe" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "079044df30bb07de7d846d41a184c4b00e66ebdac93ee459253474f3a47e50ae" -dependencies = [ - "enum-ordinalize", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "either" version = "1.8.1" @@ -798,19 +761,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "enum-ordinalize" -version = "3.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4f76552f53cefc9a7f64987c3701b99d982f7690606fd67de1d09712fbf52f1" -dependencies = [ - "num-bigint", - "num-traits", - "proc-macro2", - "quote", - "syn 2.0.28", -] - [[package]] name = "env_logger" version = "0.7.1" @@ -1168,7 +1118,6 @@ dependencies = [ "tokio 1.28.2", "tonic 0.8.3", "tonic-build 0.8.4", - "tor-rtcompat", "tower 0.4.13", "url", "vls-core", @@ -2025,7 +1974,7 @@ dependencies = [ "neon-build", "neon-macros", "neon-runtime", - "semver 0.9.0", + "semver", "smallvec", ] @@ -2916,15 +2865,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.18", -] - [[package]] name = "rusticata-macros" version = "4.1.0" @@ -3109,12 +3049,6 @@ dependencies = [ "semver-parser", ] -[[package]] -name = "semver" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" - [[package]] name = "semver-parser" version = "0.7.0" @@ -3762,20 +3696,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "tor-rtcompat" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad4346d4b728444d9976830f7b055ea61eff0afd3d856c777b8b63263c274032" -dependencies = [ - "async-trait", - "async_executors", - "educe", - "futures", - "pin-project 1.1.0", - "thiserror", -] - [[package]] name = "tower" version = "0.3.1" diff --git a/libs/gl-client/Cargo.toml b/libs/gl-client/Cargo.toml index f5ac13cca..b24ac495a 100644 --- a/libs/gl-client/Cargo.toml +++ b/libs/gl-client/Cargo.toml @@ -26,7 +26,6 @@ rustls-pemfile = "*" sha256 = "1.1.4" tokio = { version = "1", features = ["full"] } tonic = { version = "^0.8", features = ["tls", "transport"] } -tor-rtcompat = {version="0.9.2"} tower = { version = "0.4" } rcgen = { version = "0.10.0", features = ["pem", "x509-parser"]} tempfile = "3.3.0" diff --git a/libs/gl-client/src/lnurl/mod.rs b/libs/gl-client/src/lnurl/mod.rs index 9d8cd35c1..f6208320e 100644 --- a/libs/gl-client/src/lnurl/mod.rs +++ b/libs/gl-client/src/lnurl/mod.rs @@ -9,8 +9,8 @@ use pay::resolve_to_invoice; pub struct LNURL; impl LNURL { - pub async fn resolve_lnurl_to_invoice(&self, lnurl: &str, amount: u64) -> Result { + pub async fn resolve_lnurl_to_invoice(&self, lnurl: &str, amount_msats: u64) -> Result { let http_client = LnUrlHttpClearnetClient::new(); - resolve_to_invoice(http_client, lnurl, amount).await + resolve_to_invoice(http_client, lnurl, amount_msats).await } } diff --git a/libs/gl-client/src/lnurl/models.rs b/libs/gl-client/src/lnurl/models.rs index a0a493864..ef19f7504 100644 --- a/libs/gl-client/src/lnurl/models.rs +++ b/libs/gl-client/src/lnurl/models.rs @@ -36,7 +36,6 @@ pub trait LnUrlHttpClient { async fn get_pay_request_callback_response( &self, callback_url: &str, - amount: u64, ) -> Result; } @@ -72,7 +71,6 @@ impl LnUrlHttpClient for LnUrlHttpClearnetClient { async fn get_pay_request_callback_response( &self, callback_url: &str, - amount: u64, ) -> Result { self.get::(callback_url).await } diff --git a/libs/gl-client/src/lnurl/pay/mod.rs b/libs/gl-client/src/lnurl/pay/mod.rs index 8e6a384f5..e7f519d6c 100644 --- a/libs/gl-client/src/lnurl/pay/mod.rs +++ b/libs/gl-client/src/lnurl/pay/mod.rs @@ -1,27 +1,24 @@ use super::models; use super::utils::parse_lnurl; -use crate::lnurl::models::{ - LnUrlHttpClient, MockLnUrlHttpClient, PayRequestCallbackResponse, PayRequestResponse, -}; +use crate::lnurl::models::{LnUrlHttpClient, PayRequestCallbackResponse, PayRequestResponse}; use anyhow::{anyhow, ensure, Result}; -use futures::future; use lightning_invoice::{Invoice, InvoiceDescription}; use log::debug; use reqwest::Url; use sha256; -use std::str::FromStr; // Import the future module +use std::str::FromStr; pub async fn resolve_to_invoice( http_client: T, lnurl: &str, - amount: u64, + amount_msats: u64, ) -> Result { let url = parse_lnurl(lnurl)?; let lnurl_pay_request_response: PayRequestResponse = http_client.get_pay_request_response(&url).await?; - validate_pay_request_response(&lnurl_pay_request_response, amount)?; + validate_pay_request_response(&lnurl_pay_request_response, amount_msats)?; let description = extract_description(&lnurl_pay_request_response)?; debug!("Domain: {}", Url::parse(&url).unwrap().host().unwrap()); @@ -31,13 +28,13 @@ pub async fn resolve_to_invoice( lnurl_pay_request_response.min_sendable, lnurl_pay_request_response.max_sendable ); - let callback_url = build_callback_url(&lnurl_pay_request_response, amount)?; + let callback_url = build_callback_url(&lnurl_pay_request_response, amount_msats)?; let callback_response: PayRequestCallbackResponse = http_client - .get_pay_request_callback_response(&callback_url, amount) + .get_pay_request_callback_response(&callback_url) .await?; let invoice = parse_invoice(&callback_response.pr)?; - validate_invoice_from_callback_response(&invoice, amount, lnurl_pay_request_response)?; + validate_invoice_from_callback_response(&invoice, amount_msats, lnurl_pay_request_response)?; Ok(invoice.to_string()) } @@ -108,7 +105,7 @@ fn validate_pay_request_response( fn validate_invoice_from_callback_response( invoice: &Invoice, amount: u64, - lnurl_pay_request: PayRequestResponse, + lnurl_pay_request_response: PayRequestResponse, ) -> Result<()> { ensure!(invoice.amount_milli_satoshis().unwrap_or_default() == amount , "Amount found in invoice was not equal to the amount found in the original request\nRequest amount: {}\nInvoice amount:{:?}", amount, invoice.amount_milli_satoshis().unwrap() @@ -120,7 +117,7 @@ fn validate_invoice_from_callback_response( }; ensure!( - description_hash == sha256::digest(lnurl_pay_request.metadata), + description_hash == sha256::digest(lnurl_pay_request_response.metadata), "description_hash does not match the hash of the metadata" ); Ok(()) @@ -128,6 +125,8 @@ fn validate_invoice_from_callback_response( #[cfg(test)] mod tests { + use crate::lnurl::models::MockLnUrlHttpClient; + use futures::future; use futures::future::Ready; use std::pin::Pin; @@ -160,7 +159,7 @@ mod tests { convert_to_async_return_value(Ok(x)) }); - mock_http_client.expect_get_pay_request_callback_response().returning(|_url, _amount| { + mock_http_client.expect_get_pay_request_callback_response().returning(|_url| { let invoice = "lnbc1u1pjv9qrvsp5e5wwexctzp9yklcrzx448c68q2a7kma55cm67ruajjwfkrswnqvqpp55x6mmz8ch6nahrcuxjsjvs23xkgt8eu748nukq463zhjcjk4s65shp5dd6hc533r655wtyz63jpf6ja08srn6rz6cjhwsjuyckrqwanhjtsxqzjccqpjrzjqw6lfdpjecp4d5t0gxk5khkrzfejjxyxtxg5exqsd95py6rhwwh72rpgrgqq3hcqqgqqqqlgqqqqqqgq9q9qxpqysgq95njz4sz6h7r2qh7txnevcrvg0jdsfpe72cecmjfka8mw5nvm7tydd0j34ps2u9q9h6v5u8h3vxs8jqq5fwehdda6a8qmpn93fm290cquhuc6r"; let callback_response_json = format!("{{\"pr\":\"{}\",\"routes\":[]}}", invoice).to_string(); let x = serde_json::from_str(&callback_response_json).unwrap(); @@ -202,7 +201,7 @@ mod tests { convert_to_async_return_value(Ok(x)) }); - mock_http_client.expect_get_pay_request_callback_response().returning(|_url, _amount| { + mock_http_client.expect_get_pay_request_callback_response().returning(|_url| { let invoice = "lnbc1u1pjv9qrvsp5e5wwexctzp9yklcrzx448c68q2a7kma55cm67ruajjwfkrswnqvqpp55x6mmz8ch6nahrcuxjsjvs23xkgt8eu748nukq463zhjcjk4s65shp5dd6hc533r655wtyz63jpf6ja08srn6rz6cjhwsjuyckrqwanhjtsxqzjccqpjrzjqw6lfdpjecp4d5t0gxk5khkrzfejjxyxtxg5exqsd95py6rhwwh72rpgrgqq3hcqqgqqqqlgqqqqqqgq9q9qxpqysgq95njz4sz6h7r2qh7txnevcrvg0jdsfpe72cecmjfka8mw5nvm7tydd0j34ps2u9q9h6v5u8h3vxs8jqq5fwehdda6a8qmpn93fm290cquhuc6r"; let callback_response_json = format!("{{\"pr\":\"{}\",\"routes\":[]}}", invoice).to_string(); let callback_response = serde_json::from_str(&callback_response_json).unwrap(); @@ -231,7 +230,7 @@ mod tests { convert_to_async_return_value(Ok(x)) }); - mock_http_client.expect_get_pay_request_callback_response().returning(|_url, _amount| { + mock_http_client.expect_get_pay_request_callback_response().returning(|_url| { let invoice = "lnbc1u1pjv9qrvsp5e5wwexctzp9yklcrzx448c68q2a7kma55cm67ruajjwfkrswnqvqpp55x6mmz8ch6nahrcuxjsjvs23xkgt8eu748nukq463zhjcjk4s65shp5dd6hc533r655wtyz63jpf6ja08srn6rz6cjhwsjuyckrqwanhjtsxqzjccqpjrzjqw6lfdpjecp4d5t0gxk5khkrzfejjxyxtxg5exqsd95py6rhwwh72rpgrgqq3hcqqgqqqqlgqqqqqqgq9q9qxpqysgq95njz4sz6h7r2qh7txnevcrvg0jdsfpe72cecmjfka8mw5nvm7tydd0j34ps2u9q9h6v5u8h3vxs8jqq5fwehdda6a8qmpn93fm290cquhuc6r"; let callback_response_json = format!("{{\"pr\":\"{}\",\"routes\":[]}}", invoice).to_string(); let value = serde_json::from_str(&callback_response_json).unwrap();