Implement query list-contract-by-code for the CLI

This commit is contained in:
Assaf Morami 2020-03-04 12:12:36 +02:00 committed by GitHub
parent 64d7d04890
commit bb18c59c5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -33,6 +33,7 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
}
queryCmd.AddCommand(flags.GetCommands(
GetCmdListCode(cdc),
GetCmdListContractByCode(cdc),
GetCmdQueryCode(cdc),
GetCmdGetContractInfo(cdc),
GetCmdGetContractState(cdc),
@ -61,6 +62,32 @@ func GetCmdListCode(cdc *codec.Codec) *cobra.Command {
}
}
// GetCmdListContractByCode lists all wasm code uploaded for given code id
func GetCmdListContractByCode(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "list-contract-by-code [code_id]",
Short: "List wasm all bytecode on the chain for given code id",
Long: "List wasm all bytecode on the chain for given code id",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
codeID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}
route := fmt.Sprintf("custom/%s/%s/%d", types.QuerierRoute, keeper.QueryListContractByCode, codeID)
res, _, err := cliCtx.Query(route)
if err != nil {
return err
}
fmt.Println(string(res))
return nil
},
}
}
// GetCmdQueryCode returns the bytecode for a given contract
func GetCmdQueryCode(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{