public static async Task <AliceClient> CreateNewAsync(long roundId, IEnumerable <BitcoinAddress> registeredAddresses, IEnumerable <SchnorrPubKey> schnorrPubKeys, IEnumerable <Requester> requesters, Network network, InputsRequest request, Func <Uri> baseUriAction, EndPoint torSocks5EndPoint) { AliceClient client = new AliceClient(roundId, registeredAddresses, schnorrPubKeys, requesters, network, baseUriAction, torSocks5EndPoint); try { // Correct it if forgot to set. if (request.RoundId != roundId) { if (request.RoundId == 0) { request.RoundId = roundId; } else { throw new NotSupportedException($"InputRequest {nameof(roundId)} does not match to the provided {nameof(roundId)}: {request.RoundId} != {roundId}."); } } using HttpResponseMessage response = await client.TorClient.SendAsync(HttpMethod.Post, $"/api/v{Helpers.Constants.BackendMajorVersion}/btc/chaumiancoinjoin/inputs/", request.ToHttpStringContent()).ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.OK) { await response.ThrowRequestExceptionFromContentAsync().ConfigureAwait(false); } var inputsResponse = await response.Content.ReadAsJsonAsync <InputsResponse>().ConfigureAwait(false); if (inputsResponse.RoundId != roundId) // This should never happen. If it does, that's a bug in the coordinator. { throw new NotSupportedException($"Coordinator assigned us to the wrong round: {inputsResponse.RoundId}. Requested round: {roundId}."); } client.UniqueId = inputsResponse.UniqueId; Logger.LogInfo($"Round ({client.RoundId}), Alice ({client.UniqueId}): Registered {request.Inputs.Count()} inputs."); return(client); } catch { client?.Dispose(); throw; } }
public async Task <InputsResponse> PostInputsAsync(InputsRequest request) { using (HttpResponseMessage response = await TorClient.SendAsync(HttpMethod.Post, "/api/v1/btc/chaumiancoinjoin/inputs/", request.ToHttpStringContent())) { if (response.StatusCode != HttpStatusCode.OK) { 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}"); } } return(await response.Content.ReadAsJsonAsync <InputsResponse>()); } }
public static async Task <AliceClient> CreateNewAsync(Network network, InputsRequest request, Uri baseUri, IPEndPoint torSocks5EndPoint = null) { AliceClient client = new AliceClient(network, baseUri, torSocks5EndPoint); try { using (HttpResponseMessage response = await client.TorClient.SendAsync(HttpMethod.Post, $"/api/v{Helpers.Constants.BackendMajorVersion}/btc/chaumiancoinjoin/inputs/", request.ToHttpStringContent())) { if (response.StatusCode != HttpStatusCode.OK) { await response.ThrowRequestExceptionFromContentAsync(); } var inputsResponse = await response.Content.ReadAsJsonAsync <InputsResponse>(); client.RoundId = inputsResponse.RoundId; client.UniqueId = inputsResponse.UniqueId; client.BlindedOutputSignature = inputsResponse.BlindedOutputSignature; Logger.LogInfo <AliceClient>($"Round ({client.RoundId}), Alice ({client.UniqueId}): Registered {request.Inputs.Count()} inputs."); return(client); } } catch { client.Dispose(); throw; } }
public static async Task <AliceClient> CreateNewAsync(InputsRequest request, Uri baseUri, IPEndPoint torSocks5EndPoint = null) { AliceClient client = new AliceClient(baseUri, torSocks5EndPoint); try { using (HttpResponseMessage response = await client.TorClient.SendAsync(HttpMethod.Post, "/api/v1/btc/chaumiancoinjoin/inputs/", request.ToHttpStringContent())) { if (response.StatusCode != HttpStatusCode.OK) { string error = await response.Content.ReadAsJsonAsync <string>(); var errorMessage = error == null ? string.Empty : $"\n{error}"; throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}"); } var inputsResponse = await response.Content.ReadAsJsonAsync <InputsResponse>(); client.RoundId = inputsResponse.RoundId; client.UniqueId = inputsResponse.UniqueId; client.BlindedOutputSignature = inputsResponse.BlindedOutputSignature; Logger.LogInfo <AliceClient>($"Round ({client.RoundId}), Alice ({client.UniqueId}): Registered {request.Inputs.Count()} inputs."); return(client); } } catch { client.Dispose(); throw; } }