From 4b8d5c36119b9a8a4c1d503ef4d4883046476ff1 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Sat, 12 Oct 2024 22:39:40 +0200 Subject: [PATCH] Fix bug, parse_cipher keeps a cipher we can't decrypt --- src/api.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api.rs b/src/api.rs index ad5497b..4e7d533 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1111,10 +1111,18 @@ pub fn parse_cipher(cipher_msg: String) -> ApiResult { .map_err(|e| ApiError::new(format!("Failed to handle decrypted message: {}", e))); } - // If both decryption attempts fail, return an error - Err(ApiError::new( - "Failed to decrypt cipher with any known method".to_owned(), - )) + // If both decryption attempts fail, we keep it just in case we receive the transaction later + let mut return_msg = CachedMessage::new(); + return_msg.cipher = vec![cipher_msg]; + return_msg.status = CachedMessageStatus::CipherWaitingTx; + + let mut messages_cache = lock_messages()?; + messages_cache.push(return_msg.clone()); + + Ok(ApiReturn { + updated_cached_msg: vec![return_msg], + ..Default::default() + }) } #[wasm_bindgen]