Exemplo n.º 1
0
 public BatchController(BlockchainController blockchainController, ChaumianCoinJoinController chaumianCoinJoinController, HomeController homeController, OffchainController offchainController)
 {
     BlockchainController       = blockchainController;
     ChaumianCoinJoinController = chaumianCoinJoinController;
     HomeController             = homeController;
     OffchainController         = offchainController;
 }
Exemplo n.º 2
0
        public async Task <IActionResult> GetSynchronizeAsync([FromQuery, Required] string bestKnownBlockHash, [FromQuery, Required] int maxNumberOfFilters, [FromQuery] string?estimateSmartFeeMode = nameof(EstimateSmartFeeMode.Conservative))
        {
            bool estimateSmartFee     = !string.IsNullOrWhiteSpace(estimateSmartFeeMode);
            EstimateSmartFeeMode mode = EstimateSmartFeeMode.Conservative;

            if (estimateSmartFee)
            {
                if (!Enum.TryParse(estimateSmartFeeMode, ignoreCase: true, out mode))
                {
                    return(BadRequest("Invalid estimation mode is provided, possible values: ECONOMICAL/CONSERVATIVE."));
                }
            }

            if (!uint256.TryParse(bestKnownBlockHash, out var knownHash))
            {
                return(BadRequest($"Invalid {nameof(bestKnownBlockHash)}."));
            }

            (Height bestHeight, IEnumerable <FilterModel> filters) = Global.IndexBuilderService.GetFilterLinesExcluding(knownHash, maxNumberOfFilters, out bool found);

            var response = new SynchronizeResponse {
                Filters = Enumerable.Empty <FilterModel>(), BestHeight = bestHeight
            };

            if (!found)
            {
                response.FiltersResponseState = FiltersResponseState.BestKnownHashNotFound;
            }
            else if (!filters.Any())
            {
                response.FiltersResponseState = FiltersResponseState.NoNewFilter;
            }
            else
            {
                response.FiltersResponseState = FiltersResponseState.NewFilters;
                response.Filters = filters;
            }

            response.CcjRoundStates = ChaumianCoinJoinController.GetStatesCollection();

            if (estimateSmartFee)
            {
                try
                {
                    response.AllFeeEstimate = await BlockchainController.GetAllFeeEstimateAsync(mode);
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                }
            }

            response.ExchangeRates = await OffchainController.GetExchangeRatesCollectionAsync();

            response.UnconfirmedCoinJoins = await ChaumianCoinJoinController.GetUnconfirmedCoinJoinCollectionAsync();

            return(Ok(response));
        }
Exemplo n.º 3
0
 public LegacyController(BlockchainController blockchainController, OffchainController offchainController)
 {
     BlockchainController = blockchainController;
     OffchainController   = offchainController;
 }
Exemplo n.º 4
0
 public async Task <IActionResult> GetAllFeesV3Async([FromQuery, Required] string estimateSmartFeeMode)
 => await BlockchainController.GetAllFeesAsync(estimateSmartFeeMode);
Exemplo n.º 5
0
        public async Task <IActionResult> GetSynchronizeAsync([FromQuery] string bestKnownBlockHash, [FromQuery] int maxNumberOfFilters, [FromQuery] string estimateSmartFeeMode)
        {
            if (string.IsNullOrWhiteSpace(bestKnownBlockHash))
            {
                return(BadRequest("Invalid block hash is provided."));
            }
            if (maxNumberOfFilters <= 0)
            {
                return(BadRequest("Invalid maxNumberOfFilters is provided."));
            }

            bool estimateSmartFee     = !string.IsNullOrWhiteSpace(estimateSmartFeeMode);
            EstimateSmartFeeMode mode = EstimateSmartFeeMode.Conservative;

            if (estimateSmartFee)
            {
                if (!Enum.TryParse(estimateSmartFeeMode, ignoreCase: true, out mode))
                {
                    return(BadRequest("Invalid estimation mode is provided, possible values: ECONOMICAL/CONSERVATIVE."));
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Wrong body is provided."));
            }

            var knownHash = new uint256(bestKnownBlockHash);

            (Height bestHeight, IEnumerable <string> filters) = Global.IndexBuilderService.GetFilterLinesExcluding(knownHash, maxNumberOfFilters, out bool found);

            var response = new SynchronizeResponse();

            response.Filters    = new string[0];
            response.BestHeight = bestHeight;

            if (!found)
            {
                response.FiltersResponseState = FiltersResponseState.BestKnownHashNotFound;
            }
            else if (!filters.Any())
            {
                response.FiltersResponseState = FiltersResponseState.NoNewFilter;
            }
            else
            {
                response.FiltersResponseState = FiltersResponseState.NewFilters;
                response.Filters = filters;
            }

            response.CcjRoundStates = ChaumianCoinJoinController.GetStatesCollection();

            if (estimateSmartFee)
            {
                response.AllFeeEstimate = await BlockchainController.GetAllFeeEstimateAsync(mode);
            }

            response.ExchangeRates = await OffchainController.GetExchangeRatesCollectionAsync();

            return(Ok(response));
        }