Skip to content

Commit 23a5138

Browse files
committed
fix(cardano-blockchain-types): time_to_slot calculation
Signed-off-by: bkioshn <[email protected]>
1 parent f3871a8 commit 23a5138

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

rust/cardano-blockchain-types/src/network.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,25 @@ impl Network {
185185
return None;
186186
}
187187

188-
let elapsed_slots = if time < shelley_start_time {
188+
let (elapsed_slots, era_known_slot) = if time < shelley_start_time {
189189
// Byron era
190190
let time_diff = time - byron_start_time;
191-
time_diff.num_seconds() / i64::from(genesis.byron_slot_length)
191+
(
192+
time_diff.num_seconds() / i64::from(genesis.byron_slot_length),
193+
genesis.byron_known_slot,
194+
)
192195
} else {
193196
// Shelley era
194197
let time_diff = time - shelley_start_time;
195-
time_diff.num_seconds() / i64::from(genesis.shelley_slot_length)
198+
(
199+
time_diff.num_seconds() / i64::from(genesis.shelley_slot_length),
200+
genesis.shelley_known_slot,
201+
)
196202
};
197-
Some(Slot::from_saturating(elapsed_slots))
203+
204+
let era_known_slot = i64::try_from(era_known_slot).ok()?;
205+
206+
Some(Slot::from_saturating(elapsed_slots + era_known_slot))
198207
}
199208
}
200209

0 commit comments

Comments
 (0)