Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: use submit_and_await_commit API #1187

Merged
merged 19 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,29 @@ 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?;
let _status = self.client.await_transaction_commit(&tx_id).await?;

pub async fn send_transaction_and_await_commit<T: Transaction>(
hal3e marked this conversation as resolved.
Show resolved Hide resolved
&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.clone().into())
.await?;
#[cfg(feature = "coin-cache")]
{
if matches!(
_status,
_tx_status,
TransactionStatus::SqueezedOut { .. } | TransactionStatus::Failure { .. }
) {
self.cache.lock().await.remove_items(tx.used_coins())
}
}

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 @@ -228,10 +233,18 @@ 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?;
self.submit(tx).await
}

pub async fn await_transaction_commit<T: Transaction>(&self, id: TxId) -> Result<TxStatus> {
Ok(self.client.await_transaction_commit(&id).await?.into())
}

async fn validate_transaction<T: Transaction>(&self, tx: T) -> Result<()> {
let tolerance = 0.0;
let TransactionCost {
Expand Down
5 changes: 5 additions & 0 deletions packages/fuels-accounts/src/provider/retryable_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ impl RetryableClient {
.await
}

pub async fn submit_and_await_commit(&self, tx: &Transaction) -> io::Result<TransactionStatus> {
iqdecay marked this conversation as resolved.
Show resolved Hide resolved
self.our_retry(|| self.client.submit_and_await_commit(tx))
.await
}

pub async fn submit(&self, tx: &Transaction) -> io::Result<types::primitives::TransactionId> {
self.our_retry(|| self.client.submit(tx)).await
}
Expand Down
Loading