From e2c0fd1b4bbef8cfd90dea7502e6ac3a15ca6eb8 Mon Sep 17 00:00:00 2001 From: CodingEnthusiast Date: Tue, 7 May 2024 09:11:34 +0330 Subject: [PATCH] Use the DNS seeds in Constants --- Src/Denovo/Models/Configuration.cs | 25 ++----------------- .../ViewModels/ConfigurationViewModel.cs | 11 ++++---- Src/Denovo/ViewModels/MinerViewModel.cs | 4 +-- Src/Denovo/ViewModels/PushTxViewModel.cs | 2 +- Src/Denovo/Views/ConfigurationView.axaml | 2 ++ 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/Src/Denovo/Models/Configuration.cs b/Src/Denovo/Models/Configuration.cs index e6b384f8..e9fa60fb 100644 --- a/Src/Denovo/Models/Configuration.cs +++ b/Src/Denovo/Models/Configuration.cs @@ -98,33 +98,12 @@ public PeerDiscoveryOption SelectedPeerDiscoveryOption } - public static readonly string[] DnsMain = new string[] - { - "seed.bitcoin.sipa.be", // Pieter Wuille, only supports x1, x5, x9, and xd - "dnsseed.bluematt.me", // Matt Corallo, only supports x9 - "dnsseed.bitcoin.dashjr.org", // Luke Dashjr - "seed.bitcoinstats.com", // Christian Decker, supports x1 - xf - "seed.bitcoin.jonasschnelli.ch", // Jonas Schnelli, only supports x1, x5, x9, and xd - "seed.btc.petertodd.org", // Peter Todd, only supports x1, x5, x9, and xd - "seed.bitcoin.sprovoost.nl", // Sjors Provoost - "dnsseed.emzy.de", // Stephan Oeste - "seed.bitcoin.wiz.biz", // Jason Maurice - }; - - public static readonly string[] DnsTest = new string[] - { - "testnet-seed.bitcoin.jonasschnelli.ch", - "seed.tbtc.petertodd.org", - "seed.testnet.bitcoin.sprovoost.nl", - "testnet-seed.bluematt.me", - }; - private string GetDnsList() { return Network switch { - NetworkType.MainNet => string.Join(Environment.NewLine, DnsMain), - NetworkType.TestNet => string.Join(Environment.NewLine, DnsTest), + NetworkType.MainNet => string.Join(Environment.NewLine, Constants.GetMainNetDnsSeeds()), + NetworkType.TestNet => string.Join(Environment.NewLine, Constants.GetTestNetDnsSeeds()), NetworkType.RegTest => "Not defined.", _ => "Not defined." }; diff --git a/Src/Denovo/ViewModels/ConfigurationViewModel.cs b/Src/Denovo/ViewModels/ConfigurationViewModel.cs index d65940b8..f1f7c246 100644 --- a/Src/Denovo/ViewModels/ConfigurationViewModel.cs +++ b/Src/Denovo/ViewModels/ConfigurationViewModel.cs @@ -9,7 +9,6 @@ using Avalonia.Controls.ApplicationLifetimes; using Denovo.Models; using Denovo.MVVM; -using Denovo.Services; using System.Collections.Generic; using System.ComponentModel; @@ -18,15 +17,17 @@ namespace Denovo.ViewModels public class ConfigurationViewModel : VmWithSizeBase { // This will make designer happy - public ConfigurationViewModel() : base(500, 600) + public ConfigurationViewModel() : this(new Configuration(NetworkType.MainNet)) { - Config = new Configuration(NetworkType.MainNet); } public ConfigurationViewModel(Configuration config) : base(500, 600) { Config = config; Config.PropertyChanged += Config_PropertyChanged; + + ClientTypes = EnumHelper.GetAllEnumValues(); + PeerDiscoveryOptions = EnumHelper.GetAllEnumValues(); } @@ -50,8 +51,8 @@ private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e) } public Configuration Config { get; set; } - public IEnumerable ClientTypes { get; } = EnumHelper.GetAllEnumValues(); - public IEnumerable PeerDiscoveryOptions { get; } = EnumHelper.GetAllEnumValues(); + public IEnumerable ClientTypes { get; } + public IEnumerable PeerDiscoveryOptions { get; } private string _desc; public string Desc diff --git a/Src/Denovo/ViewModels/MinerViewModel.cs b/Src/Denovo/ViewModels/MinerViewModel.cs index 7de6beb5..b81b04b1 100644 --- a/Src/Denovo/ViewModels/MinerViewModel.cs +++ b/Src/Denovo/ViewModels/MinerViewModel.cs @@ -25,7 +25,7 @@ public MinerViewModel() : base(650, 650) AllNodes = new NodePool(5); MinimalClientSettings clientSettings = new(NetworkType.TestNet, 5, AllNodes) { - DnsSeeds = Configuration.DnsTest, + DnsSeeds = Constants.GetTestNetDnsSeeds(), UserAgent = "/Satoshi:0.22.0/", }; client = new MinimalClient(clientSettings); @@ -114,7 +114,7 @@ public async void StartMining() IBlock result = await miner.Start(prvBlock, BlockHeight, tokenSource.Token); - if (!(result is null)) + if (result is not null) { FastStream stream = new(); result.Serialize(stream); diff --git a/Src/Denovo/ViewModels/PushTxViewModel.cs b/Src/Denovo/ViewModels/PushTxViewModel.cs index 602fe0b8..4568b6ec 100644 --- a/Src/Denovo/ViewModels/PushTxViewModel.cs +++ b/Src/Denovo/ViewModels/PushTxViewModel.cs @@ -73,7 +73,7 @@ public void Connect() { settings = new(SelectedNetwork, 4, null) { - DnsSeeds = SelectedNetwork == NetworkType.MainNet ? Configuration.DnsMain : Configuration.DnsTest, + DnsSeeds = SelectedNetwork == NetworkType.MainNet ? Constants.GetMainNetDnsSeeds() : Constants.GetTestNetDnsSeeds(), UserAgent = "/Satoshi:0.22.0/", }; client = new(settings); diff --git a/Src/Denovo/Views/ConfigurationView.axaml b/Src/Denovo/Views/ConfigurationView.axaml index 05ac9719..f90050a5 100644 --- a/Src/Denovo/Views/ConfigurationView.axaml +++ b/Src/Denovo/Views/ConfigurationView.axaml @@ -38,6 +38,7 @@ --> + +