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

Wire up outstanding new IPC queries to the cli #2290

Merged
merged 6 commits into from
Feb 9, 2021

Conversation

Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Jan 19, 2021

Depends on #2275
The following cli commands were updated with the new IPC.

  • tip
  • utxo
  • ledger-state
  • protocol-state

@Jimbo4350 Jimbo4350 force-pushed the jordan/wire-up-remaining-api-queries-final branch 4 times, most recently from 4f63c04 to 67db64f Compare January 21, 2021 13:57
@Jimbo4350 Jimbo4350 force-pushed the jordan/wire-up-remaining-api-queries-final branch 2 times, most recently from be36ba2 to ec658d4 Compare January 27, 2021 13:59
@Jimbo4350 Jimbo4350 marked this pull request as ready for review January 27, 2021 14:00
@Jimbo4350 Jimbo4350 force-pushed the jordan/wire-up-remaining-api-queries-final branch 4 times, most recently from 56c7a9b to da28b27 Compare January 28, 2021 11:48
@Jimbo4350 Jimbo4350 force-pushed the jordan/wire-up-remaining-api-queries-final branch from da28b27 to 5f7ff36 Compare January 28, 2021 16:25
@Jimbo4350 Jimbo4350 force-pushed the jordan/wire-up-remaining-api-queries-final branch from 25329bb to e3f8b18 Compare February 2, 2021 16:04
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.

Definitely going in the right direction.

Main thing is to look more closely at the ToJSON instances you're providing. Where we do provide ToJSON instances they should be sane machine-readable choices, and reflect the surface structure of the types, not revealing lots of internals (so not using Generic or Show).

cardano-api/src/Cardano/Api/Block.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/Block.hs Outdated Show resolved Hide resolved
cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/TxBody.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/TxBody.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/Block.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/Query.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/TxBody.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/TxBody.hs Outdated Show resolved Hide resolved
@Jimbo4350 Jimbo4350 force-pushed the jordan/wire-up-remaining-api-queries-final branch 3 times, most recently from ef64b98 to 250cf11 Compare February 5, 2021 13:29
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.

Nearly there!

cardano-api/src/Cardano/Api/Query.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/Query.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/Query.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/TxBody.hs Outdated Show resolved Hide resolved
Comment on lines 237 to 242
instance ToJSON TxIn where
toJSON (TxIn txId (TxIx ix)) =
Aeson.String ( Text.decodeUtf8 (serialiseToRawBytesHex txId)
<> "#"
<> Text.pack (show ix)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh what happened to the ToJSONKey instance? Perhaps I misread and you only have the ToJSONKey for the underlying Shelley type.

We should provide it for the surface type because it's directly useful and so we can use the simple instance for UTxO above.

The ToJSONKey instance should use this rendering as a single string with the #, but the ToJSON should still give us an object with two fieldstxid and txix.

cardano-api/src/Cardano/Api/TxBody.hs Show resolved Hide resolved
Comment on lines +38 to +39
-- Orphan instances involved in the JSON output of the API queries.
-- We will remove/replace these as we provide more API wrapper types
Copy link
Contributor

Choose a reason for hiding this comment

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

Mmm. This does make me a little nervous. Where do we still need these? Is this for the ToJSON instance for the ledger state? Otherwise I think we should be able to do everything with JSON instances only for the API surface types.

Copy link
Contributor Author

@Jimbo4350 Jimbo4350 Feb 5, 2021

Choose a reason for hiding this comment

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

Yes these are for the LedgerState and ProtocolState which are just type wrappers around the underlying ledger-specs types. We could do something similar for them (e.g the api's UTxO and having conversion function from the underlying ledger types) but I figured implementing JSON instances would be less time consuming and OK for now as these are used in rendering the output for protocol-state and ledger-state cli commands.

:: Query.SerialisedLedgerState era
-> Either LBS.ByteString (Query.LedgerState era)
decodeLedgerState (Query.SerialisedLedgerState (Serialised ls)) =
first (const ls) (decodeFull ls)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably provide something like thisin the API itself to get from the SerialisedLedgerState to a LedgerState (or error), rather than having to know the underlying details of how it works here.

Copy link
Contributor Author

@Jimbo4350 Jimbo4350 Feb 5, 2021

Choose a reason for hiding this comment

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

I'll add this to my TODO list or I can delegate this as a small task. This might be a good task for John or Yuri to get their feet wet in the API.

@Jimbo4350 Jimbo4350 force-pushed the jordan/wire-up-remaining-api-queries-final branch from 250cf11 to 03783fe Compare February 5, 2021 15:39
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.

LGTM!

Lets squash the last three patches into a single "review fixes for JSON output" patch, and merge.

@Jimbo4350 Jimbo4350 force-pushed the jordan/wire-up-remaining-api-queries-final branch from 5ddada9 to f3088d7 Compare February 8, 2021 15:59
@Jimbo4350
Copy link
Contributor Author

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 9, 2021

@iohk-bors iohk-bors bot merged commit f10af95 into master Feb 9, 2021
@iohk-bors iohk-bors bot deleted the jordan/wire-up-remaining-api-queries-final branch February 9, 2021 08:44
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.

3 participants