Skip to content

Commit

Permalink
pcli: show sender in notes-by-commitment
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence committed Jan 3, 2024
1 parent 1d9d8e3 commit 717b8a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/bin/pcli/src/command/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl ViewCmd {
}
ViewCmd::Balance(balance_cmd) => {
let view_client = app.view();
balance_cmd.exec(&full_viewing_key, view_client).await?;
balance_cmd.exec(view_client).await?;
}
ViewCmd::Staked(staked_cmd) => {
let channel = app.pd_channel().await?;
Expand Down
26 changes: 21 additions & 5 deletions crates/bin/pcli/src/command/view/balance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use comfy_table::{presets, Table};

use penumbra_keys::FullViewingKey;
use penumbra_keys::AddressView;
use penumbra_sct::CommitmentSource;
use penumbra_view::ViewClient;

Expand All @@ -17,7 +17,7 @@ impl BalanceCmd {
false
}

pub async fn exec<V: ViewClient>(&self, fvk: &FullViewingKey, view: &mut V) -> Result<()> {
pub async fn exec<V: ViewClient>(&self, view: &mut V) -> Result<()> {
let asset_cache = view.assets().await?;

// Initialize the table
Expand All @@ -27,7 +27,7 @@ impl BalanceCmd {
let notes = view.unspent_notes_by_account_and_asset().await?;

if self.by_note {
table.set_header(vec!["Account", "Value", "Source"]);
table.set_header(vec!["Account", "Value", "Source", "Sender"]);

let rows = notes
.iter()
Expand All @@ -39,21 +39,23 @@ impl BalanceCmd {
*index,
asset.value(record.note.amount()),
record.source.clone(),
record.return_address.clone(),
)
})
})
})
// Exclude withdrawn LPNFTs.
.filter(|(_, value, _)| match asset_cache.get(&value.asset_id) {
.filter(|(_, value, _, _)| match asset_cache.get(&value.asset_id) {
None => true,
Some(denom) => !denom.is_withdrawn_position_nft(),
});

for (index, value, source) in rows {
for (index, value, source, return_address) in rows {
table.add_row(vec![
format!("# {}", index),
value.format(&asset_cache),
format_source(&source),
format_return_address(&return_address),
]);
}

Expand Down Expand Up @@ -111,3 +113,17 @@ fn format_source(source: &CommitmentSource) -> String {
),
}
}

fn format_return_address(return_address: &Option<penumbra_keys::AddressView>) -> String {
match return_address {
None => "Unknown".to_owned(),
Some(AddressView::Opaque { address }) => address.display_short_form(),
Some(AddressView::Visible { index, .. }) => {
if index.is_ephemeral() {
format!("[account {} (IBC deposit address)]", index.account)
} else {
format!("[account {}]", index.account)
}
}
}
}

0 comments on commit 717b8a0

Please sign in to comment.