Skip to content

Commit

Permalink
Same output
Browse files Browse the repository at this point in the history
  • Loading branch information
sevanspowell committed Jan 14, 2021
1 parent dfa2b2c commit acb3741
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -19,3 +19,6 @@ style: ## Apply stylish-haskell on all *.hs files

test-integration:
nix-build -A integration-tests

test:
nix-build default.nix -A haskellPackages.voting-tools.checks.unit-tests
16 changes: 11 additions & 5 deletions src/Cardano/CLI/Query.hs
Expand Up @@ -120,20 +120,26 @@ queryVoteRegistrationInfo
-> m (Contributions VotingKeyPublic (Api.Hash Api.StakeKey) Integer)
queryVoteRegistrationInfo mSlotNo (Api.Lovelace threshold) = do
regos <- queryVoteRegistration mSlotNo
liftIO $ putStrLn $ show $ length regos

let
-- Each stake key has one public voting key it can stake to
xs :: Map (Api.Hash Api.StakeKey) VotingKeyPublic
xs = foldMap (\(_txid, rego) ->
xs = fmap snd $ foldl' (\acc (txid, rego) ->
let
verKeyHash = getStakeHash . voteRegistrationVerificationKey $ rego
votePub = voteRegistrationPublicKey rego
in
M.insert verKeyHash votePub mempty
) regos
case M.lookup verKeyHash acc of
Nothing -> M.insert verKeyHash (txid, votePub) acc
Just (t, v) -> if txid >= t
then M.insert verKeyHash (txid, votePub) acc
else acc
) mempty regos

liftIO $ putStrLn $ show $ length xs

fmap mconcat $ forM (M.toList xs) (\(verKeyHash, votepub) -> do
fmap mconcat $ forM (M.toList $ xs) (\(verKeyHash, votepub) -> do
(Api.Lovelace stake) <- queryStake mSlotNo verKeyHash

pure $
Expand Down Expand Up @@ -211,7 +217,7 @@ queryVoteRegistration mSlotNo =
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) <> ";")
Nothing -> (sqlBase <> "LIMIT 100;")
Nothing -> (sqlBase <> ";")
r <- ask
(results :: [(Single ByteString, Single TxId, Single (Maybe Text), Single (Maybe Text))]) <- (flip runReaderT) r $ rawSql sql []
forM results $ \(Single txHash, Single txId, Single mMetadata, Single mSignature) -> do
Expand Down
2 changes: 1 addition & 1 deletion src/Main.hs
Expand Up @@ -32,7 +32,7 @@ import Cardano.API.Extended (readEnvSocketPath)
import Cardano.CLI.Fetching (Fund, chunkFund, fundFromVotingFunds)
import Cardano.CLI.Query (MetadataError)
import qualified Cardano.CLI.Query as Query
import Cardano.CLI.Voting (createVoteRegistration, encodeVote, prettyTx, signTx)
import Cardano.CLI.Voting (createVoteRegistration, encodeVoteRegistration, prettyTx, signTx)
import Cardano.CLI.Voting.Error (AppError)
import Cardano.CLI.Voting.Metadata (voteSignature)
import Cardano.CLI.Voting.Signing (verificationKeyRawBytes)
Expand Down

0 comments on commit acb3741

Please sign in to comment.