From b327cdbb5ef2222e688454f6f1d08a1f9fc3244f Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 18 Aug 2023 00:17:16 +0800 Subject: [PATCH 1/4] feat: add event-query-tx-for cmd to subscribe and wait for transaction (#17274) (cherry picked from commit d0f23440bb043bac7d9eeacf2318fa5f1eeea76c) # Conflicts: # CHANGELOG.md # simapp/simd/cmd/commands.go --- CHANGELOG.md | 11 ++ client/rpc/tx.go | 140 +++++++++++++++++++ simapp/simd/cmd/commands.go | 263 ++++++++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+) create mode 100644 client/rpc/tx.go create mode 100644 simapp/simd/cmd/commands.go diff --git a/CHANGELOG.md b/CHANGELOG.md index f4c2a79626a8..7678f0698620 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,17 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +<<<<<<< HEAD +======= +### Features + +* (keyring) [#17424](https://github.com/cosmos/cosmos-sdk/pull/17424) Allows to import private keys encoded in hex. +* (x/bank) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16852) Add `DenomMetadataByQueryString` query in bank module to support metadata query by query string. +* (client/rpc) [#17274](https://github.com/cosmos/cosmos-sdk/pull/17274) Add `QueryEventForTxCmd` cmd to subscribe and wait event for transaction by hash. +* (baseapp) [#16239](https://github.com/cosmos/cosmos-sdk/pull/16239) Add Gas Limits to allow node operators to resource bound queries. +* (baseapp) [#17393](https://github.com/cosmos/cosmos-sdk/pull/17394) Check BlockID Flag on Votes in `ValidateVoteExtensions` + +>>>>>>> d0f23440b (feat: add event-query-tx-for cmd to subscribe and wait for transaction (#17274)) ### Improvements * (x/gov) [#17387](https://github.com/cosmos/cosmos-sdk/pull/17387) Add `MsgSubmitProposal` `SetMsgs` method. diff --git a/client/rpc/tx.go b/client/rpc/tx.go new file mode 100644 index 000000000000..02b9852b8601 --- /dev/null +++ b/client/rpc/tx.go @@ -0,0 +1,140 @@ +package rpc + +import ( + "context" + "encoding/hex" + "fmt" + "strings" + "time" + + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + coretypes "github.com/cometbft/cometbft/rpc/core/types" + tmtypes "github.com/cometbft/cometbft/types" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" +) + +func newTxResponseCheckTx(res *coretypes.ResultBroadcastTxCommit) *sdk.TxResponse { + if res == nil { + return nil + } + + var txHash string + if res.Hash != nil { + txHash = res.Hash.String() + } + + parsedLogs, _ := sdk.ParseABCILogs(res.CheckTx.Log) + + return &sdk.TxResponse{ + Height: res.Height, + TxHash: txHash, + Codespace: res.CheckTx.Codespace, + Code: res.CheckTx.Code, + Data: strings.ToUpper(hex.EncodeToString(res.CheckTx.Data)), + RawLog: res.CheckTx.Log, + Logs: parsedLogs, + Info: res.CheckTx.Info, + GasWanted: res.CheckTx.GasWanted, + GasUsed: res.CheckTx.GasUsed, + Events: res.CheckTx.Events, + } +} + +func newTxResponseDeliverTx(res *coretypes.ResultBroadcastTxCommit) *sdk.TxResponse { + if res == nil { + return nil + } + + var txHash string + if res.Hash != nil { + txHash = res.Hash.String() + } + + parsedLogs, _ := sdk.ParseABCILogs(res.TxResult.Log) + + return &sdk.TxResponse{ + Height: res.Height, + TxHash: txHash, + Codespace: res.TxResult.Codespace, + Code: res.TxResult.Code, + Data: strings.ToUpper(hex.EncodeToString(res.TxResult.Data)), + RawLog: res.TxResult.Log, + Logs: parsedLogs, + Info: res.TxResult.Info, + GasWanted: res.TxResult.GasWanted, + GasUsed: res.TxResult.GasUsed, + Events: res.TxResult.Events, + } +} + +func newResponseFormatBroadcastTxCommit(res *coretypes.ResultBroadcastTxCommit) *sdk.TxResponse { + if res == nil { + return nil + } + + if !res.CheckTx.IsOK() { + return newTxResponseCheckTx(res) + } + + return newTxResponseDeliverTx(res) +} + +// QueryEventForTxCmd returns a CLI command that subscribes to a WebSocket connection and waits for a transaction event with the given hash. +func QueryEventForTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "event-query-tx-for [hash]", + Short: "Query for a transaction by hash", + Long: `Subscribes to a CometBFT WebSocket connection and waits for a transaction event with the given hash.`, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + c, err := rpchttp.New(clientCtx.NodeURI, "/websocket") + if err != nil { + return err + } + if err := c.Start(); err != nil { + return err + } + defer c.Stop() //nolint:errcheck // ignore stop error + + ctx, cancel := context.WithTimeout(context.Background(), time.Second*15) + defer cancel() + + hash := args[0] + query := fmt.Sprintf("%s='%s' AND %s='%s'", tmtypes.EventTypeKey, tmtypes.EventTx, tmtypes.TxHashKey, hash) + const subscriber = "subscriber" + eventCh, err := c.Subscribe(ctx, subscriber, query) + if err != nil { + return fmt.Errorf("failed to subscribe to tx: %w", err) + } + defer c.UnsubscribeAll(context.Background(), subscriber) //nolint:errcheck // ignore unsubscribe error + + select { + case evt := <-eventCh: + if txe, ok := evt.Data.(tmtypes.EventDataTx); ok { + res := &coretypes.ResultBroadcastTxCommit{ + TxResult: txe.Result, + Hash: tmtypes.Tx(txe.Tx).Hash(), + Height: txe.Height, + } + return clientCtx.PrintProto(newResponseFormatBroadcastTxCommit(res)) + } + case <-ctx.Done(): + return errors.ErrLogic.Wrapf("timed out waiting for event, the transaction could have already been included or wasn't yet included") + } + return nil + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/simapp/simd/cmd/commands.go b/simapp/simd/cmd/commands.go new file mode 100644 index 000000000000..5f0294fd9d33 --- /dev/null +++ b/simapp/simd/cmd/commands.go @@ -0,0 +1,263 @@ +package cmd + +import ( + "errors" + "io" + "os" + + cmtcfg "github.com/cometbft/cometbft/config" + dbm "github.com/cosmos/cosmos-db" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "cosmossdk.io/log" + "cosmossdk.io/simapp" + confixcmd "cosmossdk.io/tools/confix/cmd" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/debug" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/keys" + "github.com/cosmos/cosmos-sdk/client/pruning" + "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/client/snapshot" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/server" + serverconfig "github.com/cosmos/cosmos-sdk/server/config" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" +) + +// initCometBFTConfig helps to override default CometBFT Config values. +// return cmtcfg.DefaultConfig if no custom configuration is required for the application. +func initCometBFTConfig() *cmtcfg.Config { + cfg := cmtcfg.DefaultConfig() + + // these values put a higher strain on node memory + // cfg.P2P.MaxNumInboundPeers = 100 + // cfg.P2P.MaxNumOutboundPeers = 40 + + return cfg +} + +// initAppConfig helps to override default appConfig template and configs. +// return "", nil if no custom configuration is required for the application. +func initAppConfig() (string, interface{}) { + // The following code snippet is just for reference. + + // WASMConfig defines configuration for the wasm module. + type WASMConfig struct { + // This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries + QueryGasLimit uint64 `mapstructure:"query_gas_limit"` + + // Address defines the gRPC-web server to listen on + LruSize uint64 `mapstructure:"lru_size"` + } + + type CustomAppConfig struct { + serverconfig.Config `mapstructure:",squash"` + + WASM WASMConfig `mapstructure:"wasm"` + } + + // Optionally allow the chain developer to overwrite the SDK's default + // server config. + srvCfg := serverconfig.DefaultConfig() + // The SDK's default minimum gas price is set to "" (empty value) inside + // app.toml. If left empty by validators, the node will halt on startup. + // However, the chain developer can set a default app.toml value for their + // validators here. + // + // In summary: + // - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their + // own app.toml config, + // - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their + // own app.toml to override, or use this default value. + // + // In simapp, we set the min gas prices to 0. + srvCfg.MinGasPrices = "0stake" + // srvCfg.BaseConfig.IAVLDisableFastNode = true // disable fastnode by default + + customAppConfig := CustomAppConfig{ + Config: *srvCfg, + WASM: WASMConfig{ + LruSize: 1, + QueryGasLimit: 300000, + }, + } + + customAppTemplate := serverconfig.DefaultConfigTemplate + ` +[wasm] +# This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries +query_gas_limit = 300000 +# This is the number of wasm vm instances we keep cached in memory for speed-up +# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally +lru_size = 0` + + return customAppTemplate, customAppConfig +} + +func initRootCmd( + rootCmd *cobra.Command, + txConfig client.TxConfig, + interfaceRegistry codectypes.InterfaceRegistry, + appCodec codec.Codec, + basicManager module.BasicManager, +) { + cfg := sdk.GetConfig() + cfg.Seal() + + rootCmd.AddCommand( + genutilcli.InitCmd(basicManager), + NewTestnetCmd(basicManager, banktypes.GenesisBalancesIterator{}), + debug.Cmd(), + confixcmd.ConfigCommand(), + pruning.Cmd(newApp), + snapshot.Cmd(newApp), + ) + + server.AddCommands(rootCmd, newApp, appExport, addModuleInitFlags) + + // add keybase, auxiliary RPC, query, genesis, and tx child commands + rootCmd.AddCommand( + server.StatusCommand(), + genesisCommand(txConfig, basicManager), + queryCommand(), + txCommand(), + keys.Commands(), + ) +} + +func addModuleInitFlags(startCmd *cobra.Command) { + crisis.AddModuleInitFlags(startCmd) +} + +// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter +func genesisCommand(txConfig client.TxConfig, basicManager module.BasicManager, cmds ...*cobra.Command) *cobra.Command { + cmd := genutilcli.Commands(txConfig, basicManager) + + for _, subCmd := range cmds { + cmd.AddCommand(subCmd) + } + return cmd +} + +func queryCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "query", + Aliases: []string{"q"}, + Short: "Querying subcommands", + DisableFlagParsing: false, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + rpc.QueryEventForTxCmd(), + server.QueryBlockCmd(), + authcmd.QueryTxsByEventsCmd(), + server.QueryBlocksCmd(), + authcmd.QueryTxCmd(), + server.QueryBlockResultsCmd(), + ) + + return cmd +} + +func txCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "tx", + Short: "Transactions subcommands", + DisableFlagParsing: false, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + authcmd.GetSignCommand(), + authcmd.GetSignBatchCommand(), + authcmd.GetMultiSignCommand(), + authcmd.GetMultiSignBatchCmd(), + authcmd.GetValidateSignaturesCommand(), + authcmd.GetBroadcastCommand(), + authcmd.GetEncodeCommand(), + authcmd.GetDecodeCommand(), + authcmd.GetAuxToFeeCommand(), + authcmd.GetSimulateCmd(), + ) + + return cmd +} + +// newApp creates the application +func newApp( + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + appOpts servertypes.AppOptions, +) servertypes.Application { + baseappOptions := server.DefaultBaseappOptions(appOpts) + + return simapp.NewSimApp( + logger, db, traceStore, true, + appOpts, + baseappOptions..., + ) +} + +// appExport creates a new simapp (optionally at a given height) and exports state. +func appExport( + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + height int64, + forZeroHeight bool, + jailAllowedAddrs []string, + appOpts servertypes.AppOptions, + modulesToExport []string, +) (servertypes.ExportedApp, error) { + // this check is necessary as we use the flag in x/upgrade. + // we can exit more gracefully by checking the flag here. + homePath, ok := appOpts.Get(flags.FlagHome).(string) + if !ok || homePath == "" { + return servertypes.ExportedApp{}, errors.New("application home not set") + } + + viperAppOpts, ok := appOpts.(*viper.Viper) + if !ok { + return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper") + } + + // overwrite the FlagInvCheckPeriod + viperAppOpts.Set(server.FlagInvCheckPeriod, 1) + appOpts = viperAppOpts + + var simApp *simapp.SimApp + if height != -1 { + simApp = simapp.NewSimApp(logger, db, traceStore, false, appOpts) + + if err := simApp.LoadHeight(height); err != nil { + return servertypes.ExportedApp{}, err + } + } else { + simApp = simapp.NewSimApp(logger, db, traceStore, true, appOpts) + } + + return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) +} + +var tempDir = func() string { + dir, err := os.MkdirTemp("", "simapp") + if err != nil { + dir = simapp.DefaultNodeHome + } + defer os.RemoveAll(dir) + + return dir +} From 99ce7e0e1efceeb1e01f987a22aa18c8e2ba8f5d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 17 Aug 2023 18:28:53 +0200 Subject: [PATCH 2/4] partly fixing --- CHANGELOG.md | 7 - simapp/simd/cmd/commands.go | 263 ------------------------------------ simapp/simd/cmd/root.go | 1 + 3 files changed, 1 insertion(+), 270 deletions(-) delete mode 100644 simapp/simd/cmd/commands.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 7678f0698620..24e7b99db686 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,17 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] -<<<<<<< HEAD -======= ### Features -* (keyring) [#17424](https://github.com/cosmos/cosmos-sdk/pull/17424) Allows to import private keys encoded in hex. -* (x/bank) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16852) Add `DenomMetadataByQueryString` query in bank module to support metadata query by query string. * (client/rpc) [#17274](https://github.com/cosmos/cosmos-sdk/pull/17274) Add `QueryEventForTxCmd` cmd to subscribe and wait event for transaction by hash. -* (baseapp) [#16239](https://github.com/cosmos/cosmos-sdk/pull/16239) Add Gas Limits to allow node operators to resource bound queries. -* (baseapp) [#17393](https://github.com/cosmos/cosmos-sdk/pull/17394) Check BlockID Flag on Votes in `ValidateVoteExtensions` ->>>>>>> d0f23440b (feat: add event-query-tx-for cmd to subscribe and wait for transaction (#17274)) ### Improvements * (x/gov) [#17387](https://github.com/cosmos/cosmos-sdk/pull/17387) Add `MsgSubmitProposal` `SetMsgs` method. diff --git a/simapp/simd/cmd/commands.go b/simapp/simd/cmd/commands.go deleted file mode 100644 index 5f0294fd9d33..000000000000 --- a/simapp/simd/cmd/commands.go +++ /dev/null @@ -1,263 +0,0 @@ -package cmd - -import ( - "errors" - "io" - "os" - - cmtcfg "github.com/cometbft/cometbft/config" - dbm "github.com/cosmos/cosmos-db" - "github.com/spf13/cobra" - "github.com/spf13/viper" - - "cosmossdk.io/log" - "cosmossdk.io/simapp" - confixcmd "cosmossdk.io/tools/confix/cmd" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/debug" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/client/pruning" - "github.com/cosmos/cosmos-sdk/client/rpc" - "github.com/cosmos/cosmos-sdk/client/snapshot" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/server" - serverconfig "github.com/cosmos/cosmos-sdk/server/config" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/cosmos-sdk/x/crisis" - genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" -) - -// initCometBFTConfig helps to override default CometBFT Config values. -// return cmtcfg.DefaultConfig if no custom configuration is required for the application. -func initCometBFTConfig() *cmtcfg.Config { - cfg := cmtcfg.DefaultConfig() - - // these values put a higher strain on node memory - // cfg.P2P.MaxNumInboundPeers = 100 - // cfg.P2P.MaxNumOutboundPeers = 40 - - return cfg -} - -// initAppConfig helps to override default appConfig template and configs. -// return "", nil if no custom configuration is required for the application. -func initAppConfig() (string, interface{}) { - // The following code snippet is just for reference. - - // WASMConfig defines configuration for the wasm module. - type WASMConfig struct { - // This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries - QueryGasLimit uint64 `mapstructure:"query_gas_limit"` - - // Address defines the gRPC-web server to listen on - LruSize uint64 `mapstructure:"lru_size"` - } - - type CustomAppConfig struct { - serverconfig.Config `mapstructure:",squash"` - - WASM WASMConfig `mapstructure:"wasm"` - } - - // Optionally allow the chain developer to overwrite the SDK's default - // server config. - srvCfg := serverconfig.DefaultConfig() - // The SDK's default minimum gas price is set to "" (empty value) inside - // app.toml. If left empty by validators, the node will halt on startup. - // However, the chain developer can set a default app.toml value for their - // validators here. - // - // In summary: - // - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their - // own app.toml config, - // - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their - // own app.toml to override, or use this default value. - // - // In simapp, we set the min gas prices to 0. - srvCfg.MinGasPrices = "0stake" - // srvCfg.BaseConfig.IAVLDisableFastNode = true // disable fastnode by default - - customAppConfig := CustomAppConfig{ - Config: *srvCfg, - WASM: WASMConfig{ - LruSize: 1, - QueryGasLimit: 300000, - }, - } - - customAppTemplate := serverconfig.DefaultConfigTemplate + ` -[wasm] -# This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries -query_gas_limit = 300000 -# This is the number of wasm vm instances we keep cached in memory for speed-up -# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally -lru_size = 0` - - return customAppTemplate, customAppConfig -} - -func initRootCmd( - rootCmd *cobra.Command, - txConfig client.TxConfig, - interfaceRegistry codectypes.InterfaceRegistry, - appCodec codec.Codec, - basicManager module.BasicManager, -) { - cfg := sdk.GetConfig() - cfg.Seal() - - rootCmd.AddCommand( - genutilcli.InitCmd(basicManager), - NewTestnetCmd(basicManager, banktypes.GenesisBalancesIterator{}), - debug.Cmd(), - confixcmd.ConfigCommand(), - pruning.Cmd(newApp), - snapshot.Cmd(newApp), - ) - - server.AddCommands(rootCmd, newApp, appExport, addModuleInitFlags) - - // add keybase, auxiliary RPC, query, genesis, and tx child commands - rootCmd.AddCommand( - server.StatusCommand(), - genesisCommand(txConfig, basicManager), - queryCommand(), - txCommand(), - keys.Commands(), - ) -} - -func addModuleInitFlags(startCmd *cobra.Command) { - crisis.AddModuleInitFlags(startCmd) -} - -// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter -func genesisCommand(txConfig client.TxConfig, basicManager module.BasicManager, cmds ...*cobra.Command) *cobra.Command { - cmd := genutilcli.Commands(txConfig, basicManager) - - for _, subCmd := range cmds { - cmd.AddCommand(subCmd) - } - return cmd -} - -func queryCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "query", - Aliases: []string{"q"}, - Short: "Querying subcommands", - DisableFlagParsing: false, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - rpc.QueryEventForTxCmd(), - server.QueryBlockCmd(), - authcmd.QueryTxsByEventsCmd(), - server.QueryBlocksCmd(), - authcmd.QueryTxCmd(), - server.QueryBlockResultsCmd(), - ) - - return cmd -} - -func txCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "tx", - Short: "Transactions subcommands", - DisableFlagParsing: false, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - authcmd.GetSignCommand(), - authcmd.GetSignBatchCommand(), - authcmd.GetMultiSignCommand(), - authcmd.GetMultiSignBatchCmd(), - authcmd.GetValidateSignaturesCommand(), - authcmd.GetBroadcastCommand(), - authcmd.GetEncodeCommand(), - authcmd.GetDecodeCommand(), - authcmd.GetAuxToFeeCommand(), - authcmd.GetSimulateCmd(), - ) - - return cmd -} - -// newApp creates the application -func newApp( - logger log.Logger, - db dbm.DB, - traceStore io.Writer, - appOpts servertypes.AppOptions, -) servertypes.Application { - baseappOptions := server.DefaultBaseappOptions(appOpts) - - return simapp.NewSimApp( - logger, db, traceStore, true, - appOpts, - baseappOptions..., - ) -} - -// appExport creates a new simapp (optionally at a given height) and exports state. -func appExport( - logger log.Logger, - db dbm.DB, - traceStore io.Writer, - height int64, - forZeroHeight bool, - jailAllowedAddrs []string, - appOpts servertypes.AppOptions, - modulesToExport []string, -) (servertypes.ExportedApp, error) { - // this check is necessary as we use the flag in x/upgrade. - // we can exit more gracefully by checking the flag here. - homePath, ok := appOpts.Get(flags.FlagHome).(string) - if !ok || homePath == "" { - return servertypes.ExportedApp{}, errors.New("application home not set") - } - - viperAppOpts, ok := appOpts.(*viper.Viper) - if !ok { - return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper") - } - - // overwrite the FlagInvCheckPeriod - viperAppOpts.Set(server.FlagInvCheckPeriod, 1) - appOpts = viperAppOpts - - var simApp *simapp.SimApp - if height != -1 { - simApp = simapp.NewSimApp(logger, db, traceStore, false, appOpts) - - if err := simApp.LoadHeight(height); err != nil { - return servertypes.ExportedApp{}, err - } - } else { - simApp = simapp.NewSimApp(logger, db, traceStore, true, appOpts) - } - - return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) -} - -var tempDir = func() string { - dir, err := os.MkdirTemp("", "simapp") - if err != nil { - dir = simapp.DefaultNodeHome - } - defer os.RemoveAll(dir) - - return dir -} diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 6bb213832cd0..a6270721d16d 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -214,6 +214,7 @@ func queryCommand() *cobra.Command { } cmd.AddCommand( + rpc.QueryEventForTxCmd(), authcmd.GetAccountCmd(), rpc.ValidatorCommand(), rpc.BlockCommand(), From ec7f20fa0169680094915fe0619d35d25d666af7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 18 Aug 2023 00:07:16 +0200 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: mmsqe --- client/rpc/tx.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/client/rpc/tx.go b/client/rpc/tx.go index 02b9852b8601..3e9d68e92150 100644 --- a/client/rpc/tx.go +++ b/client/rpc/tx.go @@ -55,20 +55,20 @@ func newTxResponseDeliverTx(res *coretypes.ResultBroadcastTxCommit) *sdk.TxRespo txHash = res.Hash.String() } - parsedLogs, _ := sdk.ParseABCILogs(res.TxResult.Log) + parsedLogs, _ := sdk.ParseABCILogs(res.DeliverTx.Log) return &sdk.TxResponse{ Height: res.Height, TxHash: txHash, - Codespace: res.TxResult.Codespace, - Code: res.TxResult.Code, - Data: strings.ToUpper(hex.EncodeToString(res.TxResult.Data)), - RawLog: res.TxResult.Log, + Codespace: res.DeliverTx.Codespace, + Code: res.DeliverTx.Code, + Data: strings.ToUpper(hex.EncodeToString(res.DeliverTx.Data)), + RawLog: res.DeliverTx.Log, Logs: parsedLogs, - Info: res.TxResult.Info, - GasWanted: res.TxResult.GasWanted, - GasUsed: res.TxResult.GasUsed, - Events: res.TxResult.Events, + Info: res.DeliverTx.Info, + GasWanted: res.DeliverTx.GasWanted, + GasUsed: res.DeliverTx.GasUsed, + Events: res.DeliverTx.Events, } } @@ -121,7 +121,7 @@ func QueryEventForTxCmd() *cobra.Command { case evt := <-eventCh: if txe, ok := evt.Data.(tmtypes.EventDataTx); ok { res := &coretypes.ResultBroadcastTxCommit{ - TxResult: txe.Result, + DeliverTx: txe.Result, Hash: tmtypes.Tx(txe.Tx).Hash(), Height: txe.Height, } From ca4df1e171dee6aefad8dabf2d6dd5768d681d8a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 18 Aug 2023 10:35:26 +0200 Subject: [PATCH 4/4] fix lint --- client/rpc/tx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/rpc/tx.go b/client/rpc/tx.go index 3e9d68e92150..f77d6cf0a140 100644 --- a/client/rpc/tx.go +++ b/client/rpc/tx.go @@ -122,8 +122,8 @@ func QueryEventForTxCmd() *cobra.Command { if txe, ok := evt.Data.(tmtypes.EventDataTx); ok { res := &coretypes.ResultBroadcastTxCommit{ DeliverTx: txe.Result, - Hash: tmtypes.Tx(txe.Tx).Hash(), - Height: txe.Height, + Hash: tmtypes.Tx(txe.Tx).Hash(), + Height: txe.Height, } return clientCtx.PrintProto(newResponseFormatBroadcastTxCommit(res)) }