Skip to content

Commit

Permalink
Remove JSON marshaler for base account (#6054)
Browse files Browse the repository at this point in the history
* Remove JSON marshaler for base account

* Add changelog entries
  • Loading branch information
alexanderbez authored Apr 22, 2020
1 parent 92d85bd commit b737e7f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 45 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Client Breaking

* (x/auth) [\#6054](https://github.com/cosmos/cosmos-sdk/pull/6054) Remove custom JSON marshaling for base accounts as multsigs cannot be bech32 decoded.
* (modules) [\#5572](https://github.com/cosmos/cosmos-sdk/pull/5572) The `/bank/balances/{address}` endpoint now returns all account
balances or a single balance by denom when the `denom` query parameter is present.
* (client) [\#5640](https://github.com/cosmos/cosmos-sdk/pull/5640) The rest server endpoint `/swagger-ui/` is replaced by ´/´.
Expand Down
45 changes: 0 additions & 45 deletions x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,51 +150,6 @@ func (acc BaseAccount) MarshalYAML() (interface{}, error) {
return string(bz), err
}

// MarshalJSON returns the JSON representation of a BaseAccount.
func (acc BaseAccount) MarshalJSON() ([]byte, error) {
alias := baseAccountPretty{
Address: acc.Address,
AccountNumber: acc.AccountNumber,
Sequence: acc.Sequence,
}

if acc.PubKey != nil {
pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.GetPubKey())
if err != nil {
return nil, err
}

alias.PubKey = pks
}

return json.Marshal(alias)
}

// UnmarshalJSON unmarshals raw JSON bytes into a BaseAccount.
func (acc *BaseAccount) UnmarshalJSON(bz []byte) error {
var alias baseAccountPretty
if err := json.Unmarshal(bz, &alias); err != nil {
return err
}

// NOTE: This will not work for multisig-based accounts as their Bech32
// encoding is too long.
if alias.PubKey != "" {
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey)
if err != nil {
return err
}

acc.PubKey = pk.Bytes()
}

acc.Address = alias.Address
acc.AccountNumber = alias.AccountNumber
acc.Sequence = alias.Sequence

return nil
}

// NewModuleAddress creates an AccAddress from the hash of the module's name
func NewModuleAddress(name string) sdk.AccAddress {
return sdk.AccAddress(crypto.AddressHash([]byte(name)))
Expand Down

0 comments on commit b737e7f

Please sign in to comment.