Skip to content

Commit dcc189f

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 dcc189f

File tree

3 files changed

+234
-142
lines changed

3 files changed

+234
-142
lines changed

common/examples/test_streaming_parser.rs

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,28 +275,88 @@ 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 = match cred {
292+
acropolis_common::StakeCredential::AddrKeyHash(h) => {
293+
format!("KeyHash({}...)", &hex::encode(&h[..4]))
294+
}
295+
acropolis_common::StakeCredential::ScriptHash(h) => {
296+
format!("ScriptHash({}...)", &hex::encode(&h[..4]))
297+
}
298+
};
299+
eprintln!(
300+
" [{}] {} -> {:.2} ADA",
301+
i + 1,
302+
cred_str,
303+
*amount as f64 / 1_000_000.0
304+
);
305+
}
306+
}
307+
eprintln!();
308+
309+
eprintln!("Set Snapshot:");
310+
eprintln!(" Delegators: {}", snapshots.set.0.len());
311+
eprintln!(" Total stake: {:.2} ADA", set_total as f64 / 1_000_000.0);
312+
if !snapshots.set.0.is_empty() {
313+
eprintln!(" Sample stakes (first 5):");
314+
for (i, (cred, amount)) in snapshots.set.0.iter().take(5).enumerate() {
315+
let cred_str = match cred {
316+
acropolis_common::StakeCredential::AddrKeyHash(h) => {
317+
format!("KeyHash({}...)", &hex::encode(&h[..4]))
318+
}
319+
acropolis_common::StakeCredential::ScriptHash(h) => {
320+
format!("ScriptHash({}...)", &hex::encode(&h[..4]))
321+
}
322+
};
323+
eprintln!(
324+
" [{}] {} -> {:.2} ADA",
325+
i + 1,
326+
cred_str,
327+
*amount as f64 / 1_000_000.0
328+
);
329+
}
330+
}
331+
eprintln!();
332+
333+
eprintln!("Go Snapshot:");
334+
eprintln!(" Delegators: {}", snapshots.go.0.len());
335+
eprintln!(" Total stake: {:.2} ADA", go_total as f64 / 1_000_000.0);
336+
if !snapshots.go.0.is_empty() {
337+
eprintln!(" Sample stakes (first 5):");
338+
for (i, (cred, amount)) in snapshots.go.0.iter().take(5).enumerate() {
339+
let cred_str = match cred {
340+
acropolis_common::StakeCredential::AddrKeyHash(h) => {
341+
format!("KeyHash({}...)", &hex::encode(&h[..4]))
342+
}
343+
acropolis_common::StakeCredential::ScriptHash(h) => {
344+
format!("ScriptHash({}...)", &hex::encode(&h[..4]))
345+
}
346+
};
347+
eprintln!(
348+
" [{}] {} -> {:.2} ADA",
349+
i + 1,
350+
cred_str,
351+
*amount as f64 / 1_000_000.0
352+
);
353+
}
354+
}
355+
eprintln!();
356+
357+
eprintln!("Fee: {:.2} ADA", snapshots.fee as f64 / 1_000_000.0);
358+
eprintln!();
359+
300360
Ok(())
301361
}
302362
}

0 commit comments

Comments
 (0)