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

Require proto.Message in client.Context.PrintOutput #6999

Merged
merged 11 commits into from
Aug 11, 2020

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Aug 10, 2020

Was originally part of #6859 but split out into a smaller PR

This is a stepping stone to enabling protobuf JSON generally in #6859.

  • client.Context.PrintOutput now requires proto.Message - proto JSON is more or less impossible to enforce without this. Queries that returned arrays from query responses, now return the full response. This probably the correct behavior because these queries should also eventually include pagination data if they don't already
  • client.Context.PrintOutputLegacy was added to use amino JSON where we don't have proto types yet. Rather than dealing with all of the migrations in this already large PR, stuff that wasn't migrated uses PrintOutputLegacy and the issues are tracked in Migrate remaining CLI cmd's to proto #6987

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Aug 10, 2020

Codecov Report

Merging #6999 into master will decrease coverage by 2.54%.
The diff coverage is 44.11%.

@@            Coverage Diff             @@
##           master    #6999      +/-   ##
==========================================
- Coverage   61.94%   59.39%   -2.55%     
==========================================
  Files         519      368     -151     
  Lines       32088    21741   -10347     
==========================================
- Hits        19877    12914    -6963     
+ Misses      10597     7754    -2843     
+ Partials     1614     1073     -541     

@aaronc aaronc changed the title Enable proto JSON json for cli tx & query Enable proto JSON for cli tx & query Aug 10, 2020
@aaronc aaronc changed the title Enable proto JSON for cli tx & query Require proto.Message in client.Context.PrintOutput Aug 10, 2020
@@ -287,7 +287,7 @@ Where proposal.json contains:
return err
}

proposal, err := ParseCommunityPoolSpendProposalJSON(clientCtx.JSONMarshaler, args[0])
proposal, err := ParseCommunityPoolSpendProposalJSON(clientCtx.Codec, args[0])
Copy link
Member Author

Choose a reason for hiding this comment

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

To be migrated in #6987

@@ -19,7 +19,8 @@ type (
)

// ParseCommunityPoolSpendProposalJSON reads and parses a CommunityPoolSpendProposalJSON from a file.
func ParseCommunityPoolSpendProposalJSON(cdc codec.JSONMarshaler, proposalFile string) (CommunityPoolSpendProposalJSON, error) {
// TODO: migrate this to protobuf
Copy link
Member Author

Choose a reason for hiding this comment

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

To be migrated in #6987

}

// PrintOutputLegacy is a variant of PrintOutput that doesn't require a proto type
// and uses amino JSON encoding. It will be removed in the near future!
Copy link
Member Author

Choose a reason for hiding this comment

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

To be removed in #6987 when all the remaining pieces are migrated to proto

x/gov/client/cli/query.go Show resolved Hide resolved
x/gov/client/cli/query.go Show resolved Hide resolved
x/gov/client/cli/query.go Show resolved Hide resolved
x/gov/client/cli/query.go Outdated Show resolved Hide resolved
x/ibc/02-client/client/cli/query.go Show resolved Hide resolved
@@ -84,7 +85,7 @@ func GetCmdQueryInflation() *cobra.Command {
return err
}

return clientCtx.PrintOutput(res.Inflation)
return clientCtx.PrintString(fmt.Sprintf("%s\n", res.Inflation))
Copy link
Collaborator

Choose a reason for hiding this comment

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

why PrintString?

Copy link
Member Author

@aaronc aaronc Aug 10, 2020

Choose a reason for hiding this comment

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

Inflation is a Dec and we can't print simply a Dec with jsonpb, but a Dec can just be printed as a string.

The previous output was something like "1234.00000" in quotes. The new version just prints a number not in quotes 1234.00000. If we actually want to print a JSON string we will need to print something like {"inflation":"1234.00000"} wrapped in an object. Would that be preferable?

Copy link
Collaborator

@anilcse anilcse Aug 10, 2020

Choose a reason for hiding this comment

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

Yes, {"inflation":"1234.00000"} would be better. May be return clientCtx.PrintOutput(res)?

@@ -116,7 +117,7 @@ func GetCmdQueryAnnualProvisions() *cobra.Command {
return err
}

return clientCtx.PrintOutput(res.AnnualProvisions)
return clientCtx.PrintString(fmt.Sprintf("%s\n", res.AnnualProvisions))
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

see comment above regarding Inflation Dec

x/staking/client/cli/query.go Outdated Show resolved Hide resolved
x/staking/client/cli/query.go Show resolved Hide resolved
@@ -105,7 +105,7 @@ func GetAppliedPlanCmd() *cobra.Command {
if err != nil {
return err
}
return clientCtx.PrintOutput(string(bz))
return clientCtx.PrintString(fmt.Sprintf("%s\n", string(bz)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

This was just printing a string using amino. It doesn't work in proto. So the easiest thing seems to be to just print a string. If a json string is really needed we could use encoding/json

x/auth/client/cli/query.go Show resolved Hide resolved
client/context.go Outdated Show resolved Hide resolved
aaronc and others added 2 commits August 10, 2020 17:41
Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
@fedekunze fedekunze merged commit 7de8ef7 into master Aug 11, 2020
@fedekunze fedekunze deleted the aaronc/cli-print-output-proto branch August 11, 2020 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants