-
Notifications
You must be signed in to change notification settings - Fork 261
/
encoding.go
51 lines (43 loc) · 1.45 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
40
41
42
43
44
45
46
47
48
49
50
51
package encoding
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)
type ModuleRegister interface {
RegisterLegacyAminoCodec(*codec.LegacyAmino)
RegisterInterfaces(codectypes.InterfaceRegistry)
}
// Config specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type Config struct {
InterfaceRegistry codectypes.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
// MakeConfig creates an encoding config for the app.
func MakeConfig(regs ...ModuleRegister) Config {
// create the codec
amino := codec.NewLegacyAmino()
interfaceRegistry := codectypes.NewInterfaceRegistry()
// register the standard types from the sdk
std.RegisterLegacyAminoCodec(amino)
std.RegisterInterfaces(interfaceRegistry)
// register specific modules
for _, reg := range regs {
reg.RegisterInterfaces(interfaceRegistry)
reg.RegisterLegacyAminoCodec(amino)
}
// create the final configuration
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)
return Config{
InterfaceRegistry: interfaceRegistry,
Codec: marshaler,
TxConfig: txCfg,
Amino: amino,
}
}