From bac98a6ddfeecb09d237ec1d73c8e58a9ea0c004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Granh=C3=A3o?= Date: Tue, 17 Dec 2024 10:32:42 +0000 Subject: [PATCH] Move `get_all_external_input_parsers` to `Config` --- lib/core/src/model.rs | 19 +++++++++++++++++++ lib/core/src/sdk.rs | 20 +------------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index 01266d6..0f5546f 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -20,6 +20,7 @@ use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; use crate::error::{PaymentError, SdkError, SdkResult}; +use crate::prelude::DEFAULT_EXTERNAL_INPUT_PARSERS; use crate::receive_swap::{ DEFAULT_ZERO_CONF_MAX_SAT, DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET, DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET, @@ -127,6 +128,24 @@ impl Config { LiquidNetwork::Testnet => None, } } + + pub(crate) fn get_all_external_input_parsers(&self) -> Vec { + let mut external_input_parsers = Vec::new(); + if self.use_default_external_input_parsers { + let default_parsers = DEFAULT_EXTERNAL_INPUT_PARSERS + .iter() + .map(|(id, regex, url)| ExternalInputParser { + provider_id: id.to_string(), + input_regex: regex.to_string(), + parser_url: url.to_string(), + }) + .collect::>(); + external_input_parsers.extend(default_parsers); + } + external_input_parsers.extend(self.external_input_parsers.clone().unwrap_or_default()); + + external_input_parsers + } } /// Network chosen for this Liquid SDK instance. Note that it represents both the Liquid and the diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index 645c48a..9e742b4 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -225,7 +225,7 @@ impl LiquidSdk { let buy_bitcoin_service = Arc::new(BuyBitcoinService::new(config.clone(), breez_server.clone())); - let external_input_parsers = Self::get_all_external_input_parsers(&config); + let external_input_parsers = config.get_all_external_input_parsers(); let sdk = Arc::new(LiquidSdk { config: config.clone(), @@ -250,24 +250,6 @@ impl LiquidSdk { Ok(sdk) } - fn get_all_external_input_parsers(config: &Config) -> Vec { - let mut external_input_parsers = Vec::new(); - if config.use_default_external_input_parsers { - let default_parsers = DEFAULT_EXTERNAL_INPUT_PARSERS - .iter() - .map(|(id, regex, url)| ExternalInputParser { - provider_id: id.to_string(), - input_regex: regex.to_string(), - parser_url: url.to_string(), - }) - .collect::>(); - external_input_parsers.extend(default_parsers); - } - external_input_parsers.extend(config.external_input_parsers.clone().unwrap_or_default()); - - external_input_parsers - } - /// Starts an SDK instance. /// /// Internal method. Should only be called once per instance.