public async Task <CommandHandlingResult> Handle(CreateForwardCashinCommand command, IEventPublisher eventPublisher) { var entity = Mapper.Map <Cashin>(command); if (!await _historyRecordsRepository.TryInsertAsync(entity)) { _logger.Warning($"Skipped duplicated forward cashin record", context: new { id = command.OperationId }); return(CommandHandlingResult.Ok()); } eventPublisher.PublishEvent(new ForwardCashinCreatedEvent { AssetId = command.AssetId, OperationId = command.OperationId, Timestamp = command.Timestamp, Volume = command.Volume, WalletId = command.WalletId }); return(CommandHandlingResult.Ok()); }
public async Task <CommandHandlingResult> Handle(CashOutProcessedEvent cashOutProcessedEvent, ICommandSender commandSender) { var bitcoinTransactionExists = await _bitCoinTransactionsRepository.ForwardWithdrawalExistsAsync(cashOutProcessedEvent.OperationId.ToString()); if (!bitcoinTransactionExists) { _log.Info("Skip cashout - not forward withdrawal.", context: cashOutProcessedEvent.ToJson()); return(CommandHandlingResult.Ok()); } var record = await _repository.TryGetByCashoutIdAsync(cashOutProcessedEvent.WalletId.ToString(), cashOutProcessedEvent.OperationId.ToString()); if (record != null) { if (!Guid.TryParse(record.CashInId, out var cashinId)) { _log.Warning($"Cannot parse data : {record.ToJson()}"); return(CommandHandlingResult.Ok()); } var asset = await _assetsServiceWithCache.TryGetAssetAsync(record.AssetId); var forwardAsset = await _assetsServiceWithCache.TryGetAssetAsync(asset.ForwardBaseAsset); var settlementDate = record.DateTime.AddDays(asset.ForwardFrozenDays); var command = new CreateForwardCashinCommand { AssetId = forwardAsset.Id, OperationId = cashinId, Timestamp = settlementDate, Volume = Math.Abs(cashOutProcessedEvent.Volume).TruncateDecimalPlaces(forwardAsset.Accuracy), WalletId = cashOutProcessedEvent.WalletId }; commandSender.SendCommand(command, HistoryBoundedContext.Name); _log.Info("CreateForwardCashinCommand has been sent.", command); return(CommandHandlingResult.Ok()); } _log.Warning("No forward withdrawal record found.", context: new { Id = cashOutProcessedEvent.OperationId.ToString() }); return(CommandHandlingResult.Fail(TimeSpan.FromSeconds(10))); }
private CreateForwardCashinCommand CreateForwardCashinRecord() { var cqrs = _container.Resolve <ICqrsEngine>(); var id = Guid.NewGuid(); var clientId = Guid.NewGuid(); var volume = 54.31M; var command = new CreateForwardCashinCommand { OperationId = id, WalletId = clientId, Volume = volume, AssetId = "LKK", Timestamp = DateTime.UtcNow }; cqrs.SendCommand(command, HistoryBoundedContext.Name, HistoryBoundedContext.Name); return(command); }