public override async Task <Empty> AcceptOperation(OperationIdRequest request, ServerCallContext context) { var result = new Empty(); if (string.IsNullOrEmpty(request.Id)) { return(result); } if (!Guid.TryParse(request.Id, out var operationId)) { return(result); } var operation = await _validationRepository.TryGetAsync(operationId); if (operation == null) { _log.Warning("Operation not found", context: request.Id); return(result); } operation.Resolve(OperationValidationResolution.Accepted); await _validationRepository.SaveAsync(operation); _cqrsEngine.PublishEvent(new OperationAcceptedEvent { OperationId = operationId }, BlockchainRiskControlBoundedContext.Name); return(result); }
public async Task <OperationValidation> ValidateAsync(Operation operation) { var validation = await _validationRepository.TryGetAsync(operation.Id); if (validation != null) { return(validation); } var risk = await _operationRiskEstimator.ValidateAsync(operation); validation = OperationValidation.Create(operation, risk); await _validationRepository.AddAsync(validation); return(validation); }
public async Task RegisterStatisticsAsync(Guid operationId) { var validation = await _validationRepository.TryGetAsync(operationId); if (validation == null) { throw new InvalidOperationException($"Operation validation {operationId} to get statistics has not been found."); } await _statisticsRepository.RegisterOperationAsync(validation.Operation); }