Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcli: add display for auction transactions #4814

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 74 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,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())
Expand Down Expand Up @@ -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::<Vec<_>>()
.as_slice()
.join(", ");
action = format!("{} -> [{}]", x.action.auction_id, inside);
["Dutch Auction Withdraw", &action]
}
};

Expand Down
Loading