Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #379 from consensus-shipyard/ipc-373-fix-balances
Browse files Browse the repository at this point in the history
IPC-373: Fix balances returned with bogus rpc
  • Loading branch information
adlrocha authored Nov 6, 2023
2 parents 0148c7b + 1ea406e commit 65c132e
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions ipc/cli/src/commands/wallet/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ impl CommandLineHandler for WalletBalances {

let wallet_type = WalletType::from_str(&arguments.wallet_type)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let mut errors = Vec::new();

match wallet_type {
WalletType::Evm => {
let wallet = provider.evm_wallet()?;
let addresses = wallet.read().unwrap().list()?;
let mut no_balance = addresses.clone();
let r = addresses
.iter()
.map(|addr| {
Expand All @@ -50,15 +51,27 @@ impl CommandLineHandler for WalletBalances {

let v: Vec<anyhow::Result<(TokenAmount, &EthKeyAddress)>> = join_all(r).await;

for r in v.into_iter().filter_map(|r| r.ok()) {
let (balance, addr) = r;
if addr.to_string() != "default-key" {
println!("{} - Balance: {}", addr.to_string(), balance);
no_balance.retain(|a| a != addr);
for r in v.into_iter() {
match r {
Ok(i) => {
let (balance, addr) = i;
if addr.to_string() != "default-key" {
println!("{} - Balance: {}", addr.to_string(), balance);
}
}
Err(e) => {
errors.push(e);
}
}
}
for addr in no_balance {
println!("{} - Balance: 0", addr.to_string());

if !errors.is_empty() {
let error = errors
.into_iter()
.fold(anyhow::anyhow!("Error fetching balances"), |acc, err| {
acc.context(err)
});
return Err(error);
}
}
WalletType::Fvm => {
Expand Down

0 comments on commit 65c132e

Please sign in to comment.