From 44812155268a553e2e2073d3d978e2413f98d7d4 Mon Sep 17 00:00:00 2001 From: hal3e Date: Wed, 27 Sep 2023 12:59:18 +0200 Subject: [PATCH] feat: check deploy tx status --- packages/fuels-core/src/types/errors.rs | 2 ++ packages/fuels-core/src/types/tx_status.rs | 36 ++++++++++++++-------- packages/fuels-programs/src/contract.rs | 4 ++- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/fuels-core/src/types/errors.rs b/packages/fuels-core/src/types/errors.rs index e6e5c6f1ca..c76bfd93dd 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")] + SqueezedOutTransactionError, #[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..3fcc6d9999 100644 --- a/packages/fuels-core/src/types/tx_status.rs +++ b/packages/fuels-core/src/types/tx_status.rs @@ -25,16 +25,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 => Err(Error::SqueezedOutTransactionError), + 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 +51,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 2f413dcaf9..9174fb96ad 100644 --- a/packages/fuels-programs/src/contract.rs +++ b/packages/fuels-programs/src/contract.rs @@ -315,7 +315,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()) }