Skip to content

Commit

Permalink
add cmd cli for query
Browse files Browse the repository at this point in the history
  • Loading branch information
skyargos committed Nov 15, 2023
1 parent cfc9ddf commit 432822e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
1 change: 1 addition & 0 deletions x/bounty/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
FlagFindingDescription = "desc"
FlagFindingProofOfContent = "poc"
FlagFindingSeverityLevel = "severity-level"
FlagFindingPaymentHash = "payment-hash"
FlagFindingFingerprint = "fingerprint"
FlagSubmitterAddress = "submitter-address"
)
48 changes: 44 additions & 4 deletions x/bounty/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func GetQueryCmd() *cobra.Command {
GetCmdQueryPrograms(),
GetCmdQueryFinding(),
GetCmdQueryFindings(),
GetCmdQueryFindingFingerPrint(),
GetCmdQueryFindingFingerprint(),
GetCmdQueryProgramFingerprint(),
)

return bountyQueryCmd
Expand Down Expand Up @@ -249,10 +250,10 @@ $ %s query bounty findings --page=1 --limit=100
return cmd
}

// GetCmdQueryFindingFingerPrint implements the query finding fingerPrint command.
func GetCmdQueryFindingFingerPrint() *cobra.Command {
// GetCmdQueryFindingFingerprint implements the query finding fingerPrint command.
func GetCmdQueryFindingFingerprint() *cobra.Command {
cmd := &cobra.Command{
Use: "fingerprint [finding-id]",
Use: "finding-fingerprint [finding-id]",
Args: cobra.ExactArgs(1),
Short: "Query fingerPrint of a single finding",
Long: strings.TrimSpace(
Expand Down Expand Up @@ -287,3 +288,42 @@ $ %s query bounty finding 1
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// GetCmdQueryProgramFingerprint implements the query program fingerPrint command.
func GetCmdQueryProgramFingerprint() *cobra.Command {
cmd := &cobra.Command{
Use: "program-fingerprint [program-id]",
Args: cobra.ExactArgs(1),
Short: "Query fingerPrint of a single program",
Long: strings.TrimSpace(
fmt.Sprintf(`Query fingerPrint for a program. You can find the program-id by running "%s query bounty findings".
Example:
$ %s query bounty program 1
`,
version.AppName, version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

// Query the program
res, err := queryClient.ProgramFingerprint(
cmd.Context(),
&types.QueryProgramFingerprintRequest{
ProgramId: args[0],
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
8 changes: 7 additions & 1 deletion x/bounty/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ func NewEditFindingCmd() *cobra.Command {
hash := sha256.Sum256([]byte(desc + poc + submitAddr.String()))
hashString := hex.EncodeToString(hash[:])

msg := types.NewMsgEditFinding(fid, title, detail, hashString, submitAddr, byteSeverityLevel)
paymentHash, err := cmd.Flags().GetString(FlagFindingPaymentHash)
if err != nil {
return err
}

msg := types.NewMsgEditFinding(fid, title, detail, hashString, paymentHash, submitAddr, byteSeverityLevel)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
Expand All @@ -283,6 +288,7 @@ func NewEditFindingCmd() *cobra.Command {
cmd.Flags().String(FlagFindingProofOfContent, "", "The finding's proof of content")
cmd.Flags().String(FlagDetail, "", "The finding's detail")
cmd.Flags().String(FlagFindingSeverityLevel, "unspecified", "The finding's severity level")
cmd.Flags().String(FlagFindingPaymentHash, "", "The finding's payment hash")
flags.AddTxFlagsToCmd(cmd)

_ = cmd.MarkFlagRequired(flags.FlagFrom)
Expand Down
3 changes: 2 additions & 1 deletion x/bounty/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,15 @@ func (msg MsgSubmitFinding) ValidateBasic() error {
}

// NewMsgEditFinding submit a new finding.
func NewMsgEditFinding(fid, title, detail, hash string, operator sdk.AccAddress, level SeverityLevel) *MsgEditFinding {
func NewMsgEditFinding(fid, title, detail, hash, paymentHash string, operator sdk.AccAddress, level SeverityLevel) *MsgEditFinding {
return &MsgEditFinding{
FindingId: fid,
Title: title,
FindingHash: hash,
OperatorAddress: operator.String(),
SeverityLevel: level,
Detail: detail,
PaymentHash: paymentHash,
}

Check warning on line 205 in x/bounty/types/msgs.go

View check run for this annotation

Codecov / codecov/patch

x/bounty/types/msgs.go#L196-L205

Added lines #L196 - L205 were not covered by tests
}

Expand Down

0 comments on commit 432822e

Please sign in to comment.