From 317896278e95f1fdb391661bf27f00af1f146086 Mon Sep 17 00:00:00 2001 From: Danil Date: Wed, 14 Aug 2024 15:52:09 +0200 Subject: [PATCH] fix(zk_toolbox): Do not panic during mint Signed-off-by: Danil --- zk_toolbox/crates/common/src/ethereum.rs | 29 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/zk_toolbox/crates/common/src/ethereum.rs b/zk_toolbox/crates/common/src/ethereum.rs index e0141e38b09f..93393f8a59c3 100644 --- a/zk_toolbox/crates/common/src/ethereum.rs +++ b/zk_toolbox/crates/common/src/ethereum.rs @@ -9,7 +9,7 @@ use ethers::{ types::{Address, TransactionRequest, H256}, }; -use crate::wallets::Wallet; +use crate::{logger, wallets::Wallet}; pub fn create_ethers_client( private_key: H256, @@ -79,15 +79,26 @@ pub async fn mint_token( let contract = TokenContract::new(token_address, client); // contract for address in addresses { - contract - .mint(address, amount.into()) - .send() - .await? - // It's safe to set such low number of confirmations and low interval for localhost - .confirmations(1) - .interval(Duration::from_millis(30)) - .await?; + if let Err(err) = mint(&contract, address, amount).await { + logger::warn(format!("Failed to mint {err}")) + } } Ok(()) } + +async fn mint( + contract: &TokenContract, + 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(1) + .interval(Duration::from_millis(30)) + .await?; + Ok(()) +}