From bc0a7dbf2be7e1c09c5b3a3a03eb4506231616ab Mon Sep 17 00:00:00 2001 From: yse <70684173+hydra-yse@users.noreply.github.com> Date: Thu, 6 Feb 2025 09:19:18 +0100 Subject: [PATCH] feat: add log header on SDK init (#717) --- lib/core/src/sdk.rs | 19 +++++++++++-------- lib/core/src/utils.rs | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index 54e28c0..f5146a2 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -99,14 +99,22 @@ impl LiquidSdk { /// * `mnemonic` - the Liquid wallet mnemonic /// * `config` - the SDK [Config] pub async fn connect(req: ConnectRequest) -> Result> { + let start_ts = Instant::now(); + let signer = Box::new(SdkSigner::new( req.mnemonic.as_ref(), req.config.network == LiquidNetwork::Mainnet, )?); - Self::connect_with_signer(ConnectWithSignerRequest { config: req.config }, signer) - .inspect_err(|e| error!("Failed to connect: {:?}", e)) - .await + let sdk = + Self::connect_with_signer(ConnectWithSignerRequest { config: req.config }, signer) + .inspect_err(|e| error!("Failed to connect: {:?}", e)) + .await; + + let init_time = Instant::now().duration_since(start_ts); + utils::log_print_header(init_time); + + sdk } pub async fn connect_with_signer( @@ -285,8 +293,6 @@ impl LiquidSdk { /// Should only be called as part of [LiquidSdk::connect]. async fn start(self: &Arc) -> SdkResult<()> { let mut is_started = self.is_started.write().await; - let start_ts = Instant::now(); - self.persister .update_send_swaps_by_state(Created, TimedOut) .inspect_err(|e| error!("Failed to update send swaps by state: {:?}", e))?; @@ -295,9 +301,6 @@ impl LiquidSdk { .inspect_err(|e| error!("Failed to start background tasks: {:?}", e)) .await?; *is_started = true; - - let start_duration = start_ts.elapsed(); - info!("Liquid SDK initialized in: {start_duration:?}"); Ok(()) } diff --git a/lib/core/src/utils.rs b/lib/core/src/utils.rs index fc438da..7e85d8f 100644 --- a/lib/core/src/utils.rs +++ b/lib/core/src/utils.rs @@ -1,5 +1,5 @@ use std::str::FromStr; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use crate::ensure_sdk; use crate::error::{PaymentError, SdkResult}; @@ -147,6 +147,26 @@ pub(crate) fn increment_invoice_amount_up_to_drain_amount( } } +pub(crate) fn log_print_header(init_time_ms: Duration) { + log::info!( + " + ↘↘↘ + ↘↘↘↘↘↘↘↘ + ↘↘↘↘↘↘↘↘ + ↘↘↘↘↘ ↘↘↘↘ + ↘↘↘ Breez SDK Nodeless - version {} + ↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘ Initialization time: {init_time_ms:?} + ↘↘↘↘ Github: https://github.com/breez/breez-sdk-liquid + ↘↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘ Docs: https://sdk-doc-liquid.breez.technology/ + ↘↘↘↘↘ + ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘ + ↘↘↘↘↘↘↘↘↘↘ + ↘↘↘ + ", + env!("CARGO_PKG_VERSION"), + ); +} + #[cfg(test)] mod tests { use crate::error::PaymentError;