diff --git a/packages/fuels-accounts/src/coin_cache.rs b/packages/fuels-accounts/src/coin_cache.rs index 0b69e4249..5b2040beb 100644 --- a/packages/fuels-accounts/src/coin_cache.rs +++ b/packages/fuels-accounts/src/coin_cache.rs @@ -41,23 +41,6 @@ impl CoinsCache { } } - pub fn find_already_inserted<'a>( - &mut self, - coin_ids: impl IntoIterator)>, - ) -> Option<(CoinCacheKey, CoinTypeId)> { - for (key, ids) in coin_ids { - if let Some(items) = self.items.get(key) { - for id in ids { - if items.contains(&CoinCacheItem::new(id.clone())) { - return Some((key.clone(), id.clone())); - } - } - } - } - - None - } - pub fn get_active(&mut self, key: &CoinCacheKey) -> HashSet { self.remove_expired_entries(key); diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index bfc306bdd..70204a947 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -237,6 +237,28 @@ impl Provider { Ok(self.client.submit(&tx.into()).await?) } + #[cfg(feature = "coin-cache")] + async fn find_in_cache<'a>( + &self, + coin_ids: impl IntoIterator)>, + ) -> Option<((Bech32Address, AssetId), CoinTypeId)> { + for (key, ids) in coin_ids { + let items = self.cache.lock().await.get_active(key); + + if items.is_empty() { + continue; + } + + for id in ids { + if items.contains(id) { + return Some((key.clone(), id.clone())); + } + } + } + + None + } + #[cfg(feature = "coin-cache")] async fn check_inputs_already_in_cache<'a>( &self, @@ -244,9 +266,7 @@ impl Provider { ) -> Result<()> { use fuels_core::types::errors::{transaction, Error}; - if let Some(((addr, asset_id), coin_type_id)) = - self.cache.lock().await.find_already_inserted(coin_ids) - { + if let Some(((addr, asset_id), coin_type_id)) = self.find_in_cache(coin_ids).await { let msg = match coin_type_id { CoinTypeId::UtxoId(utxo_id) => format!("coin with utxo_id: `{utxo_id:x}`"), CoinTypeId::Nonce(nonce) => format!("message with nonce: `{nonce}`"),