Skip to content

Commit

Permalink
fix: display full return address or the account if viewable
Browse files Browse the repository at this point in the history
In pcli view tx, we should show the full address if its opaque,
since we might want to send funds back to the sender, or, if we
can view, show which of our accounts the tx was sent from.
  • Loading branch information
redshiftzero committed Nov 16, 2023
1 parent 3bef4f9 commit 63075a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions crates/bin/pcli/src/command/view/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ fn format_address(ivk: &IncomingViewingKey, address: &Address) -> String {
}
}

fn format_full_address(ivk: &IncomingViewingKey, address: &Address) -> String {
if ivk.views_address(address) {
let account = ivk.index_for_diversifier(address.diversifier()).account;

format!("[account {account:?}]")
} else {
format!("{}", address)
}
}

fn format_position_row(asset_cache: &Cache, position: Position) -> String {
let trading_pair = position.phi.pair;
let denom_1 = asset_cache
Expand Down Expand Up @@ -431,8 +441,11 @@ impl TxCmd {
ciphertext: _,
} => {
metadata_table.add_row(vec![
"Transaction Memo Sender",
&plaintext.return_address.address().to_string(),
"Transaction Memo Return Address",
&format_full_address(
fvk.incoming(),
&plaintext.return_address.address(),
),
]);
metadata_table.add_row(vec!["Transaction Memo Text", &plaintext.text]);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/view/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ impl ViewProtocolService for ViewService {
address_views.insert(address, fvk.view_address(address));
asset_ids.insert(note.asset_id());

// Also add an AddressView for the sender address in the memo.
// Also add an AddressView for the return address in the memo.
let memo = tx.decrypt_memo(&fvk).map_err(|_| {
tonic::Status::internal("Error decrypting memo for OutputView")
})?;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub async fn transaction_info_inner(
address_views.insert(address, fvk.view_address(address));
asset_ids.insert(note.asset_id());

// Also add an AddressView for the sender address in the memo.
// Also add an AddressView for the return address in the memo.
let memo = tx.decrypt_memo(&fvk)?;
address_views.insert(memo.return_address, fvk.view_address(address));
}
Expand Down

0 comments on commit 63075a2

Please sign in to comment.