예제 #1
0
        private async void Synchronizer_ResponseArrivedAsync(object sender, SynchronizeResponse response)
        {
            try
            {
                using (await ProcessLock.LockAsync())
                {
                    var unconfirmedCoinJoinHashes = response.UnconfirmedCoinJoins;
                    if (!unconfirmedCoinJoinHashes.Any())
                    {
                        return;
                    }

                    var txsNotKnownByAWallet = WalletManager.FilterUnknownCoinjoins(unconfirmedCoinJoinHashes);

                    using var client = new WasabiClient(Synchronizer.WasabiClient.TorClient.DestinationUriAction, Synchronizer.WasabiClient.TorClient.TorSocks5EndPoint);

                    var unconfirmedCoinJoins = await client.GetTransactionsAsync(Synchronizer.Network, txsNotKnownByAWallet, CancellationToken.None).ConfigureAwait(false);

                    foreach (var tx in unconfirmedCoinJoins.Select(x => new SmartTransaction(x, Height.Mempool)))
                    {
                        if (RpcClient is null ||
                            await TryBroadcastTransactionWithRpcAsync(tx).ConfigureAwait(false) ||
                            (await RpcClient.TestAsync().ConfigureAwait(false)) is { })                                // If the test throws exception then I believe it, because RPC is down and the backend is the god.
                        {
                            WalletManager.ProcessCoinJoin(tx);
                        }
                    }
예제 #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));
        }
예제 #3
0
        private async void Synchronizer_ResponseArrivedAsync(object sender, SynchronizeResponse e)
        {
            try
            {
                IEnumerable <CcjRunningRoundState> newRoundStates = e.CcjRoundStates;

                await ProcessStatusAsync(newRoundStates);
            }
            catch (Exception ex)
            {
                Logger.LogWarning <CcjClient>(ex);
            }
        }
예제 #4
0
            public override async Task <SynchronizeResponse> Synchronize(SynchronizeRequest request,
                                                                         ServerCallContext context)
            {
                this.logger.Info("Got Synchronize");
                this.OnSynchronize?.Invoke(request.PublicEndpoint);
                var result = new SynchronizeResponse()
                {
                    Timestamp = Timestamp.FromDateTime(this.globalConfigurationService.ConfigurationManager.Timestamp
                                                       .ToUniversalTime())
                };

                if (this.globalConfigurationService.ConfigurationManager.Ftp.Host != null)
                {
                    result.Ftp = this.globalConfigurationService.ConfigurationManager.Ftp.ToGrpc();
                }

                if (this.globalConfigurationService.ConfigurationManager.Database.Connection.Host != null)
                {
                    result.Database = this.globalConfigurationService.ConfigurationManager.Database.ToGrpc();
                }
                return(await Task.FromResult(result));
            }
예제 #5
0
 private async void Synchronizer_ResponseArrivedAsync(object sender, SynchronizeResponse e)
 {
     await TryProcessStatusAsync(e?.CcjRoundStates).ConfigureAwait(false);
 }
예제 #6
0
        private async void Synchronizer_ResponseArrivedAsync(object sender, SynchronizeResponse e)
        {
            IEnumerable <CcjRunningRoundState> newRoundStates = e.CcjRoundStates;

            await ProcessStatusAsync(newRoundStates);
        }
예제 #7
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));
        }