Skip to content

Commit

Permalink
Add governance action deposits to stake-address-info query
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosLopezDeLara committed Jan 24, 2025
1 parent ac43aa8 commit 2c01812
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,15 @@ runQueryStakeAddressInfoCmd

writeStakeAddressInfo sbe said mOutFile

-- | Container for data returned by 'callQueryStakeAddressInfoCmd'
-- | Container for data returned by 'callQueryStakeAddressInfoCmd' where:
-- rewards: is the map of stake addresses to poolid and rewards balance
-- deposits: is the current the stake address registration deposit
-- gaDeposits: is a map of governance actions and their deposits associated to the reward account
-- delegatees: is a map of stake addresses and their delegation preference
data StakeAddressInfoData = StakeAddressInfoData
{ rewards :: DelegationsAndRewards
, deposits :: Map StakeAddress Lovelace
, gaDeposits :: Map (L.GovActionId L.StandardCrypto) Lovelace
, delegatees :: Map StakeAddress (L.DRep L.StandardCrypto)
}

Expand Down Expand Up @@ -974,13 +979,35 @@ callQueryStakeAddressInfoCmd

stakeDelegDeposits <- easyRunQuery (queryStakeDelegDeposits beo stakeAddr)

stakeVoteDelegatees <- monoidForEraInEonA era $ \ceo ->
easyRunQuery (queryStakeVoteDelegatees ceo stakeAddr)
(stakeVoteDelegatees, gaDeposits) <-
caseShelleyToBabbageOrConwayEraOnwards
(const $ pure (Map.empty, Map.empty))
( \ceo -> do
stakeVoteDelegatees <- easyRunQuery (queryStakeVoteDelegatees ceo stakeAddr)

govActionStates :: (Seq.Seq (L.GovActionState (ShelleyLedgerEra era))) <-
easyRunQuery $ queryProposals ceo Set.empty

let gaDeposits =
conwayEraOnwardsConstraints ceo $
Map.fromList
[ (L.gasId gas, L.pProcDeposit proc)
| gas <- toList govActionStates
, let proc = L.gasProposalProcedure gas
, let rewardAccount = L.pProcReturnAddr proc
stakeCredential :: Api.StakeCredential = fromShelleyStakeCredential $ L.raCredential rewardAccount
, stakeCredential == fromShelleyStakeCredential addr
]

return (stakeVoteDelegatees, gaDeposits)
)
(convert beo)

pure $
StakeAddressInfoData
(DelegationsAndRewards (stakeRewardAccountBalances, stakePools))
(Map.mapKeys (makeStakeAddress networkId) stakeDelegDeposits)
gaDeposits
(Map.mapKeys (makeStakeAddress networkId) stakeVoteDelegatees)
& onLeft (left . QueryCmdAcquireFailure)
& onLeft left
Expand All @@ -997,6 +1024,7 @@ writeStakeAddressInfo
( StakeAddressInfoData
{ rewards = DelegationsAndRewards (stakeAccountBalances, stakePools)
, deposits = stakeDelegDeposits
, gaDeposits = gaDeposits
, delegatees = voteDelegatees
}
)
Expand Down Expand Up @@ -1028,6 +1056,7 @@ writeStakeAddressInfo
, "voteDelegation" .= fmap friendlyDRep mDRep
, "rewardAccountBalance" .= mBalance
, "delegationDeposit" .= mDeposit
, "govActionDeposits" .= gaDeposits
]
)
merged
Expand Down

0 comments on commit 2c01812

Please sign in to comment.