Skip to content

Commit 698ffde

Browse files
authored
Merge pull request #2037 from IntersectMBO/erikd/fix-balance-report-2031
Fix queryOutput* database value to Ada conversions
2 parents 24fc662 + 0e1c6cc commit 698ffde

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

cardano-db/src/Cardano/Db/Statement/DbTool.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import Cardano.Db.Statement.Function.Core (runSession)
3434
import Cardano.Db.Statement.Function.Query (adaDecoder)
3535
import Cardano.Db.Statement.Types (tableName)
3636
import Cardano.Db.Types (Ada (..), DbLovelace, DbM, dbLovelaceDecoder, lovelaceToAda)
37-
import Data.Fixed (Fixed (..))
3837

3938
------------------------------------------------------------------------------------------------------------
4039
-- DbTool Epcoh
@@ -805,9 +804,9 @@ queryOutputsCoreStmt =
805804
fees <- HsqlD.column (HsqlD.nonNullable HsqlD.int8)
806805
deposit <- HsqlD.column (HsqlD.nonNullable HsqlD.int8)
807806
pure
808-
( lovelaceToAda (MkFixed $ fromIntegral outputs)
809-
, lovelaceToAda (MkFixed $ fromIntegral fees)
810-
, lovelaceToAda (MkFixed $ fromIntegral deposit)
807+
( lovelaceToAda (fromIntegral outputs)
808+
, lovelaceToAda (fromIntegral fees)
809+
, lovelaceToAda (fromIntegral deposit)
811810
)
812811
txOutCoreTable = tableName (Proxy @SVC.TxOutCore)
813812
txTable = tableName (Proxy @SVC.Tx)
@@ -843,9 +842,9 @@ queryOutputsAddressStmt =
843842
fees <- HsqlD.column (HsqlD.nonNullable HsqlD.int8)
844843
deposit <- HsqlD.column (HsqlD.nonNullable HsqlD.int8)
845844
pure
846-
( lovelaceToAda (MkFixed $ fromIntegral outputs)
847-
, lovelaceToAda (MkFixed $ fromIntegral fees)
848-
, lovelaceToAda (MkFixed $ fromIntegral deposit)
845+
( lovelaceToAda (fromIntegral outputs)
846+
, lovelaceToAda (fromIntegral fees)
847+
, lovelaceToAda (fromIntegral deposit)
849848
)
850849
txOutAddressTable = tableName (Proxy @SVA.TxOutAddress)
851850
addressTable = tableName (Proxy @SVA.Address)

cardano-db/src/Cardano/Db/Statement/Function/Query.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
module Cardano.Db.Statement.Function.Query where
1313

1414
import Cardano.Prelude (HasCallStack, Proxy (..), Word64, listToMaybe)
15-
import Data.Fixed (Fixed (..))
1615
import Data.Functor.Contravariant (Contravariant (..))
1716
import qualified Data.List.NonEmpty as NE
1817
import qualified Data.Text as Text
@@ -265,5 +264,5 @@ adaSumDecoder :: HsqlD.Row Ada
265264
adaSumDecoder = do
266265
amount <- HsqlD.column (HsqlD.nullable HsqlD.int8)
267266
case amount of
268-
Just value -> pure $ lovelaceToAda (MkFixed $ fromIntegral value)
267+
Just value -> pure $ lovelaceToAda (fromIntegral value)
269268
Nothing -> pure $ Ada 0

cardano-db/src/Cardano/Db/Types.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,16 +532,16 @@ word128Encoder = fromInteger . toInteger >$< HsqlE.numeric
532532
word128Decoder :: HsqlD.Value Word128
533533
word128Decoder = fromInteger . fromIntegral . coefficient <$> HsqlD.numeric
534534

535-
lovelaceToAda :: Micro -> Ada
535+
lovelaceToAda :: Integer -> Ada
536536
lovelaceToAda ll =
537-
Ada (ll / 1000000)
537+
Ada (fromIntegral ll / 1000000)
538538

539539
renderAda :: Ada -> Text
540540
renderAda (Ada a) = Text.pack (show a)
541541

542542
scientificToAda :: Scientific -> Ada
543543
scientificToAda s =
544-
word64ToAda $ floor (s * 1000000)
544+
lovelaceToAda $ floor (s * 1000000)
545545

546546
word64ToAda :: Word64 -> Ada
547547
word64ToAda w =

0 commit comments

Comments
 (0)