Пример #1
0
 public BatchController(BlockchainController blockchainController, ChaumianCoinJoinController chaumianCoinJoinController, HomeController homeController, OffchainController offchainController, Global global)
 {
     BlockchainController       = blockchainController;
     ChaumianCoinJoinController = chaumianCoinJoinController;
     HomeController             = homeController;
     OffchainController         = offchainController;
     Global = global;
 }
Пример #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 = ChaumianCoinJoinController.GetUnconfirmedCoinJoinCollection();

        return(Ok(response));
    }