Skip to content

Commit bcb2902

Browse files
committed
add CLI cmds
1 parent 40232ca commit bcb2902

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

x/lending/client/cli/query.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func GetQueryCmd(_ string) *cobra.Command {
3838
cmd.AddCommand(CmdQueryLoans())
3939
cmd.AddCommand(CmdQueryLoansByAddress())
4040
cmd.AddCommand(CmdQueryDlcMeta())
41+
cmd.AddCommand(CmdQueryCancellation())
4142
cmd.AddCommand(CmdQueryRepayment())
4243
// this line is used by starport scaffolding # 1
4344

@@ -383,6 +384,33 @@ func CmdQueryDlcMeta() *cobra.Command {
383384
return cmd
384385
}
385386

387+
func CmdQueryCancellation() *cobra.Command {
388+
cmd := &cobra.Command{
389+
Use: "cancellation [loan id]",
390+
Short: "Query the cancellation of the given loan",
391+
Args: cobra.ExactArgs(1),
392+
RunE: func(cmd *cobra.Command, args []string) error {
393+
clientCtx, err := client.GetClientQueryContext(cmd)
394+
if err != nil {
395+
return err
396+
}
397+
398+
queryClient := types.NewQueryClient(clientCtx)
399+
400+
res, err := queryClient.LoanCancellation(cmd.Context(), &types.QueryLoanCancellationRequest{LoanId: args[0]})
401+
if err != nil {
402+
return err
403+
}
404+
405+
return clientCtx.PrintProto(res)
406+
},
407+
}
408+
409+
flags.AddQueryFlagsToCmd(cmd)
410+
411+
return cmd
412+
}
413+
386414
func CmdQueryRepayment() *cobra.Command {
387415
cmd := &cobra.Command{
388416
Use: "repayment [loan id]",

x/lending/client/cli/tx.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,37 @@ func CmdApprove() *cobra.Command {
272272
return cmd
273273
}
274274

275+
func CmdCancel() *cobra.Command {
276+
cmd := &cobra.Command{
277+
Use: "cancel [loan id] [tx] [signatures]",
278+
Short: "Cancel the given loan along with the cancellation tx",
279+
Args: cobra.ExactArgs(3),
280+
RunE: func(cmd *cobra.Command, args []string) (err error) {
281+
clientCtx, err := client.GetClientTxContext(cmd)
282+
if err != nil {
283+
return err
284+
}
285+
286+
msg := types.NewMsgCancel(
287+
clientCtx.GetFromAddress().String(),
288+
args[0],
289+
args[1],
290+
strings.Split(args[2], listSeparator),
291+
)
292+
293+
if err := msg.ValidateBasic(); err != nil {
294+
return err
295+
}
296+
297+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
298+
},
299+
}
300+
301+
flags.AddTxFlagsToCmd(cmd)
302+
303+
return cmd
304+
}
305+
275306
func CmdRedeem() *cobra.Command {
276307
cmd := &cobra.Command{
277308
Use: "redeem [loan id] [loan secret]",

x/lending/types/msg_cancel.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import (
1212

1313
var _ sdk.Msg = &MsgCancel{}
1414

15-
func NewMsgCancel(borrower string, loanId string) *MsgCancel {
15+
func NewMsgCancel(borrower string, loanId string, tx string, signatures []string) *MsgCancel {
1616
return &MsgCancel{
17-
Borrower: borrower,
18-
LoanId: loanId,
17+
Borrower: borrower,
18+
LoanId: loanId,
19+
Tx: tx,
20+
Signatures: signatures,
1921
}
2022
}
2123

0 commit comments

Comments
 (0)