Finalize the query cli commands for x/wasm

This commit is contained in:
Ethan Frey 2019-11-22 17:57:24 +01:00
parent 4a77f43b63
commit d79ff0cd19
1 changed files with 78 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmwasm/wasmd/x/wasm/internal/keeper"
"github.com/cosmwasm/wasmd/x/wasm/internal/types"
@ -27,6 +28,9 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
queryCmd.AddCommand(client.GetCommands(
GetCmdListCode(cdc),
GetCmdQueryCode(cdc),
GetCmdListContracts(cdc),
GetCmdGetContractInfo(cdc),
GetCmdGetContractState(cdc),
)...)
return queryCmd
}
@ -82,8 +86,81 @@ func GetCmdQueryCode(cdc *codec.Codec) *cobra.Command {
return err
}
fmt.Printf("Writing wasm code to %s\n", args[1])
fmt.Printf("Downloading wasm code to %s\n", args[1])
return ioutil.WriteFile(args[1], code.Code, 0644)
},
}
}
// GetCmdListContracts lists all instantiated contracts
func GetCmdListContracts(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "list-contracts",
Short: "List addresses of all instantiated contracts on the chain",
Long: "List addresses of all instantiated contracts on the chain",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, keeper.QueryListContracts)
res, _, err := cliCtx.Query(route)
if err != nil {
return err
}
fmt.Println(res)
return nil
},
}
}
// GetCmdGetContractInfo gets details about a given contract
func GetCmdGetContractInfo(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "contract [bech32_address]",
Short: "Prints out metadata of a contract given its address",
Long: "Prints out metadata of a contract given its address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
route := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContract, addr.String())
res, _, err := cliCtx.Query(route)
if err != nil {
return err
}
fmt.Println(res)
return nil
},
}
}
// GetCmdGetContractState dumps full internal state of a given contract
func GetCmdGetContractState(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "contract-state [bech32_address]",
Short: "Prints out internal state of a contract given its address",
Long: "Prints out internal state of a contract given its address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
route := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContractState, addr.String())
res, _, err := cliCtx.Query(route)
if err != nil {
return err
}
fmt.Println(res)
return nil
},
}
}