Handle sections
MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/ConfigTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/ConfigTests.cs
@@ -146,5 +146,40 @@ buz = qux
Assert.Equal(expectedConfig, coreConfig.ToString());
}
+
+ [Fact]
+ public void HandlesSections()
+ {
+ var testConfig =
+@"qux=1
+[main]
+foo=1
+bar=1
+[test]
+foo=2
+bar=2
+[regtest]
+foo=3
+bar=4
+[main]
+buz=1
+test.buz=2";
+ var coreConfig = new CoreConfig();
+ coreConfig.TryAdd(testConfig);
+
+ var expectedConfig =
+@"qux = 1
+main.foo = 1
+main.bar = 1
+test.foo = 2
+test.bar = 2
+regtest.foo = 3
+regtest.bar = 4
+main.buz = 1
+test.buz = 2
+";
+
+ Assert.Equal(expectedConfig, coreConfig.ToString());
+ }
}
}

MODIFY
WalletWasabi/BitcoinCore/Configuration/CoreConfig.cs
WalletWasabi/BitcoinCore/Configuration/CoreConfig.cs
@@ -122,9 +122,41 @@ namespace WalletWasabi.BitcoinCore.Configuration
{
configString = Guard.Correct(configString);
var allLines = configString.Split('\n', StringSplitOptions.None);
- return allLines
- .Select(x => Guard.Correct(x))
- .Where((x, i) => i == 0 || x != allLines[i - 1])
+ var allCorrectedLines = allLines.Select(x => Guard.Correct(x))
+ .Where((x, i) => i == 0 || x != allLines[i - 1]);
+
+ var retLines = new List<string>();
+ string section = null;
+ foreach (var line in allCorrectedLines)
+ {
+ if (line == "[main]")
+ {
+ section = "main.";
+ }
+ else if (line == "[test]")
+ {
+ section = "test.";
+ }
+ else if (line == "[regtest]")
+ {
+ section = "regtest.";
+ }
+ else
+ {
+ if (section is null
+ || line.StartsWith("main.", StringComparison.OrdinalIgnoreCase)
+ || line.StartsWith("test.", StringComparison.OrdinalIgnoreCase)
+ || line.StartsWith("regtest.", StringComparison.OrdinalIgnoreCase))
+ {
+ retLines.Add(line);
+ }
+ else
+ {
+ retLines.Add($"{section}{line}");
+ }
+ }
+ }
+ return retLines
.Select(x => new CoreConfigLine(x));
}
}

Handle sections