Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cardano-db/src/Cardano/Db/Statement/DbTool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Cardano.Db.Statement.Function.Core (runSession)
import Cardano.Db.Statement.Function.Query (adaDecoder)
import Cardano.Db.Statement.Types (tableName)
import Cardano.Db.Types (Ada (..), DbLovelace, DbM, dbLovelaceDecoder, lovelaceToAda)
import Data.Fixed (Fixed (..))

------------------------------------------------------------------------------------------------------------
-- DbTool Epcoh
Expand Down Expand Up @@ -805,9 +804,9 @@ queryOutputsCoreStmt =
fees <- HsqlD.column (HsqlD.nonNullable HsqlD.int8)
deposit <- HsqlD.column (HsqlD.nonNullable HsqlD.int8)
pure
( lovelaceToAda (MkFixed $ fromIntegral outputs)
, lovelaceToAda (MkFixed $ fromIntegral fees)
, lovelaceToAda (MkFixed $ fromIntegral deposit)
( lovelaceToAda (fromIntegral outputs)
, lovelaceToAda (fromIntegral fees)
, lovelaceToAda (fromIntegral deposit)
)
txOutCoreTable = tableName (Proxy @SVC.TxOutCore)
txTable = tableName (Proxy @SVC.Tx)
Expand Down Expand Up @@ -843,9 +842,9 @@ queryOutputsAddressStmt =
fees <- HsqlD.column (HsqlD.nonNullable HsqlD.int8)
deposit <- HsqlD.column (HsqlD.nonNullable HsqlD.int8)
pure
( lovelaceToAda (MkFixed $ fromIntegral outputs)
, lovelaceToAda (MkFixed $ fromIntegral fees)
, lovelaceToAda (MkFixed $ fromIntegral deposit)
( lovelaceToAda (fromIntegral outputs)
, lovelaceToAda (fromIntegral fees)
, lovelaceToAda (fromIntegral deposit)
)
txOutAddressTable = tableName (Proxy @SVA.TxOutAddress)
addressTable = tableName (Proxy @SVA.Address)
Expand Down
3 changes: 1 addition & 2 deletions cardano-db/src/Cardano/Db/Statement/Function/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module Cardano.Db.Statement.Function.Query where

import Cardano.Prelude (HasCallStack, Proxy (..), Word64, listToMaybe)
import Data.Fixed (Fixed (..))
import Data.Functor.Contravariant (Contravariant (..))
import qualified Data.List.NonEmpty as NE
import qualified Data.Text as Text
Expand Down Expand Up @@ -265,5 +264,5 @@ adaSumDecoder :: HsqlD.Row Ada
adaSumDecoder = do
amount <- HsqlD.column (HsqlD.nullable HsqlD.int8)
case amount of
Just value -> pure $ lovelaceToAda (MkFixed $ fromIntegral value)
Just value -> pure $ lovelaceToAda (fromIntegral value)
Nothing -> pure $ Ada 0
6 changes: 3 additions & 3 deletions cardano-db/src/Cardano/Db/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -532,16 +532,16 @@ word128Encoder = fromInteger . toInteger >$< HsqlE.numeric
word128Decoder :: HsqlD.Value Word128
word128Decoder = fromInteger . fromIntegral . coefficient <$> HsqlD.numeric

lovelaceToAda :: Micro -> Ada
lovelaceToAda :: Integer -> Ada
lovelaceToAda ll =
Ada (ll / 1000000)
Ada (fromIntegral ll / 1000000)

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

scientificToAda :: Scientific -> Ada
scientificToAda s =
word64ToAda $ floor (s * 1000000)
lovelaceToAda $ floor (s * 1000000)

word64ToAda :: Word64 -> Ada
word64ToAda w =
Expand Down
Loading