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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
use axum::extract::{Path, State};
use axum::response::{Html, IntoResponse};
use fedimint_core::epoch::ConsensusItem;
use fedimint_core::hex;
use fedimint_core::session_outcome::{AcceptedItem, SessionStatusV2};
use fedimint_core::transaction::TransactionSignature;
use fedimint_server_core::dashboard_ui::DynDashboardApi;
use fedimint_ui_common::UiState;
use fedimint_ui_common::auth::UserAuth;
use maud::{Markup, html};
use crate::dashboard::dashboard_layout;
/// Handler for the consensus explorer view
pub async fn consensus_explorer_view(
State(state): State<UiState<DynDashboardApi>>,
_auth: UserAuth,
session_idx: Option<Path<u64>>,
) -> impl IntoResponse {
let session_count = state.api.session_count().await;
let last_sessin_idx = session_count.saturating_sub(1);
// If a specific session index was provided, show only that session
// Otherwise, show the current session
let session_idx = session_idx.map(|p| p.0).unwrap_or(last_sessin_idx);
let (_sigs, items) = match state.api.get_session_status(session_idx).await {
SessionStatusV2::Initial => (None, vec![]),
SessionStatusV2::Pending(items) => (None, items),
SessionStatusV2::Complete(signed_session_outcome) => (
Some(signed_session_outcome.signatures),
signed_session_outcome.session_outcome.items,
),
};
let content = html! {
div class="row mb-4" {
div class="col-12" {
div class="d-flex justify-content-between align-items-center" {
h2 { "Consensus Explorer" }
a href="/" class="btn btn-outline-primary" { "Back to Dashboard" }
}
}
}
div class="row mb-4" {
div class="col-12" {
div class="d-flex justify-content-between align-items-center" {
// Session navigation
div class="btn-group" role="group" aria-label="Session navigation" {
@if 0 < session_idx {
a href={ "/explorer/" (session_idx - 1) } class="btn btn-outline-secondary" {
"← Previous Session"
}
} @else {
button class="btn btn-outline-secondary" disabled { "← Previous Session" }
}
@if session_idx < last_sessin_idx {
a href={ "/explorer/" (session_idx + 1) } class="btn btn-outline-secondary" {
"Next Session →"
}
} @else {
button class="btn btn-outline-secondary" disabled { "Next Session →" }
}
}
// Jump to session form
form class="d-flex" action="javascript:void(0);" onsubmit="window.location.href='/explorer/' + document.getElementById('session-jump').value" {
div class="input-group" {
input type="number" class="form-control" id="session-jump" min="0" max=(session_count - 1) placeholder="Session #";
button class="btn btn-outline-primary" type="submit" { "Go" }
}
}
}
}
}
div class="row" {
div class="col-12" {
div class="card mb-4" {
div class="card-header" {
div class="d-flex justify-content-between align-items-center" {
h5 class="mb-0" { "Session #" (session_idx) }
span class="badge bg-primary" { (items.len()) " items" }
}
}
div class="card-body" {
@if items.is_empty() {
div class="alert alert-secondary" {
"This session contains no consensus items."
}
} @else {
div class="table-responsive" {
table class="table table-striped table-hover" {
thead {
tr {
th { "Item #" }
th { "Type" }
th { "Peer" }
th { "Details" }
}
}
tbody {
@for (item_idx, item) in items.iter().enumerate() {
tr {
td { (item_idx) }
td { (format_item_type(&item.item)) }
td { (item.peer) }
td { (format_item_details(item)) }
}
}
}
}
}
// Display signatures if available
@if let Some(signatures) = _sigs {
div class="mt-4" {
h5 { "Session Signatures" }
div class="alert alert-info" {
p { "This session was signed by the following peers:" }
ul class="mb-0" {
@for peer_id in signatures.keys() {
li { "Guardian " (peer_id.to_string()) }
}
}
}
}
}
}
}
}
}
}
};
let version = state.api.fedimintd_version().await;
Html(dashboard_layout(content, &version).into_string()).into_response()
}
/// Format the type of consensus item for display
fn format_item_type(item: &ConsensusItem) -> String {
match item {
ConsensusItem::Transaction(_) => "Transaction".to_string(),
ConsensusItem::Module(_) => "Module".to_string(),
ConsensusItem::Default { variant, .. } => format!("Unknown ({variant})"),
}
}
/// Format details about a consensus item
fn format_item_details(item: &AcceptedItem) -> Markup {
match &item.item {
ConsensusItem::Transaction(tx) => {
html! {
div class="consensus-item-details" {
div class="mb-2" {
"Transaction ID: " code { (tx.tx_hash()) }
}
div class="mb-2" {
"Nonce: " code { (hex::encode(tx.nonce)) }
}
// Inputs section
details class="mb-2" {
summary { "Inputs: " strong { (tx.inputs.len()) } }
@if tx.inputs.is_empty() {
div class="alert alert-secondary mt-2" { "No inputs" }
} @else {
div class="table-responsive mt-2" {
table class="table table-sm" {
thead {
tr {
th { "#" }
th { "Module ID" }
th { "Type" }
}
}
tbody {
@for (idx, input) in tx.inputs.iter().enumerate() {
tr {
td { (idx) }
td { (input.module_instance_id()) }
td { (input.to_string()) }
}
}
}
}
}
}
}
// Outputs section
details class="mb-2" {
summary { "Outputs: " strong { (tx.outputs.len()) } }
@if tx.outputs.is_empty() {
div class="alert alert-secondary mt-2" { "No outputs" }
} @else {
div class="table-responsive mt-2" {
table class="table table-sm" {
thead {
tr {
th { "#" }
th { "Module ID" }
th { "Type" }
}
}
tbody {
@for (idx, output) in tx.outputs.iter().enumerate() {
tr {
td { (idx) }
td { (output.module_instance_id()) }
td { (output.to_string()) }
}
}
}
}
}
}
}
// Signature info
details class="mb-2" {
summary { "Signature Info" }
div class="mt-2" {
@match &tx.signatures {
TransactionSignature::NaiveMultisig(sigs) => {
div { "Type: NaiveMultisig" }
div { "Signatures: " (sigs.len()) }
}
TransactionSignature::Default { variant, bytes } => {
div { "Type: Unknown (variant " (variant) ")" }
div { "Size: " (bytes.len()) " bytes" }
}
}
}
}
}
}
}
ConsensusItem::Module(module_item) => {
html! {
div class="consensus-item-details" {
div class="mb-2" {
"Module Instance ID: " code { (module_item.module_instance_id()) }
}
@if let Some(kind) = module_item.module_kind() {
div class="mb-2" {
"Module Kind: " strong { (kind.to_string()) }
}
} @else {
div class="alert alert-warning mb-2" {
"Unknown Module Kind"
}
}
div class="mb-2" {
"Module Item: " code { (module_item.to_string()) }
}
}
}
}
ConsensusItem::Default { variant, bytes } => {
html! {
div class="consensus-item-details" {
div class="alert alert-warning mb-2" {
"Unknown Consensus Item Type (variant " (variant) ")"
}
div class="mb-2" {
"Size: " (bytes.len()) " bytes"
}
@if !bytes.is_empty() {
details {
summary { "Raw Data (Hex)" }
div class="mt-2" {
code class="user-select-all" style="word-break: break-all;" {
(hex::encode(bytes))
}
}
}
}
}
}
}
}
}