diff --git a/BTCPayServer/WalletId.cs b/BTCPayServer/WalletId.cs index bc361d778..e9a7749ff 100644 --- a/BTCPayServer/WalletId.cs +++ b/BTCPayServer/WalletId.cs @@ -11,6 +11,8 @@ namespace BTCPayServer static readonly Regex _WalletStoreRegex = new Regex("^S-([a-zA-Z0-9]{30,60})-([a-zA-Z]{2,5})$"); public static bool TryParse(string str, out WalletId walletId) { + if (str == null) + throw new ArgumentNullException(nameof(str)); walletId = null; WalletId w = new WalletId(); var match = _WalletStoreRegex.Match(str); @@ -32,8 +34,37 @@ namespace BTCPayServer } public string StoreId { get; set; } public string CryptoCode { get; set; } + + + public override bool Equals(object obj) + { + WalletId item = obj as WalletId; + if (item == null) + return false; + return ToString().Equals(item.ToString(), StringComparison.InvariantCulture); + } + public static bool operator ==(WalletId a, WalletId b) + { + if (System.Object.ReferenceEquals(a, b)) + return true; + if (((object)a == null) || ((object)b == null)) + return false; + return a.ToString() == b.ToString(); + } + + public static bool operator !=(WalletId a, WalletId b) + { + return !(a == b); + } + + public override int GetHashCode() + { + return ToString().GetHashCode(StringComparison.Ordinal); + } public override string ToString() { + if (StoreId == null || CryptoCode == null) + return ""; return $"S-{StoreId}-{CryptoCode.ToUpperInvariant()}"; } }