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

small impr #165

Merged
merged 3 commits into from
May 24, 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
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ pub async fn get_balance(

let token_balance = U256::from_big_endian(&call_result);

log::error!(
log::debug!(
"Token balance response: {:?} - token balance: {}",
block_info,
token_balance
Expand Down
23 changes: 22 additions & 1 deletion crates/erc20_payment_lib_extra/src/account_balance.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::{DateTime, Utc};
use erc20_payment_lib::config;
use erc20_payment_lib::eth::{get_balance, GetBalanceArgs};
use erc20_payment_lib::setup::PaymentSetup;
Expand All @@ -12,6 +13,7 @@ use std::rc::Rc;
use std::str::FromStr;
use stream_rate_limiter::{RateLimitOptions, StreamRateLimitExt};
use structopt::StructOpt;
use tokio::time::Instant;
use web3::types::Address;

#[derive(Clone, StructOpt)]
Expand All @@ -36,6 +38,9 @@ pub struct BalanceOptions {
#[structopt(long = "tasks", default_value = "1")]
pub tasks: usize,

#[structopt(long = "no-wrapper-contract")]
pub no_wrapper_contract: bool,

#[structopt(long = "interval")]
pub interval: Option<f64>,
}
Expand All @@ -49,6 +54,8 @@ pub struct BalanceResult {
pub token: Option<String>,
pub token_decimal: Option<String>,
pub token_human: Option<String>,
pub block_number: u64,
pub block_datetime: DateTime<Utc>,
}

pub async fn account_balance(
Expand Down Expand Up @@ -102,7 +109,12 @@ pub async fn account_balance(
RateLimitOptions::empty()
};

let wrapper_contract_address = chain_cfg.wrapper_contract.clone().map(|v| v.address);
let wrapper_contract_address = if account_balance_options.no_wrapper_contract {
None
} else {
chain_cfg.wrapper_contract.clone().map(|v| v.address)
};

stream::iter(0..jobs.len())
.rate_limit(rate_limit_options)
.for_each_concurrent(account_balance_options.tasks, |i| {
Expand All @@ -118,7 +130,14 @@ pub async fn account_balance(
block_number: None,
chain_id: Some(chain_cfg.chain_id as u64),
};
let current_time = Instant::now();
let balance = get_balance(web3, args).await.unwrap();
let elapsed = current_time.elapsed();
log::info!(
"Got balance for account: {:#x} in {}ms",
job,
elapsed.as_millis()
);

let gas_balance = balance.gas_balance.map(|b| b.to_string());
let token_balance = balance.token_balance.map(|b| b.to_string());
Expand Down Expand Up @@ -153,6 +172,8 @@ pub async fn account_balance(
token: token_balance,
token_decimal: token_balance_decimal,
token_human: token_balance_human,
block_number: balance.block_number,
block_datetime: balance.block_datetime,
},
);
}
Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib_test/src/get_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub async fn test_get_balance(
block_number: None,
tasks: 4,
interval: Some(0.001),
no_wrapper_contract: false,
};

account_balance(account_balance_options.clone(), &config_check).await
Expand Down
Loading