From a60ab41e7537423e2c717d60e5482dc11c76e071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Wed, 27 Mar 2024 21:04:19 +0100 Subject: [PATCH] Remove the duplicated code --- sdk/src/wallet/operations/block.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/src/wallet/operations/block.rs b/sdk/src/wallet/operations/block.rs index d18294f7eb..8a3dc576f6 100644 --- a/sdk/src/wallet/operations/block.rs +++ b/sdk/src/wallet/operations/block.rs @@ -72,20 +72,20 @@ where .await; log::debug!("submitting block {}", block.id(&protocol_parameters)); - for attempt in 1..MAX_POST_BLOCK_ATTEMPTS { - if let Ok(block_id) = self.client().post_block(&block).await { - log::debug!("submitted block {}", block_id); - return Ok(block_id); + log::debug!("submitting block {block:?}"); + + let mut attempt = 1; + loop { + match self.client().post_block(&block).await { + Ok(block_id) => break Ok(block_id), + Err(err) => { + if attempt >= MAX_POST_BLOCK_ATTEMPTS { + return Err(err.into()); + } + } } tokio::time::sleep(std::time::Duration::from_secs(attempt)).await; + attempt += 1; } - - log::debug!("submitting block {block:?}"); - - let block_id = self.client().post_block(&block).await?; - - log::debug!("submitted block {block_id}"); - - Ok(block_id) } }