-
Notifications
You must be signed in to change notification settings - Fork 6
IPC-373: Fix balances returned with bogus rpc #379
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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| { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we talked about this, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kind of agree, but let's tackle this as a joint effort after LabWeek and let's track the final approach we want to follow here: consensus-shipyard/ipc#365. So far depending on who is reviewing the PR they suggest one approach or the other 🙈 For this one specifically, this approach seems more readable for humans than returning a JSON. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sure it is more readable, and I agree you can postpone it. I guess like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ I like this idea of having a flag for human-readable v.s. computer-readable. Will track it in the issue 🙏 |
||
} | ||
} | ||
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) | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
return Err(error); | ||
} | ||
} | ||
WalletType::Fvm => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this
"default-key"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the internal key used by the wallet store to tag the address being used as the default one for the wallet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's strange to see that returned in the API 🤔
And why do we skip printing the balance? Aren't you interested in seeing the balance of your default (maybe only) address? In JSON this could be
{addr: "f410...", balance: 1.23, default: true}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the default still stands as its own entry, no? At least I still see my default address printed out under its address, just not duplicated as
default-key
. A more elegant approach for the future would be to mark the default address with a>
or*
.