Skip to content

Commit

Permalink
Bank proto buf migration (cosmos#6166)
Browse files Browse the repository at this point in the history
* Bank proto buf migration

* WIP: Added proto code for bank

* added supply on bank module

* Bank module proto migration

* formatter applied

* Added comment for RegisterInterfaceTypes in bank/module
  • Loading branch information
atheeshp authored May 12, 2020
1 parent 2f68c41 commit da92383
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 595 deletions.
42 changes: 0 additions & 42 deletions std/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/bank"
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
)

var (
_ auth.Codec = (*Codec)(nil)
_ bank.Codec = (*Codec)(nil)
_ gov.Codec = (*Codec)(nil)
)

Expand Down Expand Up @@ -74,45 +71,6 @@ func (c *Codec) UnmarshalAccountJSON(bz []byte) (authexported.Account, error) {
return acc.GetAccount(), nil
}

// MarshalSupply marshals a SupplyI interface. If the given type implements
// the Marshaler interface, it is treated as a Proto-defined message and
// serialized that way. Otherwise, it falls back on the internal Amino codec.
func (c *Codec) MarshalSupply(supplyI bankexported.SupplyI) ([]byte, error) {
supply := &Supply{}
if err := supply.SetSupplyI(supplyI); err != nil {
return nil, err
}

return c.Marshaler.MarshalBinaryBare(supply)
}

// UnmarshalSupply returns a SupplyI interface from raw encoded account bytes
// of a Proto-based SupplyI type. An error is returned upon decoding failure.
func (c *Codec) UnmarshalSupply(bz []byte) (bankexported.SupplyI, error) {
supply := &Supply{}
if err := c.Marshaler.UnmarshalBinaryBare(bz, supply); err != nil {
return nil, err
}

return supply.GetSupplyI(), nil
}

// MarshalSupplyJSON JSON encodes a supply object implementing the SupplyI
// interface.
func (c *Codec) MarshalSupplyJSON(supply bankexported.SupplyI) ([]byte, error) {
return c.Marshaler.MarshalJSON(supply)
}

// UnmarshalSupplyJSON returns a SupplyI from JSON encoded bytes.
func (c *Codec) UnmarshalSupplyJSON(bz []byte) (bankexported.SupplyI, error) {
supply := &Supply{}
if err := c.Marshaler.UnmarshalJSON(bz, supply); err != nil {
return nil, err
}

return supply.GetSupplyI(), nil
}

// MarshalProposal marshals a Proposal. It accepts a Proposal defined by the x/gov
// module and uses the application-level Proposal type which has the concrete
// Content implementation to serialize.
Expand Down
Loading

0 comments on commit da92383

Please sign in to comment.