public async Task BlockCypherTestsAsync(string networkString)
        {
            var network = Network.GetNetwork(networkString);

            using (var client = new BlockCypherClient(network))
            {
                var response = await client.GetGeneralInformationAsync(CancellationToken.None);

                Assert.NotNull(response.Hash);
                Assert.NotNull(response.LastForkHash);
                Assert.NotNull(response.PreviousHash);
                Assert.True(response.UnconfirmedCount > 0);
                Assert.InRange(response.LowFee.FeePerK, Money.Zero, response.MediumFee.FeePerK);
                Assert.InRange(response.MediumFee.FeePerK, response.LowFee.FeePerK, response.HighFee.FeePerK);
                Assert.InRange(response.HighFee.FeePerK, response.MediumFee.FeePerK, new Money(0.1m, MoneyUnit.BTC));
                Assert.True(response.Height >= 491999);
                Assert.Equal(new Uri(client.BaseAddress.ToString().Replace("http", "https") + "/blocks/" + response.Hash.ToString()), response.LatestUrl);
                Assert.Equal(new Uri(client.BaseAddress.ToString().Replace("http", "https") + "/blocks/" + response.PreviousHash.ToString()), response.PreviousUrl);
                if (network == Network.Main)
                {
                    Assert.Equal("BTC.main", response.Name);
                }
                else
                {
                    Assert.Equal("BTC.test3", response.Name);
                }
                Assert.True(response.PeerCount > 0);
            }
        }
示例#2
0
        private bool _disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    // dispose managed state (managed objects).
                    BlockCypherClient?.Dispose();
                    if (DisposeTorControl)
                    {
                        try
                        {
                            TorControlPortClient?.DisconnectDisposeSocket();
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                }

                // free unmanaged resources (unmanaged objects) and override a finalizer below.
                // set large fields to null.

                _disposedValue = true;
            }
        }
示例#3
0
        public async Task StartAsync(CancellationToken ctsToken)
        {
            while (true)
            {
                try
                {
                    await Semaphore.WaitAsync(ctsToken).ConfigureAwait(false);

                    if (ctsToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (TorControlPortClient != null)
                    {
                        await TorControlPortClient.ChangeCircuitAsync(ctsToken).ConfigureAwait(false);
                    }

                    var generalInfo = await BlockCypherClient.GetGeneralInformationAsync(ctsToken).ConfigureAwait(false);

                    _lowFee    = generalInfo.LowFee;
                    _mediumFee = generalInfo.MediumFee;
                    _highFee   = generalInfo.HighFee;

                    if (ctsToken.IsCancellationRequested)
                    {
                        return;
                    }
                    _firstRun = false;
                }
                catch (OperationCanceledException)
                {
                    if (ctsToken.IsCancellationRequested)
                    {
                        return;
                    }
                    continue;
                }
                catch (Exception ex)
                {
                    if (_firstRun)
                    {
                        throw;
                    }

                    Debug.WriteLine($"Ignoring {nameof(FeeService)} exception:");
                    Debug.WriteLine(ex);
                }
                finally
                {
                    Semaphore.SafeRelease();
                }

                var waitMinutes = new Random().Next(3, 10);
                await Task.Delay(TimeSpan.FromMinutes(waitMinutes), ctsToken).ContinueWith(t => { }).ConfigureAwait(false);
            }
        }
示例#4
0
 public FeeService(Network network, DotNetTor.ControlPort.Client torControlPortClient = null, bool disposeTorControl = false, HttpMessageHandler handler = null, bool disposeHandler = false)
 {
     TorControlPortClient = torControlPortClient;
     DisposeTorControl    = disposeTorControl;
     Network = network ?? throw new ArgumentNullException(nameof(network));
     if (network == Network.Main)
     {
         BlockCypherClient = new BlockCypherClient(Network.Main, handler, disposeHandler);
     }
     else
     {
         // BlockCypher doesn't support anything else
         BlockCypherClient = new BlockCypherClient(Network.TestNet, handler, disposeHandler);
     }
 }
示例#5
0
 public FeeService(Network network, DotNetTor.ControlPort.Client torControlPortClient = null, bool disposeTorControl = false, HttpMessageHandler handler = null, bool disposeHandler = false)
 {
     TorControlPortClient = torControlPortClient;
     DisposeTorControl    = disposeTorControl;
     Network   = network ?? throw new ArgumentNullException(nameof(network));
     Semaphore = new SemaphoreSlim(1, 1); // don't make async requests, linux and mac can fail for no reason
     if (network == Network.Main)
     {
         BlockCypherClient = new BlockCypherClient(Network.Main, handler, disposeHandler);
     }
     else
     {
         // BlockCypher doesn't support anything else
         BlockCypherClient = new BlockCypherClient(Network.TestNet, handler, disposeHandler);
     }
 }
示例#6
0
        public async Task BlockCypherTestsAsync(string networkString)
        {
            if (!await TestAsync("https://api.blockcypher.com/v1/btc/main"))
            {
                return;                 // If website doesn't work, don't bother failing.
            }

            var network = Network.GetNetwork(networkString);

            using (var client = new BlockCypherClient(network))
            {
                BlockCypherGeneralInformation response = null;
                try
                {
                    response = await client.GetGeneralInformationAsync(CancellationToken.None);
                }
                catch                 // stupid CI internet conenction sometimes fails
                {
                    await Task.Delay(3000);

                    response = await client.GetGeneralInformationAsync(CancellationToken.None);
                }
                Assert.NotNull(response.Hash);
                Assert.NotNull(response.LastForkHash);
                Assert.NotNull(response.PreviousHash);
                Assert.True(response.UnconfirmedCount > 0);
                Assert.InRange(response.LowFee.FeePerK, Money.Zero, response.MediumFee.FeePerK);
                Assert.InRange(response.MediumFee.FeePerK, response.LowFee.FeePerK, response.HighFee.FeePerK);
                Assert.InRange(response.HighFee.FeePerK, response.MediumFee.FeePerK, Money.Coins(0.1m));
                Assert.True(response.Height >= 491999);
                Assert.Equal(new Uri(client.BaseAddress.ToString().Replace("http", "https") + "/blocks/" + response.Hash), response.LatestUrl);
                Assert.Equal(new Uri(client.BaseAddress.ToString().Replace("http", "https") + "/blocks/" + response.PreviousHash), response.PreviousUrl);
                if (network == Network.Main)
                {
                    Assert.Equal("BTC.main", response.Name);
                }
                else
                {
                    Assert.Equal("BTC.test3", response.Name);
                }
                Assert.True(response.PeerCount > 0);
            }
        }