diff --git a/cmd/exchaincli/main.go b/cmd/exchaincli/main.go index 6fc07e2537..85477e8620 100644 --- a/cmd/exchaincli/main.go +++ b/cmd/exchaincli/main.go @@ -1,11 +1,17 @@ package main import ( + "encoding/hex" "fmt" - "github.com/okex/exchain/x/order" - "github.com/okex/exchain/x/dex" + "strings" + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/x/auth/client/utils" + "github.com/okex/exchain/x/dex" + evmtypes "github.com/okex/exchain/x/evm/types" + "github.com/okex/exchain/x/order" "github.com/spf13/cobra" + "github.com/spf13/viper" tmamino "github.com/tendermint/tendermint/crypto/encoding/amino" "github.com/tendermint/tendermint/crypto/multisig" @@ -100,7 +106,7 @@ func queryCmd(cdc *sdkcodec.Codec) *cobra.Command { authcmd.GetAccountCmd(cdc), flags.LineBreak, authcmd.QueryTxsByEventsCmd(cdc), - authcmd.QueryTxCmd(cdc), + queryTxCmd(cdc), flags.LineBreak, ) @@ -136,8 +142,8 @@ func txCmd(cdc *sdkcodec.Codec) *cobra.Command { for _, cmd := range txCmd.Commands() { if cmd.Use == auth.ModuleName || - cmd.Use == order.ModuleName|| - cmd.Use == dex.ModuleName|| + cmd.Use == order.ModuleName || + cmd.Use == dex.ModuleName || cmd.Use == bank.ModuleName { cmdsToRemove = append(cmdsToRemove, cmd) } @@ -147,3 +153,44 @@ func txCmd(cdc *sdkcodec.Codec) *cobra.Command { return txCmd } + +// queryTxCmd implements the default command for a tx query. +func queryTxCmd(cdc *sdkcodec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "tx [hash]", + Short: "Query for a transaction by hash in a committed block", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx := context.NewCLIContext().WithCodec(cdc) + + output, err := utils.QueryTx(cliCtx, args[0]) + if err != nil { + ss := strings.Split(output.TxHash, "/") + if len(ss) != 2 { + return err + } + txBytes, err := hex.DecodeString(ss[1]) + var tx evmtypes.MsgEthereumTx + err = cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx) + if err != nil { + return err + } + output.TxHash = ss[0] + output.Tx = tx + } + + if output.Empty() { + return fmt.Errorf("no transaction found with hash %s", args[0]) + } + + return cliCtx.PrintOutput(output) + }, + } + + cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to") + viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode)) + cmd.Flags().Bool(flags.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)") + viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode)) + + return cmd +} diff --git a/go.mod b/go.mod index 0089f4e82d..dea45c9e94 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/okex/cosmos-sdk v0.39.2-exchain5 + github.com/cosmos/cosmos-sdk => github.com/okex/cosmos-sdk v0.39.2-exchain6 github.com/tendermint/iavl => github.com/okex/iavl v0.14.3-exchain github.com/tendermint/tendermint => github.com/okex/tendermint v0.33.9-exchain4 ) diff --git a/go.sum b/go.sum index c3eba2262e..7678013aed 100644 --- a/go.sum +++ b/go.sum @@ -499,8 +499,8 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/okex/cosmos-sdk v0.39.2-exchain5 h1:gJpGyhyJvE1C0tVST3fxaGFVq2tfYzOxFmC2vNFMnEg= -github.com/okex/cosmos-sdk v0.39.2-exchain5/go.mod h1:IvlniaZoJAtzILHgcmnfaJ5S125TYJWfJvGqY9zSXb4= +github.com/okex/cosmos-sdk v0.39.2-exchain6 h1:QERnXF6F8FTDkDKVEa2YSqNj66+Ef5Bkdc0Q/Bp/7TM= +github.com/okex/cosmos-sdk v0.39.2-exchain6/go.mod h1:IvlniaZoJAtzILHgcmnfaJ5S125TYJWfJvGqY9zSXb4= github.com/okex/iavl v0.14.3-exchain h1:kwRIwpFD6B8mDDqoaxeUN3Pg2GW0Vr+sA+b86renWcA= github.com/okex/iavl v0.14.3-exchain/go.mod h1:vHLYxU/zuxBmxxr1v+5Vnd/JzcIsyK17n9P9RDubPVU= github.com/okex/tendermint v0.33.9-exchain4 h1:PKXnawZpuczfcIwuaUuvqobv/qcKnW2e7Apk5Ei4TUM=