1use console::Style;
2use tensor_marketplace::accounts::{BidState, ListState};
3
4use crate::formatting::{format_timestamp, option_formatter, pad_label};
5
6use super::CustomFormat;
7
8const LABEL_LENGTH: usize = 20;
9
10impl CustomFormat for BidState {
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 color.apply_to("BidState------------"),
41 pad_label("discriminator", LABEL_LENGTH),
42 color.apply_to(hex::encode(self.discriminator)),
43 pad_label("version", LABEL_LENGTH),
44 color.apply_to(self.version),
45 pad_label("bump", LABEL_LENGTH),
46 color.apply_to(self.bump[0]),
47 pad_label("owner", LABEL_LENGTH),
48 color.apply_to(self.owner),
49 pad_label("bid_id", LABEL_LENGTH),
50 color.apply_to(self.bid_id),
51 pad_label("target", LABEL_LENGTH),
52 color.apply_to(self.target),
53 pad_label("target_id", LABEL_LENGTH),
54 color.apply_to(self.target_id),
55 pad_label("field", LABEL_LENGTH),
56 color.apply_to(option_formatter(&self.field)),
57 pad_label("field_id", LABEL_LENGTH),
58 color.apply_to(option_formatter(&self.field_id)),
59 pad_label("quantity", LABEL_LENGTH),
60 color.apply_to(self.quantity),
61 pad_label("filled_quantity", LABEL_LENGTH),
62 color.apply_to(self.filled_quantity),
63 pad_label("amount", LABEL_LENGTH),
64 color.apply_to(self.amount),
65 pad_label("currency", LABEL_LENGTH),
66 color.apply_to(option_formatter(&self.currency)),
67 pad_label("expiry", LABEL_LENGTH),
68 color.apply_to(format_timestamp(self.expiry)),
69 pad_label("private_taker", LABEL_LENGTH),
70 color.apply_to(option_formatter(&self.private_taker)),
71 pad_label("maker_broker", LABEL_LENGTH),
72 color.apply_to(option_formatter(&self.maker_broker)),
73 pad_label("margin", LABEL_LENGTH),
74 color.apply_to(option_formatter(&self.margin)),
75 pad_label("updated_at", LABEL_LENGTH),
76 color.apply_to(format_timestamp(self.updated_at)),
77 pad_label("cosigner", LABEL_LENGTH),
78 color.apply_to(self.cosigner),
79 pad_label("rent_payer", LABEL_LENGTH),
80 color.apply_to(self.rent_payer),
81 pad_label("reserved", LABEL_LENGTH),
82 color.apply_to(if self.reserved.iter().all(|&x| x == 0) {
83 "[all zeros]".to_string()
84 } else {
85 "[non-zero]".to_string()
86 }),
87 pad_label("reserved1", LABEL_LENGTH),
88 color.apply_to(if self.reserved1.iter().all(|&x| x == 0) {
89 "[all zeros]".to_string()
90 } else {
91 "[non-zero]".to_string()
92 }),
93 pad_label("reserved2", LABEL_LENGTH),
94 color.apply_to(if self.reserved2.iter().all(|&x| x == 0) {
95 "[all zeros]".to_string()
96 } else {
97 "[non-zero]".to_string()
98 })
99 )
100 }
101}
102
103impl CustomFormat for ListState {
104 fn custom_format(&self) -> String {
105 let color = Style::new();
107
108 format!(
109 "{}
110{}: {}
111{}: {}
112{}: {}
113{}: {}
114{}: {}
115{}: {}
116{}: {}
117{}: {}
118{}: {}
119{}: {}
120{}: {}
121{}: {}
122{}: {}",
123 color.apply_to("ListState-----------"),
124 pad_label("discriminator", LABEL_LENGTH),
125 color.apply_to(hex::encode(self.discriminator)),
126 pad_label("version", LABEL_LENGTH),
127 color.apply_to(self.version),
128 pad_label("bump", LABEL_LENGTH),
129 color.apply_to(self.bump[0]),
130 pad_label("owner", LABEL_LENGTH),
131 color.apply_to(self.owner),
132 pad_label("asset_id", LABEL_LENGTH),
133 color.apply_to(self.asset_id),
134 pad_label("amount", LABEL_LENGTH),
135 color.apply_to(self.amount),
136 pad_label("currency", LABEL_LENGTH),
137 color.apply_to(option_formatter(&self.currency)),
138 pad_label("expiry", LABEL_LENGTH),
139 color.apply_to(format_timestamp(self.expiry)),
140 pad_label("private_taker", LABEL_LENGTH),
141 color.apply_to(option_formatter(&self.private_taker)),
142 pad_label("maker_broker", LABEL_LENGTH),
143 color.apply_to(option_formatter(&self.maker_broker)),
144 pad_label("rent_payer", LABEL_LENGTH),
145 color.apply_to(format!("{}", self.rent_payer)),
146 pad_label("cosigner", LABEL_LENGTH),
147 color.apply_to(format!("{}", &self.cosigner)),
148 pad_label("reserved1", LABEL_LENGTH),
149 color.apply_to(if self.reserved1.iter().all(|&x| x == 0) {
150 "[all zeros]".to_string()
151 } else {
152 "[non-zero]".to_string()
153 })
154 )
155 }
156}