@@ -334,12 +334,21 @@ func (m msgServer) Close(goCtx context.Context, msg *types.MsgClose) (*types.Msg
334334 return nil , types .ErrInvalidRepayment
335335 }
336336
337- repay := m .GetRepayment (ctx , msg .LoanId )
337+ repayment := m .GetRepayment (ctx , msg .LoanId )
338+ if len (repayment .DcaAdaptorSignature ) == 0 {
339+ return nil , types .ErrRepaymentAdaptorSigDoesNotExist
340+ }
341+
342+ sigBytes , _ := hex .DecodeString (msg .Signature )
343+ adaptorSigBytes , _ := hex .DecodeString (repayment .DcaAdaptorSignature )
338344
339345 // extract secret from signature
340- secret := msg .Signature + repay .RepayAdaptorPoint // fix it later.
346+ secret := adaptor .Extract (sigBytes , adaptorSigBytes )
347+ if len (secret ) == 0 {
348+ return nil , types .ErrInvalidSignature
349+ }
341350
342- if types .AdaptorPoint (secret ) != repay .RepayAdaptorPoint {
351+ if types .AdaptorPoint (secret ) != repayment .RepayAdaptorPoint {
343352 return nil , types .ErrInvalidRepaymentSecret
344353 }
345354
@@ -355,7 +364,7 @@ func (m msgServer) Close(goCtx context.Context, msg *types.MsgClose) (*types.Msg
355364
356365 m .EmitEvent (ctx , msg .Relayer ,
357366 sdk .NewAttribute ("loan_id" , loan .VaultAddress ),
358- sdk .NewAttribute ("payment_secret" , secret ),
367+ sdk .NewAttribute ("payment_secret" , hex . EncodeToString ( secret ) ),
359368 )
360369
361370 return & types.MsgCloseResponse {}, nil
0 commit comments