Skip to content

Commit

Permalink
Merge pull request #720 from worldcoin/0xkitsune/simulate-tx
Browse files Browse the repository at this point in the history
feat(simulate-tx): simulate transactions before broadcasting
  • Loading branch information
0xKitsune authored May 2, 2024
2 parents 408b6a8 + c1e660e commit 1e97fe2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
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

0 comments on commit 1e97fe2

Please sign in to comment.