Skip to content

Commit c610cc8

Browse files
authored
StatefulSwap now checks for unlocked Timelock accounts (#177)
1 parent c72ca0d commit c610cc8

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

ocp/rpc/transaction/swap.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,16 @@ func (s *transactionServer) StatefulSwap(streamer transactionpb.Transaction_Stat
166166
return handleStatefulSwapError(streamer, err)
167167
}
168168

169-
_, err = s.data.GetTimelockByVault(ctx, ownerSourceTimelockVault.PublicKey().ToBase58())
169+
sourceTimelockAccountRecord, err := s.data.GetTimelockByVault(ctx, ownerSourceTimelockVault.PublicKey().ToBase58())
170170
if err == timelock.ErrTimelockNotFound {
171171
return handleStatefulSwapError(streamer, NewSwapValidationError("source timelock vault account not opened"))
172172
} else if err != nil {
173173
log.With(zap.Error(err)).Warn("failure getting source timelock record")
174174
return handleStatefulSwapError(streamer, err)
175175
}
176+
if !sourceTimelockAccountRecord.IsLocked() {
177+
return handleStatefulSwapError(streamer, NewSwapDeniedError("source timelock account isn't locked"))
178+
}
176179

177180
switch initiateReserveSwapReq.FundingSource {
178181
case transactionpb.FundingSource_FUNDING_SOURCE_SUBMIT_INTENT:
@@ -273,13 +276,16 @@ func (s *transactionServer) StatefulSwap(streamer transactionpb.Transaction_Stat
273276
return handleStatefulSwapError(streamer, err)
274277
}
275278

276-
_, err = s.data.GetTimelockByVault(ctx, ownerDestinationTimelockVault.PublicKey().ToBase58())
279+
destinationTimelockAccountRecord, err := s.data.GetTimelockByVault(ctx, ownerDestinationTimelockVault.PublicKey().ToBase58())
277280
if err == timelock.ErrTimelockNotFound {
278281
return handleStatefulSwapError(streamer, NewSwapValidationError("destination timelock vault account not opened"))
279282
} else if err != nil {
280283
log.With(zap.Error(err)).Warn("failure getting destination timelock record")
281284
return handleStatefulSwapError(streamer, err)
282285
}
286+
if !destinationTimelockAccountRecord.IsLocked() {
287+
return handleStatefulSwapError(streamer, NewSwapDeniedError("destination timelock account isn't locked"))
288+
}
283289

284290
err = vm.EnsureVirtualTimelockAccountIsInitialized(ctx, s.data, ownerDestinationTimelockVault, false)
285291
if err != nil {

0 commit comments

Comments
 (0)