Add Guard.Correct pattern
MODIFY
MagicalCryptoWallet/Helpers/Guard.cs
MagicalCryptoWallet/Helpers/Guard.cs
@@ -124,5 +124,12 @@ namespace MagicalCryptoWallet.Helpers
return (int)value;
}
+
+ public static string Correct(string str)
+ {
+ return string.IsNullOrWhiteSpace(str)
+ ? string.Empty
+ : str.Trim();
+ }
}
}

MODIFY
MagicalCryptoWallet/KeyManagement/HdPubKey.cs
MagicalCryptoWallet/KeyManagement/HdPubKey.cs
@@ -29,8 +29,7 @@ namespace MagicalCryptoWallet.KeyManagement
{
PubKey = Guard.NotNull(nameof(pubKey), pubKey);
FullKeyPath = Guard.NotNull(nameof(fullKeyPath), fullKeyPath);
- label = label ?? "";
- Label = label.Trim();
+ label = Guard.Correct(label);
KeyState = keyState;
}

MODIFY
MagicalCryptoWallet/Models/SmartCoin.cs
MagicalCryptoWallet/Models/SmartCoin.cs
@@ -57,7 +57,7 @@ namespace MagicalCryptoWallet.Models
Amount = Guard.NotNull(nameof(amount), amount);
SpentOutputs = Guard.NotNull(nameof(spentOutputs), spentOutputs);
Height = height;
- Label = string.IsNullOrWhiteSpace(label) ? "" : label.Trim();
+ Label = Guard.Correct(label);
SpenderTransactionId = spenderTransactionId;
}

MODIFY
MagicalCryptoWallet/Services/WalletService.cs
MagicalCryptoWallet/Services/WalletService.cs
@@ -196,15 +196,7 @@ namespace MagicalCryptoWallet.Services
public HdPubKey GetReceiveKey(string label)
{
- // ToDo, put this correction pattern into the Guard class: Guard.Correct(string ...)
- if (string.IsNullOrWhiteSpace(label))
- {
- label = "";
- }
- else
- {
- label = label.Trim();
- }
+ label = Guard.Correct(label);
// Make sure there's always 21 clean keys generated and indexed.
AssertCleanKeysIndexed(21, false);

Add Guard.Correct pattern