Ejemplo n.º 1
0
        private async Task <IActionResult> BuildTxInternal(BuildSingleTransactionRequest request, decimal feeFactor)
        {
            _addressValidationService.AssertValid(request?.FromAddress);
            _addressValidationService.AssertValid(request?.ToAddress);

            try
            {
                var response = await _txBuilderService.BuildSingleTransactionAsync(request, feeFactor);

                return(Json(response));
            }

            catch (BusinessException exception) when(exception.Reason == ErrorReason.AmountTooSmall)
            {
                Response.StatusCode = (int)HttpStatusCode.Conflict;
                return(Json(new
                {
                    errorCode = "amountIsTooSmall",
                    transactionContext = (string)null
                }));
            }

            catch (BusinessException exception) when(exception.Reason == ErrorReason.NotEnoughBalance)
            {
                Response.StatusCode = (int)HttpStatusCode.Conflict;
                return(Json(new
                {
                    errorCode = "notEnoughBalance",
                    transactionContext = (string)null
                }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Subscribe(string address)
        {
            _addressValidator.AssertValid(address);

            try
            {
                await _service.SubscribeAsync(address);

                return(Ok());
            }
            catch (BusinessException e) when(e.Reason == ErrorReason.DuplicateRecord)
            {
                Response.StatusCode = (int)HttpStatusCode.Conflict;
                return(Json(new { errorMessage = "Address already being observed" }));
            }
        }
        private async Task <IActionResult> BuildTxInternal(BuildSingleTransactionRequest request, decimal feeFactor)
        {
            _addressValidationService.AssertValid(request?.FromAddress);
            _addressValidationService.AssertValid(request?.ToAddress);

            try
            {
                var response = await _txBuilderService.BuildSingleTransactionAsync(request, feeFactor);

                return(Json(response));
            }

            catch (BusinessException exception) when(exception.Reason == ErrorReason.AmountTooSmall)
            {
                Response.StatusCode = (int)HttpStatusCode.Conflict;
                return(Json(new
                {
                    errorCode = BlockchainErrorCode.AmountIsTooSmall,
                    transactionContext = (string)null
                }));
            }

            catch (BusinessException exception) when(exception.Reason == ErrorReason.NotEnoughBalance)
            {
                Response.StatusCode = (int)HttpStatusCode.Conflict;
                return(Json(new
                {
                    errorCode = BlockchainErrorCode.NotEnoughBalance,
                    transactionContext = (string)null
                }));
            }

            catch (BusinessException ex) when(ex.Reason == ErrorReason.DuplicateRecord)
            {
                // If this operationid was already broadcast, return 409 conflict.
                return(await GenericErrorResponse(ex, request.OperationId, HttpStatusCode.Conflict));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> SubscribeAddressFrom(string address)
        {
            _addressValidator.AssertValid(address);

            try
            {
                await _transactionHistoryService.SubscribeAddressFrom(address);

                return(Ok());
            }
            catch (BusinessException e) when(e.Reason == ErrorReason.DuplicateRecord)
            {
                return(new StatusCodeResult(409));
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Observe receiving transactions for this address.
 /// Only need this to return expected errors.
 /// </summary>
 /// <param name="address"></param>
 /// <returns></returns>
 public async Task SubscribeAddressFrom(string address)
 {
     _addressValidator.AssertValid(address);
     var entity = new ObservableAddressEntity(address, TxDirection.Outgoing);
     await _operationRepo.InsertAsync(entity);
 }