From a276511e788d05b772a2a7dba4b05c063035e3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Granh=C3=A3o?= <32176319+danielgranhao@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:42:15 +0100 Subject: [PATCH] Use `register_topup` (#679) --- Cargo.lock | 8 ++++---- Cargo.toml | 8 ++++---- src/fiat_topup.rs | 2 ++ src/lib.rs | 24 +++++++++++------------- src/lipalightninglib.udl | 1 + 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d65ca3a..0b7d7074 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -698,7 +698,7 @@ dependencies = [ [[package]] name = "chameleon" version = "0.1.0" -source = "git+https://github.com/getlipa/wild?tag=v1.11.0#32b82d80641981d0591ceef754a174961ecdca66" +source = "git+https://github.com/getlipa/wild?tag=v1.12.0#abb5de0c58487955ce13d1d5446cc11fe2d9e91e" dependencies = [ "graphql", "honey-badger", @@ -868,7 +868,7 @@ dependencies = [ [[package]] name = "crow" version = "0.1.0" -source = "git+https://github.com/getlipa/wild?tag=v1.11.0#32b82d80641981d0591ceef754a174961ecdca66" +source = "git+https://github.com/getlipa/wild?tag=v1.12.0#abb5de0c58487955ce13d1d5446cc11fe2d9e91e" dependencies = [ "graphql", "honey-badger", @@ -1540,7 +1540,7 @@ dependencies = [ [[package]] name = "graphql" version = "0.1.0" -source = "git+https://github.com/getlipa/wild?tag=v1.11.0#32b82d80641981d0591ceef754a174961ecdca66" +source = "git+https://github.com/getlipa/wild?tag=v1.12.0#abb5de0c58487955ce13d1d5446cc11fe2d9e91e" dependencies = [ "chrono", "graphql_client", @@ -1741,7 +1741,7 @@ dependencies = [ [[package]] name = "honey-badger" version = "1.0.1" -source = "git+https://github.com/getlipa/wild?tag=v1.11.0#32b82d80641981d0591ceef754a174961ecdca66" +source = "git+https://github.com/getlipa/wild?tag=v1.12.0#abb5de0c58487955ce13d1d5446cc11fe2d9e91e" dependencies = [ "base64 0.21.4", "bdk", diff --git a/Cargo.toml b/Cargo.toml index 3c212afa..1f0530aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,11 @@ name = "uniffi_lipalightninglib" nigiri = [] [dependencies] -chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.11.0" } -crow = { git = "https://github.com/getlipa/wild", tag = "v1.11.0" } -honey-badger = { git = "https://github.com/getlipa/wild", tag = "v1.11.0" } +chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.12.0" } +crow = { git = "https://github.com/getlipa/wild", tag = "v1.12.0" } +honey-badger = { git = "https://github.com/getlipa/wild", tag = "v1.12.0" } +graphql = { git = "https://github.com/getlipa/wild", tag = "v1.12.0" } perro = { git = "https://github.com/getlipa/perro", tag = "v1.1.0" } -graphql = { git = "https://github.com/getlipa/wild", tag = "v1.11.0" } breez-sdk-core = { git = "https://github.com/breez/breez-sdk", tag = "0.2.5" } diff --git a/src/fiat_topup.rs b/src/fiat_topup.rs index 2dcd0117..44d28591 100644 --- a/src/fiat_topup.rs +++ b/src/fiat_topup.rs @@ -19,6 +19,7 @@ pub enum TopupCurrency { #[derive(Debug)] pub struct FiatTopupInfo { + pub order_id: String, pub debitor_iban: String, pub creditor_reference: String, pub creditor_iban: String, @@ -38,6 +39,7 @@ pub struct FiatTopupInfo { impl FiatTopupInfo { fn from_pocket_create_order_response(create_order_response: CreateOrderResponse) -> Self { FiatTopupInfo { + order_id: create_order_response.id, debitor_iban: create_order_response.payment_method.debitor_iban, creditor_reference: create_order_response.payment_method.creditor_reference, creditor_iban: create_order_response.payment_method.creditor_iban, diff --git a/src/lib.rs b/src/lib.rs index b5a9c486..d3a86a4b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -736,25 +736,23 @@ impl LightningNode { user_currency: TopupCurrency, ) -> Result { trace!("register_fiat_topup() - called with - email: {email:?} - user_iban: {user_iban} - user_currency: {user_currency:?}"); - if let Err(e) = user_iban.parse::() { - return Err(invalid_input(format!("Invalid user_iban: {}", e))); - } + user_iban + .parse::() + .map_to_invalid_input("Invalid user_iban")?; - if let Some(email) = email { - if let Err(e) = EmailAddress::from_str(&email) { - return Err(invalid_input(format!("Invalid email: {}", e))); - } - self.offer_manager - .register_email(email) - .map_runtime_error_to(RuntimeErrorCode::AuthServiceUnavailable)?; + if let Some(email) = email.as_ref() { + EmailAddress::from_str(email).map_to_invalid_input("Invalid email")?; } + let topup_info = self + .fiat_topup_client + .register_pocket_fiat_topup(&user_iban, user_currency)?; + self.offer_manager - .register_node(self.get_node_info()?.node_pubkey) + .register_topup(topup_info.order_id.clone(), email) .map_runtime_error_to(RuntimeErrorCode::OfferServiceUnavailable)?; - self.fiat_topup_client - .register_pocket_fiat_topup(&user_iban, user_currency) + Ok(topup_info) } pub fn query_uncompleted_offers(&self) -> Result> { diff --git a/src/lipalightninglib.udl b/src/lipalightninglib.udl index beccdffa..6cc34e11 100644 --- a/src/lipalightninglib.udl +++ b/src/lipalightninglib.udl @@ -419,6 +419,7 @@ enum TopupCurrency { // Information about a fiat top-up registration dictionary FiatTopupInfo { + string order_id; string debitor_iban; // The user should transfer fiat from this IBAN string creditor_reference; // This reference should be included in the fiat transfer reference string creditor_iban; // The user should transfer fiat to this IBAN