/// <summary> /// Process offchain channel /// </summary> /// <returns></returns> //[HttpPost("finalizeRefLinkTransfer")] --reserved for version 2 //[SwaggerOperation("FinalizeRefLinkTransfer")] //[ProducesResponseType(typeof(OffchainSuccessTradeRespModel), (int)HttpStatusCode.OK)] //[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] //[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.NotFound)] private async Task <IActionResult> Finalize([FromBody] OffchainFinalizeModel request) { var clientId = request.ClientId; await CheckOffchain(clientId); if (string.IsNullOrEmpty(request.ClientRevokePubKey)) { return(await LogAndReturnBadRequest(request, ControllerContext, "ClientRevokePubKey must not be empty")); } if (string.IsNullOrEmpty(request.SignedTransferTransaction)) { return(await LogAndReturnBadRequest(request, ControllerContext, "SignedTransferTransaction must not be empty")); } if (string.IsNullOrEmpty(request.TransferId)) { return(await LogAndReturnBadRequest(request, ControllerContext, "TransferId must not be empty")); } var refLinkEntity = await _referralLinksService.GetReferralLinkById(request.RefLinkId); if (refLinkEntity == null) { return(await LogAndReturnBadRequest(request, ControllerContext, "RefLinkId not found")); } try { var response = await _offchainService.Finalize(clientId, request.TransferId, request.ClientRevokePubKey, request.ClientRevokeEncryptedPrivateKey, request.SignedTransferTransaction); if (response == null) { return(await LogAndReturnNotFound(request, ControllerContext, "OffchainService Finalize returned NULL. Can not finalize transfer.")); } if (response.OperationResult == OffchainOperationResult.ClientCommitment) { AttachSenderTransferToRefLink(refLinkEntity, response.TransferId); } else { await LogWarn(request, ControllerContext, $"_offchainService.Finalize returned unexpected result : {response.ToJson()}"); } var offchainRequest = (await _offchainRequestRepository.GetRequestsForClient(clientId)).FirstOrDefault( x => x.TransferId == request.TransferId); if (offchainRequest != null) { await _offchainRequestRepository.Complete(offchainRequest.RequestId); await LogInfo(request, ControllerContext, $"Offchain request set to complete: {offchainRequest.ToJson()}"); } return(Ok(new OffchainSuccessTradeRespModel { TransferId = response.TransferId, TransactionHex = response.TransactionHex, OperationResult = response.OperationResult, })); } catch (OffchainException ex) { return(await LogOffchainExceptionAndReturn(request, ControllerContext, ex)); } catch (Exception ex) { return(await LogAndReturnNotFound(request, ControllerContext, ex.Message)); } }
public Task Complete(string requestId) { return(_offchainRequestRepository.Complete(requestId)); }