Skip to content

Commit

Permalink
Merge PR: fix query evm tx failed (#902)
Browse files Browse the repository at this point in the history
* fix query evm tx failed

* fix query evm tx failed

* change cosmos-sdk version
  • Loading branch information
xiangjianmeng authored Jun 15, 2021
1 parent e938592 commit e5ab93b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
57 changes: 52 additions & 5 deletions cmd/exchaincli/main.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit e5ab93b

Please sign in to comment.