From cb2e4c8df21bf79332553a46f8c1029e40533f5c Mon Sep 17 00:00:00 2001 From: hal3e Date: Wed, 13 Dec 2023 09:17:18 +0100 Subject: [PATCH] refactor: use receipts from `TransactionStatus` (#1234) --- packages/fuels-accounts/Cargo.toml | 1 - packages/fuels-accounts/src/provider.rs | 45 ++++--------------- .../src/provider/retryable_client.rs | 9 ---- packages/fuels-core/src/types/tx_status.rs | 6 ++- 4 files changed, 12 insertions(+), 49 deletions(-) diff --git a/packages/fuels-accounts/Cargo.toml b/packages/fuels-accounts/Cargo.toml index 2755ae237f..b5b97fe47e 100644 --- a/packages/fuels-accounts/Cargo.toml +++ b/packages/fuels-accounts/Cargo.toml @@ -18,7 +18,6 @@ fuel-core-client = { workspace = true, optional = true } fuel-crypto = { workspace = true, features = ["random"] } fuel-tx = { workspace = true } fuel-types = { workspace = true, features = ["random"] } -fuel-vm = { workspace = true } fuels-core = { workspace = true, default-features = false } hex = { workspace = true, default-features = false, features = ["std"] } rand = { workspace = true, default-features = false } diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index 0ae4f4610f..0deef1fc64 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -8,16 +8,17 @@ mod supported_versions; use std::sync::Arc; use chrono::{DateTime, Utc}; +#[cfg(feature = "coin-cache")] +use fuel_core_client::client::types::TransactionStatus; use fuel_core_client::client::{ pagination::{PageDirection, PaginatedResult, PaginationRequest}, - types::{balance::Balance, contract::ContractBalance, TransactionStatus}, + types::{balance::Balance, contract::ContractBalance}, }; use fuel_tx::{ AssetId, ConsensusParameters, Receipt, ScriptExecutionResult, Transaction as FuelTransaction, TxId, UtxoId, }; use fuel_types::{Address, Bytes32, ChainId, Nonce}; -use fuel_vm::state::ProgramState; #[cfg(feature = "coin-cache")] use fuels_core::types::coin_type_id::CoinTypeId; use fuels_core::{ @@ -269,41 +270,11 @@ impl Provider { } pub async fn tx_status(&self, tx_id: &TxId) -> ProviderResult { - let fetch_receipts = || async { - let receipts = self.client.receipts(tx_id).await?; - receipts.ok_or_else(|| ProviderError::ReceiptsNotPropagatedYet) - }; - - let tx_status = self.client.transaction_status(tx_id).await?; - let status = match tx_status { - TransactionStatus::Success { .. } => { - let receipts = fetch_receipts().await?; - TxStatus::Success { receipts } - } - TransactionStatus::Failure { - reason, - program_state, - .. - } => { - let receipts = fetch_receipts().await?; - let revert_id = program_state - .and_then(|state| match state { - ProgramState::Revert(revert_id) => Some(revert_id), - _ => None, - }) - .expect("Transaction failed without a `revert_id`"); - - TxStatus::Revert { - receipts, - reason, - revert_id, - } - } - TransactionStatus::Submitted { .. } => TxStatus::Submitted, - TransactionStatus::SqueezedOut { reason } => TxStatus::SqueezedOut { reason }, - }; - - Ok(status) + self.client + .transaction_status(tx_id) + .await + .map(Into::into) + .map_err(Into::into) } pub async fn chain_info(&self) -> ProviderResult { diff --git a/packages/fuels-accounts/src/provider/retryable_client.rs b/packages/fuels-accounts/src/provider/retryable_client.rs index 1ae5669f47..4c9c7ee1cb 100644 --- a/packages/fuels-accounts/src/provider/retryable_client.rs +++ b/packages/fuels-accounts/src/provider/retryable_client.rs @@ -67,15 +67,6 @@ impl RetryableClient { self.our_retry(|| self.client.submit(tx)).await } - pub async fn receipts(&self, id: &TxId) -> io::Result>> { - retry_util::retry( - || self.client.receipts(id), - &self.retry_config, - |result| !matches!(result, Ok(Some(_))), - ) - .await - } - pub async fn transaction_status(&self, id: &TxId) -> io::Result { self.our_retry(|| self.client.transaction_status(id)).await } diff --git a/packages/fuels-core/src/types/tx_status.rs b/packages/fuels-core/src/types/tx_status.rs index e6d7ca5e78..e61bee27fe 100644 --- a/packages/fuels-core/src/types/tx_status.rs +++ b/packages/fuels-core/src/types/tx_status.rs @@ -87,15 +87,17 @@ impl TxStatus { } } } + #[cfg(feature = "std")] impl From for TxStatus { fn from(client_status: ClientTransactionStatus) -> Self { match client_status { ClientTransactionStatus::Submitted { .. } => TxStatus::Submitted {}, - ClientTransactionStatus::Success { .. } => TxStatus::Success { receipts: vec![] }, + ClientTransactionStatus::Success { receipts, .. } => TxStatus::Success { receipts }, ClientTransactionStatus::Failure { reason, program_state, + receipts, .. } => { let revert_id = program_state @@ -105,7 +107,7 @@ impl From for TxStatus { }) .expect("Transaction failed without a `revert_id`"); TxStatus::Revert { - receipts: vec![], + receipts, reason, revert_id, }