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

transaction view: show proposals and votes #774

Merged
merged 3 commits into from
May 30, 2024

Conversation

smelc
Copy link
Contributor

@smelc smelc commented May 23, 2024

Changelog

- description: |
    transaction view: show proposals and votes

    This adds to new fiels to the JSON output of `transaction view`: `governance actions` and `voters`.
    Please see https://github.com/IntersectMBO/cardano-cli/pull/774#issuecomment-2139062455 for example outputs.
    When those fields are irrelevant, they are present but there value is `null`.
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - refactoring    # QoL changes
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Fixes #711

How to trust this PR

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@CarlosLopezDeLara
Copy link
Contributor

CarlosLopezDeLara commented May 23, 2024

Nice!!! Here is the output of a transaction with three votes:

{
    "type": "Witnessed Tx ConwayEra",
    "description": "Ledger Cddl Format",
    "cborHex": "84a400d901028182582096e3be606ca03f67b0d299ca0eb0d660670edaa8452fffcc4bfccd8757a9b45d0001818258390062573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c4208f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d31b0000000b8641a6ef021a0002d45913a18202581cefda35608d806f37ac3948f1ddaff912e5f9130e9b52035c166bd8f2a38258204c2121ececebac2a364878d295c959029e55225b426dfea5e0511ae0abc28d50008201f682582067820c121787464a9b670cf4c648f67cabd9573eb71b220214971ce467d25027008200f68258209bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397008202f6a100d90102828258208e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc0258408e92da471878c0fe6b97a4390df93cc81a6b84348bf1b393e6270b680b0d6402c9681672f393a54b35817c92884f7806ed5a00811e5aff6cfee8468100fecb048258208a10253789af22a6493dbe6a3a415732152989a9bd00b010e18f07a7cabcc74a584080bf834e873c59259fe6248cb98d7de49e7214f293895bbc7e0064030c7de10e565f867c5dfded379aaa8bfd2140f41ace6301f02e2b6678ad020a72e26b6505f5f6"
}
./dist-newstyle/build/x86_64-linux/ghc-9.6.4/cardano-cli-8.23.1.0/x/cardano-cli/build/cardano-cli/cardano-cli conway transaction view --tx-file ~/networks/sancho/transactions/threevotes-tx.signed 
{
    "auxiliary scripts": null,
    "certificates": null,
    "collateral inputs": [],
    "era": "Conway",
    "fee": "185433 Lovelace",
    "governance actions": [],
    "inputs": [
        "96e3be606ca03f67b0d299ca0eb0d660670edaa8452fffcc4bfccd8757a9b45d#0"
    ],
    "metadata": null,
    "mint": null,
    "outputs": [
        {
            "address": "addr_test1qp39w0fa0ccdc4gmg87puydf2kxt5mgt0vteq4a22ktrcssg7ysmx64l90xa0k4z25wpuejngya833qeu9cdxvveynfscsskf5",
            "address era": "Shelley",
            "amount": {
                "lovelace": 49497089775
            },
            "network": "Testnet",
            "payment credential key hash": "62573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c42",
            "reference script": null,
            "stake reference": {
                "stake credential key hash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
            }
        }
    ],
    "redeemers": {},
    "reference inputs": [],
    "required signers (payment key hashes needed for scripts)": null,
    "return collateral": null,
    "total collateral": null,
    "update proposal": null,
    "validity range": {
        "lower bound": null,
        "upper bound": null
    },
    "votes": {
        "drep-keyHash-efda35608d806f37ac3948f1ddaff912e5f9130e9b52035c166bd8f2": {
            "4c2121ececebac2a364878d295c959029e55225b426dfea5e0511ae0abc28d50#0": {
                "anchor": null,
                "decision": "VoteYes"
            },
            "67820c121787464a9b670cf4c648f67cabd9573eb71b220214971ce467d25027#0": {
                "anchor": null,
                "decision": "VoteNo"
            },
            "9bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397#0": {
                "anchor": null,
                "decision": "Abstain"
            }
        }
    },
    "withdrawals": null,
    "witnesses": [
        {
            "key": "VKey (VerKeyEd25519DSIGN \"8e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02\")",
            "signature": "SignedDSIGN (SigEd25519DSIGN \"8e92da471878c0fe6b97a4390df93cc81a6b84348bf1b393e6270b680b0d6402c9681672f393a54b35817c92884f7806ed5a00811e5aff6cfee8468100fecb04\")"
        },
        {
            "key": "VKey (VerKeyEd25519DSIGN \"8a10253789af22a6493dbe6a3a415732152989a9bd00b010e18f07a7cabcc74a\")",
            "signature": "SignedDSIGN (SigEd25519DSIGN \"80bf834e873c59259fe6248cb98d7de49e7214f293895bbc7e0064030c7de10e565f867c5dfded379aaa8bfd2140f41ace6301f02e2b6678ad020a72e26b6505\")"
        }
    ]
}

@CarlosLopezDeLara
Copy link
Contributor

CarlosLopezDeLara commented May 23, 2024

And the output of a transaction with a proposal

{
    "type": "Witnessed Tx ConwayEra",
    "description": "Ledger Cddl Format",
    "cborHex": "84a400d9010281825820e51d839ec4ef4b3522a965dab8cbd0a2c52ecd5959a469384c001c8691a98ab60001818258390062573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c4208f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d31b0000000ba438aef3021a0002c50d14d9010281841b0000000ba43b7400581de008f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d38301f6820a0082784b68747470733a2f2f6769746875622e636f6d2f6361726c6f736c6f64656c61722f70726f706f73616c732f626c6f622f6d61696e2f7768792d68617264666f726b2d746f2d31302e74787458206fad941a5236c151b44c23458fb99d6812bbc5c6eb3a3a8a5d2518e8be8962aba100d90102818258208e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02584028230d2507267600d17c7f062d9f3184f4686af570c31e2f9ed652d339d776dcd72fccf30dd17bc077d2615845bbad64fd6ddffdba5b2874651d0c3533e10d0bf5f6"
}
./dist-newstyle/build/x86_64-linux/ghc-9.6.4/cardano-cli-8.23.1.0/x/cardano-cli/build/cardano-cli/cardano-cli conway transaction view --tx-file ~/networks/sancho/transactions/hardfork-tx.signed 
{
    "auxiliary scripts": null,
    "certificates": null,
    "collateral inputs": [],
    "era": "Conway",
    "fee": "181517 Lovelace",
    "governance actions": [
        {
            "anchor": {
                "dataHash": "6fad941a5236c151b44c23458fb99d6812bbc5c6eb3a3a8a5d2518e8be8962ab",
                "url": "https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt"
            },
            "deposit": 50000000000,
            "governance action": {
                "contents": [
                    null,
                    {
                        "major": 10,
                        "minor": 0
                    }
                ],
                "tag": "HardForkInitiation"
            },
            "return address": {
                "credential": {
                    "keyHash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
                },
                "network": "Testnet"
            }
        }
    ],
    "inputs": [
        "e51d839ec4ef4b3522a965dab8cbd0a2c52ecd5959a469384c001c8691a98ab6#0"
    ],
    "metadata": null,
    "mint": null,
    "outputs": [
        {
            "address": "addr_test1qp39w0fa0ccdc4gmg87puydf2kxt5mgt0vteq4a22ktrcssg7ysmx64l90xa0k4z25wpuejngya833qeu9cdxvveynfscsskf5",
            "address era": "Shelley",
            "amount": {
                "lovelace": 49999818483
            },
            "network": "Testnet",
            "payment credential key hash": "62573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c42",
            "reference script": null,
            "stake reference": {
                "stake credential key hash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
            }
        }
    ],
    "redeemers": {},
    "reference inputs": [],
    "required signers (payment key hashes needed for scripts)": null,
    "return collateral": null,
    "total collateral": null,
    "update proposal": null,
    "validity range": {
        "lower bound": null,
        "upper bound": null
    },
    "votes": {},
    "withdrawals": null,
    "witnesses": [
        {
            "key": "VKey (VerKeyEd25519DSIGN \"8e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02\")",
            "signature": "SignedDSIGN (SigEd25519DSIGN \"28230d2507267600d17c7f062d9f3184f4686af570c31e2f9ed652d339d776dcd72fccf30dd17bc077d2615845bbad64fd6ddffdba5b2874651d0c3533e10d0b\")"
        }
    ]
}

@smelc smelc marked this pull request as ready for review May 24, 2024 07:39
@smelc smelc force-pushed the smelc/governance-view-show-proposals-and-votes branch from 7ff9d85 to 7baffc5 Compare May 24, 2024 07:45
@smelc
Copy link
Contributor Author

smelc commented May 24, 2024

@mkoura> can you look at the newly versioned golden files and let me know if the JSON format for the new fields governance actions and voters is what we want?

"lower bound": null,
"upper bound": null
},
"voters": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This field can contain multiple voters: voters is a map from voter to votes of this voter. This output shows a case where there is one voter, with three votes.

friendlyLedgerProposal cOnwards proposalProcedure = object $ friendlyProposalImpl cOnwards (Proposal proposalProcedure)

friendlyVotingProcedures :: ConwayEraOnwards era -> L.VotingProcedures (ShelleyLedgerEra era) -> Aeson.Value
friendlyVotingProcedures cOnwards x = conwayEraOnwardsConstraints cOnwards $ toJSON x
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carbolymer, @Jimbo4350> defaulting to the ledger's JSON instance here. Can you confirm that's what we want?

TODO @smelc Inline this if this is what we want

Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine. Would pretty json be nicer to read?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Jimbo4350> I'm not sure what you mean, since we're returning Aeson.Value here. Prettying (if any) the String output happens in the caller and I didn't change it.

So I'm leaving as is, but let me know later if you want to revisit.

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

LGTM! I would consider my refactoring suggestion but its not mandatory.

@@ -200,7 +207,36 @@ friendlyTxBodyImpl
, "update proposal" .= friendlyUpdateProposal txUpdateProposal
, "validity range" .= friendlyValidityRange era (txValidityLowerBound, txValidityUpperBound)
, "withdrawals" .= friendlyWithdrawals txWithdrawals
])
]) ++
(inEonForEra
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than using ++ it's ok to return "governance actions" .= Null. Although if you really don't like that you can use a combination of maybe and mempty to get the desired result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't have used Null myself directly, but since this is the behavior of many existing fields; I did this change to be consistent 👍 (and code is slightly nicer to read)

friendlyLedgerProposal cOnwards proposalProcedure = object $ friendlyProposalImpl cOnwards (Proposal proposalProcedure)

friendlyVotingProcedures :: ConwayEraOnwards era -> L.VotingProcedures (ShelleyLedgerEra era) -> Aeson.Value
friendlyVotingProcedures cOnwards x = conwayEraOnwardsConstraints cOnwards $ toJSON x
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine. Would pretty json be nicer to read?

@smelc smelc force-pushed the smelc/governance-view-show-proposals-and-votes branch from 7baffc5 to e193497 Compare May 29, 2024 13:50
@smelc smelc force-pushed the smelc/governance-view-show-proposals-and-votes branch from e193497 to 026cf6d Compare May 29, 2024 14:38
@smelc smelc enabled auto-merge May 29, 2024 14:38
@smelc smelc added this pull request to the merge queue May 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks May 29, 2024
@smelc smelc added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@smelc
Copy link
Contributor Author

smelc commented May 30, 2024

If you want to see the JSON output of the new fields, execute these examples:

#!/usr/bin/env bash

threeVotesTx='{
    "type": "Witnessed Tx ConwayEra",
    "description": "Ledger Cddl Format",
    "cborHex": "84a400d901028182582096e3be606ca03f67b0d299ca0eb0d660670edaa8452fffcc4bfccd8757a9b45d0001818258390062573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c4208f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d31b0000000b8641a6ef021a0002d45913a18202581cefda35608d806f37ac3948f1ddaff912e5f9130e9b52035c166bd8f2a38258204c2121ececebac2a364878d295c959029e55225b426dfea5e0511ae0abc28d50008201f682582067820c121787464a9b670cf4c648f67cabd9573eb71b220214971ce467d25027008200f68258209bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397008202f6a100d90102828258208e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc0258408e92da471878c0fe6b97a4390df93cc81a6b84348bf1b393e6270b680b0d6402c9681672f393a54b35817c92884f7806ed5a00811e5aff6cfee8468100fecb048258208a10253789af22a6493dbe6a3a415732152989a9bd00b010e18f07a7cabcc74a584080bf834e873c59259fe6248cb98d7de49e7214f293895bbc7e0064030c7de10e565f867c5dfded379aaa8bfd2140f41ace6301f02e2b6678ad020a72e26b6505f5f6"
}'

proposalTx='{
    "type": "Witnessed Tx ConwayEra",
    "description": "Ledger Cddl Format",
    "cborHex": "84a400d9010281825820e51d839ec4ef4b3522a965dab8cbd0a2c52ecd5959a469384c001c8691a98ab60001818258390062573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c4208f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d31b0000000ba438aef3021a0002c50d14d9010281841b0000000ba43b7400581de008f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d38301f6820a0082784b68747470733a2f2f6769746875622e636f6d2f6361726c6f736c6f64656c61722f70726f706f73616c732f626c6f622f6d61696e2f7768792d68617264666f726b2d746f2d31302e74787458206fad941a5236c151b44c23458fb99d6812bbc5c6eb3a3a8a5d2518e8be8962aba100d90102818258208e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02584028230d2507267600d17c7f062d9f3184f4686af570c31e2f9ed652d339d776dcd72fccf30dd17bc077d2615845bbad64fd6ddffdba5b2874651d0c3533e10d0bf5f6"
}'

tx_file="/tmp/tx.json"
rm -Rf "$tx_file"
echo $threeVotesTx > "$tx_file"
set -x
cardano-cli conway transaction view --tx-file "$tx_file"
set +x

rm -Rf "$tx_file"
echo $proposalTx > "$tx_file"
set -x
cardano-cli conway transaction view --tx-file "$tx_file"
set +x

This will output:

{
    "auxiliary scripts": null,
    "certificates": null,
    "collateral inputs": [],
    "era": "Conway",
    "fee": "185433 Lovelace",
    "governance actions": [],
    "inputs": [
        "96e3be606ca03f67b0d299ca0eb0d660670edaa8452fffcc4bfccd8757a9b45d#0"
    ],
    "metadata": null,
    "mint": null,
    "outputs": [
        {
            "address": "addr_test1qp39w0fa0ccdc4gmg87puydf2kxt5mgt0vteq4a22ktrcssg7ysmx64l90xa0k4z25wpuejngya833qeu9cdxvveynfscsskf5",
            "address era": "Shelley",
            "amount": {
                "lovelace": 49497089775
            },
            "network": "Testnet",
            "payment credential key hash": "62573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c42",
            "reference script": null,
            "stake reference": {
                "stake credential key hash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
            }
        }
    ],
    "redeemers": {},
    "reference inputs": [],
    "required signers (payment key hashes needed for scripts)": null,
    "return collateral": null,
    "total collateral": null,
    "update proposal": null,
    "validity range": {
        "lower bound": null,
        "upper bound": null
    },
    "voters": {
        "drep-keyHash-efda35608d806f37ac3948f1ddaff912e5f9130e9b52035c166bd8f2": {
            "4c2121ececebac2a364878d295c959029e55225b426dfea5e0511ae0abc28d50#0": {
                "anchor": null,
                "decision": "VoteYes"
            },
            "67820c121787464a9b670cf4c648f67cabd9573eb71b220214971ce467d25027#0": {
                "anchor": null,
                "decision": "VoteNo"
            },
            "9bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397#0": {
                "anchor": null,
                "decision": "Abstain"
            }
        }
    },
    "withdrawals": null,
    "witnesses": [
        {
            "key": "VKey (VerKeyEd25519DSIGN \"8e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02\")",
            "signature": "SignedDSIGN (SigEd25519DSIGN \"8e92da471878c0fe6b97a4390df93cc81a6b84348bf1b393e6270b680b0d6402c9681672f393a54b35817c92884f7806ed5a00811e5aff6cfee8468100fecb04\")"
        },
        {
            "key": "VKey (VerKeyEd25519DSIGN \"8a10253789af22a6493dbe6a3a415732152989a9bd00b010e18f07a7cabcc74a\")",
            "signature": "SignedDSIGN (SigEd25519DSIGN \"80bf834e873c59259fe6248cb98d7de49e7214f293895bbc7e0064030c7de10e565f867c5dfded379aaa8bfd2140f41ace6301f02e2b6678ad020a72e26b6505\")"
        }
    ]
}

and

{
    "auxiliary scripts": null,
    "certificates": null,
    "collateral inputs": [],
    "era": "Conway",
    "fee": "181517 Lovelace",
    "governance actions": [
        {
            "anchor": {
                "dataHash": "6fad941a5236c151b44c23458fb99d6812bbc5c6eb3a3a8a5d2518e8be8962ab",
                "url": "https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt"
            },
            "deposit": 50000000000,
            "governance action": {
                "contents": [
                    null,
                    {
                        "major": 10,
                        "minor": 0
                    }
                ],
                "tag": "HardForkInitiation"
            },
            "return address": {
                "credential": {
                    "keyHash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
                },
                "network": "Testnet"
            }
        }
    ],
    "inputs": [
        "e51d839ec4ef4b3522a965dab8cbd0a2c52ecd5959a469384c001c8691a98ab6#0"
    ],
    "metadata": null,
    "mint": null,
    "outputs": [
        {
            "address": "addr_test1qp39w0fa0ccdc4gmg87puydf2kxt5mgt0vteq4a22ktrcssg7ysmx64l90xa0k4z25wpuejngya833qeu9cdxvveynfscsskf5",
            "address era": "Shelley",
            "amount": {
                "lovelace": 49999818483
            },
            "network": "Testnet",
            "payment credential key hash": "62573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c42",
            "reference script": null,
            "stake reference": {
                "stake credential key hash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
            }
        }
    ],
    "redeemers": {},
    "reference inputs": [],
    "required signers (payment key hashes needed for scripts)": null,
    "return collateral": null,
    "total collateral": null,
    "update proposal": null,
    "validity range": {
        "lower bound": null,
        "upper bound": null
    },
    "voters": {},
    "withdrawals": null,
    "witnesses": [
        {
            "key": "VKey (VerKeyEd25519DSIGN \"8e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02\")",
            "signature": "SignedDSIGN (SigEd25519DSIGN \"28230d2507267600d17c7f062d9f3184f4686af570c31e2f9ed652d339d776dcd72fccf30dd17bc077d2615845bbad64fd6ddffdba5b2874651d0c3533e10d0b\")"
        }
    ]
}

@smelc smelc merged commit 1f81d15 into main May 30, 2024
23 checks passed
@smelc smelc deleted the smelc/governance-view-show-proposals-and-votes branch May 30, 2024 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] - Update transaction view command so that it shows proposals and votes inside the transaction.
3 participants