|
3 | 3 | {-# LANGUAGE DataKinds #-} |
4 | 4 | {-# LANGUAGE FlexibleContexts #-} |
5 | 5 | {-# LANGUAGE GADTs #-} |
6 | | -{-# LANGUAGE OverloadedStrings #-} |
7 | 6 | {-# LANGUAGE ScopedTypeVariables #-} |
8 | 7 | {-# LANGUAGE TupleSections #-} |
9 | 8 | {-# LANGUAGE TypeOperators #-} |
@@ -46,12 +45,13 @@ import Prelude (id) |
46 | 45 | data StakeSliceRes |
47 | 46 | = Slice !StakeSlice !Bool -- True if this is the final slice for this epoch. Can be used for logging. |
48 | 47 | | NoSlices |
| 48 | + deriving (Show) |
49 | 49 |
|
50 | 50 | data StakeSlice = StakeSlice |
51 | 51 | { sliceEpochNo :: !EpochNo |
52 | 52 | , sliceDistr :: !(Map StakeCred (Coin, PoolKeyHash)) |
53 | 53 | } |
54 | | - deriving (Eq) |
| 54 | + deriving (Show, Eq) |
55 | 55 |
|
56 | 56 | emptySlice :: EpochNo -> StakeSlice |
57 | 57 | emptySlice epoch = StakeSlice epoch Map.empty |
@@ -95,11 +95,13 @@ genericStakeSlice :: |
95 | 95 | LedgerState (ShelleyBlock p era) -> |
96 | 96 | Bool -> |
97 | 97 | StakeSliceRes |
98 | | -genericStakeSlice pInfo epochBlockNo lstate isMigration |
99 | | - | index > delegationsLen = NoSlices |
100 | | - | index == delegationsLen = Slice (emptySlice epoch) True |
101 | | - | index + size > delegationsLen = Slice (mkSlice (delegationsLen - index)) True |
102 | | - | otherwise = Slice (mkSlice size) False |
| 98 | +genericStakeSlice pInfo epochBlockNo lstate isMigration = do |
| 99 | + case compare index delegationsLen of |
| 100 | + GT -> NoSlices |
| 101 | + EQ -> Slice (emptySlice epoch) True |
| 102 | + LT -> case compare (index + size) delegationsLen of |
| 103 | + GT -> Slice (mkSlice (delegationsLen - index)) True |
| 104 | + _otherwise -> Slice (mkSlice size) False |
103 | 105 | where |
104 | 106 | epoch :: EpochNo |
105 | 107 | epoch = EpochNo $ 1 + unEpochNo (Shelley.nesEL (Consensus.shelleyLedgerState lstate)) |
@@ -149,10 +151,10 @@ genericStakeSlice pInfo epochBlockNo lstate isMigration |
149 | 151 |
|
150 | 152 | -- The starting index of the data in the delegation vector. |
151 | 153 | index :: Word64 |
152 | | - index |
153 | | - | isMigration = 0 |
154 | | - | epochBlockNo < k = delegationsLen + 1 -- so it creates the empty Slice. |
155 | | - | otherwise = (epochBlockNo - k) * epochSliceSize |
| 154 | + index = |
| 155 | + if isMigration |
| 156 | + then 0 |
| 157 | + else (epochBlockNo - k) * epochSliceSize |
156 | 158 |
|
157 | 159 | size :: Word64 |
158 | 160 | size |
|
0 commit comments