Skip to content

Commit

Permalink
perf: send mint transactions asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Sep 16, 2024
1 parent f576837 commit fee8489
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions zk_toolbox/crates/common/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,24 @@ pub async fn mint_token(
)?);

let contract = TokenContract::new(token_address, client);
// contract

let mut pending_calls = vec![];
for address in addresses {
if let Err(err) = mint(&contract, address, amount).await {
logger::warn(format!("Failed to mint {err}"))
}
pending_calls.push(contract.mint(address, amount.into()));
}

Ok(())
}
let mut pending_txs = vec![];
for call in &pending_calls {
pending_txs.push(
call.send()
.await?
// It's safe to set such low number of confirmations and low interval for localhost
.confirmations(3)
.interval(Duration::from_millis(30)),
);
}

futures::future::join_all(pending_txs).await;

async fn mint<T: Middleware + 'static>(
contract: &TokenContract<T>,
address: Address,
amount: u128,
) -> anyhow::Result<()> {
contract
.mint(address, amount.into())
.send()
.await?
// It's safe to set such low number of confirmations and low interval for localhost
.confirmations(3)
.interval(Duration::from_millis(30))
.await?;
Ok(())
}

0 comments on commit fee8489

Please sign in to comment.