Skip to content

Commit

Permalink
chore: re-add removed await_transaction_commit API
Browse files Browse the repository at this point in the history
  • Loading branch information
iqdecay committed Nov 6, 2023
1 parent 40f053b commit 4d6d4fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,16 @@ impl Provider {
) -> Result<TxId> {
self.prepare_transaction_for_sending(&mut tx).await?;
let tx_id = tx.id(self.chain_id());
let _tx_status = self.client.submit_and_await_commit(&tx.into()).await?;
Ok(tx_id)
let tx_status = self.client.submit_and_await_commit(&tx.into()).await?;
match tx_status {
TransactionStatus::Submitted { .. } => Ok(tx_id),
TransactionStatus::Success { .. } => Ok(tx_id),
TransactionStatus::Failure { .. } => Ok(tx_id),
TransactionStatus::SqueezedOut { reason } => Err(error!(
ProviderError,
"Transaction was squeezed out for the following reason: {reason}"
)),
}
}

async fn prepare_transaction_for_sending<T: Transaction>(&self, tx: &mut T) -> Result<()> {
Expand Down
4 changes: 4 additions & 0 deletions packages/fuels-accounts/src/provider/retryable_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ impl RetryableClient {
self.our_retry(|| self.client.chain_info()).await
}

pub async fn await_transaction_commit(&self, id: &TxId) -> io::Result<TransactionStatus> {
self.our_retry(|| self.client.await_transaction_commit(id))
}

pub async fn submit_and_await_commit(&self, tx: &Transaction) -> io::Result<TransactionStatus> {
self.our_retry(|| self.client.submit_and_await_commit(tx))
.await
Expand Down

0 comments on commit 4d6d4fd

Please sign in to comment.