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

refactor: remove gogoproto stringer annotations and MarshalYAML functions #13850

Merged
merged 25 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
93831c0
fix: bump gogoproto and fix tests mentioning #10965
julienrbrt Nov 14, 2022
67ac3fd
updates
julienrbrt Nov 14, 2022
d0f0e1d
`make proto-gen` again
julienrbrt Nov 14, 2022
3a7a2a9
updates
julienrbrt Nov 14, 2022
c861389
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 16, 2022
64db167
e.g of less human-readable string
julienrbrt Nov 16, 2022
65e7f8b
updates
julienrbrt Nov 16, 2022
fb0e230
migrate modules
julienrbrt Nov 16, 2022
cea5002
Revert "migrate modules"
julienrbrt Nov 16, 2022
3b3eeaa
split modules migrations
julienrbrt Nov 16, 2022
6fe2374
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 16, 2022
82734b2
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 17, 2022
84906ac
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 18, 2022
06a7d61
updates
julienrbrt Nov 18, 2022
aac0a14
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 21, 2022
fa77fc1
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 23, 2022
220d639
`make proto-gen`
julienrbrt Nov 23, 2022
0a37f03
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 23, 2022
0206892
feedback
julienrbrt Nov 23, 2022
c359074
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 25, 2022
1763fe9
`make proto-gen`
julienrbrt Nov 25, 2022
7c03bab
Merge branch 'main' into julien/bump-gogoproto
tac0turtle Nov 27, 2022
8a20880
Merge branch 'main' into julien/bump-gogoproto
tac0turtle Nov 27, 2022
d872a2a
add changelog and upgrading.md
julienrbrt Nov 28, 2022
2ce9cbb
Merge branch 'main' into julien/bump-gogoproto
julienrbrt Nov 28, 2022
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (x/auth) [#13850](https://github.com/cosmos/cosmos-sdk/pull/13850/) Remove `MarshalYAML` methods from `x/auth` types.
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
* (x/evidence) [#13740](https://github.com/cosmos/cosmos-sdk/pull/13740) The `NewQueryEvidenceRequest` function now takes `hash` as a HEX encoded `string`.
* (server) [#13485](https://github.com/cosmos/cosmos-sdk/pull/13485) The `Application` service now requires the `RegisterNodeService` method to be implemented.
* (x/slashing, x/staking) [#13122](https://github.com/cosmos/cosmos-sdk/pull/13122) Add the infraction a validator commited type as an argument to the `Slash` keeper method.
Expand Down Expand Up @@ -176,8 +177,9 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf

### Bug Fixes

* (x/auth) [#13838](https://github.com/cosmos/cosmos-sdk/pull/13838) Fix calling `String()` panics when pubkey is set on a `BaseAccount`.
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
* (x/group) [#13869](https://github.com/cosmos/cosmos-sdk/pull/13869) Group members weight must be positive and a finite number.
* (x/auth) [#13838](https://github.com/cosmos/cosmos-sdk/pull/13838) Fix calling `String()` and `MarshalYAML` panics when pubkey is set on a `BaseAccount`.
* (x/auth) [#13838](https://github.com/cosmos/cosmos-sdk/pull/13838) Fix calling `String()` panics when pubkey is set on a `BaseAccount`.
* (rosetta) [#13583](https://github.com/cosmos/cosmos-sdk/pull/13583) Misc fixes for cosmos-rosetta.
* (x/evidence) [#13740](https://github.com/cosmos/cosmos-sdk/pull/13740) Fix evidence query API to decode the hash properly.
* (bank) [#13691](https://github.com/cosmos/cosmos-sdk/issues/13691) Fix unhandled error for vesting account transfers, when total vesting amount exceeds total balance.
Expand Down
80 changes: 40 additions & 40 deletions api/cosmos/auth/v1beta1/auth.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/cosmos/gov/v1beta1/gov.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions proto/cosmos/auth/v1beta1/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ message BaseAccount {
message ModuleAccount {
option (amino.name) = "cosmos-sdk/ModuleAccount";
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos_proto.implements_interface) = "ModuleAccountI";

BaseAccount base_account = 1 [(gogoproto.embed) = true];
Expand All @@ -38,9 +37,8 @@ message ModuleAccount {

// Params defines the parameters for the auth module.
message Params {
option (amino.name) = "cosmos-sdk/x/auth/Params";
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
option (amino.name) = "cosmos-sdk/x/auth/Params";
option (gogoproto.equal) = true;

uint64 max_memo_characters = 1;
uint64 tx_sig_limit = 2;
Expand Down
4 changes: 1 addition & 3 deletions proto/cosmos/gov/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import "amino/amino.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1";

option (gogoproto.goproto_stringer_all) = false;
option (gogoproto.stringer_all) = false;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.goproto_getters_all) = false;

// VoteOption enumerates the valid vote options for a given governance proposal.
enum VoteOption {
Expand Down
46 changes: 0 additions & 46 deletions x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import (

"github.com/cosmos/gogoproto/proto"
"github.com/tendermint/tendermint/crypto"
"sigs.k8s.io/yaml"

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -138,18 +135,6 @@ func (acc BaseAccount) Validate() error {
return nil
}

// MarshalYAML returns the YAML representation of an account.
func (acc BaseAccount) MarshalYAML() (interface{}, error) {
registry := codectypes.NewInterfaceRegistry()
cryptocodec.RegisterInterfaces(registry)

bz, err := codec.MarshalYAML(codec.NewProtoCodec(registry), &acc)
if err != nil {
return nil, err
}
return string(bz), err
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (acc BaseAccount) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
if acc.PubKey == nil {
Expand Down Expand Up @@ -251,37 +236,6 @@ type moduleAccountPretty struct {
Permissions []string `json:"permissions"`
}

func (ma ModuleAccount) String() string {
out, err := ma.MarshalYAML()
if err != nil {
panic(err)
}

return out.(string)
}

// MarshalYAML returns the YAML representation of a ModuleAccount.
func (ma ModuleAccount) MarshalYAML() (interface{}, error) {
accAddr, err := sdk.AccAddressFromBech32(ma.Address)
if err != nil {
return nil, err
}

bs, err := yaml.Marshal(moduleAccountPretty{
Address: accAddr,
PubKey: "",
AccountNumber: ma.AccountNumber,
Sequence: ma.Sequence,
Name: ma.Name,
Permissions: ma.Permissions,
})
if err != nil {
return nil, err
}

return string(bs), nil
}

// MarshalJSON returns the JSON representation of a ModuleAccount.
func (ma ModuleAccount) MarshalJSON() ([]byte, error) {
accAddr, err := sdk.AccAddressFromBech32(ma.Address)
Expand Down
18 changes: 7 additions & 11 deletions x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"github.com/stretchr/testify/require"
"sigs.k8s.io/yaml"

"cosmossdk.io/depinject"

Expand Down Expand Up @@ -51,11 +50,8 @@ func TestBaseAddressPubKey(t *testing.T) {
require.Nil(t, err)
require.EqualValues(t, addr2, acc2.GetAddress())

// no error when calling MarshalYAML with an account with pubkey
_, err = acc.MarshalYAML()
require.Nil(t, err)

// no panic on calling string with an account with pubkey
require.NotEmpty(t, acc.String())
require.NotPanics(t, func() { _ = acc.String() })
}

Expand Down Expand Up @@ -127,14 +123,14 @@ func TestGenesisAccountValidate(t *testing.T) {
}
}

func TestModuleAccountMarshalYAML(t *testing.T) {
func TestModuleAccountString(t *testing.T) {
name := "test"
moduleAcc := types.NewEmptyModuleAccount(name, types.Minter, types.Burner, types.Staking)
bs, err := yaml.Marshal(moduleAcc)
require.NoError(t, err)

want := "account_number: 0\naddress: cosmos1n7rdpqvgf37ktx30a2sv2kkszk3m7ncmg5drhe\nname: test\npermissions:\n- minter\n- burner\n- staking\npublic_key: \"\"\nsequence: 0\n"
require.Equal(t, want, string(bs))
want := `base_account:<address:"cosmos1n7rdpqvgf37ktx30a2sv2kkszk3m7ncmg5drhe" > name:"test" permissions:"minter" permissions:"burner" permissions:"staking" `
require.Equal(t, want, moduleAcc.String())
moduleAcc.SetSequence(10)
want = `base_account:<address:"cosmos1n7rdpqvgf37ktx30a2sv2kkszk3m7ncmg5drhe" sequence:10 > name:"test" permissions:"minter" permissions:"burner" permissions:"staking" `
require.Equal(t, want, moduleAcc.String())
}

func TestHasPermissions(t *testing.T) {
Expand Down
Loading