From f682f0af01a2c4753967b008b163ef7a96d7ae7a Mon Sep 17 00:00:00 2001 From: Samuel Leathers Date: Sat, 16 Jan 2021 01:02:19 -0500 Subject: [PATCH] call unSlotNo on slotNo to get raw integer value --- src/Cardano/CLI/Query.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Cardano/CLI/Query.hs b/src/Cardano/CLI/Query.hs index f53be94..48af651 100644 --- a/src/Cardano/CLI/Query.hs +++ b/src/Cardano/CLI/Query.hs @@ -28,6 +28,8 @@ import Database.Persist.Postgresql (Entity, IsolationLevel (Serializab SqlPersistT, rawSql, runSqlConnWithIsolation) import System.IO (hPutStr, hPutStrLn, stderr) +import Ouroboros.Network.Block (unSlotNo) + import Cardano.API (SlotNo) import qualified Cardano.API as Api import Cardano.API.Extended (VotingKeyPublic, serialiseToBech32') @@ -94,14 +96,14 @@ queryStake mSlotRestriction stakeHash = do -- Get first tx is slot after one we've asked to restrict the -- query to, we don't want to get this Tx or any later Txs. let - firstUnwantedTxIdSql = "SELECT tx.id FROM tx LEFT OUTER JOIN block ON block.id = tx.block_id WHERE block.slot_no > " <> T.pack (show slotNo) <> " LIMIT 1"; + firstUnwantedTxIdSql = "SELECT tx.id FROM tx LEFT OUTER JOIN block ON block.id = tx.block_id WHERE block.slot_no > " <> T.pack (show $ unSlotNo slotNo) <> " LIMIT 1"; (txids :: [Single Word64]) <- (flip runReaderT) r $ rawSql firstUnwantedTxIdSql [] case txids of [] -> error $ "No txs found in slot " <> show (slotNo + 1)-- TODO throwError (_NoTxsFoundInSlot # (slotNo + 1)) x1:(x2:xs) -> error $ "Too many txs found for slot " <> show slotNo <> ", add 'LIMIT 1' to query." (Single txid):[] -> - pure $ "SELECT SUM(tx_out.value) FROM tx_out INNER JOIN tx ON tx.id = tx_out.tx_id LEFT OUTER JOIN tx_in ON tx_out.tx_id = tx_in.tx_out_id AND tx_out.index = tx_in.tx_out_index AND tx_in_id < " <> T.pack (show txid) <> " INNER JOIN block ON block.id = tx.block_id AND block.slot_no < " <> T.pack (show slotNo) <> " WHERE CAST(encode(address_raw, 'hex') AS text) LIKE '%" <> stkHashSql <> "' AND tx_in.tx_in_id is null;" + pure $ "SELECT SUM(tx_out.value) FROM tx_out INNER JOIN tx ON tx.id = tx_out.tx_id LEFT OUTER JOIN tx_in ON tx_out.tx_id = tx_in.tx_out_id AND tx_out.index = tx_in.tx_out_index AND tx_in_id < " <> T.pack (show txid) <> " INNER JOIN block ON block.id = tx.block_id AND block.slot_no < " <> T.pack (show $ unSlotNo slotNo) <> " WHERE CAST(encode(address_raw, 'hex') AS text) LIKE '%" <> stkHashSql <> "' AND tx_in.tx_in_id is null;" (stakeValues :: [Single (Maybe DbLovelace)]) <- (flip runReaderT) r $ rawSql stakeQuerySql [] case stakeValues of @@ -222,7 +224,7 @@ queryVoteRegistration mSlotNo = in do let sql = case mSlotNo of - Just slot -> (sqlBase <> "INNER JOIN block ON block.id = tx.block_id WHERE block.slot_no < " <> T.pack (show slot) <> ";") + Just slot -> (sqlBase <> "INNER JOIN block ON block.id = tx.block_id WHERE block.slot_no < " <> T.pack (show $ unSlotNo slot) <> ";") Nothing -> (sqlBase <> ";") r <- ask (results :: [(Single ByteString, Single TxId, Single (Maybe Text), Single (Maybe Text))]) <- (flip runReaderT) r $ rawSql sql []