From 378d94e7b8d875c75897313479856c223be5a86b Mon Sep 17 00:00:00 2001 From: silverpill Date: Tue, 28 Mar 2023 00:10:49 +0000 Subject: [PATCH] Don't reopen monero wallet on each subscription monitor run --- CHANGELOG.md | 1 + src/monero/wallet.rs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a435650..d362236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fixed error in emoji update SQL query. - Restart stalled background jobs. - Order attachments by creation date. +- Don't reopen monero wallet on each subscription monitor run. ## [1.18.0] - 2023-03-21 diff --git a/src/monero/wallet.rs b/src/monero/wallet.rs index 2d42266..1b60f6f 100644 --- a/src/monero/wallet.rs +++ b/src/monero/wallet.rs @@ -56,11 +56,20 @@ pub async fn open_monero_wallet( let wallet_client = RpcClientBuilder::new() .build(config.wallet_url.clone())? .wallet(); - if let Some(ref wallet_name) = config.wallet_name { - wallet_client.open_wallet( - wallet_name.clone(), - config.wallet_password.clone(), - ).await?; + if let Err(error) = wallet_client.refresh(None).await { + if error.to_string() == "Server error: No wallet file" { + // Try to open wallet + if let Some(ref wallet_name) = config.wallet_name { + wallet_client.open_wallet( + wallet_name.clone(), + config.wallet_password.clone(), + ).await?; + } else { + return Err(MoneroError::WalletRpcError("wallet file is required")); + }; + } else { + return Err(error.into()); + }; }; Ok(wallet_client) }