add code-info query command
This commit is contained in:
@@ -33,6 +33,7 @@ func GetQueryCmd() *cobra.Command {
|
||||
GetCmdListCode(),
|
||||
GetCmdListContractByCode(),
|
||||
GetCmdQueryCode(),
|
||||
GetCmdQueryCodeInfo(),
|
||||
GetCmdGetContractInfo(),
|
||||
GetCmdGetContractHistory(),
|
||||
GetCmdGetContractState(),
|
||||
@@ -181,6 +182,45 @@ func GetCmdQueryCode() *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryCodeInfo returns the code info for a given code id
|
||||
func GetCmdQueryCodeInfo() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "code-info [code_id]",
|
||||
Short: "Prints out metadata of a code id",
|
||||
Long: "Prints out metadata of a code id",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
codeID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
res, err := queryClient.Code(
|
||||
context.Background(),
|
||||
&types.QueryCodeRequest{
|
||||
CodeId: codeID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if res.CodeInfoResponse == nil {
|
||||
return fmt.Errorf("contract not found")
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res.CodeInfoResponse)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdGetContractInfo gets details about a given contract
|
||||
func GetCmdGetContractInfo() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
|
||||
Reference in New Issue
Block a user