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

JSON format for leadership schedule #3687

Merged
merged 2 commits into from
Mar 31, 2022

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Mar 7, 2022

No description provided.

@newhoggy
Copy link
Contributor Author

newhoggy commented Mar 7, 2022

Resolves #3678

@newhoggy newhoggy force-pushed the newhoggy/json-format-for-leadership-schedule branch 2 times, most recently from 68c8620 to 7631d02 Compare March 15, 2022 10:47
@newhoggy
Copy link
Contributor Author

Example output:

$ CARDANO_NODE_SOCKET_PATH=/private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/chairman/test-14a8914f9f284a51/socket/node-bft1 cardano-cli query leadership-schedule --testnet-magic 1925 --genesis /private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/chairman/test-14a8914f9f284a51/shelley/genesis.json --vrf-signing-key-file /private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/chairman/test-14a8914f9f284a51/node-pool1/shelley/vrf.skey --stake-pool-id $(cardano-cli stake-pool id --cold-verification-key-file /private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/chairman/test-14a8914f9f284a51/node-pool1/shelley/operator.vkey) --current
     SlotNo                          UTC Time
-------------------------------------------------------------
     185016                   2022-03-17 12:31:23.16 UTC
     185063                   2022-03-17 12:31:23.63 UTC
     185106                   2022-03-17 12:31:24.06 UTC
     185126                   2022-03-17 12:31:24.26 UTC
     185139                   2022-03-17 12:31:24.39 UTC
     185166                   2022-03-17 12:31:24.66 UTC
     185183                   2022-03-17 12:31:24.83 UTC
     185196                   2022-03-17 12:31:24.96 UTC
     185199                   2022-03-17 12:31:24.99 UTC
     185273                   2022-03-17 12:31:25.73 UTC
     185339                   2022-03-17 12:31:26.39 UTC
     185343                   2022-03-17 12:31:26.43 UTC
     185406                   2022-03-17 12:31:27.06 UTC
     185446                   2022-03-17 12:31:27.46 UTC
     185456                   2022-03-17 12:31:27.56 UTC
     185489                   2022-03-17 12:31:27.89 UTC
$ CARDANO_NODE_SOCKET_PATH=/private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/chairman/test-14a8914f9f284a51/socket/node-bft1 cardano-cli query leadership-schedule --testnet-magic 1925 --genesis /private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/chairman/test-14a8914f9f284a51/shelley/genesis.json --vrf-signing-key-file /private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/chairman/test-14a8914f9f284a51/node-pool1/shelley/vrf.skey --stake-pool-id $(cardano-cli stake-pool id --cold-verification-key-file /private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/chairman/test-14a8914f9f284a51/node-pool1/shelley/operator.vkey) --current --output-as json
[
    {
        "slotNumber": 185016,
        "slotTime": "2022-03-17T12:31:23.16Z"
    },
    {
        "slotNumber": 185063,
        "slotTime": "2022-03-17T12:31:23.63Z"
    },
    {
        "slotNumber": 185106,
        "slotTime": "2022-03-17T12:31:24.06Z"
    },
    {
        "slotNumber": 185126,
        "slotTime": "2022-03-17T12:31:24.26Z"
    },
    {
        "slotNumber": 185139,
        "slotTime": "2022-03-17T12:31:24.39Z"
    },
    {
        "slotNumber": 185166,
        "slotTime": "2022-03-17T12:31:24.66Z"
    },
    {
        "slotNumber": 185183,
        "slotTime": "2022-03-17T12:31:24.83Z"
    },
    {
        "slotNumber": 185196,
        "slotTime": "2022-03-17T12:31:24.96Z"
    },
    {
        "slotNumber": 185199,
        "slotTime": "2022-03-17T12:31:24.99Z"
    },
    {
        "slotNumber": 185273,
        "slotTime": "2022-03-17T12:31:25.73Z"
    },
    {
        "slotNumber": 185339,
        "slotTime": "2022-03-17T12:31:26.39Z"
    },
    {
        "slotNumber": 185343,
        "slotTime": "2022-03-17T12:31:26.43Z"
    },
    {
        "slotNumber": 185406,
        "slotTime": "2022-03-17T12:31:27.06Z"
    },
    {
        "slotNumber": 185446,
        "slotTime": "2022-03-17T12:31:27.46Z"
    },
    {
        "slotNumber": 185456,
        "slotTime": "2022-03-17T12:31:27.56Z"
    },
    {
        "slotNumber": 185489,
        "slotTime": "2022-03-17T12:31:27.89Z"
    }
]

The testnet for the above test was created via: IntersectMBO/plutus-apps#364

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.

Nice. A couple comments.

import Data.Eq
import Text.Show

data OutputAs = OutputAsJson | OutputAsText deriving (Eq, Show)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be in Cardano.CLI.Shelley.Output. However I'm also wondering if this is necessary as we use Maybe OutputFile to determine if we are rendering as JSON to disk or if we are printing to stdout. Are there instances where we don't render as JSON to disk?

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 just had this idea that we could have --json-output=FILE and if users really want it in stdout, they can do this: --json-output=/dev/stdout.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. How about modifying OutputFile to encompass this?

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 thought about this and I think it's better to follow the existing convention.

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 have pushed the update.

readerOutputAs = do
v <- Opt.str @Text
case v of
"json" -> return OutputAsJson
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be better as a flag as we can take advantage of the Alternative instance of Parser ((<|>)) which would eliminate ambiguity (therefore eliminating any error case).

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 went with your suggestion after all.

@newhoggy newhoggy force-pushed the newhoggy/json-format-for-leadership-schedule branch from 7631d02 to 16e0db3 Compare March 31, 2022 12:11
@newhoggy newhoggy requested a review from Jimbo4350 March 31, 2022 12:11
@newhoggy newhoggy dismissed Jimbo4350’s stale review March 31, 2022 12:22

Comments addressed

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! Just squash the commits 👍

@newhoggy
Copy link
Contributor Author

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 31, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 0e204ec into master Mar 31, 2022
@iohk-bors iohk-bors bot deleted the newhoggy/json-format-for-leadership-schedule branch March 31, 2022 14:13
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.

2 participants