Progress AliceClient
MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -1388,7 +1388,6 @@ namespace WalletWasabi.Tests
Assert.Empty(wallet.Coins);
-
// Get some money, make it confirm.
// this is necesary because we are in a fork now.
var tx0Id = await Global.RpcClient.SendToAddressAsync(key.GetP2wpkhAddress(network), new Money(1m, MoneyUnit.BTC),
@@ -1603,11 +1602,8 @@ namespace WalletWasabi.Tests
Assert.NotEqual(Guid.Empty, inputsResponse.UniqueId);
Assert.True(inputsResponse.RoundId > 0);
long roundId = inputsResponse.RoundId;
- string queryString = $"/api/v1/btc/chaumiancoinjoin/confirmation?uniqueId={inputsResponse.UniqueId}&roundId={inputsResponse.RoundId}";
- using (var response2 = await torClient.SendAsync(HttpMethod.Post, queryString))
- {
- Assert.Equal(HttpStatusCode.NoContent, response2.StatusCode);
- }
+
+ Assert.Null(await aliceClient.PostConfirmationAsync(inputsResponse.RoundId, inputsResponse.UniqueId));
CcjRunningRoundState roundState = await satoshiClient.GetRoundStateAsync(roundId);
Assert.Equal(CcjRoundPhase.InputRegistration, roundState.Phase);
@@ -1747,17 +1743,9 @@ namespace WalletWasabi.Tests
Guid uniqueAliceId = inputsResponse.UniqueId;
Assert.True(inputsResponse.RoundId > 0);
roundId = inputsResponse.RoundId;
- using (var response = await torClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/confirmation?uniqueId={uniqueAliceId}&roundId={roundId}"))
- {
- Assert.True(response.IsSuccessStatusCode);
- Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
- }
+ Assert.Null(await aliceClient.PostConfirmationAsync(roundId, uniqueAliceId));
// Double the request.
- using (var response = await torClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/confirmation?uniqueId={uniqueAliceId}&roundId={roundId}"))
- {
- Assert.True(response.IsSuccessStatusCode);
- Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
- }
+ Assert.Null(await aliceClient.PostConfirmationAsync(roundId, uniqueAliceId));
// badrequests
using (var response = await torClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/confirmation"))
{
@@ -1794,11 +1782,7 @@ namespace WalletWasabi.Tests
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Null(await response.Content.ReadAsJsonAsync<string>());
}
- using (var response = await torClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/confirmation?uniqueId={uniqueAliceId}&roundId={roundId}"))
- {
- Assert.True(response.IsSuccessStatusCode);
- Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
- }
+ Assert.Null(await aliceClient.PostConfirmationAsync(roundId, uniqueAliceId));
using (var response = await torClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/confirmation?uniqueId={uniqueAliceId}&roundId={long.MaxValue}"))
{
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@@ -1826,11 +1810,7 @@ namespace WalletWasabi.Tests
Assert.True(inputsResponse.RoundId > 0);
roundId = inputsResponse.RoundId;
- using (var response = await torClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/confirmation?uniqueId={uniqueAliceId}&roundId={roundId}"))
- {
- Assert.True(response.IsSuccessStatusCode);
- Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
- }
+ Assert.Null(await aliceClient.PostConfirmationAsync(roundId, uniqueAliceId));
using (var response = await torClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/unconfirmation?uniqueId={uniqueAliceId}&roundId={roundId}"))
{
Assert.True(response.IsSuccessStatusCode);

MODIFY
WalletWasabi/WebClients/ChaumianCoinJoin/AliceClient.cs
WalletWasabi/WebClients/ChaumianCoinJoin/AliceClient.cs
@@ -26,7 +26,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
public async Task<InputsResponse> PostInputsAsync(InputsRequest request)
{
- using (var response = await TorClient.SendAsync(HttpMethod.Post, "/api/v1/btc/chaumiancoinjoin/inputs/", request.ToHttpStringContent()))
+ using (HttpResponseMessage response = await TorClient.SendAsync(HttpMethod.Post, "/api/v1/btc/chaumiancoinjoin/inputs/", request.ToHttpStringContent()))
{
if (response.StatusCode != HttpStatusCode.OK)
{
@@ -56,6 +56,54 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
return await PostInputsAsync(request);
}
+ /// <returns>null or roundHash</returns>
+ public async Task<string> PostConfirmationAsync(long roundId, Guid uniqueAliceId)
+ {
+ using (HttpResponseMessage response = await TorClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/confirmation?uniqueId={uniqueAliceId}&roundId={roundId}"))
+ {
+ if (response.StatusCode == HttpStatusCode.NoContent)
+ {
+ return null;
+ }
+ else if (response.StatusCode == HttpStatusCode.OK)
+ {
+ return await response.Content.ReadAsJsonAsync<string>();
+ }
+ else
+ {
+ string error = await response.Content.ReadAsJsonAsync<string>();
+ if (error == null)
+ {
+ throw new HttpRequestException(response.StatusCode.ToReasonString());
+ }
+ else
+ {
+ throw new HttpRequestException($"{response.StatusCode.ToReasonString()}\n{error}");
+ }
+ }
+ }
+ }
+
+ /// <returns>null or roundHash</returns>
+ public async Task PostUnConfirmationAsync(long roundId, Guid uniqueAliceId)
+ {
+ using (HttpResponseMessage response = await TorClient.SendAsync(HttpMethod.Post, $"/api/v1/btc/chaumiancoinjoin/unconfirmation?uniqueId={uniqueAliceId}&roundId={roundId}"))
+ {
+ if (!response.IsSuccessStatusCode)
+ {
+ string error = await response.Content.ReadAsJsonAsync<string>();
+ if (error == null)
+ {
+ throw new HttpRequestException(response.StatusCode.ToReasonString());
+ }
+ else
+ {
+ throw new HttpRequestException($"{response.StatusCode.ToReasonString()}\n{error}");
+ }
+ }
+ }
+ }
+
#region IDisposable Support
private volatile bool _disposedValue = false; // To detect redundant calls

Progress AliceClient