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

fix(zk_toolbox): Do not panic during mint #2658

Merged
merged 1 commit into from
Aug 14, 2024
Merged
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
29 changes: 20 additions & 9 deletions zk_toolbox/crates/common/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<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(1)
.interval(Duration::from_millis(30))
.await?;
Ok(())
}
Loading