diff --git a/app/app.go b/app/app.go index d5f0153c..70ee99f4 100644 --- a/app/app.go +++ b/app/app.go @@ -52,13 +52,16 @@ import ( "github.com/cosmos/cosmos-sdk/std" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + "github.com/cosmos/cosmos-sdk/x/auth/tx" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -381,6 +384,21 @@ func NewApp( logger, ) + // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) + enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := tx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), + } + txConfig, err = tx.NewTxConfigWithOptions( + appCodec, + txConfigOpts, + ) + if err != nil { + panic(err) + } + app.txConfig = txConfig + app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), diff --git a/app/encoding.go b/app/encoding.go index 6af75256..cff24f3c 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -4,12 +4,8 @@ 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/x/auth/tx" ) -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. type EncodingConfig struct { @@ -18,36 +14,3 @@ type EncodingConfig struct { TxConfig client.TxConfig Amino *codec.LegacyAmino } - -// GetEncodingConfig returns the EncodingConfig. -func GetEncodingConfig() EncodingConfig { - return encodingConfig -} - -// makeEncodingConfig creates an EncodingConfig for an amino based test configuration. -func makeEncodingConfig() EncodingConfig { - amino := codec.NewLegacyAmino() - interfaceRegistry := types.NewInterfaceRegistry() - codec := codec.NewProtoCodec(interfaceRegistry) - txCfg := tx.NewTxConfig(codec, tx.DefaultSignModes) - - 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 -} diff --git a/cmd/seda-chaind/cmd/root.go b/cmd/seda-chaind/cmd/root.go index e132b721..ce7c95ee 100644 --- a/cmd/seda-chaind/cmd/root.go +++ b/cmd/seda-chaind/cmd/root.go @@ -37,7 +37,10 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/tx/signing" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" + "github.com/cosmos/cosmos-sdk/x/auth/tx" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -105,6 +108,26 @@ func NewRootCmd() *cobra.Command { return err } + // This needs to go after ReadFromClientConfig, as that function + // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode + // is only available if the client is online. + if !initClientCtx.Offline { + enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := tx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx), + } + txConfig, err := tx.NewTxConfigWithOptions( + initClientCtx.Codec, + txConfigOpts, + ) + if err != nil { + return err + } + + initClientCtx = initClientCtx.WithTxConfig(txConfig) + } + if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err } @@ -139,8 +162,8 @@ func NewRootCmd() *cobra.Command { GetClientConn: func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { return client.GetClientQueryContext(cmd) }, - // AddQueryConnFlags: sdkflags.AddQueryFlagsToCmd, - AddTxConnFlags: sdkflags.AddTxFlagsToCmd, + AddQueryConnFlags: sdkflags.AddQueryFlagsToCmd, + AddTxConnFlags: sdkflags.AddTxFlagsToCmd, } if err := autoCliOpts.EnhanceRootCommandWithBuilder(rootCmd, builder); err != nil { panic(err) diff --git a/e2e/chain.go b/e2e/chain.go index 7491b4d7..fe34e01e 100644 --- a/e2e/chain.go +++ b/e2e/chain.go @@ -8,6 +8,9 @@ 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/x/auth/tx" "github.com/sedaprotocol/seda-chain/app" ) @@ -24,7 +27,15 @@ var ( ) func init() { - encodingConfig = app.GetEncodingConfig() + encodingConfig.Amino = codec.NewLegacyAmino() + encodingConfig.InterfaceRegistry = types.NewInterfaceRegistry() + encodingConfig.Marshaler = codec.NewProtoCodec(encodingConfig.InterfaceRegistry) + encodingConfig.TxConfig = tx.NewTxConfig(encodingConfig.Marshaler, tx.DefaultSignModes) + + std.RegisterLegacyAminoCodec(encodingConfig.Amino) + std.RegisterInterfaces(encodingConfig.InterfaceRegistry) + app.ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) + cdc = encodingConfig.Marshaler txConfig = encodingConfig.TxConfig } diff --git a/testutil/network/network.go b/testutil/network/network.go index ac7c9848..65fb0dd9 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -12,12 +12,16 @@ import ( pruningtypes "cosmossdk.io/store/pruning/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/testutil/network" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/sedaprotocol/seda-chain/app" @@ -54,10 +58,18 @@ func New(t *testing.T, configs ...Config) *Network { // DefaultConfig will initialize config for the network with custom application, // genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig func DefaultConfig() network.Config { - var ( - encoding = app.GetEncodingConfig() - chainID = "chain-" + tmrand.NewRand().Str(6) - ) + chainID := "chain-" + tmrand.NewRand().Str(6) + + var encoding app.EncodingConfig + encoding.Amino = codec.NewLegacyAmino() + encoding.InterfaceRegistry = types.NewInterfaceRegistry() + encoding.Marshaler = codec.NewProtoCodec(encoding.InterfaceRegistry) + encoding.TxConfig = tx.NewTxConfig(encoding.Marshaler, tx.DefaultSignModes) + + std.RegisterLegacyAminoCodec(encoding.Amino) + std.RegisterInterfaces(encoding.InterfaceRegistry) + app.ModuleBasics.RegisterInterfaces(encoding.InterfaceRegistry) + return network.Config{ Codec: encoding.Marshaler, TxConfig: encoding.TxConfig,