public async Task <IActionResult> Post(TransactionDto transactionDto) { // Todo: make uri dynamically read from config var uri = new Uri("https://localhost:44341/report/transaction"); var result = await _transactionBroadCastingService.BroadcastTransaction(transactionDto, uri); if (result.IsSuccessStatusCode) { return(new OkResult()); } // Todo: could be handled better return(new ObjectResult(result)); }
public async Task <IActionResult> BroadcastTransaction([FromBody] BroadcastTransactionRequest request) { if (request == null) { return(BadRequest(ErrorResponse.Create("Unable to deserialize request"))); } var aggregate = await _operationRepository.GetOrDefault(request.OperationId); if (aggregate == null) { return(BadRequest(ErrorResponse.Create($"Operation {request.OperationId} not found"))); } Transaction tx; try { tx = TransactionSerializer.Deserialize(request.SignedTransaction).transaction; } catch (InvalidTransactionException) { return(BadRequest(ErrorResponse.Create($"{nameof(request.SignedTransaction)} is invalid"))); } if (aggregate.IsBroadcasted) { return(Conflict()); } try { await _transactionBroadcaster.BroadcastTransaction(tx, aggregate); } catch (TransactionAlreadyBroadcastedException) { return(Conflict()); } aggregate.OnBroadcasted(DateTime.UtcNow); await _operationRepository.Save(aggregate); return(Ok()); }