public static QBitNinjaConfiguration FromConfiguration(IConfiguration configuration)
        {
            // Make sure the networks are registered
            NBitcoin.Altcoins.AltNetworkSets.GetAll().Select(c => c.Regtest).ToList();
            var conf = new QBitNinjaConfiguration
            {
                Indexer             = IndexerConfiguration.FromConfiguration(configuration),
                LocalChain          = configuration["LocalChain"],
                ServiceBus          = configuration["ServiceBus"],
                RPCConnectionString = configuration["RPCConnectionString"],
            };
            var nocache       = configuration["NoLocalChain"] == "true";
            var qbitDirectory = QBitNinja.DefaultDataDirectory.GetDirectory("qbitninja", conf.Indexer.Network.ToString());

            if (string.IsNullOrEmpty(conf.LocalChain))
            {
                conf.LocalChain = Path.Combine(qbitDirectory, "LocalChain.dat");
            }
            if (nocache)
            {
                conf.LocalChain = null;
            }
            conf.CoinbaseMaturity = conf.Indexer.Network.Consensus.CoinbaseMaturity;
            return(conf);
        }
Exemplo n.º 2
0
        public QBitTopics(QBitNinjaConfiguration configuration)
        {
            _BroadcastedTransactions = new QBitNinjaTopic <BroadcastedTransaction>(configuration.ServiceBus, new TopicCreation(configuration.Indexer.GetTable("broadcastedtransactions").Name)
            {
                EnableExpress = true
            }, new SubscriptionCreation()
            {
                AutoDeleteOnIdle = TimeSpan.FromHours(24.0)
            });

            _AddedAddresses = new QBitNinjaTopic <WalletAddress[]>(configuration.ServiceBus, new TopicCreation(configuration.Indexer.GetTable("walletrules").Name)
            {
                EnableExpress            = true,
                DefaultMessageTimeToLive = TimeSpan.FromMinutes(5.0)
            }, new SubscriptionCreation()
            {
                AutoDeleteOnIdle = TimeSpan.FromHours(24.0)
            });

            _NewBlocks = new QBitNinjaTopic <BlockHeader>(configuration.ServiceBus, new TopicCreation(configuration.Indexer.GetTable("newblocks").Name)
            {
                DefaultMessageTimeToLive = TimeSpan.FromMinutes(5.0),
                EnableExpress            = true
            }, new SubscriptionCreation()
            {
                AutoDeleteOnIdle = TimeSpan.FromHours(24.0)
            });

            _NewTransactions = new QBitNinjaTopic <Transaction>(configuration.ServiceBus, new TopicCreation(configuration.Indexer.GetTable("newtransactions").Name)
            {
                DefaultMessageTimeToLive = TimeSpan.FromMinutes(5.0),
            }, new SubscriptionCreation()
            {
                AutoDeleteOnIdle = TimeSpan.FromHours(24.0),
            });

            _SubscriptionChanges = new QBitNinjaTopic <SubscriptionChange>(configuration.ServiceBus, new TopicCreation(configuration.Indexer.GetTable("subscriptionchanges").Name)
            {
                DefaultMessageTimeToLive = TimeSpan.FromMinutes(5.0),
                EnableExpress            = true
            });

            _SendNotifications = new QBitNinjaQueue <Notify>(configuration.ServiceBus, new QueueCreation(configuration.Indexer.GetTable("sendnotifications").Name)
            {
                RequiresDuplicateDetection          = true,
                DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(10.0),
            });
            _SendNotifications.GetMessageId = (n) => Hashes.Hash256(Encoding.UTF32.GetBytes(n.Notification.ToString())).ToString();


            _InitialIndexing = new QBitNinjaQueue <BlockRange>(configuration.ServiceBus, new QueueCreation(configuration.Indexer.GetTable("intitialindexing").Name)
            {
                RequiresDuplicateDetection          = true,
                DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(10.0),
                MaxDeliveryCount = int.MaxValue,
                LockDuration     = TimeSpan.FromMinutes(5.0)
            });
            _InitialIndexing.GetMessageId = (n) => n.ToString();
        }
Exemplo n.º 3
0
        public static QBitNinjaConfiguration FromConfiguration()
        {
            var conf = new QBitNinjaConfiguration
            {
                Indexer    = IndexerConfiguration.FromConfiguration(),
                LocalChain = ConfigurationManager.AppSettings["LocalChain"],
                ServiceBus = ConfigurationManager.AppSettings["ServiceBus"]
            };

            return(conf);
        }
Exemplo n.º 4
0
 public InitialIndexer(QBitNinjaConfiguration conf)
 {
     if (conf == null)
     {
         throw new ArgumentNullException("conf");
     }
     _Conf               = conf;
     BlockGranularity    = 100;
     TransactionsPerWork = 1000 * 1000;
     Init();
 }
        public static QBitNinjaConfiguration FromConfiguration()
        {
            var conf = new QBitNinjaConfiguration
            {
                Indexer    = IndexerConfiguration.FromConfiguration(new ConfigurationManagerConfiguration()),
                LocalChain = ConfigurationManager.AppSettings["LocalChain"],
                ServiceBus = ConfigurationManager.AppSettings["ServiceBus"]
            };

            conf.CoinbaseMaturity = conf.Indexer.Network.Consensus.CoinbaseMaturity;
            return(conf);
        }
Exemplo n.º 6
0
 public static void Register(HttpConfiguration config, QBitNinjaConfiguration QBitNinja)
 {
     SetThrottling();
     if (QBitNinja == null)
     {
         QBitNinja = QBitNinjaConfiguration.FromConfiguration();
     }
     QBitNinja.EnsureSetup();
     config.MapHttpAttributeRoutes();
     config.Formatters.Clear();
     config.Formatters.Add(new CustomJsonMediaTypeFormatter()
     {
         Indent = true,
     });
     config.DependencyResolver = new QBitNinjaDependencyResolver(QBitNinja, config.DependencyResolver);
     config.Filters.Add(new GlobalExceptionFilter());
     config.Services.Replace(typeof(IBodyModelValidator), new NoBodyModelProvider());
     Serializer.RegisterFrontConverters(config.Formatters.JsonFormatter.SerializerSettings, QBitNinja.Indexer.Network);
 }
Exemplo n.º 7
0
        public QBitNinjaDependencyResolver(QBitNinjaConfiguration configuration, IDependencyResolver defaultResolver)
        {
            _defaultResolver = defaultResolver;
            ContainerBuilder       builder     = new ContainerBuilder();
            ChainSynchronizeStatus chainStatus = new ChainSynchronizeStatus();

            builder.Register(ctx => chainStatus).SingleInstance();
            builder.Register(ctx => configuration).SingleInstance();
            builder.Register(ctx => configuration.Indexer.CreateIndexerClient());
            builder.Register(ctx =>
            {
                var client            = ctx.Resolve <IndexerClient>();
                ConcurrentChain chain = new ConcurrentChain(configuration.Indexer.Network);
                _ = LoadChain(configuration, client, chain, chainStatus);
                return(chain);
            }).SingleInstance();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            _container = builder.Build();
        }
Exemplo n.º 8
0
        public QBitNinjaDependencyResolver(QBitNinjaConfiguration configuration, IDependencyResolver defaultResolver)
        {
            _defaultResolver = defaultResolver;
            ContainerBuilder builder = new ContainerBuilder();

            builder.Register(ctx => configuration).SingleInstance();
            builder.Register(ctx => configuration.Indexer.CreateIndexerClient());
            builder.Register(ctx =>
            {
                var client            = ctx.Resolve <IndexerClient>();
                ConcurrentChain chain = new ConcurrentChain(configuration.Indexer.Network);
                LoadCache(chain, configuration.LocalChain);
                var changes = client.GetChainChangesUntilFork(chain.Tip, false);
                try
                {
                    changes.UpdateChain(chain);
                }
                catch (ArgumentException) //Happen when chain in table is corrupted
                {
                    client.Configuration.GetChainTable().DeleteIfExists();
                    for (int i = 0; i < 20; i++)
                    {
                        try
                        {
                            if (client.Configuration.GetChainTable().CreateIfNotExists())
                            {
                                break;
                            }
                        }
                        catch
                        {
                        }
                        Thread.Sleep(10000);
                    }
                    client.Configuration.CreateIndexer().IndexChain(chain);
                }
                SaveChainCache(chain, configuration.LocalChain);
                return(chain);
            }).SingleInstance();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            _container = builder.Build();
        }
Exemplo n.º 9
0
        public QBitNinjaDependencyResolver(QBitNinjaConfiguration configuration, IDependencyResolver defaultResolver)
        {
            _defaultResolver = defaultResolver;
            ContainerBuilder builder = new ContainerBuilder();

            builder.Register(ctx => configuration).SingleInstance();
            builder.Register(ctx => configuration.Indexer.CreateIndexerClient());
            builder.Register(ctx =>
            {
                var client            = ctx.Resolve <IndexerClient>();
                ConcurrentChain chain = new ConcurrentChain(configuration.Indexer.Network);
                LoadCache(chain, configuration.LocalChain);
                var changes = client.GetChainChangesUntilFork(chain.Tip, false);
                changes.UpdateChain(chain);
                SaveChainCache(chain, configuration.LocalChain);
                return(chain);
            }).SingleInstance();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            _container = builder.Build();
        }
Exemplo n.º 10
0
        public static QBitNinjaConfiguration FromConfiguration()
        {
            var conf = new QBitNinjaConfiguration
            {
                Indexer    = IndexerConfiguration.FromConfiguration(new ConfigurationManagerConfiguration()),
                LocalChain = ConfigurationManager.AppSettings["LocalChain"],
                ServiceBus = ConfigurationManager.AppSettings["ServiceBus"]
            };
            var nocache       = ConfigurationManager.AppSettings["NoLocalChain"] == "true";
            var qbitDirectory = QBitNinja.DefaultDataDirectory.GetDirectory("qbitninja", conf.Indexer.Network.ToString());

            if (string.IsNullOrEmpty(conf.LocalChain))
            {
                conf.LocalChain = Path.Combine(qbitDirectory, "LocalChain.dat");
            }
            if (nocache)
            {
                conf.LocalChain = null;
            }
            conf.CoinbaseMaturity = conf.Indexer.Network.Consensus.CoinbaseMaturity;
            return(conf);
        }
Exemplo n.º 11
0
        private async Task LoadChain(QBitNinjaConfiguration configuration, IndexerClient client, ConcurrentChain chain, ChainSynchronizeStatus status)
        {
            await Task.Delay(1).ConfigureAwait(false);

            LoadCache(chain, configuration.LocalChain, configuration.Indexer.Network);
            status.FileCachedHeight = chain.Height;
            var changes = client.GetChainChangesUntilFork(chain.Tip, false);

            try
            {
                await changes.UpdateChain(chain, _Cts.Token);
            }
            catch (ArgumentException) //Happen when chain in table is corrupted
            {
                client.Configuration.GetChainTable().DeleteIfExists();
                for (int i = 0; i < 20; i++)
                {
                    try
                    {
                        if (client.Configuration.GetChainTable().CreateIfNotExists())
                        {
                            break;
                        }
                    }
                    catch
                    {
                    }
                    await Task.Delay(10000);
                }
                status.ReindexHeaders = true;
                await client.Configuration.CreateIndexer().IndexChain(chain, _Cts.Token);
            }
            status.TableFetchedHeight = chain.Height;
            SaveChainCache(chain, configuration.LocalChain);
            status.Synchronizing = false;
            Interlocked.Decrement(ref _UpdateChain);
        }
Exemplo n.º 12
0
 public BlockEventManager(QBitNinjaConfiguration conf)
 {
     Configuration = conf;
     Timeout       = TimeSpan.FromMinutes(1);
 }
Exemplo n.º 13
0
 public static void Register(HttpConfiguration config, QBitNinjaConfiguration QBitNinja)
 {
     Register(config, QBitNinja, true);
 }
Exemplo n.º 14
0
 public QBitNinjaListener(QBitNinjaConfiguration configuration)
 {
     _Configuration = configuration;
 }