Skip to content

Commit

Permalink
feat: check deploy tx status
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e committed Sep 27, 2023
1 parent 39bd29f commit 4481215
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/fuels-core/src/types/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub enum Error {
revert_id: u64,
receipts: Vec<Receipt>,
},
#[error("Transaction was squeezed out")]
SqueezedOutTransactionError,
#[error("Transaction build error: {0}")]
TransactionBuildError(String),
}
Expand Down
36 changes: 23 additions & 13 deletions packages/fuels-core/src/types/tx_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")),
Expand All @@ -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(),
})
}

Expand Down
4 changes: 3 additions & 1 deletion packages/fuels-programs/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit 4481215

Please sign in to comment.