github.com/InjectiveLabs/sdk-go@v1.53.0/chain/codec/types/types.go (about) 1 package types 2 3 import ( 4 "cosmossdk.io/x/tx/signing" 5 "github.com/cosmos/cosmos-sdk/client" 6 "github.com/cosmos/cosmos-sdk/codec" 7 "github.com/cosmos/cosmos-sdk/codec/address" 8 "github.com/cosmos/cosmos-sdk/codec/types" 9 sdktypes "github.com/cosmos/cosmos-sdk/types" 10 "github.com/cosmos/cosmos-sdk/x/auth/tx" 11 "github.com/cosmos/gogoproto/proto" 12 13 injcodec "github.com/InjectiveLabs/sdk-go/chain/codec" 14 ) 15 16 type EncodingConfig struct { 17 InterfaceRegistry types.InterfaceRegistry 18 Codec codec.Codec 19 TxConfig client.TxConfig 20 Amino *codec.LegacyAmino 21 } 22 23 // MakeEncodingConfig creates an EncodingConfig for testing 24 func MakeEncodingConfig() EncodingConfig { 25 cdc := codec.NewLegacyAmino() 26 interfaceRegistry := NewInterfaceRegistry() 27 appCodec := codec.NewProtoCodec(interfaceRegistry) 28 encodingConfig := EncodingConfig{ 29 InterfaceRegistry: interfaceRegistry, 30 Codec: appCodec, 31 TxConfig: tx.NewTxConfig(appCodec, tx.DefaultSignModes), 32 Amino: cdc, 33 } 34 35 injcodec.RegisterInterfaces(encodingConfig.InterfaceRegistry) 36 injcodec.RegisterLegacyAminoCodec(encodingConfig.Amino) 37 return encodingConfig 38 } 39 40 // NewInterfaceRegistry returns a new InterfaceRegistry 41 func NewInterfaceRegistry() types.InterfaceRegistry { 42 registry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ 43 ProtoFiles: proto.HybridResolver, 44 SigningOptions: signing.Options{ 45 AddressCodec: address.Bech32Codec{ 46 Bech32Prefix: sdktypes.GetConfig().GetBech32AccountAddrPrefix(), 47 }, 48 ValidatorAddressCodec: address.Bech32Codec{ 49 Bech32Prefix: sdktypes.GetConfig().GetBech32ValidatorAddrPrefix(), 50 }, 51 }, 52 }) 53 if err != nil { 54 panic(err) 55 } 56 return registry 57 }