use crate::postgres::{ get_pg_client, get_pg_client2, };
use std::error::Error;
pub async fn examine_addresses(seed: i64) -> Result<Vec<String>, Box<dyn Error>> {
let (client1, connection1) = get_pg_client().await?;
tokio::spawn(async move {
if let Err(e) = connection1.await {
eprintln!("DB1 Postgres connection error: {}", e);
}
});
let (client2, connection2) = get_pg_client2().await?;
tokio::spawn(async move {
if let Err(e) = connection2.await {
eprintln!("DB2 Postgres connection error: {}", e);
}
});
let rows = client1
.query("SELECT address FROM addresses WHERE seed_id = $1", &[&seed])
.await?;
let mut matches = Vec::new();
for row in rows {
let address: String = row.get("address");
let exists = client2
.query_opt(
"SELECT 1 FROM wallet_balances WHERE wallet_address = $1",
&[&address],
)
.await?;
if exists.is_some() {
matches.push(address);
}
}
Ok(matches)
}