Skip to content

Commit

Permalink
refactor: use submit_and_await_commit API
Browse files Browse the repository at this point in the history
  • Loading branch information
iqdecay committed Nov 5, 2023
1 parent 87aa2a9 commit 40f053b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,17 @@ impl Provider {
}

/// Sends a transaction to the underlying Provider's client.
pub async fn send_transaction_and_await_commit<T: Transaction>(&self, tx: T) -> Result<TxId> {
let tx_id = self.send_transaction(tx.clone()).await?;
self.client.await_transaction_commit(&tx_id).await?;

pub async fn send_transaction_and_await_commit<T: Transaction>(
&self,
mut tx: T,
) -> 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)
}

pub async fn send_transaction<T: Transaction>(&self, mut tx: T) -> Result<TxId> {
async fn prepare_transaction_for_sending<T: Transaction>(&self, tx: &mut T) -> Result<()> {
tx.precompute(&self.chain_id())?;

let chain_info = self.chain_info().await?;
Expand All @@ -207,7 +210,11 @@ impl Provider {
}

self.validate_transaction(tx.clone()).await?;
Ok(())
}

pub async fn send_transaction<T: Transaction>(&self, mut tx: T) -> Result<TxId> {
self.prepare_transaction_for_sending(&mut tx).await?;
Ok(self.client.submit(&tx.into()).await?)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/fuels-accounts/src/provider/retryable_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ 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 40f053b

Please sign in to comment.