Skip to content

Commit

Permalink
update repay message
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyluis committed Jan 1, 2025
1 parent b3e0f4a commit 045327b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions proto/side/lending/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ message MsgRepay{
string borrower = 1;
string loan_id = 2;
string adaptor_point = 3;
string claim_tx_id = 4;
string adaptor_signature = 5;
// string claim_tx_id = 4;
// string adaptor_signature = 5;
}

message MsgRepayResponse{}
Expand Down
24 changes: 8 additions & 16 deletions x/lending/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func (m msgServer) Apply(goCtx context.Context, msg *types.MsgApply) (*types.Msg
Interests: interests,
Fees: fees,
EventId: msg.EventId,
Cets: msg.Cets,
DepositTxs: []string{depositTxid},
CreateAt: ctx.BlockTime(),
PoolId: msg.PoolId,
Status: types.LoanStatus_Apply,
// Cets: msg.Cets,
DepositTxs: []string{depositTxid},
CreateAt: ctx.BlockTime(),
PoolId: msg.PoolId,
Status: types.LoanStatus_Apply,
}

m.SetLoan(ctx, loan)
Expand Down Expand Up @@ -168,7 +168,7 @@ func (m msgServer) Approve(goCtx context.Context, msg *types.MsgApprove) (*types
sdk.NewAttribute("vault", loan.VaultAddress),
sdk.NewAttribute("deposit_tx", msg.DepositTxId),
sdk.NewAttribute("proof", msg.Poof),
sdk.NewAttribute("height", string(msg.Height)),
sdk.NewAttribute("height", fmt.Sprint(msg.Height)),
)

return &types.MsgApproveResponse{}, nil
Expand All @@ -193,9 +193,10 @@ func (m msgServer) Redeem(goCtx context.Context, msg *types.MsgRedeem) (*types.M
return nil, types.ErrMismatchLoanSecret
}

m.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, borrower, *loan.BorrowAmount)
m.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, borrower, sdk.NewCoins(*loan.BorrowAmount))

loan.Status = types.LoanStatus_Disburse
loan.LoanSecret = msg.LoanSecret

m.SetLoan(ctx, loan)

Expand Down Expand Up @@ -247,20 +248,11 @@ func (m msgServer) Repay(goCtx context.Context, msg *types.MsgRepay) (*types.Msg
return nil, err
}

// verify claimTx is msg.claimTx later
if claimTx.UnsignedTx.TxHash().String() != msg.ClaimTxId {
return nil, types.ErrInvalidRepayment
}

// verify signature
// msg.AdaptorSignature,

repayment := types.Repayment{
LoanId: msg.LoanId,
Txid: claimTx.UnsignedTx.TxHash().String(),
Tx: tx,
RepayAdaptorPoint: msg.AdaptorPoint,
BorrowerSignature: msg.AdaptorSignature,
CreateAt: ctx.BlockTime(),
}

Expand Down

0 comments on commit 045327b

Please sign in to comment.