Skip to content

Commit

Permalink
Make query stake-address-info callable programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc authored and CarlosLopezDeLara committed Dec 20, 2024
1 parent c4ab625 commit f477420
Showing 1 changed file with 48 additions and 16 deletions.
64 changes: 48 additions & 16 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,40 @@ runQueryStakeAddressInfoCmd
=> Cmd.QueryStakeAddressInfoCmdArgs
-> ExceptT QueryCmdError IO ()
runQueryStakeAddressInfoCmd
cmd@Cmd.QueryStakeAddressInfoCmdArgs
{ Cmd.commons =
Cmd.QueryCommons
{ Cmd.nodeSocketPath
, Cmd.consensusModeParams
, Cmd.networkId
, Cmd.target
}
, Cmd.mOutFile
} = do
let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath
AnyCardanoEra era <-
firstExceptT
QueryCmdAcquireFailure
(newExceptT $ executeLocalStateQueryExpr localNodeConnInfo target queryCurrentEra)
& onLeft (left . QueryCmdUnsupportedNtcVersion)
sbe <- requireShelleyBasedEra era & onNothing (left QueryCmdByronEra)

said <- callQueryStakeAddressInfoCmd cmd

writeStakeAddressInfo sbe said mOutFile

-- | Container for data returned by 'callQueryStakeAddressInfoCmd'
data StakeAddressInfoData = StakeAddressInfoData
{ rewards :: DelegationsAndRewards
, deposits :: Map StakeAddress Lovelace
, delegatees :: Map StakeAddress (L.DRep L.StandardCrypto)
}

callQueryStakeAddressInfoCmd
:: ()
=> Cmd.QueryStakeAddressInfoCmdArgs
-> ExceptT QueryCmdError IO StakeAddressInfoData
callQueryStakeAddressInfoCmd
Cmd.QueryStakeAddressInfoCmdArgs
{ Cmd.commons =
Cmd.QueryCommons
Expand Down Expand Up @@ -908,13 +942,12 @@ runQueryStakeAddressInfoCmd
stakeVoteDelegatees <- monoidForEraInEonA era $ \ceo ->
easyRunQuery (queryStakeVoteDelegatees ceo stakeAddr)

return $ do
writeStakeAddressInfo
sbe
mOutFile
(DelegationsAndRewards (stakeRewardAccountBalances, stakePools))
(Map.mapKeys (makeStakeAddress networkId) stakeDelegDeposits)
(Map.mapKeys (makeStakeAddress networkId) stakeVoteDelegatees)
return $
return $
StakeAddressInfoData
(DelegationsAndRewards (stakeRewardAccountBalances, stakePools))
(Map.mapKeys (makeStakeAddress networkId) stakeDelegDeposits)
(Map.mapKeys (makeStakeAddress networkId) stakeVoteDelegatees)
)
& onLeft (left . QueryCmdAcquireFailure)
& onLeft left
Expand All @@ -923,19 +956,18 @@ runQueryStakeAddressInfoCmd

writeStakeAddressInfo
:: ShelleyBasedEra era
-> StakeAddressInfoData
-> Maybe (File () Out)
-> DelegationsAndRewards
-> Map StakeAddress Lovelace
-- ^ deposits
-> Map StakeAddress (L.DRep L.StandardCrypto)
-- ^ vote delegatees
-> ExceptT QueryCmdError IO ()
writeStakeAddressInfo
sbe
mOutFile
(DelegationsAndRewards (stakeAccountBalances, stakePools))
stakeDelegDeposits
voteDelegatees =
( StakeAddressInfoData
{ rewards = DelegationsAndRewards (stakeAccountBalances, stakePools)
, deposits = stakeDelegDeposits
, delegatees = voteDelegatees
}
)
mOutFile =
firstExceptT QueryCmdWriteFileError . newExceptT $
writeLazyByteStringOutput mOutFile (encodePretty $ jsonInfo sbe)
where
Expand Down

0 comments on commit f477420

Please sign in to comment.