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

Robert/api clientctx #8107

Merged
merged 5 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ Ref: https://keepachangelog.com/en/1.0.0/

### State Machine Breaking Changes

* (x/upgrade) [\#7979](https://github.com/cosmos/cosmos-sdk/pull/7979) keeper pubkey storage serialization migration from bech32 to protobuf.
* (x/upgrade) [\#7979](https://github.com/cosmos/cosmos-sdk/pull/7979) keeper pubkey storage serialization migration from bech32 to protobuf.

### Bug Fixes

* (crypto) [\#7966](https://github.com/cosmos/cosmos-sdk/issues/7966) `Bip44Params` `String()` function now correctly returns the absolute HD path by adding the `m/` prefix.

### Client Breaking

* (client) [\#8107](https://github.com/cosmos/cosmos-sdk/pull/8107) Renamed `PrintOutput` and `PrintOutputLegacy` methods of the `context.Client` object to `PrintObject` and `PrintObjectLegacy`.

## [v0.40.0-rc3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.40.0-rc3) - 2020-11-06

### Client Breaking
Expand All @@ -74,7 +78,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Client Breaking

* (x/upgrade) [#7697](https://github.com/cosmos/cosmos-sdk/pull/7697) Rename flag name "--time" to "--upgrade-time", "--info" to "--upgrade-info", to keep it consistent with help message.
* (x/auth) [#7788](https://github.com/cosmos/cosmos-sdk/pull/7788) Remove `tx auth` subcommands, all auth subcommands exist as `tx <subcommand>`
* (x/auth) [#7788](https://github.com/cosmos/cosmos-sdk/pull/7788) Remove `tx auth` subcommands, all auth subcommands exist as `tx <subcommand>`

### API Breaking

Expand Down Expand Up @@ -134,7 +138,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

* (modules) [\#7540](https://github.com/cosmos/cosmos-sdk/issues/7540) Protobuf service definitions can now be used for
packing `Msg`s in transactions as defined in [ADR 031](./docs/architecture/adr-031-msg-service.md). All modules now
packing `Msg`s in transactions as defined in [ADR 031](./docs/architecture/adr-031-msg-service.md). All modules now
define a `Msg` protobuf service.
* (codec) [\#7519](https://github.com/cosmos/cosmos-sdk/pull/7519) `InterfaceRegistry` now inherits `jsonpb.AnyResolver`, and has a `RegisterCustomTypeURL` method to support ADR 031 packing of `Any`s. `AnyResolver` is now a required parameter to `RejectUnknownFields`.
* (baseapp) [\#7519](https://github.com/cosmos/cosmos-sdk/pull/7519) Add `ServiceMsgRouter` to BaseApp to handle routing of protobuf service `Msg`s. The two new types defined in ADR 031, `sdk.ServiceMsg` and `sdk.MsgRequest` are introduced with this router.
Expand Down Expand Up @@ -738,7 +742,7 @@ generalized genesis accounts through the `GenesisAccount` interface.
* (sdk) [\#4758](https://github.com/cosmos/cosmos-sdk/issues/4758) update `x/genaccounts` to match module spec
* (simulation) [\#4824](https://github.com/cosmos/cosmos-sdk/issues/4824) `PrintAllInvariants` flag will print all failed invariants
* (simulation) [\#4490](https://github.com/cosmos/cosmos-sdk/issues/4490) add `InitialBlockHeight` flag to resume a simulation from a given block

* Support exporting the simulation stats to a given JSON file
* (simulation) [\#4847](https://github.com/cosmos/cosmos-sdk/issues/4847), [\#4838](https://github.com/cosmos/cosmos-sdk/pull/4838) and [\#4869](https://github.com/cosmos/cosmos-sdk/pull/4869) `SimApp` and simulation refactors:
* Implement `SimulationManager` for executing modules' simulation functionalities in a modularized way
Expand Down Expand Up @@ -1052,7 +1056,7 @@ that error is that the account doesn't exist.
* (simulation) PrintAllInvariants flag will print all failed invariants
* (simulation) Add `InitialBlockHeight` flag to resume a simulation from a given block
* (simulation) [\#4670](https://github.com/cosmos/cosmos-sdk/issues/4670) Update simulation statistics to JSON format

- Support exporting the simulation stats to a given JSON file
* [\#4775](https://github.com/cosmos/cosmos-sdk/issues/4775) Refactor CI config
* Upgrade IAVL to v0.12.4
Expand Down Expand Up @@ -1658,9 +1662,9 @@ BREAKING CHANGES
FEATURES

* Gaia REST API

* [\#2358](https://github.com/cosmos/cosmos-sdk/issues/2358) Add distribution module REST interface

* Gaia CLI (`gaiacli`)
* [\#3429](https://github.com/cosmos/cosmos-sdk/issues/3429) Support querying
for all delegator distribution rewards.
Expand Down
8 changes: 4 additions & 4 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ func (ctx Context) PrintString(str string) error {
return err
}

// PrintOutput outputs toPrint to the ctx.Output based on ctx.OutputFormat which is
// PrintObject outputs toPrint to the ctx.Output based on ctx.OutputFormat which is
// either text or json. If text, toPrint will be YAML encoded. Otherwise, toPrint
// will be JSON encoded using ctx.JSONMarshaler. An error is returned upon failure.
func (ctx Context) PrintOutput(toPrint proto.Message) error {
func (ctx Context) PrintObject(toPrint proto.Message) error {
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
// always serialize JSON initially because proto json can't be directly YAML encoded
out, err := ctx.JSONMarshaler.MarshalJSON(toPrint)
if err != nil {
Expand All @@ -220,9 +220,9 @@ func (ctx Context) PrintOutput(toPrint proto.Message) error {
return ctx.printOutput(out)
}

// PrintOutputLegacy is a variant of PrintOutput that doesn't require a proto type
// PrintObjectLegacy is a variant of PrintObject that doesn't require a proto type
// and uses amino JSON encoding. It will be removed in the near future!
func (ctx Context) PrintOutputLegacy(toPrint interface{}) error {
func (ctx Context) PrintObjectLegacy(toPrint interface{}) error {
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
out, err := ctx.LegacyAmino.MarshalJSON(toPrint)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions client/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestContext_PrintOutput(t *testing.T) {
func TestContext_PrintObject(t *testing.T) {
ctx := client.Context{}

animal := &testdata.Dog{
Expand All @@ -47,7 +47,7 @@ func TestContext_PrintOutput(t *testing.T) {
buf := &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "json"
err = ctx.PrintOutput(hasAnimal)
err = ctx.PrintObject(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`{"animal":{"@type":"/testdata.Dog","size":"big","name":"Spot"},"x":"10"}
Expand All @@ -57,7 +57,7 @@ func TestContext_PrintOutput(t *testing.T) {
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "text"
err = ctx.PrintOutput(hasAnimal)
err = ctx.PrintObject(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`animal:
Expand All @@ -77,7 +77,7 @@ x: "10"
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "json"
err = ctx.PrintOutputLegacy(hasAnimal)
err = ctx.PrintObjectLegacy(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`{"type":"testdata/HasAnimal","value":{"animal":{"type":"testdata/Dog","value":{"size":"big","name":"Spot"}},"x":"10"}}
Expand All @@ -87,7 +87,7 @@ x: "10"
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "text"
err = ctx.PrintOutputLegacy(hasAnimal)
err = ctx.PrintObjectLegacy(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`type: testdata/HasAnimal
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func ValidatorCommand() *cobra.Command {
return err
}

return clientCtx.PrintOutputLegacy(result)
return clientCtx.PrintObjectLegacy(result)
},
}

Expand Down
2 changes: 1 addition & 1 deletion client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
return err
}

return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
}

// WriteGeneratedTxResponse writes a generated unsigned transaction to the
Expand Down
2 changes: 1 addition & 1 deletion docs/building-modules/module-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ This query returns the account at a given address. The getter function does the
- The function should first initialize a new client [`Context`](../interfaces/query-lifecycle.md#context) as described in the [previous section](#transaction-commands)
- If applicable, the `Context` is used to retrieve any parameters (e.g. the query originator's address to be used in the query) and marshal them with the query parameter type, in preparation to be relayed to a node. There are no `Context` parameters in this case because the query does not involve any information about the user.
- A new `queryClient` should be initialized using `NewQueryClient(clientCtx)`, this method being generated from `query.proto`. Then it can be used to call the appropriate [query](./messages-and-queries.md#grpc-queries).
- The `clientCtx.PrintOutput` method is used to print the output back to the user.
- The `clientCtx.PrintObject` method is used to format a `proto.Message` object and print it back to the user.
- **Flags.** Add any [flags](#flags) to the command.

Finally, the module also needs a `GetQueryCmd`, which aggregates all of the query commands of the module. Application developers wishing to include the module's queries will call this function to add them as subcommands in their CLI. Its structure is identical to the `GetTxCmd` command shown above.
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/cli/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $ <appd> tx broadcast ./mytxn.json
return err
}

return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
},
}

Expand Down
8 changes: 4 additions & 4 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ $ <appd> query auth params
return err
}

return clientCtx.PrintOutput(&res.Params)
return clientCtx.PrintObject(&res.Params)
},
}

Expand Down Expand Up @@ -98,7 +98,7 @@ func GetAccountCmd() *cobra.Command {
return err
}

return clientCtx.PrintOutput(res.Account)
return clientCtx.PrintObject(res.Account)
},
}

Expand Down Expand Up @@ -167,7 +167,7 @@ $ %s query txs --%s 'message.sender=cosmos1...&message.action=withdraw_delegator
return err
}

return clientCtx.PrintOutput(txs)
return clientCtx.PrintObject(txs)
},
}

Expand Down Expand Up @@ -203,7 +203,7 @@ func QueryTxCmd() *cobra.Command {
return fmt.Errorf("no transaction found with hash %s", args[0])
}

return clientCtx.PrintOutput(output)
return clientCtx.PrintObject(output)
},
}

Expand Down
8 changes: 4 additions & 4 deletions x/bank/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Example:
if err != nil {
return err
}
return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
}

params := types.NewQueryBalanceRequest(addr, denom)
Expand All @@ -93,7 +93,7 @@ Example:
return err
}

return clientCtx.PrintOutput(res.Balance)
return clientCtx.PrintObject(res.Balance)
},
}

Expand Down Expand Up @@ -140,15 +140,15 @@ To query for the total supply of a specific coin denomination use:
return err
}

return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
}

res, err := queryClient.SupplyOf(context.Background(), &types.QuerySupplyOfRequest{Denom: denom})
if err != nil {
return err
}

return clientCtx.PrintOutput(&res.Amount)
return clientCtx.PrintObject(&res.Amount)
},
}

Expand Down
14 changes: 7 additions & 7 deletions x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func GetCmdQueryParams() *cobra.Command {
return err
}

return clientCtx.PrintOutput(&res.Params)
return clientCtx.PrintObject(&res.Params)
},
}

Expand Down Expand Up @@ -103,7 +103,7 @@ $ %s query distribution validator-outstanding-rewards %s1lwjmdnks33xwnmfayc64ycp
return err
}

return clientCtx.PrintOutput(&res.Rewards)
return clientCtx.PrintObject(&res.Rewards)
},
}

Expand Down Expand Up @@ -149,7 +149,7 @@ $ %s query distribution commission %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
return err
}

return clientCtx.PrintOutput(&res.Commission)
return clientCtx.PrintObject(&res.Commission)
},
}

Expand Down Expand Up @@ -215,7 +215,7 @@ $ %s query distribution slashes %svaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
return err
}

return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
},
}

Expand Down Expand Up @@ -271,7 +271,7 @@ $ %s query distribution rewards %s1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p %s1ggh
return err
}

return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
}

res, err := queryClient.DelegationTotalRewards(
Expand All @@ -282,7 +282,7 @@ $ %s query distribution rewards %s1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p %s1ggh
return err
}

return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
},
}

Expand Down Expand Up @@ -318,7 +318,7 @@ $ %s query distribution community-pool
return err
}

return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
},
}

Expand Down
6 changes: 3 additions & 3 deletions x/evidence/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GetQueryCmd() *cobra.Command {
Short: "Query for evidence by hash or for all (paginated) submitted evidence",
Long: strings.TrimSpace(
fmt.Sprintf(`Query for specific submitted evidence by hash or query for all (paginated) evidence:

Example:
$ %s query %s DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660
$ %s query %s --page=2 --limit=50
Expand Down Expand Up @@ -81,7 +81,7 @@ func queryEvidence(clientCtx client.Context, hash string) error {
return err
}

return clientCtx.PrintOutput(res.Evidence)
return clientCtx.PrintObject(res.Evidence)
}

func queryAllEvidence(clientCtx client.Context, pageReq *query.PageRequest) error {
Expand All @@ -96,5 +96,5 @@ func queryAllEvidence(clientCtx client.Context, pageReq *query.PageRequest) erro
return err
}

return clientCtx.PrintOutput(res)
return clientCtx.PrintObject(res)
}
Loading