1use console::Style;
2use tensor_price_lock::accounts::{OrderNftReceipt, OrderState};
3
4use crate::formatting::{format_timestamp, option_formatter, pad_label};
5
6use super::CustomFormat;
7
8const LABEL_LENGTH: usize = 25;
9
10impl CustomFormat for OrderState {
11 fn custom_format(&self) -> String {
12 let color = Style::new();
14
15 format!(
16 "{}
17{}: {}
18{}: {}
19{}: {}
20{}: {}
21{}: {}
22{}: {}
23{}: {}
24{}: {}
25{}: {}
26{}: {}
27{}: {}
28{}: {}
29{}: {}
30{}: {}
31{}: {}
32{}: {}
33{}: {}
34{}: {}
35{}: {}
36{}: {}
37{}: {}
38{}: {}
39{}: {}
40{}: {}
41{}: {}
42{}: {}
43{}: {}
44{}: {}
45{}: {}
46{}: {}
47{}: {}
48{}: {}",
49 color.apply_to("OrderState---------------"),
50 pad_label("discriminator", LABEL_LENGTH),
51 color.apply_to(hex::encode(self.discriminator)),
52 pad_label("version", LABEL_LENGTH),
53 color.apply_to(self.version),
54 pad_label("bump", LABEL_LENGTH),
55 color.apply_to(self.bump[0]),
56 pad_label("order_id", LABEL_LENGTH),
57 color.apply_to(hex::encode(self.order_id)),
58 pad_label("order_type", LABEL_LENGTH),
59 color.apply_to(format!("{:?}", self.order_type)),
60 pad_label("nonce", LABEL_LENGTH),
61 color.apply_to(self.nonce),
62 pad_label("maker", LABEL_LENGTH),
63 color.apply_to(self.maker),
64 pad_label("price", LABEL_LENGTH),
65 color.apply_to(self.price),
66 pad_label("currency", LABEL_LENGTH),
67 color.apply_to(option_formatter(&self.currency)),
68 pad_label("apr_bps", LABEL_LENGTH),
69 color.apply_to(self.apr_bps),
70 pad_label("duration_sec", LABEL_LENGTH),
71 color.apply_to(self.duration_sec),
72 pad_label("whitelist", LABEL_LENGTH),
73 color.apply_to(self.whitelist),
74 pad_label("maker_broker", LABEL_LENGTH),
75 color.apply_to(option_formatter(&self.maker_broker)),
76 pad_label("margin", LABEL_LENGTH),
77 color.apply_to(option_formatter(&self.margin)),
78 pad_label("expiry", LABEL_LENGTH),
79 color.apply_to(format_timestamp(self.expiry)),
80 pad_label("created_at", LABEL_LENGTH),
81 color.apply_to(format_timestamp(self.created_at)),
82 pad_label("updated_at", LABEL_LENGTH),
83 color.apply_to(format_timestamp(self.updated_at)),
84 pad_label("nfts_held", LABEL_LENGTH),
85 color.apply_to(self.nfts_held),
86 pad_label("vault_balance", LABEL_LENGTH),
87 color.apply_to(self.vault_balance),
88 pad_label("locked_at", LABEL_LENGTH),
89 color.apply_to(format_timestamp(self.locked_at)),
90 pad_label("locked_until", LABEL_LENGTH),
91 color.apply_to(format_timestamp(self.locked_until)),
92 pad_label("taker", LABEL_LENGTH),
93 color.apply_to(option_formatter(&self.taker)),
94 pad_label("collateral_returned", LABEL_LENGTH),
95 color.apply_to(self.collateral_returned),
96 pad_label("last_exercised_at", LABEL_LENGTH),
97 color.apply_to(format_timestamp(self.last_exercised_at)),
98 pad_label("exercise_count", LABEL_LENGTH),
99 color.apply_to(self.exercise_count),
100 pad_label("accumulated_profit", LABEL_LENGTH),
101 color.apply_to(self.accumulated_profit),
102 pad_label("taker_withdrawn_nfts", LABEL_LENGTH),
103 color.apply_to(self.taker_withdrawn_nfts),
104 pad_label("taker_withdrawn_funds", LABEL_LENGTH),
105 color.apply_to(self.taker_withdrawn_funds),
106 pad_label("early_close", LABEL_LENGTH),
107 color.apply_to(self.early_close),
108 pad_label("reserved0", LABEL_LENGTH),
109 color.apply_to(if self.reserved0.iter().all(|&x| x == 0) {
110 "[all zeros]".to_string()
111 } else {
112 "[non-zero]".to_string()
113 }),
114 pad_label("reserved1", LABEL_LENGTH),
115 color.apply_to(if self.reserved1.iter().all(|&x| x == 0) {
116 "[all zeros]".to_string()
117 } else {
118 "[non-zero]".to_string()
119 }),
120 pad_label("reserved2", LABEL_LENGTH),
121 color.apply_to(if self.reserved2.iter().all(|&x| x == 0) {
122 "[all zeros]".to_string()
123 } else {
124 "[non-zero]".to_string()
125 })
126 )
127 }
128}
129
130impl CustomFormat for OrderNftReceipt {
131 fn custom_format(&self) -> String {
132 let color = Style::new();
134
135 format!(
136 "{}
137{}: {}
138{}: {}
139{}: {}
140{}: {}",
141 color.apply_to("OrderNftReceipt---------------"),
142 pad_label("discriminator", LABEL_LENGTH),
143 color.apply_to(hex::encode(self.discriminator)),
144 pad_label("bump", LABEL_LENGTH),
145 color.apply_to(self.bump),
146 pad_label("asset", LABEL_LENGTH),
147 color.apply_to(self.asset),
148 pad_label("order_state", LABEL_LENGTH),
149 color.apply_to(self.order_state)
150 )
151 }
152}