Skip to content

Commit

Permalink
chore: revert encoding config refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jim380 committed Jan 4, 2024
1 parent 004c5ac commit 063271f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
27 changes: 21 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"cosmossdk.io/x/feegrant"
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
feegrantmodule "cosmossdk.io/x/feegrant/module"
"cosmossdk.io/x/tx/signing"
"cosmossdk.io/x/upgrade"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
upgradetypes "cosmossdk.io/x/upgrade/types"
Expand All @@ -41,6 +42,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
Expand Down Expand Up @@ -98,6 +100,7 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
Expand Down Expand Up @@ -290,12 +293,24 @@ func NewApp(
/* =================================================== */
/* ENCODING CONFIG */
/* =================================================== */
encodingConfig := GetEncodingConfig()

interfaceRegistry := encodingConfig.InterfaceRegistry
appCodec := encodingConfig.Marshaler
txConfig := encodingConfig.TxConfig
legacyAmino := encodingConfig.Amino
// building encodings
interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
},
})
if err != nil {
panic(err)
}
appCodec := codec.NewProtoCodec(interfaceRegistry)
legacyAmino := codec.NewLegacyAmino()
txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes)

std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)
Expand Down
39 changes: 14 additions & 25 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package app

import (
"cosmossdk.io/x/tx/signing"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

var encodingConfig = newEncodingConfig()
var encodingConfig = initEncodingConfig()

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
Expand All @@ -28,36 +24,29 @@ func GetEncodingConfig() EncodingConfig {
return encodingConfig
}

func newEncodingConfig() EncodingConfig {
// makeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func makeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()

interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
},
})
if err != nil {
panic(err)
}

interfaceRegistry := types.NewInterfaceRegistry()
codec := codec.NewProtoCodec(interfaceRegistry)
txCfg := authtx.NewTxConfig(codec, authtx.DefaultSignModes)
txCfg := tx.NewTxConfig(codec, tx.DefaultSignModes)

encodingConfig := EncodingConfig{
return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: codec,
TxConfig: txCfg,
Amino: amino,
}
}

// initEncodingConfig initializes an EncodingConfig.
func initEncodingConfig() EncodingConfig {
encodingConfig := makeEncodingConfig()

std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)

// ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)

return encodingConfig
Expand Down

0 comments on commit 063271f

Please sign in to comment.