tensor_eigen/formatting/
whitelist.rs

1use console::Style;
2
3use tensor_whitelist::accounts::{MintProof, MintProofV2, Whitelist, WhitelistV2};
4
5use crate::{
6    commands::{ComparisonResult, WhitelistPair},
7    formatting::pad_label,
8};
9
10use super::CustomFormat;
11
12const LABEL_LENGTH: usize = 20;
13
14impl CustomFormat for Whitelist {
15    fn custom_format(&self) -> String {
16        // Use the default text color but set this up for future use.
17        let color = Style::new();
18
19        format!(
20            "{}
21{}: {}
22{}: {}
23{}: {}
24{}: {}
25{}: {}
26{}: {}
27{}: {}
28{}: {}
29{}: {}
30{}: {}
31{}: {}",
32            color.apply_to("Whitelist-----------"),
33            pad_label("discriminator", LABEL_LENGTH),
34            color.apply_to(hex::encode(self.discriminator)),
35            pad_label("version", LABEL_LENGTH),
36            color.apply_to(self.version),
37            pad_label("bump", LABEL_LENGTH),
38            color.apply_to(self.bump),
39            pad_label("verified", LABEL_LENGTH),
40            color.apply_to(self.verified),
41            pad_label("root_hash", LABEL_LENGTH),
42            color.apply_to(hex::encode(self.root_hash)),
43            pad_label("uuid", LABEL_LENGTH),
44            color.apply_to(hex::encode(self.uuid)),
45            pad_label("name", LABEL_LENGTH),
46            color.apply_to(String::from_utf8_lossy(&self.name)),
47            pad_label("frozen", LABEL_LENGTH),
48            color.apply_to(self.frozen),
49            pad_label("voc", LABEL_LENGTH),
50            color.apply_to(
51                self.voc
52                    .map_or("None".to_string(), |pubkey| pubkey.to_string())
53            ),
54            pad_label("fvc", LABEL_LENGTH),
55            color.apply_to(
56                self.fvc
57                    .map_or("None".to_string(), |pubkey| pubkey.to_string())
58            ),
59            pad_label("reserved", LABEL_LENGTH),
60            color.apply_to(if self.reserved.iter().all(|&x| x == 0) {
61                "[all zeros]".to_string()
62            } else {
63                format!("{:?}", &self.reserved[..])
64            })
65        )
66    }
67}
68
69impl CustomFormat for WhitelistV2 {
70    fn custom_format(&self) -> String {
71        // Use the default text color but set this up for future use.
72        let color = Style::new();
73
74        format!(
75            "{}
76{}: {}
77{}: {}
78{}: {}
79{}: {}
80{}: {}
81{}: {}
82{}: {}
83{}: {}
84{}: {}",
85            color.apply_to("WhitelistV2---------"),
86            pad_label("discriminator", LABEL_LENGTH),
87            color.apply_to(hex::encode(self.discriminator)),
88            pad_label("version", LABEL_LENGTH),
89            color.apply_to(self.version),
90            pad_label("bump", LABEL_LENGTH),
91            color.apply_to(self.bump),
92            pad_label("uuid", LABEL_LENGTH),
93            color.apply_to(hex::encode(self.uuid)),
94            pad_label("state", LABEL_LENGTH),
95            color.apply_to(format!("{:?}", self.state)),
96            pad_label("update_authority", LABEL_LENGTH),
97            color.apply_to(self.update_authority),
98            pad_label("namespace", LABEL_LENGTH),
99            color.apply_to(self.namespace),
100            pad_label("freeze_authority", LABEL_LENGTH),
101            color.apply_to(self.freeze_authority),
102            pad_label("conditions", LABEL_LENGTH),
103            color.apply_to(format!("{:?}", self.conditions))
104        )
105    }
106}
107
108impl CustomFormat for MintProof {
109    fn custom_format(&self) -> String {
110        // Use the default text color but set this up for future use.
111        let color = Style::new();
112
113        format!(
114            "{}
115{}: {}
116{}: {}
117{}: {}",
118            color.apply_to("MintProof----------------"),
119            pad_label("discriminator", LABEL_LENGTH),
120            color.apply_to(hex::encode(self.discriminator)),
121            pad_label("proof_len", LABEL_LENGTH),
122            color.apply_to(self.proof_len),
123            pad_label("proof", LABEL_LENGTH),
124            color.apply_to(if self.proof_len == 0 {
125                "[empty]".to_string()
126            } else {
127                format!(
128                    "[{} entries]",
129                    self.proof[..self.proof_len as usize]
130                        .iter()
131                        .map(hex::encode)
132                        .collect::<Vec<_>>()
133                        .join(", ")
134                )
135            })
136        )
137    }
138}
139
140impl CustomFormat for MintProofV2 {
141    fn custom_format(&self) -> String {
142        // Use the default text color but set this up for future use.
143        let color = Style::new();
144
145        format!(
146            "{}
147{}: {}
148{}: {}
149{}: {}
150{}: {}
151{}: {}",
152            color.apply_to("MintProofV2--------------"),
153            pad_label("discriminator", LABEL_LENGTH),
154            color.apply_to(hex::encode(self.discriminator)),
155            pad_label("proof_len", LABEL_LENGTH),
156            color.apply_to(self.proof_len),
157            pad_label("proof", LABEL_LENGTH),
158            color.apply_to(if self.proof_len == 0 {
159                "[empty]".to_string()
160            } else {
161                format!(
162                    "[{} entries]",
163                    self.proof[..self.proof_len as usize]
164                        .iter()
165                        .map(hex::encode)
166                        .collect::<Vec<_>>()
167                        .join(", ")
168                )
169            }),
170            pad_label("creation_slot", LABEL_LENGTH),
171            color.apply_to(self.creation_slot),
172            pad_label("payer", LABEL_LENGTH),
173            color.apply_to(self.payer)
174        )
175    }
176}
177
178impl CustomFormat for ComparisonResult {
179    fn custom_format(&self) -> String {
180        // Use the default text color but set this up for future use.
181        let color = Style::new();
182        let check = "✅";
183        let cross = "X";
184
185        format!(
186            "{}
187{}: {}
188{}: {}
189{}: {}",
190            color.apply_to("Whitelist Comparison----"),
191            pad_label("Whitelist V1", LABEL_LENGTH),
192            color.apply_to(self.whitelist_v1),
193            pad_label("Whitelist V2", LABEL_LENGTH),
194            color.apply_to(self.whitelist_v2),
195            pad_label("Whitelists match", LABEL_LENGTH),
196            color.apply_to(if self.mismatch.is_none() {
197                check
198            } else {
199                cross
200            }),
201        )
202    }
203}
204
205impl CustomFormat for WhitelistPair {
206    fn custom_format(&self) -> String {
207        let color = Style::new();
208
209        format!(
210            "{}
211{}: {}
212{}
213{}: {}
214{}",
215            color.apply_to("Whitelist Pair---------"),
216            pad_label("v1_pubkey", LABEL_LENGTH),
217            color.apply_to(self.v1_pubkey),
218            self.v1_data.custom_format(),
219            pad_label("v2_pubkey", LABEL_LENGTH),
220            color.apply_to(self.v2_pubkey),
221            self.v2_data
222                .as_ref()
223                .map_or_else(|| "V2 Data: None".to_string(), |v2| v2.custom_format())
224        )
225    }
226}