示例#1
0
        private async Task LoopThroughChainWatchers(CancellationToken cancellationToken)
        {
            var chainIds = _btcPayNetworkProvider.GetAll().OfType <EthereumBTCPayNetwork>()
                           .Select(network => network.ChainId).Distinct().ToList();

            foreach (var chainId in chainIds)
            {
                try
                {
                    var settings = await _settingsRepository.GetSettingAsync <EthereumLikeConfiguration>(
                        EthereumLikeConfiguration.SettingsKey(chainId));

                    if (settings is null || string.IsNullOrEmpty(settings.Web3ProviderUrl))
                    {
                        var val     = _configuration.GetValue <string>($"chain{chainId}_web3", null);
                        var valUser = _configuration.GetValue <string>($"chain{chainId}_web3_user", null);
                        var valPass = _configuration.GetValue <string>($"chain{chainId}_web3_password", null);
                        if (val != null && First)
                        {
                            Logs.PayServer.LogInformation($"Setting eth chain {chainId} web3 to {val}");
                            settings ??= new EthereumLikeConfiguration()
                            {
                                ChainId              = chainId,
                                Web3ProviderUrl      = val,
                                Web3ProviderPassword = valPass,
                                Web3ProviderUsername = valUser
                            };
                            await _settingsRepository.UpdateSetting(settings, EthereumLikeConfiguration.SettingsKey(chainId));
                        }
                    }
                    var currentlyRunning = _chainHostedServices.ContainsKey(chainId);
                    var valid            = await EthereumConfigController.CheckValid(_httpClientFactory, _btcPayNetworkProvider.NetworkType, settings?.InvoiceId);

                    if (!currentlyRunning || (currentlyRunning && !valid))
                    {
                        await HandleChainWatcher(settings, valid, cancellationToken);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            First = false;
        }
示例#2
0
        protected override async Task ProcessEvent(object evt, CancellationToken cancellationToken)
        {
            if (evt is ReserveEthereumAddress reserveEthereumAddress)
            {
                await HandleReserveNextAddress(reserveEthereumAddress);
            }

            if (evt is SettingsChanged <EthereumLikeConfiguration> settingsChangedEthConfig)
            {
                var valid = await EthereumConfigController.CheckValid(_httpClientFactory, _btcPayNetworkProvider.NetworkType, settingsChangedEthConfig?.Settings?.InvoiceId);
                await HandleChainWatcher(settingsChangedEthConfig.Settings, valid, cancellationToken);
            }

            if (evt is CheckWatchers)
            {
                await LoopThroughChainWatchers(cancellationToken);
            }

            await base.ProcessEvent(evt, cancellationToken);
        }