diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index 59c4b8354b..8290afa8db 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -254,7 +254,7 @@ impl Provider { } } TransactionStatus::Submitted { .. } => TxStatus::Submitted, - TransactionStatus::SqueezedOut { .. } => TxStatus::SqueezedOut, + TransactionStatus::SqueezedOut { reason } => TxStatus::SqueezedOut { reason }, }; Ok(status) diff --git a/packages/fuels-core/src/types/errors.rs b/packages/fuels-core/src/types/errors.rs index e6e5c6f1ca..0a402bc618 100644 --- a/packages/fuels-core/src/types/errors.rs +++ b/packages/fuels-core/src/types/errors.rs @@ -35,6 +35,8 @@ pub enum Error { revert_id: u64, receipts: Vec, }, + #[error("Transaction was squeezed out. Reason: `{0}`")] + SqueezedOutTransactionError(String), #[error("Transaction build error: {0}")] TransactionBuildError(String), } diff --git a/packages/fuels-core/src/types/tx_status.rs b/packages/fuels-core/src/types/tx_status.rs index ca489daa5e..7b6f7b7cc0 100644 --- a/packages/fuels-core/src/types/tx_status.rs +++ b/packages/fuels-core/src/types/tx_status.rs @@ -15,7 +15,9 @@ pub enum TxStatus { receipts: Vec, }, Submitted, - SqueezedOut, + SqueezedOut { + reason: String, + }, Revert { receipts: Vec, reason: String, @@ -25,16 +27,24 @@ pub enum TxStatus { impl TxStatus { pub fn check(&self, log_decoder: Option<&LogDecoder>) -> Result<()> { - let Self::Revert { - receipts, - reason, - id, - } = &self - else { - return Ok(()); - }; + match self { + Self::SqueezedOut { reason } => Err(Error::SqueezedOutTransactionError(reason.clone())), + Self::Revert { + receipts, + reason, + id, + } => Self::map_revert_error(receipts, reason, *id, log_decoder), + _ => Ok(()), + } + } - let reason = match (*id, log_decoder) { + fn map_revert_error( + receipts: &[Receipt], + reason: &str, + id: u64, + log_decoder: Option<&LogDecoder>, + ) -> Result<()> { + let reason = match (id, log_decoder) { (FAILED_REQUIRE_SIGNAL, Some(log_decoder)) => log_decoder .decode_last_log(receipts) .unwrap_or_else(|err| format!("failed to decode log from require revert: {err}")), @@ -43,19 +53,21 @@ impl TxStatus { Ok((lhs, rhs)) => format!( "assertion failed: `(left == right)`\n left: `{lhs:?}`\n right: `{rhs:?}`" ), - Err(err) => format!("failed to decode log from assert_eq revert: {err}"), + Err(err) => { + format!("failed to decode log from assert_eq revert: {err}") + } } } (FAILED_ASSERT_SIGNAL, _) => "assertion failed.".into(), (FAILED_SEND_MESSAGE_SIGNAL, _) => "failed to send message.".into(), (FAILED_TRANSFER_TO_ADDRESS_SIGNAL, _) => "failed transfer to address.".into(), - _ => reason.clone(), + _ => reason.to_string(), }; Err(Error::RevertTransactionError { reason, - revert_id: *id, - receipts: receipts.clone(), + revert_id: id, + receipts: receipts.to_vec(), }) } diff --git a/packages/fuels-programs/src/contract.rs b/packages/fuels-programs/src/contract.rs index 18976e7ac0..8e1a3e4627 100644 --- a/packages/fuels-programs/src/contract.rs +++ b/packages/fuels-programs/src/contract.rs @@ -318,7 +318,9 @@ impl Contract { let provider = account .try_provider() .map_err(|_| error!(ProviderError, "Failed to get_provider"))?; - provider.send_transaction_and_await_commit(tx).await?; + + let tx_id = provider.send_transaction_and_await_commit(tx).await?; + provider.tx_status(&tx_id).await?.check(None)?; Ok(self.contract_id.into()) }