From f735be2dbeb473a98a0ec561dfbbf8bc6a0135dc Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 5 Oct 2021 15:03:16 +0500 Subject: [PATCH] Scaffold cancel loan message (#4) * Scaffold cancel loan message * Implement cancel loan --- docs/static/openapi.yml | 2 + proto/loan/tx.proto | 9 + readme.md | 2 + x/loan/client/cli/tx.go | 1 + x/loan/client/cli/tx_cancel_loan.go | 47 +++ x/loan/handler.go | 3 + x/loan/keeper/msg_server_cancel_loan.go | 37 ++ x/loan/types/codec.go | 4 + x/loan/types/message_cancel_loan.go | 44 +++ x/loan/types/message_cancel_loan_test.go | 40 +++ x/loan/types/tx.pb.go | 412 +++++++++++++++++++++-- 11 files changed, 576 insertions(+), 25 deletions(-) create mode 100644 x/loan/client/cli/tx_cancel_loan.go create mode 100644 x/loan/keeper/msg_server_cancel_loan.go create mode 100644 x/loan/types/message_cancel_loan.go create mode 100644 x/loan/types/message_cancel_loan_test.go diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 5bf4b2d..9490b0e 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -12713,6 +12713,8 @@ definitions: type: string cosmonaut.loan.loan.MsgApproveLoanResponse: type: object + cosmonaut.loan.loan.MsgCancelLoanResponse: + type: object cosmonaut.loan.loan.MsgLiquidateLoanResponse: type: object cosmonaut.loan.loan.MsgRepayLoanResponse: diff --git a/proto/loan/tx.proto b/proto/loan/tx.proto index 052d120..29d765e 100644 --- a/proto/loan/tx.proto +++ b/proto/loan/tx.proto @@ -11,6 +11,7 @@ service Msg { rpc ApproveLoan(MsgApproveLoan) returns (MsgApproveLoanResponse); rpc RepayLoan(MsgRepayLoan) returns (MsgRepayLoanResponse); rpc LiquidateLoan(MsgLiquidateLoan) returns (MsgLiquidateLoanResponse); + rpc CancelLoan(MsgCancelLoan) returns (MsgCancelLoanResponse); // this line is used by starport scaffolding # proto/tx/rpc } @@ -49,4 +50,12 @@ message MsgLiquidateLoan { message MsgLiquidateLoanResponse { } +message MsgCancelLoan { + string creator = 1; + uint64 id = 2; +} + +message MsgCancelLoanResponse { +} + // this line is used by starport scaffolding # proto/tx/message \ No newline at end of file diff --git a/readme.md b/readme.md index 41173bc..7229302 100644 --- a/readme.md +++ b/readme.md @@ -31,6 +31,8 @@ starport s message approve-loan id:uint starport s message repay-loan id:uint starport s message liquidate-loan id:uint + +starport s message cancel-loan id:uint ``` ## Get started diff --git a/x/loan/client/cli/tx.go b/x/loan/client/cli/tx.go index d699717..73cc619 100644 --- a/x/loan/client/cli/tx.go +++ b/x/loan/client/cli/tx.go @@ -33,6 +33,7 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand(CmdApproveLoan()) cmd.AddCommand(CmdRepayLoan()) cmd.AddCommand(CmdLiquidateLoan()) + cmd.AddCommand(CmdCancelLoan()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/loan/client/cli/tx_cancel_loan.go b/x/loan/client/cli/tx_cancel_loan.go new file mode 100644 index 0000000..7b86288 --- /dev/null +++ b/x/loan/client/cli/tx_cancel_loan.go @@ -0,0 +1,47 @@ +package cli + +import ( + "strconv" + + "github.com/spf13/cast" + "github.com/spf13/cobra" + + "github.com/cosmonaut/loan/x/loan/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" +) + +var _ = strconv.Itoa(0) + +func CmdCancelLoan() *cobra.Command { + cmd := &cobra.Command{ + Use: "cancel-loan [id]", + Short: "Broadcast message cancel-loan", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + argId, err := cast.ToUint64E(args[0]) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgCancelLoan( + clientCtx.GetFromAddress().String(), + argId, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/loan/handler.go b/x/loan/handler.go index 9567cee..8de7a46 100644 --- a/x/loan/handler.go +++ b/x/loan/handler.go @@ -29,6 +29,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgLiquidateLoan: res, err := msgServer.LiquidateLoan(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgCancelLoan: + res, err := msgServer.CancelLoan(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) // this line is used by starport scaffolding # 1 default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) diff --git a/x/loan/keeper/msg_server_cancel_loan.go b/x/loan/keeper/msg_server_cancel_loan.go new file mode 100644 index 0000000..39e10fb --- /dev/null +++ b/x/loan/keeper/msg_server_cancel_loan.go @@ -0,0 +1,37 @@ +package keeper + +import ( + "context" + "fmt" + + "github.com/cosmonaut/loan/x/loan/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func (k msgServer) CancelLoan(goCtx context.Context, msg *types.MsgCancelLoan) (*types.MsgCancelLoanResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + loan, found := k.GetLoan(ctx, msg.Id) + if !found { + return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("key %d doesn't exist", msg.Id)) + } + + if loan.Borrower != msg.Creator { + return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Cannot cancel: not the borrower") + } + + if loan.State != "requested" { + return nil, sdkerrors.Wrapf(types.ErrWrongLoanState, "%v", loan.State) + } + + borrower, _ := sdk.AccAddressFromBech32(loan.Borrower) + collateral, _ := sdk.ParseCoinsNormalized(loan.Collateral) + k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, borrower, collateral) + + loan.State = "cancelled" + + k.SetLoan(ctx, loan) + + return &types.MsgCancelLoanResponse{}, nil +} diff --git a/x/loan/types/codec.go b/x/loan/types/codec.go index dd85877..d6dfb78 100644 --- a/x/loan/types/codec.go +++ b/x/loan/types/codec.go @@ -12,6 +12,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgApproveLoan{}, "loan/ApproveLoan", nil) cdc.RegisterConcrete(&MsgRepayLoan{}, "loan/RepayLoan", nil) cdc.RegisterConcrete(&MsgLiquidateLoan{}, "loan/LiquidateLoan", nil) + cdc.RegisterConcrete(&MsgCancelLoan{}, "loan/CancelLoan", nil) // this line is used by starport scaffolding # 2 } @@ -28,6 +29,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgLiquidateLoan{}, ) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgCancelLoan{}, + ) // this line is used by starport scaffolding # 3 msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/loan/types/message_cancel_loan.go b/x/loan/types/message_cancel_loan.go new file mode 100644 index 0000000..fea5aa4 --- /dev/null +++ b/x/loan/types/message_cancel_loan.go @@ -0,0 +1,44 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var _ sdk.Msg = &MsgCancelLoan{} + +func NewMsgCancelLoan(creator string, id uint64) *MsgCancelLoan { + return &MsgCancelLoan{ + Creator: creator, + Id: id, + } +} + +func (msg *MsgCancelLoan) Route() string { + return RouterKey +} + +func (msg *MsgCancelLoan) Type() string { + return "CancelLoan" +} + +func (msg *MsgCancelLoan) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgCancelLoan) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgCancelLoan) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + return nil +} diff --git a/x/loan/types/message_cancel_loan_test.go b/x/loan/types/message_cancel_loan_test.go new file mode 100644 index 0000000..dcd186a --- /dev/null +++ b/x/loan/types/message_cancel_loan_test.go @@ -0,0 +1,40 @@ +package types + +import ( + "testing" + + "github.com/cosmonaut/loan/testutil/sample" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" +) + +func TestMsgCancelLoan_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgCancelLoan + err error + }{ + { + name: "invalid address", + msg: MsgCancelLoan{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgCancelLoan{ + Creator: sample.AccAddress(), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/loan/types/tx.pb.go b/x/loan/types/tx.pb.go index 1486c60..02a18f6 100644 --- a/x/loan/types/tx.pb.go +++ b/x/loan/types/tx.pb.go @@ -403,6 +403,94 @@ func (m *MsgLiquidateLoanResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgLiquidateLoanResponse proto.InternalMessageInfo +type MsgCancelLoan struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *MsgCancelLoan) Reset() { *m = MsgCancelLoan{} } +func (m *MsgCancelLoan) String() string { return proto.CompactTextString(m) } +func (*MsgCancelLoan) ProtoMessage() {} +func (*MsgCancelLoan) Descriptor() ([]byte, []int) { + return fileDescriptor_b8f8f93b4237d328, []int{8} +} +func (m *MsgCancelLoan) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCancelLoan) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCancelLoan.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCancelLoan) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCancelLoan.Merge(m, src) +} +func (m *MsgCancelLoan) XXX_Size() int { + return m.Size() +} +func (m *MsgCancelLoan) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCancelLoan.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCancelLoan proto.InternalMessageInfo + +func (m *MsgCancelLoan) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgCancelLoan) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +type MsgCancelLoanResponse struct { +} + +func (m *MsgCancelLoanResponse) Reset() { *m = MsgCancelLoanResponse{} } +func (m *MsgCancelLoanResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCancelLoanResponse) ProtoMessage() {} +func (*MsgCancelLoanResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b8f8f93b4237d328, []int{9} +} +func (m *MsgCancelLoanResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCancelLoanResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCancelLoanResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCancelLoanResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCancelLoanResponse.Merge(m, src) +} +func (m *MsgCancelLoanResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCancelLoanResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCancelLoanResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCancelLoanResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgRequestLoan)(nil), "cosmonaut.loan.loan.MsgRequestLoan") proto.RegisterType((*MsgRequestLoanResponse)(nil), "cosmonaut.loan.loan.MsgRequestLoanResponse") @@ -412,36 +500,40 @@ func init() { proto.RegisterType((*MsgRepayLoanResponse)(nil), "cosmonaut.loan.loan.MsgRepayLoanResponse") proto.RegisterType((*MsgLiquidateLoan)(nil), "cosmonaut.loan.loan.MsgLiquidateLoan") proto.RegisterType((*MsgLiquidateLoanResponse)(nil), "cosmonaut.loan.loan.MsgLiquidateLoanResponse") + proto.RegisterType((*MsgCancelLoan)(nil), "cosmonaut.loan.loan.MsgCancelLoan") + proto.RegisterType((*MsgCancelLoanResponse)(nil), "cosmonaut.loan.loan.MsgCancelLoanResponse") } func init() { proto.RegisterFile("loan/tx.proto", fileDescriptor_b8f8f93b4237d328) } var fileDescriptor_b8f8f93b4237d328 = []byte{ - // 378 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xc1, 0x4e, 0xea, 0x40, - 0x14, 0xa5, 0x94, 0xc7, 0x7b, 0xdc, 0x27, 0x84, 0x8c, 0x86, 0x4c, 0xba, 0x98, 0x28, 0x46, 0xa3, - 0x31, 0x96, 0x44, 0x37, 0xc6, 0xb8, 0x50, 0xd7, 0xb0, 0xe9, 0x4e, 0x37, 0x66, 0x68, 0xc7, 0xda, - 0xa4, 0x74, 0x4a, 0x67, 0x6a, 0xe0, 0x13, 0xdc, 0xf1, 0x59, 0x2e, 0x59, 0xba, 0x34, 0xf0, 0x23, - 0x86, 0x91, 0xd6, 0xd6, 0xd0, 0x00, 0x9b, 0x76, 0xee, 0xdc, 0x73, 0xcf, 0x39, 0x39, 0x93, 0x0b, - 0x75, 0x9f, 0xd3, 0xa0, 0x23, 0x47, 0x66, 0x18, 0x71, 0xc9, 0xd1, 0xae, 0xcd, 0xc5, 0x80, 0x07, - 0x34, 0x96, 0xe6, 0xa2, 0xa1, 0x3e, 0xed, 0x89, 0x06, 0x8d, 0x9e, 0x70, 0x2d, 0x36, 0x8c, 0x99, - 0x90, 0x5d, 0x4e, 0x03, 0x84, 0xe1, 0xaf, 0x1d, 0x31, 0x2a, 0x79, 0x84, 0xb5, 0x7d, 0xed, 0xa4, - 0x66, 0x25, 0x25, 0x6a, 0x41, 0x95, 0x0e, 0x78, 0x1c, 0x48, 0x5c, 0x56, 0x8d, 0x65, 0x85, 0x9a, - 0xa0, 0x3f, 0x33, 0x86, 0x75, 0x75, 0xb9, 0x38, 0x22, 0x02, 0x60, 0x73, 0xdf, 0xa7, 0x92, 0x45, - 0xd4, 0xc7, 0x15, 0xd5, 0xc8, 0xdc, 0x20, 0x03, 0xfe, 0x39, 0x8c, 0x3a, 0xbe, 0x17, 0x30, 0xfc, - 0x47, 0x75, 0xd3, 0xba, 0x8d, 0xa1, 0x95, 0x77, 0x64, 0x31, 0x11, 0xf2, 0x40, 0xb0, 0xf6, 0xb5, - 0xf2, 0x7a, 0x17, 0x86, 0x11, 0x7f, 0x65, 0x6b, 0xbc, 0x36, 0xa0, 0xec, 0x39, 0xca, 0x67, 0xc5, - 0x2a, 0x7b, 0xce, 0x92, 0x35, 0x33, 0x9b, 0xb2, 0x5e, 0xc1, 0x8e, 0xd2, 0x0b, 0xe9, 0x78, 0x4b, - 0xce, 0x16, 0xec, 0x65, 0x27, 0x53, 0xc6, 0x1b, 0x68, 0xf6, 0x84, 0xdb, 0xf5, 0x86, 0xb1, 0xe7, - 0x50, 0xb9, 0xad, 0x53, 0x03, 0xf0, 0xef, 0xe9, 0x84, 0xf9, 0xe2, 0x4d, 0x07, 0xbd, 0x27, 0x5c, - 0xf4, 0x04, 0xff, 0xb3, 0x4f, 0x76, 0x68, 0xae, 0x78, 0x5b, 0x33, 0x9f, 0xa2, 0x71, 0xb6, 0x01, - 0x28, 0x11, 0x5a, 0x08, 0x64, 0x73, 0x2e, 0x14, 0xc8, 0x80, 0x8a, 0x05, 0x56, 0xa4, 0x8e, 0x1e, - 0xa0, 0xf6, 0x13, 0xf9, 0x41, 0xb1, 0xb5, 0x25, 0xc4, 0x38, 0x5d, 0x0b, 0x49, 0xa9, 0x19, 0xd4, - 0xf3, 0xd9, 0x1f, 0x15, 0xcd, 0xe6, 0x60, 0xc6, 0xf9, 0x46, 0xb0, 0x44, 0xe6, 0xfe, 0xf6, 0x7d, - 0x46, 0xb4, 0xe9, 0x8c, 0x68, 0x9f, 0x33, 0xa2, 0x4d, 0xe6, 0xa4, 0x34, 0x9d, 0x93, 0xd2, 0xc7, - 0x9c, 0x94, 0x1e, 0x8f, 0x5d, 0x4f, 0xbe, 0xc4, 0x7d, 0xd3, 0xe6, 0x83, 0x4e, 0x4a, 0xd9, 0x51, - 0xdb, 0x38, 0xfa, 0xfe, 0xc9, 0x71, 0xc8, 0x44, 0xbf, 0xaa, 0x16, 0xf3, 0xf2, 0x2b, 0x00, 0x00, - 0xff, 0xff, 0xb4, 0x65, 0x36, 0x95, 0xa9, 0x03, 0x00, 0x00, + // 414 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x3d, 0x6f, 0xda, 0x40, + 0x18, 0xc6, 0x98, 0xd2, 0xf2, 0xb6, 0x20, 0x74, 0x6d, 0xe9, 0xc9, 0x83, 0xd5, 0xba, 0x6a, 0xd5, + 0x0f, 0xc5, 0x48, 0xc9, 0x92, 0x44, 0x19, 0xf2, 0xb1, 0xe2, 0xc5, 0x5b, 0xa2, 0x48, 0xd1, 0x61, + 0x5f, 0x1c, 0x4b, 0xc6, 0x67, 0x7c, 0xe7, 0x08, 0xfe, 0x05, 0x3f, 0x2b, 0x23, 0x63, 0xc6, 0x08, + 0x86, 0xfc, 0x8d, 0x88, 0x0b, 0x36, 0x76, 0x84, 0x05, 0x2c, 0xe0, 0xf7, 0xde, 0xe7, 0x4b, 0x7a, + 0x4e, 0x07, 0xcd, 0x80, 0x91, 0xb0, 0x2b, 0x46, 0x66, 0x14, 0x33, 0xc1, 0xd0, 0x67, 0x87, 0xf1, + 0x01, 0x0b, 0x49, 0x22, 0xcc, 0xc5, 0x42, 0xfe, 0x18, 0x13, 0x05, 0x5a, 0x16, 0xf7, 0x6c, 0x3a, + 0x4c, 0x28, 0x17, 0x3d, 0x46, 0x42, 0x84, 0xe1, 0xbd, 0x13, 0x53, 0x22, 0x58, 0x8c, 0x95, 0xef, + 0xca, 0x9f, 0x86, 0x9d, 0x8e, 0xa8, 0x03, 0x75, 0x32, 0x60, 0x49, 0x28, 0x70, 0x55, 0x2e, 0x96, + 0x13, 0x6a, 0x83, 0x7a, 0x4b, 0x29, 0x56, 0xe5, 0xe1, 0xe2, 0x13, 0xe9, 0x00, 0x0e, 0x0b, 0x02, + 0x22, 0x68, 0x4c, 0x02, 0x5c, 0x93, 0x8b, 0xdc, 0x09, 0xd2, 0xe0, 0x83, 0x4b, 0x89, 0x1b, 0xf8, + 0x21, 0xc5, 0xef, 0xe4, 0x36, 0x9b, 0x0d, 0x0c, 0x9d, 0x62, 0x22, 0x9b, 0xf2, 0x88, 0x85, 0x9c, + 0x1a, 0xc7, 0x32, 0xeb, 0x59, 0x14, 0xc5, 0xec, 0x9e, 0x6e, 0xc8, 0xda, 0x82, 0xaa, 0xef, 0xca, + 0x9c, 0x35, 0xbb, 0xea, 0xbb, 0x4b, 0xd5, 0x1c, 0x37, 0x53, 0x3d, 0x84, 0x4f, 0xd2, 0x2f, 0x22, + 0xe3, 0x1d, 0x35, 0x3b, 0xf0, 0x25, 0xcf, 0xcc, 0x14, 0x4f, 0xa0, 0x6d, 0x71, 0xaf, 0xe7, 0x0f, + 0x13, 0xdf, 0x25, 0x62, 0xd7, 0xa4, 0x1a, 0xe0, 0xb7, 0xec, 0x4c, 0xf9, 0x08, 0x9a, 0x16, 0xf7, + 0x2e, 0x48, 0xe8, 0xd0, 0x60, 0x47, 0xd9, 0x6f, 0xf0, 0xb5, 0x40, 0x4d, 0x35, 0xf7, 0x9f, 0x55, + 0x50, 0x2d, 0xee, 0xa1, 0x1b, 0xf8, 0x98, 0xbf, 0x06, 0x3f, 0xcd, 0x35, 0xf7, 0xc5, 0x2c, 0x36, + 0xa3, 0xfd, 0xdf, 0x02, 0x94, 0x1a, 0x2d, 0x0c, 0xf2, 0xdd, 0x95, 0x1a, 0xe4, 0x40, 0xe5, 0x06, + 0x6b, 0x9a, 0x44, 0x97, 0xd0, 0x58, 0xd5, 0xf8, 0xa3, 0x3c, 0xda, 0x12, 0xa2, 0xfd, 0xdd, 0x08, + 0xc9, 0xa4, 0x29, 0x34, 0x8b, 0x7d, 0xfe, 0x2a, 0xe3, 0x16, 0x60, 0xda, 0xde, 0x56, 0xb0, 0xcc, + 0xe6, 0x1a, 0x20, 0x57, 0xae, 0x51, 0x46, 0x5e, 0x61, 0xb4, 0x7f, 0x9b, 0x31, 0xa9, 0xfa, 0xf9, + 0xe9, 0xc3, 0x4c, 0x57, 0xa6, 0x33, 0x5d, 0x79, 0x9a, 0xe9, 0xca, 0x64, 0xae, 0x57, 0xa6, 0x73, + 0xbd, 0xf2, 0x38, 0xd7, 0x2b, 0x57, 0xbf, 0x3d, 0x5f, 0xdc, 0x25, 0x7d, 0xd3, 0x61, 0x83, 0x6e, + 0xa6, 0xd7, 0x95, 0xef, 0xc7, 0xe8, 0xf5, 0x4f, 0x8c, 0x23, 0xca, 0xfb, 0x75, 0xf9, 0x94, 0x1c, + 0xbc, 0x04, 0x00, 0x00, 0xff, 0xff, 0x32, 0xdd, 0x39, 0xf9, 0x5b, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -460,6 +552,7 @@ type MsgClient interface { ApproveLoan(ctx context.Context, in *MsgApproveLoan, opts ...grpc.CallOption) (*MsgApproveLoanResponse, error) RepayLoan(ctx context.Context, in *MsgRepayLoan, opts ...grpc.CallOption) (*MsgRepayLoanResponse, error) LiquidateLoan(ctx context.Context, in *MsgLiquidateLoan, opts ...grpc.CallOption) (*MsgLiquidateLoanResponse, error) + CancelLoan(ctx context.Context, in *MsgCancelLoan, opts ...grpc.CallOption) (*MsgCancelLoanResponse, error) } type msgClient struct { @@ -506,12 +599,22 @@ func (c *msgClient) LiquidateLoan(ctx context.Context, in *MsgLiquidateLoan, opt return out, nil } +func (c *msgClient) CancelLoan(ctx context.Context, in *MsgCancelLoan, opts ...grpc.CallOption) (*MsgCancelLoanResponse, error) { + out := new(MsgCancelLoanResponse) + err := c.cc.Invoke(ctx, "/cosmonaut.loan.loan.Msg/CancelLoan", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { RequestLoan(context.Context, *MsgRequestLoan) (*MsgRequestLoanResponse, error) ApproveLoan(context.Context, *MsgApproveLoan) (*MsgApproveLoanResponse, error) RepayLoan(context.Context, *MsgRepayLoan) (*MsgRepayLoanResponse, error) LiquidateLoan(context.Context, *MsgLiquidateLoan) (*MsgLiquidateLoanResponse, error) + CancelLoan(context.Context, *MsgCancelLoan) (*MsgCancelLoanResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -530,6 +633,9 @@ func (*UnimplementedMsgServer) RepayLoan(ctx context.Context, req *MsgRepayLoan) func (*UnimplementedMsgServer) LiquidateLoan(ctx context.Context, req *MsgLiquidateLoan) (*MsgLiquidateLoanResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method LiquidateLoan not implemented") } +func (*UnimplementedMsgServer) CancelLoan(ctx context.Context, req *MsgCancelLoan) (*MsgCancelLoanResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CancelLoan not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -607,6 +713,24 @@ func _Msg_LiquidateLoan_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } +func _Msg_CancelLoan_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCancelLoan) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CancelLoan(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmonaut.loan.loan.Msg/CancelLoan", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CancelLoan(ctx, req.(*MsgCancelLoan)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmonaut.loan.loan.Msg", HandlerType: (*MsgServer)(nil), @@ -627,6 +751,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "LiquidateLoan", Handler: _Msg_LiquidateLoan_Handler, }, + { + MethodName: "CancelLoan", + Handler: _Msg_CancelLoan_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "loan/tx.proto", @@ -887,6 +1015,64 @@ func (m *MsgLiquidateLoanResponse) MarshalToSizedBuffer(dAtA []byte) (int, error return len(dAtA) - i, nil } +func (m *MsgCancelLoan) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCancelLoan) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCancelLoan) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Id != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x10 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCancelLoanResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCancelLoanResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCancelLoanResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1011,6 +1197,31 @@ func (m *MsgLiquidateLoanResponse) Size() (n int) { return n } +func (m *MsgCancelLoan) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Id != 0 { + n += 1 + sovTx(uint64(m.Id)) + } + return n +} + +func (m *MsgCancelLoanResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1730,6 +1941,157 @@ func (m *MsgLiquidateLoanResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgCancelLoan) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCancelLoan: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCancelLoan: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCancelLoanResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCancelLoanResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCancelLoanResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0