Skip to content

Commit

Permalink
pcli: add display for auction views
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Aug 15, 2024
1 parent af27d7a commit 9c9976e
Showing 1 changed file with 75 additions and 5 deletions.
80 changes: 75 additions & 5 deletions crates/bin/pcli/src/transaction_view_ext.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Metadata>) -> 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 {
Expand Down Expand Up @@ -115,6 +133,27 @@ fn format_value_view(value_view: &ValueView) -> String {
}
}

fn format_amount_range(
start: Amount,
stop: Amount,
asset_id: &Id,
metadata: Option<&Metadata>,
) -> String {
dbg!(&metadata);
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())
Expand Down Expand Up @@ -378,12 +417,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.max_output,
description.min_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::<Vec<_>>()
.as_slice()
.join(", ");
action = format!("{} -> [{}]", x.action.auction_id, inside);
["Dutch Auction Withdraw", &action]
}
};

Expand Down

0 comments on commit 9c9976e

Please sign in to comment.