Improve parsing of BitcoinAddress
MODIFY
WalletWasabi/Helpers/NBitcoinHelpers.cs
WalletWasabi/Helpers/NBitcoinHelpers.cs
@@ -91,6 +91,30 @@ namespace WalletWasabi.Helpers
return epk;
}
+ public static BitcoinAddress BetterParseBitcoinAddress(string bitcoinAddressString)
+ {
+ bitcoinAddressString = Guard.NotNullOrEmptyOrWhitespace(nameof(bitcoinAddressString), bitcoinAddressString, trim: true);
+
+ BitcoinAddress ba;
+ try
+ {
+ ba = BitcoinAddress.Create(bitcoinAddressString, Network.Main);
+ }
+ catch
+ {
+ try
+ {
+ ba = BitcoinAddress.Create(bitcoinAddressString, Network.TestNet);
+ }
+ catch
+ {
+ ba = BitcoinAddress.Create(bitcoinAddressString, Network.RegTest);
+ }
+ }
+
+ return ba;
+ }
+
public static HDFingerprint BetterParseHDFingerprint(string hdFingerprintString, bool reverseByteOrder = false)
{
hdFingerprintString = Guard.NotNullOrEmptyOrWhitespace(nameof(hdFingerprintString), hdFingerprintString, trim: true);

MODIFY
WalletWasabi/JsonConverters/BitcoinAddressJsonConverter.cs
WalletWasabi/JsonConverters/BitcoinAddressJsonConverter.cs
@@ -16,17 +16,23 @@ namespace WalletWasabi.JsonConverters
/// <inheritdoc />
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
- var value = Guard.Correct((string)reader.Value);
-
- return string.IsNullOrWhiteSpace(value) ? default : Network.Parse<BitcoinAddress>(value, Network.Main);
+ var bitcoinAddressString = reader.Value as string;
+ if (string.IsNullOrWhiteSpace(bitcoinAddressString))
+ {
+ return default;
+ }
+ else
+ {
+ return NBitcoinHelpers.BetterParseBitcoinAddress(bitcoinAddressString);
+ }
}
/// <inheritdoc />
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
- var address = (BitcoinAddress)value;
+ var bitcoinAddress = value as BitcoinAddress;
- writer.WriteValue(address.ToString());
+ writer.WriteValue(bitcoinAddress.ToString());
}
}
}

Improve parsing of BitcoinAddress