cosmos-sdk/x/auth/types/codec.go

46 lines
1.3 KiB
Go
Raw Normal View History

package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
)
// RegisterCodec registers the account interfaces and concrete types on the
// provided Amino codec.
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*ModuleAccountI)(nil), nil)
cdc.RegisterInterface((*GenesisAccount)(nil), nil)
cdc.RegisterInterface((*AccountI)(nil), nil)
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil)
cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil)
2019-06-28 13:11:27 -07:00
cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil)
}
// RegisterInterface associates protoName with AccountI interface
// and creates a registry of it's concrete implementations
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterInterface(
"cosmos_sdk.auth.v1.AccountI",
(*AccountI)(nil),
&BaseAccount{},
&ModuleAccount{},
)
}
// RegisterKeyTypeCodec registers an external concrete type defined in
// another module for the internal ModuleCdc.
func RegisterKeyTypeCodec(o interface{}, name string) {
amino.RegisterConcrete(o, name, nil)
}
var (
amino = codec.New()
ModuleCdc = codec.NewHybridCodec(amino, types.NewInterfaceRegistry())
)
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
}