コード例 #1
0
ファイル: AliceClient.cs プロジェクト: knocte/WalletWasabi
        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;
            }
        }
コード例 #2
0
        public static async Task <AliceClient> CreateNewAsync(
            long roundId,
            IEnumerable <BitcoinAddress> registeredAddresses,
            IEnumerable <SchnorrPubKey> schnorrPubKeys,
            IEnumerable <Requester> requesters,
            Network network,
            InputsRequest request,
            Uri baseUri,
            IPEndPoint torSocks5EndPoint = null)
        {
            AliceClient client = new AliceClient(roundId, registeredAddresses, schnorrPubKeys, requesters, network, baseUri, torSocks5EndPoint);

            try
            {
                // Correct it if forgot to set.
                if (request.RoundId != roundId)
                {
                    if (request.RoundId == 0)
                    {
                        request.RoundId = roundId;
                    }
                    else
                    {
                        throw new NotSupportedException($"InputRequest roundId doesn't match to the provided roundId: {request.RoundId} != {roundId}.");
                    }
                }
                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>();

                    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 <AliceClient>($"Round ({client.RoundId}), Alice ({client.UniqueId}): Registered {request.Inputs.Count()} inputs.");

                    return(client);
                }
            }
            catch
            {
                client.Dispose();
                throw;
            }
        }