Integrate CoreConfig
MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/ConfigTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/ConfigTests.cs
using System;
using System.Collections.Generic;
using System.Text;
-using WalletWasabi.BitcoinCore;
+using WalletWasabi.BitcoinCore.Configuration;
using Xunit;
namespace WalletWasabi.Tests.UnitTests.BitcoinCore

RENAME
WalletWasabi/BitcoinCore/CoreConfig.cs
WalletWasabi/BitcoinCore/Configuration/CoreConfig.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using WalletWasabi.Helpers;
-namespace WalletWasabi.BitcoinCore
+namespace WalletWasabi.BitcoinCore.Configuration
{
public class CoreConfig
{

RENAME
WalletWasabi/BitcoinCore/CoreConfigLine.cs
WalletWasabi/BitcoinCore/Configuration/CoreConfigLine.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using WalletWasabi.Helpers;
-namespace WalletWasabi.BitcoinCore
+namespace WalletWasabi.BitcoinCore.Configuration
{
public class CoreConfigLine
{

MODIFY
WalletWasabi/BitcoinCore/CoreNode.cs
WalletWasabi/BitcoinCore/CoreNode.cs
@@ -13,6 +13,7 @@ using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
+using WalletWasabi.BitcoinCore.Configuration;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
@@ -35,13 +36,16 @@ namespace WalletWasabi.BitcoinCore
coreNode.DataDir = Guard.NotNullOrEmptyOrWhitespace(nameof(dataDir), dataDir);
var configPath = Path.Combine(coreNode.DataDir, "bitcoin.conf");
+ var config = new CoreConfig();
if (File.Exists(configPath))
{
- var foundConfig = await NodeConfigParameters.LoadAsync(configPath);
- var rpcPortString = foundConfig["regtest.rpcport"];
- var rpcUser = foundConfig["regtest.rpcuser"];
- var rpcPassword = foundConfig["regtest.rpcpassword"];
- var pidFileName = foundConfig["regtest.pid"];
+ var configString = await File.ReadAllTextAsync(configPath).ConfigureAwait(false);
+ config.TryAdd(configString);
+ var foundConfigDic = config.ToDictionary();
+ var rpcPortString = foundConfigDic["regtest.rpcport"];
+ var rpcUser = foundConfigDic["regtest.rpcuser"];
+ var rpcPassword = foundConfigDic["regtest.rpcpassword"];
+ var pidFileName = foundConfigDic["regtest.pid"];
var credentials = new NetworkCredential(rpcUser, rpcPassword);
try
{
@@ -108,22 +112,21 @@ namespace WalletWasabi.BitcoinCore
coreNode.RpcClient = new RPCClient($"{creds.UserName}:{creds.Password}", coreNode.RpcEndPoint.ToString(rpcPort), Network.RegTest);
- var config = new NodeConfigParameters
- {
- {"regtest", "1"},
- {"regtest.rest", "1"},
- {"regtest.listenonion", "0"},
- {"regtest.server", "1"},
- {"regtest.txindex", "1"},
- {"regtest.rpcuser", coreNode.RpcClient.CredentialString.UserPassword.UserName},
- {"regtest.rpcpassword", coreNode.RpcClient.CredentialString.UserPassword.Password},
- {"regtest.whitebind", "127.0.0.1:" + p2pPort.ToString()},
- {"regtest.rpcport", coreNode.RpcEndPoint.GetPortOrDefault().ToString()},
- {"regtest.printtoconsole", "0"}, // Set it to one if do not mind loud debug logs
- {"regtest.keypool", "10"},
- {"regtest.pid", "bitcoind.pid"}
- };
-
+ var desiredConfigString =
+@$"regtest = 1
+regtest.rest = 1
+regtest.listenonion = 0
+regtest.server = 1
+regtest.txindex = 1
+regtest.rpcuser = {coreNode.RpcClient.CredentialString.UserPassword.UserName}
+regtest.rpcpassword = {coreNode.RpcClient.CredentialString.UserPassword.Password}
+regtest.whitebind = 127.0.0.1:{p2pPort}
+regtest.rpcport = {coreNode.RpcEndPoint.GetPortOrDefault()}
+regtest.printtoconsole = 0
+regtest.keypool = 10
+regtest.pid = bitcoind.pid";
+
+ config.AddOrUpdate(desiredConfigString);
await File.WriteAllTextAsync(configPath, config.ToString());
using (await coreNode.KillerLock.LockAsync())
{

DELETE
WalletWasabi/BitcoinCore/NodeConfigParameters.cs
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace WalletWasabi.BitcoinCore
-{
- public class NodeConfigParameters : Dictionary<string, string>
- {
- public void Import(NodeConfigParameters configParameters)
- {
- foreach (var kv in configParameters)
- {
- if (!ContainsKey(kv.Key))
- {
- Add(kv.Key, kv.Value);
- }
- }
- }
-
- public override string ToString()
- {
- StringBuilder builder = new StringBuilder();
- foreach (var kv in this)
- {
- builder.AppendLine(kv.Key + "=" + kv.Value);
- }
-
- return builder.ToString();
- }
-
- public static async Task<NodeConfigParameters> LoadAsync(string configFile)
- {
- var config = new NodeConfigParameters();
- foreach (var line in await File.ReadAllLinesAsync(configFile))
- {
- if (string.IsNullOrWhiteSpace(line))
- {
- continue;
- }
- var parts = line.Split('=');
- config.Add(parts[0], parts[1]);
- }
- return config;
- }
- }
-}

Integrate CoreConfig