Refactor FindAlice
MODIFY
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
@@ -223,7 +223,7 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
}
if (request.UniqueId == null) return new BadRequestResult();
- Alice alice = FindAlice(request.UniqueId);
+ Alice alice = Global.StateMachine.FindAlice(request.UniqueId, throwException: true);
if (alice.State == AliceState.ConnectionConfirmed)
{
@@ -304,7 +304,7 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
}
if (request.UniqueId == null) return new BadRequestResult();
- Alice alice = FindAlice(request.UniqueId);
+ Alice alice = Global.StateMachine.FindAlice(request.UniqueId, throwException: true);
if (alice.State == AliceState.AskedForCoinJoin)
{
@@ -337,7 +337,7 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
if (request.UniqueId == null) return new BadRequestResult();
if (request.Signature == null) return new BadRequestResult();
- Alice alice = FindAlice(request.UniqueId);
+ Alice alice = Global.StateMachine.FindAlice(request.UniqueId, throwException: true);
throw new NotImplementedException();
}
@@ -346,16 +346,5 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
return new ObjectResult(new FailureResponse { Message = ex.Message, Details = ex.ToString() });
}
}
-
- private static Alice FindAlice(string uniqueId)
- {
- Alice alice = Global.StateMachine.Alices.FirstOrDefault(x => x.UniqueId == new Guid(uniqueId));
- if (alice == default(Alice))
- {
- throw new ArgumentException("Wrong uniqueId");
- }
-
- return alice;
- }
}
}

MODIFY
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
@@ -253,6 +253,20 @@ namespace HiddenWallet.ChaumianTumbler
}
}
+ public Alice FindAlice(string uniqueId, bool throwException)
+ {
+ Alice alice = Alices.FirstOrDefault(x => x.UniqueId == new Guid(uniqueId));
+ if (alice == default(Alice))
+ {
+ if (throwException)
+ {
+ throw new ArgumentException("Wrong uniqueId");
+ }
+ }
+
+ return alice;
+ }
+
#region IDisposable Support
private bool _disposedValue = false; // To detect redundant calls

Refactor FindAlice