Skip to content

Commit

Permalink
feat: check balances upon a change in contract addr or rpc url
Browse files Browse the repository at this point in the history
  • Loading branch information
bochaco committed Jan 15, 2025
1 parent 6bd5893 commit f66a959
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/bg_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn spawn_bg_tasks(
docker_client.clone(),
db_client.clone(),
lcd_stats.clone(),
bg_tasks_cmds_tx.subscribe(),
bg_tasks_cmds_tx.clone(),
));

tokio::spawn(async move {
Expand Down Expand Up @@ -474,7 +474,7 @@ async fn balance_checker_task(
docker_client: DockerClient,
db_client: DbClient,
lcd_stats: Arc<Mutex<HashMap<String, String>>>,
mut bg_tasks_cmds_rx: broadcast::Receiver<BgTasksCmds>,
bg_tasks_cmds_tx: broadcast::Sender<BgTasksCmds>,
) {
// helper which creates a new contract if the new configured values are valid.
let update_token_contract = |contract_addr: &str, rpc_url: &str| {
Expand Down Expand Up @@ -514,6 +514,7 @@ async fn balance_checker_task(

// cache retrieved rewards balances to not query more than once per address
let mut updated_balances = HashMap::<Address, U256>::new();
let mut bg_tasks_cmds_rx = bg_tasks_cmds_tx.subscribe();

loop {
match bg_tasks_cmds_rx.recv().await {
Expand All @@ -523,6 +524,7 @@ async fn balance_checker_task(
update_token_contract(&s.token_contract_address, &s.l2_network_rpc_url);
prev_addr = s.token_contract_address;
prev_url = s.l2_network_rpc_url;
let _ = bg_tasks_cmds_tx.send(BgTasksCmds::CheckAllBalances);
}
}
Ok(BgTasksCmds::CheckBalanceFor(container)) => {
Expand All @@ -540,8 +542,8 @@ async fn balance_checker_task(
}
}
Ok(BgTasksCmds::CheckAllBalances) => {
updated_balances.clear();
if let Some(ref token_contract) = token_contract {
updated_balances.clear();
let containers = match docker_client.get_containers_list(true).await {
Ok(containers) if !containers.is_empty() => containers,
Err(err) => {
Expand Down

0 comments on commit f66a959

Please sign in to comment.