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

feat(simulate-tx): simulate transactions before broadcasting #720

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl IdentityManager {
) -> anyhow::Result<TransactionId> {
let proof_points_array: [U256; 8] = deletion_proof.into();

let register_identities_transaction = self
let delete_identities_transaction = self
.abi
.delete_identities(
proof_points_array,
Expand All @@ -288,7 +288,7 @@ impl IdentityManager {
.tx;

self.ethereum
.send_transaction(register_identities_transaction, true)
.send_transaction(delete_identities_transaction, true)
.await
.map_err(|tx_err| anyhow!("{}", tx_err.to_string()))
}
Expand Down
6 changes: 6 additions & 0 deletions src/ethereum/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::sync::Arc;

use ethers::providers::Middleware;
use ethers::types::transaction::eip2718::TypedTransaction;
use ethers::types::Address;
pub use read::ReadProvider;
Expand Down Expand Up @@ -71,6 +72,11 @@ impl Ethereum {
tx: TypedTransaction,
only_once: bool,
) -> Result<TransactionId, TxError> {
if let Err(err) = self.read_provider.call(&tx, None).await {
tracing::error!("Error simulating transaction: {:?}", err);
return Err(TxError::Simulate(anyhow::Error::new(err)));
}

self.write_provider.send_transaction(tx, only_once).await
}

Expand Down
3 changes: 3 additions & 0 deletions src/ethereum/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub enum TxError {
#[error("Error sending transaction: {0}")]
Send(anyhow::Error),

#[error("Error simulating transaction: {0}")]
Simulate(anyhow::Error),

#[error("Timeout while waiting for confirmations")]
ConfirmationTimeout,

Expand Down
Loading