Skip to content

Commit

Permalink
refactor!: remove clientCtx.PrintObjectLegacy (#17259)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Aug 3, 2023
1 parent 0396637 commit 8fe44f1
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (client) [#17259](https://github.com/cosmos/cosmos-sdk/pull/17259) Remove deprecated `clientCtx.PrintObjectLegacy`. Use `clientCtx.PrintProto` or `clientCtx.PrintRaw` instead.
* (x/distribution) [#17115](https://github.com/cosmos/cosmos-sdk/pull/17115) Use collections for `PreviousProposer` and `ValidatorSlashEvents`:
* remove from `Keeper`: `GetPreviousProposerConsAddr`, `SetPreviousProposerConsAddr`, `GetValidatorHistoricalReferenceCount`, `GetValidatorSlashEvent`, `SetValidatorSlashEvent`.
* (x/slashing) [17063](https://github.com/cosmos/cosmos-sdk/pull/17063) Use collections for `HistoricalInfo`:
Expand Down
11 changes: 0 additions & 11 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,6 @@ func (ctx Context) PrintProto(toPrint proto.Message) error {
return ctx.printOutput(out)
}

// PrintObjectLegacy is a variant of PrintProto that doesn't require a proto.Message type
// and uses amino JSON encoding.
// Deprecated: It will be removed in the near future!
func (ctx Context) PrintObjectLegacy(toPrint interface{}) error {
out, err := ctx.LegacyAmino.MarshalJSON(toPrint)
if err != nil {
return err
}
return ctx.printOutput(out)
}

// PrintRaw is a variant of PrintProto that doesn't require a proto.Message type
// and uses a raw JSON message. No marshaling is performed.
func (ctx Context) PrintRaw(toPrint json.RawMessage) error {
Expand Down
46 changes: 0 additions & 46 deletions client/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,52 +68,6 @@ x: "10"
`, buf.String())
}

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

animal := &testdata.Dog{
Size_: "big",
Name: "Spot",
}
anyAnimal, err := types.NewAnyWithValue(animal)
require.NoError(t, err)
hasAnimal := &testdata.HasAnimal{
Animal: anyAnimal,
X: 10,
}

// amino
amino := testdata.NewTestAmino()
ctx = ctx.WithLegacyAmino(&codec.LegacyAmino{Amino: amino})

// json
buf := &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = flags.OutputFormatJSON
err = ctx.PrintObjectLegacy(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`{"type":"testpb/HasAnimal","value":{"animal":{"type":"testpb/Dog","value":{"size":"big","name":"Spot"}},"x":"10"}}
`, buf.String())

// yaml
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = flags.OutputFormatText
err = ctx.PrintObjectLegacy(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`type: testpb/HasAnimal
value:
animal:
type: testpb/Dog
value:
name: Spot
size: big
x: "10"
`, buf.String())
}

func TestContext_PrintRaw(t *testing.T) {
ctx := client.Context{}
hasAnimal := json.RawMessage(`{"animal":{"@type":"/testpb.Dog","size":"big","name":"Spot"},"x":"10"}`)
Expand Down

0 comments on commit 8fe44f1

Please sign in to comment.