Skip to content

Simplify by not using QueryStakeAddressInfoCmdArgs unnecessarily #1184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
55 changes: 28 additions & 27 deletions cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,13 @@ runQueryStakeAddressInfoCmd
=> Cmd.QueryStakeAddressInfoCmdArgs
-> ExceptT QueryCmdError IO ()
runQueryStakeAddressInfoCmd
cmd@Cmd.QueryStakeAddressInfoCmdArgs
Cmd.QueryStakeAddressInfoCmdArgs
{ Cmd.commons =
Cmd.QueryCommons
commons@Cmd.QueryCommons
{ Cmd.nodeConnInfo
, Cmd.target
}
, Cmd.addr
, Cmd.outputFormat
, Cmd.mOutFile
} = do
Expand All @@ -978,11 +979,11 @@ runQueryStakeAddressInfoCmd
& onLeft (left . QueryCmdUnsupportedNtcVersion)
sbe <- requireShelleyBasedEra era & onNothing (left QueryCmdByronEra)

said <- callQueryStakeAddressInfoCmd cmd
said <- getQueryStakeAddressInfo commons addr

writeStakeAddressInfo sbe said outputFormat mOutFile

-- | Container for data returned by 'callQueryStakeAddressInfoCmd' where:
-- | Container for data returned by 'getQueryStakeAddressInfo' where:
data StakeAddressInfoData = StakeAddressInfoData
{ rewards :: DelegationsAndRewards
-- ^ Rewards: map of stake addresses to pool ID and rewards balance.
Expand All @@ -995,19 +996,16 @@ data StakeAddressInfoData = StakeAddressInfoData
-- ^ Delegatees: map of stake addresses and their vote delegation preference.
}

callQueryStakeAddressInfoCmd
:: ()
=> Cmd.QueryStakeAddressInfoCmdArgs
getQueryStakeAddressInfo
:: Cmd.QueryCommons
-> StakeAddress
-> ExceptT QueryCmdError IO StakeAddressInfoData
callQueryStakeAddressInfoCmd
Cmd.QueryStakeAddressInfoCmdArgs
{ Cmd.commons =
Cmd.QueryCommons
{ Cmd.nodeConnInfo = nodeConnInfo@LocalNodeConnectInfo{localNodeNetworkId = networkId}
, Cmd.target
}
, Cmd.addr = StakeAddress _ addr
} =
getQueryStakeAddressInfo
Cmd.QueryCommons
{ Cmd.nodeConnInfo = nodeConnInfo@LocalNodeConnectInfo{localNodeNetworkId = networkId}
, Cmd.target
}
(StakeAddress _ addr) =
do
lift $ executeLocalStateQueryExpr nodeConnInfo target $ runExceptT $ do
AnyCardanoEra era <- easyRunQueryCurrentEra
Expand Down Expand Up @@ -1835,19 +1833,11 @@ runQuerySPOStakeDistribution
| (keyHash, addr) <- Map.toList $ L.psStakePoolParams poolState
]

mkQueryStakeAddressInfoCmdArgs addr =
Cmd.QueryStakeAddressInfoCmdArgs
{ Cmd.commons = commons
, addr
, outputFormat
, mOutFile -- unused anyway. TODO tighten this by removing the field.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both outputFormat and mOutFile are unused by callQueryStakeAddressInfoCmd, so don't bother using QueryStakeAddressInfoCmdArgs and packing unnecessary fields.

}

spoToDelegatee <-
Map.fromList . concat
<$> traverse
( \stakeAddr -> do
info <- callQueryStakeAddressInfoCmd $ mkQueryStakeAddressInfoCmdArgs stakeAddr
info <- getQueryStakeAddressInfo commons stakeAddr
return $
[ (spo, delegatee)
| (Just spo, delegatee) <-
Expand All @@ -1856,15 +1846,26 @@ runQuerySPOStakeDistribution
)
(Map.keys addressesAndRewards)

let toWrite =
let json =
[ ( spo
, coin
, Map.lookup spo spoToDelegatee
)
| (spo, coin) <- Map.assocs spoStakeDistribution
]

writeOutput mOutFile toWrite
output =
outputFormat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now respect the output format of the query spo-stake-distribution command.

& ( id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this id to get alignment from the formatter? I don't think it has any effect on the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is purely for alignment purposes.

. Vary.on (\FormatJson -> Json.encodeJson)
. Vary.on (\FormatYaml -> Json.encodeYaml)
$ Vary.exhaustiveCase
)
$ json

firstExceptT QueryCmdWriteFileError
. newExceptT
$ writeLazyByteStringOutput mOutFile output

runQueryCommitteeMembersState
:: Cmd.QueryCommitteeMembersStateCmdArgs era
Expand Down
Loading