* Update x/gov to use Any * Fixes * Remove MsgSubmitProposalLegacy * Update CHANGELOG.md * Add RegisterInterfaces for x/distribution, x/params, & x/upgrade * Fix query JSON issue * Fix gov tests * Revert custom Any Equals * Re-remove types * Rename receivers * Fix imports in gov * Sort imports * Make amino JSON signing work with Any * Run proto-gen * Create full amino wrapper * Fix errors * Fixes * Fix tests * Test fixes * Fix tests * Linting * Update ADR 019 and CHANGELOG * Updated ADR 019 * Extract Marshal/UnmarshalProposal * fix error * lint * linting * linting * Update client/keys/parse.go Co-authored-by: Marko <marbar3778@yahoo.com> * linting * Update docs/architecture/adr-019-protobuf-state-encoding.md Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Update docs/architecture/adr-019-protobuf-state-encoding.md Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Address review feedback * Add godocs * Fix errors * fix errors * revert file * Address review feedback * Address review feedback * Stacktrace debug flag * Fix tests * Address review feedback Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
package std
|
|
|
|
import (
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
|
)
|
|
|
|
var (
|
|
_ auth.Codec = (*Codec)(nil)
|
|
)
|
|
|
|
// Codec defines the application-level codec. This codec contains all the
|
|
// required module-specific codecs that are to be provided upon initialization.
|
|
type Codec struct {
|
|
codec.Marshaler
|
|
|
|
// Keep reference to the amino codec to allow backwards compatibility along
|
|
// with type, and interface registration.
|
|
amino *codec.Codec
|
|
|
|
anyUnpacker types.AnyUnpacker
|
|
}
|
|
|
|
func NewAppCodec(amino *codec.Codec, anyUnpacker types.AnyUnpacker) *Codec {
|
|
return &Codec{Marshaler: codec.NewHybridCodec(amino, anyUnpacker), amino: amino, anyUnpacker: anyUnpacker}
|
|
}
|
|
|
|
// MarshalAccount marshals an Account 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) MarshalAccount(accI authexported.Account) ([]byte, error) {
|
|
acc := &Account{}
|
|
if err := acc.SetAccount(accI); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return c.Marshaler.MarshalBinaryBare(acc)
|
|
}
|
|
|
|
// UnmarshalAccount returns an Account interface from raw encoded account bytes
|
|
// of a Proto-based Account type. An error is returned upon decoding failure.
|
|
func (c *Codec) UnmarshalAccount(bz []byte) (authexported.Account, error) {
|
|
acc := &Account{}
|
|
if err := c.Marshaler.UnmarshalBinaryBare(bz, acc); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return acc.GetAccount(), nil
|
|
}
|
|
|
|
// MarshalAccountJSON JSON encodes an account object implementing the Account
|
|
// interface.
|
|
func (c *Codec) MarshalAccountJSON(acc authexported.Account) ([]byte, error) {
|
|
return c.Marshaler.MarshalJSON(acc)
|
|
}
|
|
|
|
// UnmarshalAccountJSON returns an Account from JSON encoded bytes.
|
|
func (c *Codec) UnmarshalAccountJSON(bz []byte) (authexported.Account, error) {
|
|
acc := &Account{}
|
|
if err := c.Marshaler.UnmarshalJSON(bz, acc); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return acc.GetAccount(), nil
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// necessary types and interfaces registered. This codec is provided to all the
|
|
// modules the application depends on.
|
|
//
|
|
// NOTE: This codec will be deprecated in favor of AppCodec once all modules are
|
|
// migrated.
|
|
func MakeCodec(bm module.BasicManager) *codec.Codec {
|
|
cdc := codec.New()
|
|
|
|
bm.RegisterCodec(cdc)
|
|
vesting.RegisterCodec(cdc)
|
|
sdk.RegisterCodec(cdc)
|
|
codec.RegisterCrypto(cdc)
|
|
|
|
return cdc
|
|
}
|