@@ -2,13 +2,15 @@ package cli
22
33import (
44 "fmt"
5+
56 "github.com/cosmos/cosmos-sdk/client"
67 "github.com/cosmos/cosmos-sdk/client/context"
78 "github.com/cosmos/cosmos-sdk/codec"
89 "github.com/cosmos/ethermint/x/evm/types"
910 "github.com/spf13/cobra"
1011)
1112
13+ // GetQueryCmd defines evm module queries through the cli
1214func GetQueryCmd (moduleName string , cdc * codec.Codec ) * cobra.Command {
1315 evmQueryCmd := & cobra.Command {
1416 Use : types .ModuleName ,
@@ -21,6 +23,7 @@ func GetQueryCmd(moduleName string, cdc *codec.Codec) *cobra.Command {
2123 GetCmdGetBlockNumber (moduleName , cdc ),
2224 GetCmdGetStorageAt (moduleName , cdc ),
2325 GetCmdGetCode (moduleName , cdc ),
26+ GetCmdGetNonce (moduleName , cdc ),
2427 )... )
2528 return evmQueryCmd
2629}
@@ -94,3 +97,27 @@ func GetCmdGetCode(queryRoute string, cdc *codec.Codec) *cobra.Command {
9497 },
9598 }
9699}
100+
101+ // GetCmdGetCode queries the nonce field of a given address
102+ func GetCmdGetNonce (queryRoute string , cdc * codec.Codec ) * cobra.Command {
103+ return & cobra.Command {
104+ Use : "nonce [account]" ,
105+ Short : "Gets nonce from an account" ,
106+ Args : cobra .ExactArgs (1 ),
107+ RunE : func (cmd * cobra.Command , args []string ) error {
108+ cliCtx := context .NewCLIContext ().WithCodec (cdc )
109+
110+ // TODO: Validate args
111+ account := args [0 ]
112+
113+ res , _ , err := cliCtx .QueryWithData (fmt .Sprintf ("custom/%s/nonce/%s" , queryRoute , account ), nil )
114+ if err != nil {
115+ fmt .Printf ("could not resolve: %s\n " , err )
116+ return nil
117+ }
118+ var out types.QueryResNonce
119+ cdc .MustUnmarshalJSON (res , & out )
120+ return cliCtx .PrintOutput (out )
121+ },
122+ }
123+ }
0 commit comments