Skip to content

Commit 9a2c916

Browse files
committed
Respond to PR feedback
1 parent 1a0e8a8 commit 9a2c916

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

common/examples/test_streaming_parser.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,7 @@ impl SnapshotsCallback for CountingCallbacks {
288288
if !snapshots.mark.0.is_empty() {
289289
eprintln!(" Sample stakes (first 5):");
290290
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-
};
291+
let cred_str = cred.to_string().unwrap_or_default();
299292
eprintln!(
300293
" [{}] {} -> {:.2} ADA",
301294
i + 1,
@@ -312,14 +305,7 @@ impl SnapshotsCallback for CountingCallbacks {
312305
if !snapshots.set.0.is_empty() {
313306
eprintln!(" Sample stakes (first 5):");
314307
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-
};
308+
let cred_str = cred.to_string().unwrap_or_default();
323309
eprintln!(
324310
" [{}] {} -> {:.2} ADA",
325311
i + 1,
@@ -336,14 +322,7 @@ impl SnapshotsCallback for CountingCallbacks {
336322
if !snapshots.go.0.is_empty() {
337323
eprintln!(" Sample stakes (first 5):");
338324
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-
};
325+
let cred_str = cred.to_string().unwrap_or_default();
347326
eprintln!(
348327
" [{}] {} -> {:.2} ADA",
349328
i + 1,

common/src/snapshot/mark_set_go.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ================================================================================================
44

55
use anyhow::{Context, Error, Result};
6-
use log::info;
6+
use log::{error, info};
77

88
use minicbor::Decoder;
99
use serde::Serialize;
@@ -14,6 +14,7 @@ pub use crate::hash::Hash;
1414
use crate::snapshot::pool_params::PoolParams;
1515
use crate::snapshot::streaming_snapshot;
1616
pub use crate::stake_addresses::{AccountState, StakeAddressState};
17+
use crate::PoolId;
1718
pub use crate::StakeCredential;
1819
use crate::{address::StakeAddress, types, NetworkId, PoolRegistration};
1920

@@ -83,9 +84,9 @@ pub struct Snapshot {
8384
/// snapshot_stake: stake distribution map (credential -> lovelace amount)
8485
pub snapshot_stake: VMap<StakeCredential, i64>,
8586
// snapshot_delegations: vmap<credential, key_hash<stake_pool>>,)
86-
pub snapshot_delegations: VMap<StakeCredential, Hash<28>>,
87+
pub snapshot_delegations: VMap<StakeCredential, PoolId>,
8788
// snapshot_pool_params: vmap<key_hash<stake_pool>, pool_params>,
88-
pub snapshot_pool_params: VMap<Hash<28>, PoolRegistration>,
89+
pub snapshot_pool_params: VMap<PoolId, PoolRegistration>,
8990
}
9091

9192
impl Snapshot {
@@ -112,14 +113,14 @@ impl Snapshot {
112113
// Skip delegations (second element)
113114
info!(" {snapshot_name} snapshot - parsing snapshot_delegations...");
114115

115-
let delegations: VMap<StakeCredential, Hash<28>> =
116+
let delegations: VMap<StakeCredential, PoolId> =
116117
decoder.decode().context("Failed to parse snapshot_delegations")?;
117118

118119
info!(
119120
" {snapshot_name} snapshot - parsing snapshot_pool_registration..."
120121
);
121122
// pool_registration (third element)
122-
let pools: VMap<Hash<28>, PoolParams> = decoder
123+
let pools: VMap<PoolId, PoolParams> = decoder
123124
.decode()
124125
.context("Failed to parse snapshot_pool_registration")?;
125126
let registration = VMap(
@@ -130,7 +131,12 @@ impl Snapshot {
130131
// Convert RewardAccount (Vec<u8>) to StakeAddress
131132
let reward_account =
132133
StakeAddress::from_binary(&params.reward_account.0)
133-
.unwrap_or_else(|_| StakeAddress::default());
134+
.unwrap_or_else(|_|
135+
{
136+
error!("Failed to parse reward account for pool {pool_id}, using default");
137+
StakeAddress::default()
138+
}
139+
);
134140

135141
// Convert Set<AddrKeyhash> to Vec<StakeAddress>
136142
let pool_owners: Vec<StakeAddress> = params
@@ -140,7 +146,7 @@ impl Snapshot {
140146
.map(|keyhash| {
141147
StakeAddress::new(
142148
StakeCredential::AddrKeyHash(keyhash),
143-
NetworkId::Mainnet,
149+
NetworkId::Mainnet, // TODO: Make network configurable or get it from parameters
144150
)
145151
})
146152
.collect();

0 commit comments

Comments
 (0)