2019-06-05 16:26:17 -07:00
|
|
|
package types
|
2018-09-13 11:17:32 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2019-06-24 13:45:09 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/exported"
|
2018-09-13 11:17:32 -07:00
|
|
|
)
|
|
|
|
|
2020-02-18 04:50:13 -08:00
|
|
|
// Codec defines the interface needed to serialize x/auth state. It must be
|
|
|
|
// aware of all concrete account types.
|
|
|
|
type Codec interface {
|
|
|
|
codec.Marshaler
|
2019-09-12 12:22:25 -07:00
|
|
|
|
2020-02-18 04:50:13 -08:00
|
|
|
MarshalAccount(acc exported.Account) ([]byte, error)
|
|
|
|
UnmarshalAccount(bz []byte) (exported.Account, error)
|
|
|
|
|
|
|
|
MarshalAccountJSON(acc exported.Account) ([]byte, error)
|
|
|
|
UnmarshalAccountJSON(bz []byte) (exported.Account, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterCodec registers the account interfaces and concrete types on the
|
|
|
|
// provided Amino codec.
|
2018-09-13 11:17:32 -07:00
|
|
|
func RegisterCodec(cdc *codec.Codec) {
|
2020-04-20 12:32:10 -07:00
|
|
|
cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil)
|
2019-09-12 12:22:25 -07:00
|
|
|
cdc.RegisterInterface((*exported.GenesisAccount)(nil), nil)
|
2019-06-24 13:45:09 -07:00
|
|
|
cdc.RegisterInterface((*exported.Account)(nil), nil)
|
2019-06-28 13:11:27 -07:00
|
|
|
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/Account", nil)
|
2020-04-20 12:32:10 -07:00
|
|
|
cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil)
|
2019-06-28 13:11:27 -07:00
|
|
|
cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil)
|
2019-02-08 13:35:19 -08:00
|
|
|
}
|
|
|
|
|
2020-03-30 15:09:28 -07:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:50:13 -08:00
|
|
|
var (
|
|
|
|
amino = codec.New()
|
|
|
|
)
|
2018-09-13 11:17:32 -07:00
|
|
|
|
|
|
|
func init() {
|
2020-02-18 04:50:13 -08:00
|
|
|
RegisterCodec(amino)
|
|
|
|
codec.RegisterCrypto(amino)
|
2018-09-13 11:17:32 -07:00
|
|
|
}
|