From 9206ec925b5e5bf377d67239041bd524567f6c94 Mon Sep 17 00:00:00 2001 From: Lucas Meier Date: Wed, 14 Aug 2024 23:21:18 -0700 Subject: [PATCH] pcli: add display for auction views --- crates/bin/pcli/src/transaction_view_ext.rs | 79 +++++++++++++++++++-- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/crates/bin/pcli/src/transaction_view_ext.rs b/crates/bin/pcli/src/transaction_view_ext.rs index 5cd2cd90bc..91fb69fa20 100644 --- a/crates/bin/pcli/src/transaction_view_ext.rs +++ b/crates/bin/pcli/src/transaction_view_ext.rs @@ -1,6 +1,8 @@ use comfy_table::presets; use comfy_table::Table; use penumbra_asset::asset::Id; +use penumbra_asset::asset::Metadata; +use penumbra_asset::Value; use penumbra_asset::ValueView; use penumbra_dex::swap::SwapView; use penumbra_dex::swap_claim::SwapClaimView; @@ -16,6 +18,22 @@ use penumbra_transaction::TransactionView; // TODO: TradingPairView // Implemented some helper functions which may make more sense as methods on existing Structs +// helper function to create a value view from a value and optional metadata +fn create_value_view(value: Value, metadata: Option) -> ValueView { + match metadata { + Some(metadata) => ValueView::KnownAssetId { + amount: value.amount, + metadata, + equivalent_values: Vec::new(), + extended_metadata: None, + }, + None => ValueView::UnknownAssetId { + amount: value.amount, + asset_id: value.asset_id, + }, + } +} + // a helper function to create pretty placeholders for encrypted information fn format_opaque_bytes(bytes: &[u8]) -> String { if bytes.len() < 8 { @@ -115,6 +133,26 @@ fn format_value_view(value_view: &ValueView) -> String { } } +fn format_amount_range( + start: Amount, + stop: Amount, + asset_id: &Id, + metadata: Option<&Metadata>, +) -> String { + match metadata { + Some(denom) => { + let unit = denom.default_unit(); + format!( + "({}..{}){}", + unit.format_value(start), + unit.format_value(stop), + unit + ) + } + None => format!("({}..{}){}", start, stop, asset_id), + } +} + fn format_fee(fee: &Fee) -> String { // TODO: Implement FeeView to show decrypted fee. format!("{}", fee.amount()) @@ -378,12 +416,43 @@ impl TransactionViewExt for TransactionView { penumbra_transaction::ActionView::Delegate(_) => ["Delegation", ""], penumbra_transaction::ActionView::Undelegate(_) => ["Undelegation", ""], penumbra_transaction::ActionView::UndelegateClaim(_) => ["Undelegation Claim", ""], - penumbra_transaction::ActionView::ActionDutchAuctionSchedule(_) => todo!(), - penumbra_transaction::ActionView::ActionDutchAuctionEnd(_) => { - todo!() + penumbra_transaction::ActionView::ActionDutchAuctionSchedule(x) => { + let description = &x.action.description; + + let input: String = format_value_view(&create_value_view( + description.input, + x.input_metadata.clone(), + )); + let output: String = format_amount_range( + description.min_output, + description.max_output, + &description.output_id, + x.output_metadata.as_ref(), + ); + let start = description.start_height; + let stop = description.end_height; + let steps = description.step_count; + let auction_id = x.auction_id; + action = format!( + "{} -> {}, blocks {}..{}, in {} steps ({})", + input, output, start, stop, steps, auction_id + ); + ["Dutch Auction Schedule", &action] + } + penumbra_transaction::ActionView::ActionDutchAuctionEnd(x) => { + action = format!("{}", x.auction_id); + ["Dutch Auction End", &action] } - penumbra_transaction::ActionView::ActionDutchAuctionWithdraw(_) => { - todo!() + penumbra_transaction::ActionView::ActionDutchAuctionWithdraw(x) => { + let inside = x + .reserves + .iter() + .map(|value| format_value_view(value)) + .collect::>() + .as_slice() + .join(", "); + action = format!("{} -> [{}]", x.action.auction_id, inside); + ["Dutch Auction Withdraw", &action] } };