tensor_eigen/formatting/
whitelist.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use console::Style;

use tensor_whitelist::accounts::{MintProof, MintProofV2, Whitelist, WhitelistV2};

use crate::{commands::ComparisonResult, formatting::pad_label};

use super::CustomFormat;

const LABEL_LENGTH: usize = 20;

impl CustomFormat for Whitelist {
    fn custom_format(&self) -> String {
        // Use the default text color but set this up for future use.
        let color = Style::new();

        format!(
            "{}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}",
            color.apply_to("Whitelist-----------"),
            pad_label("discriminator", LABEL_LENGTH),
            color.apply_to(hex::encode(self.discriminator)),
            pad_label("version", LABEL_LENGTH),
            color.apply_to(self.version),
            pad_label("bump", LABEL_LENGTH),
            color.apply_to(self.bump),
            pad_label("verified", LABEL_LENGTH),
            color.apply_to(self.verified),
            pad_label("root_hash", LABEL_LENGTH),
            color.apply_to(hex::encode(self.root_hash)),
            pad_label("uuid", LABEL_LENGTH),
            color.apply_to(String::from_utf8_lossy(&self.uuid)),
            pad_label("name", LABEL_LENGTH),
            color.apply_to(String::from_utf8_lossy(&self.name)),
            pad_label("frozen", LABEL_LENGTH),
            color.apply_to(self.frozen),
            pad_label("voc", LABEL_LENGTH),
            color.apply_to(
                self.voc
                    .map_or("None".to_string(), |pubkey| pubkey.to_string())
            ),
            pad_label("fvc", LABEL_LENGTH),
            color.apply_to(
                self.fvc
                    .map_or("None".to_string(), |pubkey| pubkey.to_string())
            ),
            pad_label("reserved", LABEL_LENGTH),
            color.apply_to(if self.reserved.iter().all(|&x| x == 0) {
                "[all zeros]".to_string()
            } else {
                format!("{:?}", &self.reserved[..])
            })
        )
    }
}

impl CustomFormat for WhitelistV2 {
    fn custom_format(&self) -> String {
        // Use the default text color but set this up for future use.
        let color = Style::new();

        format!(
            "{}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}",
            color.apply_to("WhitelistV2---------"),
            pad_label("discriminator", LABEL_LENGTH),
            color.apply_to(hex::encode(self.discriminator)),
            pad_label("version", LABEL_LENGTH),
            color.apply_to(self.version),
            pad_label("bump", LABEL_LENGTH),
            color.apply_to(self.bump),
            pad_label("uuid", LABEL_LENGTH),
            color.apply_to(hex::encode(self.uuid)),
            pad_label("state", LABEL_LENGTH),
            color.apply_to(format!("{:?}", self.state)),
            pad_label("update_authority", LABEL_LENGTH),
            color.apply_to(self.update_authority),
            pad_label("namespace", LABEL_LENGTH),
            color.apply_to(self.namespace),
            pad_label("freeze_authority", LABEL_LENGTH),
            color.apply_to(self.freeze_authority),
            pad_label("conditions", LABEL_LENGTH),
            color.apply_to(format!("{:?}", self.conditions))
        )
    }
}

impl CustomFormat for MintProof {
    fn custom_format(&self) -> String {
        // Use the default text color but set this up for future use.
        let color = Style::new();

        format!(
            "{}
{}: {}
{}: {}
{}: {}",
            color.apply_to("MintProof----------------"),
            pad_label("discriminator", LABEL_LENGTH),
            color.apply_to(hex::encode(self.discriminator)),
            pad_label("proof_len", LABEL_LENGTH),
            color.apply_to(self.proof_len),
            pad_label("proof", LABEL_LENGTH),
            color.apply_to(if self.proof_len == 0 {
                "[empty]".to_string()
            } else {
                format!(
                    "[{} entries]",
                    self.proof[..self.proof_len as usize]
                        .iter()
                        .map(hex::encode)
                        .collect::<Vec<_>>()
                        .join(", ")
                )
            })
        )
    }
}

impl CustomFormat for MintProofV2 {
    fn custom_format(&self) -> String {
        // Use the default text color but set this up for future use.
        let color = Style::new();

        format!(
            "{}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}",
            color.apply_to("MintProofV2--------------"),
            pad_label("discriminator", LABEL_LENGTH),
            color.apply_to(hex::encode(self.discriminator)),
            pad_label("proof_len", LABEL_LENGTH),
            color.apply_to(self.proof_len),
            pad_label("proof", LABEL_LENGTH),
            color.apply_to(if self.proof_len == 0 {
                "[empty]".to_string()
            } else {
                format!(
                    "[{} entries]",
                    self.proof[..self.proof_len as usize]
                        .iter()
                        .map(hex::encode)
                        .collect::<Vec<_>>()
                        .join(", ")
                )
            }),
            pad_label("creation_slot", LABEL_LENGTH),
            color.apply_to(self.creation_slot),
            pad_label("payer", LABEL_LENGTH),
            color.apply_to(self.payer)
        )
    }
}

impl CustomFormat for ComparisonResult {
    fn custom_format(&self) -> String {
        // Use the default text color but set this up for future use.
        let color = Style::new();
        let check = "✅";
        let cross = "X";

        format!(
            "{}
{}: {}
{}: {}
{}: {}",
            color.apply_to("Whitelist Comparison----"),
            pad_label("Whitelist V1", LABEL_LENGTH),
            color.apply_to(self.whitelist_v1),
            pad_label("Whitelist V2", LABEL_LENGTH),
            color.apply_to(self.whitelist_v2),
            pad_label("Whitelists match", LABEL_LENGTH),
            color.apply_to(if self.mismatch.is_none() {
                check
            } else {
                cross
            }),
        )
    }
}