<commit_before>﻿using HiddenWallet.WebClients.SmartBit.Models;
using NBitcoin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Nito.AsyncEx;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace HiddenWallet.WebClients.SmartBit
{
    public class SmartBitClient : IDisposable
	{
		public Network Network { get; }
		private HttpClient HttpClient { get; }
		public Uri BaseAddress => HttpClient.BaseAddress;
		private readonly AsyncLock _asyncLock = new AsyncLock();

		public SmartBitClient(Network network, HttpMessageHandler handler = null, bool disposeHandler = false)
		{
			Network = network ?? throw new ArgumentNullException(nameof(network));
			if (handler != null)
			{
				HttpClient = new HttpClient(handler, disposeHandler);
			}
			HttpClient = new HttpClient();
			if (network == Network.Main)
			{
				HttpClient.BaseAddress = new Uri("https://api.smartbit.com.au/v1/");
			}
			else if (network == Network.TestNet)
			{
				HttpClient.BaseAddress = new Uri("https://testnet-api.smartbit.com.au/v1/");
			}
			else throw new NotSupportedException($"{network} is not supported");
		}

		public async Task PushTransactionAsync(Transaction transaction, CancellationToken cancel)
		{
			using (await _asyncLock.LockAsync(cancel))
			{
				var content = new StringContent(
					new JObject(new JProperty("hex", transaction.ToHex())).ToString(),
					Encoding.UTF8,
					"application/json");

				HttpResponseMessage response =
						await HttpClient.PostAsync("blockchain/pushtx", content, cancel);

				if (!response.IsSuccessStatusCode) throw new HttpRequestException(response.StatusCode.ToString());
				string responseString = await response.Content.ReadAsStringAsync();
				AssertSuccess(responseString);
			}
		}<commit_msg>fix: smartbit didn't go over tor<commit_after>﻿using HiddenWallet.WebClients.SmartBit.Models;
using NBitcoin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Nito.AsyncEx;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace HiddenWallet.WebClients.SmartBit
{
    public class SmartBitClient : IDisposable
	{
		public Network Network { get; }
		private HttpClient HttpClient { get; }
		public Uri BaseAddress => HttpClient.BaseAddress;
		private readonly AsyncLock _asyncLock = new AsyncLock();

		public SmartBitClient(Network network, HttpMessageHandler handler = null, bool disposeHandler = false)
		{
			Network = network ?? throw new ArgumentNullException(nameof(network));
			if (handler != null)
			{
				HttpClient = new HttpClient(handler, disposeHandler);
			}
			else
			{
				HttpClient = new HttpClient();
			}
			if (network == Network.Main)
			{
				HttpClient.BaseAddress = new Uri("https://api.smartbit.com.au/v1/");
			}
			else if (network == Network.TestNet)
			{
				HttpClient.BaseAddress = new Uri("https://testnet-api.smartbit.com.au/v1/");
			}
			else throw new NotSupportedException($"{network} is not supported");
		}

		public async Task PushTransactionAsync(Transaction transaction, CancellationToken cancel)
		{
			using (await _asyncLock.LockAsync(cancel))
			{
				var content = new StringContent(
					new JObject(new JProperty("hex", transaction.ToHex())).ToString(),
					Encoding.UTF8,
					"application/json");

				HttpResponseMessage response =
						await HttpClient.PostAsync("blockchain/pushtx", content, cancel);

				if (!response.IsSuccessStatusCode) throw new HttpRequestException(response.StatusCode.ToString());
				string responseString = await response.Content.ReadAsStringAsync();
				AssertSuccess(responseString);
			}
		}
{'fraction_non_alphanumeric': 0.10706638115631692, 'fraction_numerical': 0.0016059957173447537, 'mean_word_length': 4.392496392496392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '669763', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1068, 'n_words': 258}