private async Task SetTransferHashes(IEthereumTransactionRequest txRequest, string hash) { foreach (var id in txRequest.OperationIds) { await _transferEventsRepositoryClient.UpdateBlockChainHashAsync(txRequest.ClientId, id, hash); } }
private async Task SetCashoutHashes(IEthereumTransactionRequest txRequest, string hash) { foreach (var id in txRequest.OperationIds) { await _cashOperationsRepository.UpdateBlockchainHashAsync(txRequest.ClientId, id, hash); } }
public static EthereumTransactionReqEntity Create(IEthereumTransactionRequest request) { var entity = Mapper.Map <EthereumTransactionReqEntity>(request); entity.PartitionKey = GeneratePartition(); entity.RowKey = GenerateRowKey(request.OrderId); return(entity); }
public async Task UpdateAsync(IEthereumTransactionRequest request) { var byId = EthereumTransactionReqEntity.ById.Create(request); await _tableStorage.InsertOrReplaceAsync(byId); if (!string.IsNullOrEmpty(request.OrderId)) { var byOrder = EthereumTransactionReqEntity.ByOrderId.Create(request); await _tableStorage.InsertOrReplaceAsync(byOrder); } }
public async Task InsertAsync(IEthereumTransactionRequest request, bool insertOrder = true) { var entityById = EthereumTransactionReqEntity.ById.Create(request); await _tableStorage.InsertAsync(entityById); if (insertOrder && !string.IsNullOrEmpty(request.OrderId)) { var entitByOrder = EthereumTransactionReqEntity.ByOrderId.Create(request); await _tableStorage.InsertAsync(entitByOrder); } }
private async Task <bool> ProcessEthGuaranteeTransfer(IEthereumTransactionRequest ethereumTxRequest, List <AggregatedTransfer> operations, IClientTrade[] clientTrades) { string errMsg = string.Empty; IAsset asset = await _assetsService.TryGetAssetAsync(ethereumTxRequest.AssetId); try { var fromAddress = await _bcnClientCredentialsRepository.GetClientAddress(ethereumTxRequest.ClientId); var clientEthSellOperation = operations.First(x => x.Amount < 0 && x.ClientId == ethereumTxRequest.ClientId); var change = ethereumTxRequest.Volume - Math.Abs(clientEthSellOperation.Amount); EthereumResponse <OperationResponse> res; var minAmountForAsset = (decimal)Math.Pow(10, -asset.Accuracy); if (change > 0 && Math.Abs(change) >= minAmountForAsset) { res = await _srvEthereumHelper.SendTransferWithChangeAsync(change, ethereumTxRequest.SignedTransfer.Sign, ethereumTxRequest.SignedTransfer.Id, asset, fromAddress, _settings.HotwalletAddress, ethereumTxRequest.Volume); } else { res = await _srvEthereumHelper.SendTransferAsync(ethereumTxRequest.SignedTransfer.Id, ethereumTxRequest.SignedTransfer.Sign, asset, fromAddress, _settings.HotwalletAddress, ethereumTxRequest.Volume); } if (res.HasError) { errMsg = res.Error.ToJson(); await _log.WriteWarningAsync(nameof(TradeQueue), nameof(ProcessEthGuaranteeTransfer), errMsg, string.Empty); } ethereumTxRequest.OperationIds = clientTrades.Where(x => x.ClientId == ethereumTxRequest.ClientId && x.Amount < 0) .Select(x => x.Id) .ToArray(); await _ethereumTransactionRequestRepository.UpdateAsync(ethereumTxRequest); } catch (Exception e) { await _log.WriteErrorAsync(nameof(TradeQueue), nameof(ProcessEthGuaranteeTransfer), e.Message, e); errMsg = $"{e.GetType()}\n{e.Message}"; } if (!string.IsNullOrEmpty(errMsg)) { await _ethClientEventLogs.WriteEvent(ethereumTxRequest.ClientId, Event.Error, new { Info = $"Guarantee transfer of {asset.Id} failed", Operations = operations.ToJson(), RequestId = ethereumTxRequest.Id, Error = errMsg }.ToJson()); return(false); } return(true); }