-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoding.go
39 lines (34 loc) · 1.19 KB
/
encoding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package compass
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)
type Codec struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
func MakeCodec(moduleBasics []module.AppModuleBasic, extraCodecs []string) Codec {
modBasic := module.NewBasicManager(moduleBasics...)
encodingConfig := MakeCodecConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
modBasic.RegisterLegacyAminoCodec(encodingConfig.Amino)
modBasic.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
func MakeCodecConfig() Codec {
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
return Codec{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: tx.NewTxConfig(marshaler, tx.DefaultSignModes),
Amino: codec.NewLegacyAmino(),
}
}