Skip to content

Commit

Permalink
Merge PR: add parse app tx (#920)
Browse files Browse the repository at this point in the history
* add parse app tx

* update go.sum

* update cosmos version
  • Loading branch information
xiangjianmeng authored Jul 12, 2021
1 parent cafa364 commit a01f5ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 48 deletions.
54 changes: 9 additions & 45 deletions cmd/exchaincli/main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package main

import (
"encoding/hex"
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/client/context"
sdkcodec "github.com/cosmos/cosmos-sdk/codec"
"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"
"github.com/tendermint/tendermint/libs/cli"
Expand All @@ -21,7 +17,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
clientrpc "github.com/cosmos/cosmos-sdk/client/rpc"
sdkcodec "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -66,6 +61,7 @@ func main() {
// Add --chain-id to persistent flags and mark it required
rootCmd.PersistentFlags().String(flags.FlagChainID, "", "Chain ID of tendermint node")
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
utils.SetParseAppTx(parseMsgEthereumTx)
return client.InitConfig(rootCmd)
}

Expand Down Expand Up @@ -105,7 +101,7 @@ func queryCmd(cdc *sdkcodec.Codec) *cobra.Command {
authcmd.GetAccountCmd(cdc),
flags.LineBreak,
authcmd.QueryTxsByEventsCmd(cdc),
queryTxCmd(cdc),
authcmd.QueryTxCmd(cdc),
flags.LineBreak,
)

Expand Down Expand Up @@ -153,43 +149,11 @@ 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)
},
func parseMsgEthereumTx(cdc *sdkcodec.Codec, txBytes []byte) (sdk.Tx, error) {
var tx evmtypes.MsgEthereumTx
err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx)
if err != nil {
return nil, err
}

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
return tx, nil
}
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-exchain7
github.com/cosmos/cosmos-sdk => github.com/okex/cosmos-sdk v0.39.2-exchain8
github.com/tendermint/iavl => github.com/okex/iavl v0.14.3-exchain
github.com/tendermint/tendermint => github.com/okex/tendermint v0.33.9-exchain5
)
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-exchain7 h1:ySr9r+EErCK31LakC+fkV6TsOYf6rG64PQlwhEqFOrs=
github.com/okex/cosmos-sdk v0.39.2-exchain7/go.mod h1:IvlniaZoJAtzILHgcmnfaJ5S125TYJWfJvGqY9zSXb4=
github.com/okex/cosmos-sdk v0.39.2-exchain8 h1:kyhTZQF9RIWR63s6cCRaWfvUnOX59QB2LJd/ylp2jso=
github.com/okex/cosmos-sdk v0.39.2-exchain8/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-exchain5 h1:8nSeDVzcO+g2bFUMcT34Wkv0x/yEPD/eAFoSVExicQk=
Expand Down

0 comments on commit a01f5ca

Please sign in to comment.