-
Notifications
You must be signed in to change notification settings - Fork 86
/
Types.hs
53 lines (45 loc) · 1.6 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{-# language DeriveGeneric #-}
module TxIn.Types (
TxIn (..)
, TxOutputIds (..)
, outputTxIns
, Row (..)
, filterRowsForEBBs
) where
import Data.ByteString.Short (ShortByteString)
import Data.Word (Word32, Word64)
import qualified Data.Vector as V
import GHC.Generics (Generic())
import Data.Binary (Binary())
import Data.Foldable(toList)
data TxIn = TxIn !ShortByteString !Word32 -- index
deriving (Eq, Ord, Show, Generic)
instance Binary TxIn
data TxOutputIds = TxOutputIds !ShortByteString !Word32 -- count
deriving (Eq, Ord, Show)
outputTxIns :: TxOutputIds -> [TxIn]
outputTxIns (TxOutputIds h n) = [ TxIn h (i - 1) | i <- [1 .. n] ]
data Row = Row {
rBlockNumber :: {-# UNPACK #-} !Word64
, rSlotNumber :: {-# UNPACK #-} !Word64
, rNumTx :: {-# UNPACK #-} !Int
, rConsumed :: {-# UNPACK #-} !(V.Vector TxIn)
, rCreated :: {-# UNPACK #-} !(V.Vector TxOutputIds)
} deriving (Show)
{-
for some slots in the Byron era there is an addtional psuedo block demarcates the
beginning of the era epoch, it's called an EBB.
It never contains any transactions
-}
filterRowsForEBBs :: [Row] -> [Row]
filterRowsForEBBs = go Nothing where
go mb_x [] = toList mb_x
go Nothing (x: xs) = x : go (Just x) xs
go (Just x) (y: ys)
| rBlockNumber x == rBlockNumber y = if rNumTx y /= 0
then error "EBB block has transactions"
else go Nothing ys
| rSlotNumber x == rSlotNumber y = if rNumTx y /= 0
then error "EBB block has transactions"
else go Nothing ys
| otherwise = y : go (Just y) ys