Skip to content
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

update jq filters to work with the latest schema of gov state #139

Merged
merged 1 commit into from
Apr 22, 2024
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
56 changes: 30 additions & 26 deletions docs/tutorials/jq-filters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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[]'
```

Expand All @@ -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:
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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:
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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)'
```
```
Loading