tensor_eigen/formatting/
marketplace.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
use console::Style;
use tensor_marketplace::accounts::{BidState, ListState};

use crate::formatting::{format_timestamp, option_formatter, pad_label};

use super::CustomFormat;

const LABEL_LENGTH: usize = 20;

impl CustomFormat for BidState {
    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("BidState------------"),
            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[0]),
            pad_label("owner", LABEL_LENGTH),
            color.apply_to(self.owner),
            pad_label("bid_id", LABEL_LENGTH),
            color.apply_to(self.bid_id),
            pad_label("target", LABEL_LENGTH),
            color.apply_to(self.target),
            pad_label("target_id", LABEL_LENGTH),
            color.apply_to(self.target_id),
            pad_label("field", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.field)),
            pad_label("field_id", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.field_id)),
            pad_label("quantity", LABEL_LENGTH),
            color.apply_to(self.quantity),
            pad_label("filled_quantity", LABEL_LENGTH),
            color.apply_to(self.filled_quantity),
            pad_label("amount", LABEL_LENGTH),
            color.apply_to(self.amount),
            pad_label("currency", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.currency)),
            pad_label("expiry", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.expiry)),
            pad_label("private_taker", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.private_taker)),
            pad_label("maker_broker", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.maker_broker)),
            pad_label("margin", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.margin)),
            pad_label("updated_at", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.updated_at)),
            pad_label("cosigner", LABEL_LENGTH),
            color.apply_to(self.cosigner),
            pad_label("rent_payer", LABEL_LENGTH),
            color.apply_to(self.rent_payer),
            pad_label("reserved", LABEL_LENGTH),
            color.apply_to(if self.reserved.iter().all(|&x| x == 0) {
                "[all zeros]".to_string()
            } else {
                "[non-zero]".to_string()
            }),
            pad_label("reserved1", LABEL_LENGTH),
            color.apply_to(if self.reserved1.iter().all(|&x| x == 0) {
                "[all zeros]".to_string()
            } else {
                "[non-zero]".to_string()
            }),
            pad_label("reserved2", LABEL_LENGTH),
            color.apply_to(if self.reserved2.iter().all(|&x| x == 0) {
                "[all zeros]".to_string()
            } else {
                "[non-zero]".to_string()
            })
        )
    }
}

impl CustomFormat for ListState {
    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("ListState-----------"),
            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[0]),
            pad_label("owner", LABEL_LENGTH),
            color.apply_to(self.owner),
            pad_label("asset_id", LABEL_LENGTH),
            color.apply_to(self.asset_id),
            pad_label("amount", LABEL_LENGTH),
            color.apply_to(self.amount),
            pad_label("currency", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.currency)),
            pad_label("expiry", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.expiry)),
            pad_label("private_taker", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.private_taker)),
            pad_label("maker_broker", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.maker_broker)),
            pad_label("rent_payer", LABEL_LENGTH),
            color.apply_to(format!("{}", self.rent_payer)),
            pad_label("cosigner", LABEL_LENGTH),
            color.apply_to(format!("{}", &self.cosigner)),
            pad_label("reserved1", LABEL_LENGTH),
            color.apply_to(if self.reserved1.iter().all(|&x| x == 0) {
                "[all zeros]".to_string()
            } else {
                "[non-zero]".to_string()
            })
        )
    }
}