@@ -9,7 +9,6 @@ import Data.Functor.Contravariant ((>$<))
99import qualified Data.Text as Text
1010import qualified Data.Text.Encoding as TextEnc
1111import Data.Time (UTCTime )
12- import Data.WideWord (Word128 (.. ))
1312import qualified Hasql.Decoders as HsqlD
1413import qualified Hasql.Encoders as HsqlE
1514import qualified Hasql.Session as HsqlSes
@@ -23,7 +22,7 @@ import Cardano.Db.Statement.Function.Core (ResultType (..), runSession, runSessi
2322import Cardano.Db.Statement.Function.Insert (insert , insertCheckUnique , insertReplace )
2423import Cardano.Db.Statement.Function.Query (countAll , replace , selectByFieldFirst )
2524import Cardano.Db.Statement.Types (Entity (.. ), tableName )
26- import Cardano.Db.Types (DbLovelace (.. ), DbM )
25+ import Cardano.Db.Types (DbLovelace (.. ), DbM , scientificToWord128 , scientificToWord64 )
2726
2827--------------------------------------------------------------------------------
2928-- CostModel
@@ -129,7 +128,7 @@ queryEpochEntryStmt =
129128 HsqlStmt. Statement sql encoder decoder True
130129 where
131130 encoder = HsqlE. param (HsqlE. nonNullable $ fromIntegral >$< HsqlE. int8)
132- decoder = HsqlD. rowMaybe SEnP. epochDecoder
131+ decoder = HsqlD. rowMaybe (entityVal <$> SEnP. entityEpochDecoder)
133132 sql =
134133 TextEnc. encodeUtf8 $
135134 Text. concat
@@ -185,8 +184,8 @@ queryCalcEpochEntryStmt =
185184 blockCount <- HsqlD. column (HsqlD. nonNullable $ fromIntegral <$> HsqlD. int8)
186185 minTime <- HsqlD. column (HsqlD. nullable utcTimeAsTimestampDecoder)
187186 maxTime <- HsqlD. column (HsqlD. nullable utcTimeAsTimestampDecoder)
188- outSum <- HsqlD. column (HsqlD. nonNullable HsqlD. int8) -- Decode as single int8
189- feeSum <- HsqlD. column (HsqlD. nonNullable HsqlD. int8 )
187+ outSum <- HsqlD. column (HsqlD. nonNullable (scientificToWord128 <$> HsqlD. numeric))
188+ feeSum <- HsqlD. column (HsqlD. nonNullable (scientificToWord64 <$> HsqlD. numeric) )
190189 txCount <- HsqlD. column (HsqlD. nonNullable $ fromIntegral <$> HsqlD. int8)
191190
192191 pure $ case (blockCount, minTime, maxTime) of
@@ -196,8 +195,8 @@ queryCalcEpochEntryStmt =
196195 then convertBlk epochNo (blockCount, Just start, Just end)
197196 else
198197 SEnP. Epoch
199- { SEnP. epochOutSum = Word128 0 ( fromIntegral outSum) -- Construct Word128 from single value
200- , SEnP. epochFees = DbLovelace $ fromIntegral feeSum
198+ { SEnP. epochOutSum = outSum
199+ , SEnP. epochFees = DbLovelace feeSum
201200 , SEnP. epochTxCount = txCount
202201 , SEnP. epochBlkCount = blockCount
203202 , SEnP. epochNo = epochNo
@@ -269,7 +268,7 @@ queryLatestEpochStmt =
269268 , " WHERE no = (SELECT MAX(no) FROM epoch)"
270269 ]
271270
272- decoder = HsqlD. rowMaybe SEnP. epochDecoder
271+ decoder = HsqlD. rowMaybe (entityVal <$> SEnP. entityEpochDecoder)
273272
274273-- | Get the most recent epoch in the Epoch DB table.
275274queryLatestEpoch :: DbM (Maybe SEnP. Epoch )
0 commit comments