예제 #1
0
        /// <summary>
        /// Create offchain transfer to Lykke wallet
        /// </summary>
        /// <returns></returns>
        //[HttpPost("transferToLykkeWallet")] --reserved for version 2
        //[SwaggerOperation("TransferToLykkeWallet")]
        //[ProducesResponseType(typeof(OffchainTradeRespModel), (int)HttpStatusCode.OK)]
        //[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
        //[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.NotFound)]
        private async Task <IActionResult> TransferToLykkeWallet([FromBody] TransferToLykkeWallet model)
        {
            var clientId = model.ClientId;
            var refLink  = await _referralLinksService.GetReferralLinkById(model.ReferralLinkId);

            if (refLink == null)
            {
                return(await LogAndReturnBadRequest(model, ControllerContext, "Ref link Id not found ot missing"));
            }

            var asset = (await _assets.GetDictionaryAsync()).Values.FirstOrDefault(v => v.Id == refLink.Asset);

            if (asset == null)
            {
                return(await LogAndReturnBadRequest(model, ControllerContext, $"Specified asset id {refLink.Asset} in reflink id {refLink.Id} not found "));
            }

            await CheckOffchain(clientId);

            if (await _srvKycForAsset.IsKycNeeded(clientId, asset.Id))
            {
                return(await LogAndReturnBadRequest(model, ControllerContext, $"KYC needed for sender client id {model.ClientId} before sending asset {refLink.Asset}"));
            }

            try
            {
                var response = await _offchainService.CreateDirectTransfer(clientId, asset.Id, (decimal)refLink.Amount, model.PrevTempPrivateKey);

                var exchangeOpResult = await _exchangeOperationsService.StartTransferAsync(
                    response.TransferId,
                    _settings.ReferralLinksService.LykkeReferralClientId, //send to shared lykke wallet where coins will be temporary stored until claimed by the recipient
                    clientId,
                    TransferType.Common.ToString()
                    );

                await LogInfo(new
                {
                    Method = "StartTransferAsync",
                    response.TransferId,
                    SourceClientId = clientId
                }, ControllerContext, exchangeOpResult.ToJson());

                return(Ok(new OffchainTradeRespModel
                {
                    TransferId = response.TransferId,
                    TransactionHex = response.TransactionHex,
                    OperationResult = response.OperationResult
                }));
            }
            catch (OffchainException ex)
            {
                return(await LogOffchainExceptionAndReturn(model, ControllerContext, ex));
            }
            catch (Exception ex)
            {
                return(await LogAndReturnNotFound(model, ControllerContext, ex.Message));
            }
        }
 public Task <object> TransferToLykkeWallet(TransferToLykkeWallet request)
 {
     throw new NotImplementedException("Reserved for version 2");
     //try
     //{
     //    return await _service.TransferToLykkeWalletMethodAsync(request);
     //}
     //catch (Exception ex)
     //{
     //    await _log.WriteErrorAsync(nameof(ReferralLinksClient), nameof(TransferToLykkeWallet), ex);
     //    throw;
     //}
 }