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

Implement JSON output support for Shelley tip query command #1365

Merged
merged 1 commit into from
Jul 6, 2020

Conversation

intricate
Copy link
Contributor

Closes #1340.

Before:

$ cardano-cli shelley query tip --testnet-magic 42
Tip (SlotNo {unSlotNo = 57}) (ShelleyHash {unShelleyHash = HashHeader {unHashHeader = 5820355fd1b83b8e71191f135366ae3c07d7408dcd54329e219cead4bb0bf15f875d}}) (BlockNo {unBlockNo = 2})

After:

$ cardano-cli shelley query tip --testnet-magic 42
{
    "blockNo": 2,
    "headerHash": "5820355fd1b83b8e71191f135366ae3c07d7408dcd54329e219cead4bb0bf15f875d",
    "slotNo": 57
}

@@ -50,3 +57,13 @@ instance FromJSON Update.ApplicationName where
parseJSON invalid =
panic $ "Parsing of application name failed due to type mismatch. "
<> "Encountered: " <> (Text.pack $ Prelude.show invalid)

instance Serialise (HeaderHash blk) => ToJSON (Tip blk) where
toJSON TipGenesis = object [ "genesis" .= True ]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this an appropriate output for genesis?

{
  "genesis": true
}

Copy link
Contributor

@Jimbo4350 Jimbo4350 Jun 30, 2020

Choose a reason for hiding this comment

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

What about something like:

{
  "currentBlock": "genesis block"
}

@intricate intricate force-pushed the intricate/1340-tip-json branch 3 times, most recently from 226d47e to 0d9b2f2 Compare July 3, 2020 15:35
Copy link
Contributor

@dcoutts dcoutts left a comment

Choose a reason for hiding this comment

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

I made a change to use the underlying ToJson instance for the hash (under a couple newtype wrappers). This is both simpler and correct. Using serialise does not give the correct output (since it's not the raw hash but the CBOR encoded value).

@dcoutts
Copy link
Contributor

dcoutts commented Jul 6, 2020

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 6, 2020

@iohk-bors iohk-bors bot merged commit 42033f6 into master Jul 6, 2020
@iohk-bors iohk-bors bot deleted the intricate/1340-tip-json branch July 6, 2020 10: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.

Support JSON output for Shelley tip query command
3 participants