Skip to content

Commit 9aa7f0a

Browse files
committed
Implement snapshot parser for snapshot delegation and pool registration
* Implemented parser and type conversions for pool registration * Parsing delegations * Add logging output for new snapshot data to the test example
1 parent 6b4a449 commit 9aa7f0a

File tree

3 files changed

+220
-143
lines changed

3 files changed

+220
-143
lines changed

common/examples/test_streaming_parser.rs

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,28 +275,67 @@ impl SnapshotCallbacks for CountingCallbacks {
275275
impl SnapshotsCallback for CountingCallbacks {
276276
fn on_snapshots(&mut self, snapshots: RawSnapshotsContainer) -> Result<()> {
277277
eprintln!("Raw Snapshots Data:");
278+
eprintln!();
278279

279280
// Calculate total stakes and delegator counts from VMap data
280281
let mark_total: i64 = snapshots.mark.0.iter().map(|(_, amount)| amount).sum();
281282
let set_total: i64 = snapshots.set.0.iter().map(|(_, amount)| amount).sum();
282283
let go_total: i64 = snapshots.go.0.iter().map(|(_, amount)| amount).sum();
283284

284-
eprintln!(
285-
" Mark snapshot: {} delegators, {} total stake (ADA)",
286-
snapshots.mark.0.len(),
287-
mark_total as f64 / 1_000_000.0
288-
);
289-
eprintln!(
290-
" Set snapshot: {} delegators, {} total stake (ADA)",
291-
snapshots.set.0.len(),
292-
set_total as f64 / 1_000_000.0
293-
);
294-
eprintln!(
295-
" Go snapshot: {} delegators, {} total stake (ADA)",
296-
snapshots.go.0.len(),
297-
go_total as f64 / 1_000_000.0
298-
);
299-
eprintln!(" Fee: {} ADA", snapshots.fee as f64 / 1_000_000.0);
285+
eprintln!("Mark Snapshot:");
286+
eprintln!(" Delegators: {}", snapshots.mark.0.len());
287+
eprintln!(" Total stake: {:.2} ADA", mark_total as f64 / 1_000_000.0);
288+
if !snapshots.mark.0.is_empty() {
289+
eprintln!(" Sample stakes (first 5):");
290+
for (i, (cred, amount)) in snapshots.mark.0.iter().take(5).enumerate() {
291+
let cred_str = cred.to_string().unwrap_or_default();
292+
eprintln!(
293+
" [{}] {} -> {:.2} ADA",
294+
i + 1,
295+
cred_str,
296+
*amount as f64 / 1_000_000.0
297+
);
298+
}
299+
}
300+
eprintln!();
301+
302+
eprintln!("Set Snapshot:");
303+
eprintln!(" Delegators: {}", snapshots.set.0.len());
304+
eprintln!(" Total stake: {:.2} ADA", set_total as f64 / 1_000_000.0);
305+
if !snapshots.set.0.is_empty() {
306+
eprintln!(" Sample stakes (first 5):");
307+
for (i, (cred, amount)) in snapshots.set.0.iter().take(5).enumerate() {
308+
let cred_str = cred.to_string().unwrap_or_default();
309+
eprintln!(
310+
" [{}] {} -> {:.2} ADA",
311+
i + 1,
312+
cred_str,
313+
*amount as f64 / 1_000_000.0
314+
);
315+
}
316+
}
317+
eprintln!();
318+
319+
eprintln!("Go Snapshot:");
320+
eprintln!(" Delegators: {}", snapshots.go.0.len());
321+
eprintln!(" Total stake: {:.2} ADA", go_total as f64 / 1_000_000.0);
322+
if !snapshots.go.0.is_empty() {
323+
eprintln!(" Sample stakes (first 5):");
324+
for (i, (cred, amount)) in snapshots.go.0.iter().take(5).enumerate() {
325+
let cred_str = cred.to_string().unwrap_or_default();
326+
eprintln!(
327+
" [{}] {} -> {:.2} ADA",
328+
i + 1,
329+
cred_str,
330+
*amount as f64 / 1_000_000.0
331+
);
332+
}
333+
}
334+
eprintln!();
335+
336+
eprintln!("Fee: {:.2} ADA", snapshots.fee as f64 / 1_000_000.0);
337+
eprintln!();
338+
300339
Ok(())
301340
}
302341
}

0 commit comments

Comments
 (0)