From d63d85efdc9da7f7efed091b3004b01c37fbc05f Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara Date: Mon, 22 Apr 2024 12:14:06 -0600 Subject: [PATCH] update jq filters to work with the latest schema of gov state --- docs/tutorials/jq-filters.mdx | 56 +++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/docs/tutorials/jq-filters.mdx b/docs/tutorials/jq-filters.mdx index ea784f28..25f494a9 100644 --- a/docs/tutorials/jq-filters.mdx +++ b/docs/tutorials/jq-filters.mdx @@ -43,8 +43,9 @@ cardano-cli conway query gov-state --testnet-magic 4 \ cardano-cli conway query gov-state --testnet-magic 4 | jq -r ' .proposals | to_entries[] - | {govActionId: .key, type: .value.action.tag, drepVoteCount: (.value.dRepVotes | keys | length)} + | {govActionId: .value.actionId, type: .value.proposalProcedure.govAction.tag, drepVoteCount: (.value.dRepVotes | keys | length)} ' | jq -s 'sort_by(.voteCount) | reverse[]' + ``` ### Sort by the number of SPO votes: @@ -53,7 +54,7 @@ cardano-cli conway query gov-state --testnet-magic 4 | jq -r ' cardano-cli conway query gov-state --testnet-magic 4 | jq -r ' .proposals | to_entries[] - | {govActionId: .key, type: .value.action.tag, spoVoteCount: (.value.stakePoolVotes | keys | length)} + | {govActionId: .value.actionId, type: .value.proposalProcedure.govAction.tag, spoVoteCount: (.value.stakePoolVotes | keys | length)} ' | jq -s 'sort_by(.voteCount) | reverse[]' ``` @@ -63,9 +64,8 @@ cardano-cli conway query gov-state --testnet-magic 4 | jq -r ' cardano-cli conway query gov-state --testnet-magic 4 | jq -r ' .proposals | to_entries[] - | {govActionId: .key, ccVoteCount: (.value.committeeVotes | keys | length)} + | {govActionId: .value.actionId, type: .value.proposalProcedure.govAction.tag, ccVoteCount: (.value.committeeVotes | keys | length)} ' | jq -s 'sort_by(.voteCount) | reverse[]' - ``` ### Filter actions that expire within the current and the next two epochs, including information about all roles' votes, sorted by expiration epoch: @@ -80,8 +80,8 @@ cardano-cli conway query gov-state --testnet-magic 4 | jq -r --argjson current_e | to_entries[] | select(.value.expiresAfter >= ($current_epoch | tonumber) and .value.expiresAfter <= ($current_epoch + 2)) | { - govActionId: .key, - type: .value.action.tag, + govActionId: .value.actionId, + type: .value.proposalProcedure.govAction.tag, expiresAfter: .value.expiresAfter, committeeVotesCount: (.value.committeeVotes | length), dRepVotesCount: (.value.dRepVotes | length), @@ -93,16 +93,17 @@ cardano-cli conway query gov-state --testnet-magic 4 | jq -r --argjson current_e ### Show actions for which a specific DRep key has voted, indicating the DRep's vote and the total number of votes received for this action: -Replace `058b60ead63f667c0ff5b40e269dd1f05ce3a804256735ad4eddce20` with the hex DRep ID of your interest. +Replace `keyHash-0e7d17c8a917eaee361924d6471331128b3e0de5323f54d70dd0c8c9` with the hex DRep ID of your interest, if it is a script based DRRep, make sure +to use `scriptHash` instead of `keyHash` prefix. ``` -cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg dRepKey "keyHash-058b60ead63f667c0ff5b40e269dd1f05ce3a804256735ad4eddce20" ' +cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg dRepKey "keyHash-0e7d17c8a917eaee361924d6471331128b3e0de5323f54d70dd0c8c9" ' .proposals | to_entries[] | select(.value.dRepVotes[$dRepKey] != null) | { - govActionId: .key, - type: .value.action.tag, + govActionId: .value.actionId, + type: .value.proposalProcedure.govAction.tag, dRepVote: .value.dRepVotes[$dRepKey], expiresAfter: .value.expiresAfter, committeeVotesCount: (.value.committeeVotes | length), @@ -117,13 +118,13 @@ cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg dRepKey "keyH Replace `058b60ead63f667c0ff5b40e269dd1f05ce3a804256735ad4eddce20` with the hex DRep ID of your interest. ``` -cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg dRepKey "keyHash-058b60ead63f667c0ff5b40e269dd1f05ce3a804256735ad4eddce20" ' +cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg dRepKey "keyHash-0e7d17c8a917eaee361924d6471331128b3e0de5323f54d70dd0c8c9" ' .proposals | to_entries[] | select(.value.dRepVotes[$dRepKey] == null) | { - govActionId: .key, - type: .value.action.tag, + govActionId: .value.actionId, + type: .value.proposalProcedure.govAction.tag, expiresAfter: .value.expiresAfter, committeeVotesCount: (.value.committeeVotes | length), dRepVotesCount: (.value.dRepVotes | length), @@ -134,14 +135,17 @@ cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg dRepKey "keyH ### Show the total number of 'yes', 'no', and 'abstain' votes for a given governance action ID: -Replace `cf2dce795cef4f8e92f0ab062a5dae0c1f7d8891d943ced9c2eeda9a62d8f092#0` with the governance action ID of your interest. +Replace "1e08794a48b71ec7e48d3190c7c30455f9538d0e54f4087915ff201167334bc7" and "0" and with the governance action ID and index of your interest. + +and .value.actionId.govActionIx == $actionIndex ``` -cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg actionId "cf2dce795cef4f8e92f0ab062a5dae0c1f7d8891d943ced9c2eeda9a62d8f092#0" ' - .proposals +cardano-cli conway query gov-state --testnet-magic 4 \ + | jq -r --arg actionTxId "1e08794a48b71ec7e48d3190c7c30455f9538d0e54f4087915ff201167334bc7" --arg actionIndex "0" ' .proposals | to_entries[] - | select(.key == $actionId) - | { govActionId: .key, + | select(.value.actionId.txId == $actionTxId and .value.actionId.govActionIx == ($actionIndex | tonumber)) + | { + govActionId: .value.actionId, dRepVoteYesCount: (.value.dRepVotes | with_entries(select(.value == "VoteYes")) | length), dRepVoteNoCount: (.value.dRepVotes | with_entries(select(.value == "VoteNo")) | length), dRepAbstainCount: (.value.dRepVotes | with_entries(select(.value == "Abstain")) | length), @@ -152,7 +156,7 @@ cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg actionId "cf2 committeeVoteNoCount: (.value.committeeVotes | with_entries(select(.value == "VoteNo")) | length), committeeAbstainCount: (.value.committeeVotes | with_entries(select(.value == "Abstain")) | length) } - ' +' ``` ### Show the active `treasury withdrawal` governance actions and their current vote count: @@ -163,9 +167,9 @@ current_epoch=$(cardano-cli query tip --testnet-magic 4 | jq .epoch) cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg currentEpoch "$current_epoch" ' .proposals | to_entries[] - | select(.value.expiresAfter > ($currentEpoch | tonumber) and .value.action.tag == "TreasuryWithdrawals") - | { govActionId: .key, - type: .value.action.tag, + | select(.value.expiresAfter > ($currentEpoch | tonumber) and .value.proposalProcedure.govAction.tag == "TreasuryWithdrawals") + | { type: .value.proposalProcedure.govAction.tag, + govActionId: .value.actionId, expiresAfter: .value.expiresAfter, dRepVoteYesCount: (.value.dRepVotes | with_entries(select(.value == "VoteYes")) | length), dRepVoteNoCount: (.value.dRepVotes | with_entries(select(.value == "VoteNo")) | length), @@ -186,9 +190,9 @@ current_epoch=$(cardano-cli query tip --testnet-magic 4 | jq .epoch) cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg currentEpoch "$current_epoch" ' .proposals | to_entries[] - | select(.value.expiresAfter > ($currentEpoch | tonumber) and .value.action.tag == "UpdateCommittee") - | { govActionId: .key, - type: .value.action.tag, + | select(.value.expiresAfter > ($currentEpoch | tonumber) and.value.proposalProcedure.govAction.tag == "UpdateCommittee") + | { type: .value.proposalProcedure.govAction.tag, + govActionId: .value.actionId, expiresAfter: .value.expiresAfter, dRepVoteYesCount: (.value.dRepVotes | with_entries(select(.value == "VoteYes")) | length), dRepVoteNoCount: (.value.dRepVotes | with_entries(select(.value == "VoteNo")) | length), @@ -198,4 +202,4 @@ cardano-cli conway query gov-state --testnet-magic 4 | jq -r --arg currentEpoch stakePoolAbstainCount: (.value.stakePoolVotes | with_entries(select(.value == "Abstain")) | length) } ' | jq -s 'sort_by(.expiresAfter)' -``` +``` \ No newline at end of file