Introduce TryGetFriendlyGeneratorName method instead of implementing the logic in ToString.
MODIFY
WalletWasabi/Crypto/Groups/Generators.cs
WalletWasabi/Crypto/Groups/Generators.cs
@@ -55,5 +55,59 @@ namespace WalletWasabi.Crypto.Groups
/// Generator for serial numbers.
/// </summary>
public static GroupElement Gs { get; } = GroupElement.FromText("Gs");
+
+ public static bool TryGetFriendlyGeneratorName(GroupElement ge, out string name)
+ {
+ name = "";
+
+ if (ge.X == G.X && ge.Y == G.Y)
+ {
+ name = "Standard";
+ }
+ else if (ge.X == Gw.X && ge.Y == Gw.Y)
+ {
+ name = nameof(Gw);
+ }
+ else if (ge.X == Gwp.X && ge.Y == Gwp.Y)
+ {
+ name = nameof(Gwp);
+ }
+ else if (ge.X == Gx0.X && ge.Y == Gx0.Y)
+ {
+ name = nameof(Gx0);
+ }
+ else if (ge.X == Gx1.X && ge.Y == Gx1.Y)
+ {
+ name = nameof(Gx1);
+ }
+ else if (ge.X == GV.X && ge.Y == GV.Y)
+ {
+ name = nameof(GV);
+ }
+ else if (ge.X == Gg.X && ge.Y == Gg.Y)
+ {
+ name = nameof(Gg);
+ }
+ else if (ge.X == Gh.X && ge.Y == Gh.Y)
+ {
+ name = nameof(Gh);
+ }
+ else if (ge.X == Ga.X && ge.Y == Ga.Y)
+ {
+ name = nameof(Ga);
+ }
+ else if (ge.X == Gs.X && ge.Y == Gs.Y)
+ {
+ name = nameof(Gs);
+ }
+ else
+ {
+ return false;
+ }
+
+ name += " Generator";
+
+ return true;
+ }
}
}

MODIFY
WalletWasabi/Crypto/Groups/GroupElement.cs
WalletWasabi/Crypto/Groups/GroupElement.cs
@@ -30,6 +30,8 @@ namespace WalletWasabi.Crypto.Groups
public static GroupElement Infinity { get; } = new GroupElement(GE.Infinity);
private GE Ge { get; }
+ public FE X => Ge.x;
+ public FE Y => Ge.y;
public bool IsInfinity => Ge.IsInfinity;
@@ -70,45 +72,9 @@ namespace WalletWasabi.Crypto.Groups
{
return "Infinity";
}
- else if (Ge.x == Generators.G.Ge.x && Ge.y == Generators.G.Ge.y)
+ else if (Generators.TryGetFriendlyGeneratorName(this, out string generatorName))
{
- return $"Standard Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.Gw.Ge.x && Ge.y == Generators.Gw.Ge.y)
- {
- return $"{nameof(Generators.Gw)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.Gwp.Ge.x && Ge.y == Generators.Gwp.Ge.y)
- {
- return $"{nameof(Generators.Gwp)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.Gx0.Ge.x && Ge.y == Generators.Gx0.Ge.y)
- {
- return $"{nameof(Generators.Gx0)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.Gx1.Ge.x && Ge.y == Generators.Gx1.Ge.y)
- {
- return $"{nameof(Generators.Gx1)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.GV.Ge.x && Ge.y == Generators.GV.Ge.y)
- {
- return $"{nameof(Generators.GV)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.Gg.Ge.x && Ge.y == Generators.Gg.Ge.y)
- {
- return $"{nameof(Generators.Gg)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.Gh.Ge.x && Ge.y == Generators.Gh.Ge.y)
- {
- return $"{nameof(Generators.Gh)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.Ga.Ge.x && Ge.y == Generators.Ga.Ge.y)
- {
- return $"{nameof(Generators.Ga)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
- }
- else if (Ge.x == Generators.Gs.Ge.x && Ge.y == Generators.Gs.Ge.y)
- {
- return $"{nameof(Generators.Gs)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{generatorName}, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
else
{

Introduce TryGetFriendlyGeneratorName method instead of implementing the logic in ToString.