Exemplo n.º 1
0
 public BitcoinDWaiter(
     RPCClient rpc,
     ExplorerConfiguration configuration,
     NBXplorerNetwork network,
     SlimChain chain,
     Repository repository,
     AddressPoolService addressPoolService,
     EventAggregator eventAggregator)
 {
     if (addressPoolService == null)
     {
         throw new ArgumentNullException(nameof(addressPoolService));
     }
     _OriginalRPC    = rpc;
     _RPCWithTimeout = rpc.Clone();
     _RPCWithTimeout.RequestTimeout = TimeSpan.FromMinutes(1.0);
     _Configuration      = configuration;
     _Network            = network;
     _Chain              = chain;
     State               = BitcoinDWaiterState.NotStarted;
     _EventAggregator    = eventAggregator;
     _ChainConfiguration = _Configuration.ChainConfigurations.First(c => c.CryptoCode == _Network.CryptoCode);
     _ExplorerPrototype  = new ExplorerBehavior(repository, chain, addressPoolService, eventAggregator)
     {
         StartHeight = _ChainConfiguration.StartHeight
     };
     RPCReadyFile = Path.Combine(configuration.SignalFilesDir, $"{network.CryptoCode.ToLowerInvariant()}_fully_synched");
 }
        public ExplorerContentBase(ExplorerConfiguration configuration, XmlNode content_node)
        {
            foreach (XmlAttribute attribute in content_node.Attributes)
            {

                if (attribute.Name == configuration.getLocalIdAttr())
                {
                    localID = attribute.Value;
                }
                else if (attribute.Name == configuration.getContentNameAttr())
                {
                    name = attribute.Value;
                }
                else if (attribute.Name == configuration.getContentShortNameAttr())
                {
                    shortName = attribute.Value;
                }
            }

            if (localID == null)
            {
                //Warning, no localid provided. Generate a UUID and use that
                localID = Guid.NewGuid().ToString();
            }
            if (name == null)
            {
                throw new ExplorerParseXMLException(
                    "Name not supplied for content tag. Node: '" + content_node.OuterXml + "'", null);
            }

            if (shortName == null)
            {
                shortName = name;
            }
        }
Exemplo n.º 3
0
 public BitcoinDWaiters(
     AddressPoolServiceAccessor addressPool,
     NBXplorerNetworkProvider networkProvider,
     ChainProvider chains,
     RepositoryProvider repositoryProvider,
     ExplorerConfiguration config,
     RPCClientProvider rpcProvider,
     EventAggregator eventAggregator)
 {
     _Waiters = networkProvider
                .GetAll()
                .Select(s => (Repository: repositoryProvider.GetRepository(s),
                              RPCClient: rpcProvider.GetRPCClient(s),
                              Chain: chains.GetChain(s),
                              Network: s))
                .Where(s => s.Repository != null && s.RPCClient != null && s.Chain != null)
                .Select(s => new BitcoinDWaiter(s.RPCClient,
                                                config,
                                                networkProvider.GetFromCryptoCode(s.Network.CryptoCode),
                                                s.Chain,
                                                s.Repository,
                                                addressPool.Instance,
                                                eventAggregator))
                .ToDictionary(s => s.Network.CryptoCode, s => s);
     this.repositoryProvider = repositoryProvider;
 }
Exemplo n.º 4
0
 public ChainProvider(ExplorerConfiguration configuration)
 {
     foreach (var net in configuration.NetworkProvider.GetAll().Where(n => configuration.Supports(n)))
     {
         _Chains.Add(net.CryptoCode, new SlimChain(net.NBitcoinNetwork.GenesisHash));
     }
 }
        public ExplorerContentsContainer(ExplorerConfiguration configuration, XmlNode contents_node)
        {
            foreach (XmlNode childNode in contents_node.ChildNodes)
            {
                ExplorerContentBase newItem;
                if (childNode.Name == configuration.getImageTag())
                {
                    newItem = new ExplorerContentImage(configuration, childNode);
                }
                else if (childNode.Name == configuration.getVideoTag())
                {
                    newItem = new ExplorerContentVideo(configuration, childNode);
                }
                else if (childNode.Name == configuration.getTextTag())
                {
                    newItem = new ExplorerContentText(configuration, childNode);
                }
                else if (childNode.Name == configuration.getMapTag())
                {
                    newItem = new ExplorerContentMap(configuration, childNode);
                }
                else
                {
                    throw new ExplorerParseXMLException("Unknown child node: " + childNode.Name, null);
                }

                contentList.Add(newItem.getLocalId(), newItem);
            }
        }
Exemplo n.º 6
0
 public BrokerHostedService(BitcoinDWaitersAccessor waiters, ChainProvider chainProvider, EventAggregator eventAggregator, IOptions <ExplorerConfiguration> config, IOptions <MvcJsonOptions> jsonOptions)
 {
     _EventAggregator    = eventAggregator;
     ChainProvider       = chainProvider;
     Waiters             = waiters.Instance;
     _config             = config.Value;
     _serializerSettings = jsonOptions.Value.SerializerSettings;
 }
Exemplo n.º 7
0
 public BrokerHostedService(BitcoinDWaiters waiters, ChainProvider chainProvider, EventAggregator eventAggregator, IOptions <ExplorerConfiguration> config, MvcNewtonsoftJsonOptions jsonOptions)
 {
     _EventAggregator    = eventAggregator;
     ChainProvider       = chainProvider;
     Waiters             = waiters;
     _config             = config.Value;
     _serializerSettings = jsonOptions.SerializerSettings;
 }
Exemplo n.º 8
0
 public BrokerHostedService(BitcoinDWaiters waiters, ChainProvider chainProvider, EventAggregator eventAggregator, IOptions <ExplorerConfiguration> config, NBXplorerNetworkProvider networks)
 {
     _EventAggregator = eventAggregator;
     Networks         = networks;
     ChainProvider    = chainProvider;
     Waiters          = waiters;
     _config          = config.Value;
 }
 public ExplorerEventsContainer(ExplorerConfiguration configuration, XmlNode events_node)
 {
     foreach (XmlNode childNode in events_node.ChildNodes)
     {
         if (childNode.Name == configuration.getEventTag())
         {
             eventList.Add(new ExplorerEvent(configuration, childNode));
         }
     }
 }
 public ExplorerPointsContainer(ExplorerConfiguration configuration, XmlNode regions_node)
 {
     foreach (XmlNode childNode in regions_node.ChildNodes)
     {
         if (childNode.Name == configuration.getPointTag())
         {
             pointsList.Add(new ExplorerPoint(childNode));
         }
     }
 }
 public ExplorerRegionsContainer(ExplorerConfiguration configuration, ExplorerContentMap parent_map, XmlNode regions_node)
 {
     parentMap = parent_map;
     foreach (XmlNode childNode in regions_node.ChildNodes)
     {
         if (childNode.Name == configuration.getRegionTag())
         {
             regionList.Add(new ExplorerRegion(configuration, childNode));
         }
     }
 }
Exemplo n.º 12
0
 public RPCClientProvider(ExplorerConfiguration configuration)
 {
     foreach (var config in configuration.ChainConfigurations)
     {
         var rpc = config?.RPC;
         if (rpc != null)
         {
             _ChainConfigurations.Add(config.CryptoCode, rpc);
         }
     }
 }
Exemplo n.º 13
0
 public RPCClientProvider(ExplorerConfiguration configuration, IHttpClientFactory httpClientFactory)
 {
     foreach (var config in configuration.ChainConfigurations)
     {
         var rpc = config?.RPC;
         if (rpc != null)
         {
             rpc.HttpClient = httpClientFactory.CreateClient();
             _ChainConfigurations.Add(config.CryptoCode, rpc);
         }
     }
 }
 public RebroadcasterHostedService(
     NBXplorerNetworkProvider networkProvider,
     ExplorerConfiguration configuration,
     RepositoryProvider repositories, BitcoinDWaiters waiters, EventAggregator eventAggregator)
 {
     _Repositories   = repositories;
     _Waiters        = waiters;
     EventAggregator = eventAggregator;
     _BroadcastedTransactionsByCryptoCode = configuration.ChainConfigurations
                                            .Select(r => new RebroadcastedTransactions()
     {
         Network = networkProvider.GetFromCryptoCode(r.CryptoCode)
     }).ToDictionary(t => t.Network);
 }
 public ExplorerContentMediaBase(ExplorerConfiguration configuration, XmlNode content_node)
     : base(configuration, content_node)
 {
     foreach (XmlAttribute attribute in content_node.Attributes)
     {
         if (attribute.Name == configuration.getMediaPathAttr())
         {
             mediaPath = attribute.Value;
         }
     }
     if (mediaPath == null)
     {
         throw new ExplorerParseXMLException("Path not supplied for media tag '" + getName() + "'", null);
     }
 }
Exemplo n.º 16
0
 public NBxplorerInitializer(
     RPCClient rpc,
     ExplorerConfiguration configuration,
     ConcurrentChain chain,
     Repository repository,
     CallbackInvoker invoker,
     ChainEvents events)
 {
     _RPC           = rpc;
     _Configuration = configuration;
     _Network       = _Configuration.Network;
     _Events        = events;
     _Chain         = chain;
     _Repository    = repository;
     _Invoker       = invoker;
 }
Exemplo n.º 17
0
 public BitcoinDWaiter(
     RPCClient rpc,
     ExplorerConfiguration configuration,
     NBXplorerNetwork network,
     ConcurrentChain chain,
     Repository repository,
     EventAggregator eventAggregator)
 {
     _RPC             = rpc;
     _Configuration   = configuration;
     _Network         = network;
     _Chain           = chain;
     _Repository      = repository;
     State            = BitcoinDWaiterState.NotStarted;
     _EventAggregator = eventAggregator;
 }
Exemplo n.º 18
0
 public BitcoinDWaiters(
     AddressPoolService addressPool,
     NBXplorerNetworkProvider networkProvider,
     ChainProvider chains,
     RepositoryProvider repositoryProvider,
     ExplorerConfiguration config,
     RPCClientProvider rpcProvider,
     EventAggregator eventAggregator)
 {
     this.addressPool        = addressPool;
     this.networkProvider    = networkProvider;
     this.chains             = chains;
     this.repositoryProvider = repositoryProvider;
     this.config             = config;
     this.rpcProvider        = rpcProvider;
     this.eventAggregator    = eventAggregator;
 }
Exemplo n.º 19
0
 public MainController(
     ExplorerConfiguration explorerConfiguration,
     RepositoryProvider repositoryProvider,
     ChainProvider chainProvider,
     EventAggregator eventAggregator,
     BitcoinDWaitersAccessor waiters,
     AddressPoolServiceAccessor addressPoolService,
     ScanUTXOSetServiceAccessor scanUTXOSetService,
     IOptions <MvcJsonOptions> jsonOptions)
 {
     ExplorerConfiguration = explorerConfiguration;
     RepositoryProvider    = repositoryProvider;
     ChainProvider         = chainProvider;
     _SerializerSettings   = jsonOptions.Value.SerializerSettings;
     _EventAggregator      = eventAggregator;
     ScanUTXOSetService    = scanUTXOSetService.Instance;
     Waiters            = waiters.Instance;
     AddressPoolService = addressPoolService.Instance;
 }
 public ExplorerContentMap(ExplorerConfiguration configuration, XmlNode map_node)
     : base(configuration, map_node)
 {
     foreach (XmlNode childNode in map_node.ChildNodes)
     {
         if (childNode.Name == configuration.getEventsTag())
         {
             eventsContainer = new ExplorerEventsContainer(configuration, childNode);
         }
         else if (childNode.Name == configuration.getContentsTag())
         {
             contentsContainer = new ExplorerContentsContainer(configuration, childNode);
         }
         else if (childNode.Name == configuration.getRegionsTag())
         {
             regionsContainer = new ExplorerRegionsContainer(configuration, this, childNode);
         }
     }
 }
Exemplo n.º 21
0
        public void Configure(IApplicationBuilder app, IServiceProvider prov,
                              ExplorerConfiguration explorerConfiguration,
                              IWebHostEnvironment env,
                              ILoggerFactory loggerFactory, IServiceProvider serviceProvider,
                              CookieRepository cookieRepository)
        {
            cookieRepository.Initialize();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            Logs.Configure(loggerFactory);
            if (!string.IsNullOrEmpty(explorerConfiguration.InstanceName))
            {
                app.Use(async(httpContext, next) =>
                {
                    httpContext.Response.Headers.Add("instance-name", explorerConfiguration.InstanceName);
                    await next();
                });
            }
#if !NETCOREAPP21
            app.UseRouting();
#endif
            app.UseAuthentication();
#if !NETCOREAPP21
            app.UseAuthorization();
#endif
            app.UseWebSockets();
            //app.UseMiddleware<LogAllRequestsMiddleware>();
#if NETCOREAPP21
            app.UseMvc();
#else
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHealthChecks("health", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions()
                {
                    ResponseWriter = HealthChecks.HealthCheckWriters.WriteJSON
                });
                endpoints.MapControllers();
            });
#endif
        }
Exemplo n.º 22
0
        public RepositoryProvider(NBXplorerNetworkProvider networks, KeyPathTemplates keyPathTemplates, ExplorerConfiguration configuration)
        {
            this.keyPathTemplates = keyPathTemplates;
            _Configuration        = configuration;
            var directory = Path.Combine(configuration.DataDir, "db");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            int tried = 0;

retry:
            try
            {
                _Engine = new DBriizeEngine(new DBriizeConfiguration()
                {
                    DBriizeDataFolderName = directory
                });
            }
            catch when(tried < 10)
            {
                tried++;
                Thread.Sleep(tried * 500);
                goto retry;
            }
            foreach (var net in networks.GetAll())
            {
                var settings = GetChainSetting(net);
                if (settings != null)
                {
                    var repo = net.NBitcoinNetwork.NetworkSet == Liquid.Instance ? new LiquidRepository(_Engine, net, keyPathTemplates, settings.RPC) : new Repository(_Engine, net, keyPathTemplates, settings.RPC);
                    repo.MaxPoolSize  = configuration.MaxGapSize;
                    repo.MinPoolSize  = configuration.MinGapSize;
                    repo.MinUtxoValue = settings.MinUtxoValue;
                    _Repositories.Add(net.CryptoCode, repo);
                }
            }
        }
Exemplo n.º 23
0
 public MainController(
     ExplorerConfiguration explorerConfiguration,
     RepositoryProvider repositoryProvider,
     ChainProvider chainProvider,
     EventAggregator eventAggregator,
     BitcoinDWaiters waiters,
     AddressPoolServiceAccessor addressPoolService,
     ScanUTXOSetServiceAccessor scanUTXOSetService,
     RebroadcasterHostedService rebroadcaster,
     KeyPathTemplates keyPathTemplates,
     IOptions <MvcJsonOptions> jsonOptions)
 {
     ExplorerConfiguration = explorerConfiguration;
     RepositoryProvider    = repositoryProvider;
     ChainProvider         = chainProvider;
     _SerializerSettings   = jsonOptions.Value.SerializerSettings;
     _EventAggregator      = eventAggregator;
     ScanUTXOSetService    = scanUTXOSetService.Instance;
     Waiters               = waiters;
     Rebroadcaster         = rebroadcaster;
     this.keyPathTemplates = keyPathTemplates;
     AddressPoolService    = addressPoolService.Instance;
 }
Exemplo n.º 24
0
 public BitcoinDWaiter(
     RPCClient rpc,
     ExplorerConfiguration configuration,
     NBXplorerNetwork network,
     SlimChain chain,
     Repository repository,
     AddressPoolService addressPoolService,
     EventAggregator eventAggregator)
 {
     if (addressPoolService == null)
     {
         throw new ArgumentNullException(nameof(addressPoolService));
     }
     _RPC                = rpc;
     _Configuration      = configuration;
     _AddressPoolService = addressPoolService;
     _Network            = network;
     _Chain              = chain;
     _Repository         = repository;
     State               = BitcoinDWaiterState.NotStarted;
     _EventAggregator    = eventAggregator;
     _ChainConfiguration = _Configuration.ChainConfigurations.First(c => c.CryptoCode == _Network.CryptoCode);
 }
Exemplo n.º 25
0
        public static void Main(string[] args)
        {
            Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, (a, b) => true, false)));
            IWebHost host = null;

            try
            {
                var conf = new ExplorerConfiguration();
                conf.LoadArgs(args);
                using (var runtime = conf.CreateRuntime())
                {
                    runtime.StartNodeListener(conf.StartHeight);
                    host = runtime.CreateWebHost();
                    host.Run();
                }
            }
            catch (ConfigException ex)
            {
                if (!string.IsNullOrEmpty(ex.Message))
                {
                    Logs.Configuration.LogError(ex.Message);
                }
            }
            catch (Exception exception)
            {
                Logs.Explorer.LogError("Exception thrown while running the server");
                Logs.Explorer.LogError(exception.ToString());
            }
            finally
            {
                if (host != null)
                {
                    host.Dispose();
                }
            }
        }
Exemplo n.º 26
0
 public BitcoinDWaiter(
     RPCClient rpc,
     ExplorerConfiguration configuration,
     NBXplorerNetwork network,
     SlimChain chain,
     Repository repository,
     AddressPoolService addressPoolService,
     EventAggregator eventAggregator)
 {
     if (addressPoolService == null)
     {
         throw new ArgumentNullException(nameof(addressPoolService));
     }
     _RPC                = rpc;
     _Configuration      = configuration;
     _AddressPoolService = addressPoolService;
     _Network            = network;
     _Chain              = chain;
     _Repository         = repository;
     State               = BitcoinDWaiterState.NotStarted;
     _EventAggregator    = eventAggregator;
     _ChainConfiguration = _Configuration.ChainConfigurations.First(c => c.CryptoCode == _Network.CryptoCode);
     RPCReadyFile        = Path.Combine(configuration.DataDir, $"{network.CryptoCode.ToLowerInvariant()}_fully_synched");
 }
 public ExplorerContentVideo(ExplorerConfiguration configuration, XmlNode video_node)
     : base(configuration, video_node)
 {
     mediaElement = new MediaElement();
     mediaElement.Source = getPathUri();
 }
Exemplo n.º 28
0
 public CookieRepository(ExplorerConfiguration config)
 {
     _Config = config;
 }
Exemplo n.º 29
0
        public ExplorerRuntime(ExplorerConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            Network      = configuration.Network;
            Chain        = new ConcurrentChain(Network.GetGenesis().Header);
            RPC          = configuration.RPC.ConfigureRPCClient(configuration.Network);
            NodeEndpoint = configuration.NodeEndpoint;
            ServerUrls   = configuration.GetUrls();

            var cachePath = Path.Combine(configuration.DataDir, "chain.dat");

            if (configuration.CacheChain)
            {
                Logs.Configuration.LogInformation($"Loading chain from cache...");
                if (File.Exists(cachePath))
                {
                    Chain.Load(File.ReadAllBytes(cachePath));
                }
            }

            Logs.Configuration.LogInformation($"Loading chain from node...");
            var heightBefore = Chain.Height;

            try
            {
                if (!configuration.RPC.NoTest)
                {
                    Logs.Configuration.LogInformation("Trying to connect to node: " + configuration.NodeEndpoint);
                    using (var node = Node.Connect(Network, configuration.NodeEndpoint))
                    {
                        var cts = new CancellationTokenSource();
                        cts.CancelAfter(5000);
                        node.VersionHandshake(cts.Token);
                        node.SynchronizeChain(Chain);
                    }
                    Logs.Configuration.LogInformation("Node connection successfull");
                }
            }
            catch (Exception ex)
            {
                Logs.Configuration.LogError("Error while connecting to node: " + ex.Message);
                throw new ConfigException();
            }

            Logs.Configuration.LogInformation($"Chain loaded from node");

            if (configuration.CacheChain && heightBefore != Chain.Height)
            {
                Logs.Configuration.LogInformation($"Saving chain to cache...");
                var ms = new MemoryStream();
                Chain.WriteTo(ms);
                File.WriteAllBytes(cachePath, ms.ToArray());
            }

            var dbPath = Path.Combine(configuration.DataDir, "db");

            Repository = new Repository(dbPath, true);
            if (configuration.Rescan)
            {
                Logs.Configuration.LogInformation("Rescanning...");
                Repository.SetIndexProgress(null);
            }
        }
Exemplo n.º 30
0
 public ConfigureCookieFileBasedConfiguration(ExplorerConfiguration configuration)
 {
     _Configuration = configuration;
 }
Exemplo n.º 31
0
        public ServerTester(string directory)
        {
            try
            {
                var rootTestData = "TestData";
                var cachedNodes  = "TestData/CachedNodes";
                directory  = rootTestData + "/" + directory;
                _Directory = directory;
                if (!Directory.Exists(rootTestData))
                {
                    Directory.CreateDirectory(rootTestData);
                }
                if (!Directory.Exists(cachedNodes))
                {
                    Directory.CreateDirectory(cachedNodes);
                    RunScenario(cachedNodes);
                }

                if (!TryDelete(directory, false))
                {
                    foreach (var process in Process.GetProcessesByName("elementd"))
                    {
                        if (process.MainModule.FileName.Replace("\\", "/").StartsWith(Path.GetFullPath(rootTestData).Replace("\\", "/"), StringComparison.Ordinal))
                        {
                            process.Kill();
                            process.WaitForExit();
                        }
                    }
                    TryDelete(directory, true);
                }

                NodeBuilder = NodeBuilder.Create(directory);
                NodeBuilder.CleanBeforeStartingNode = false;
                Copy(cachedNodes, directory);


                User1    = NodeBuilder.CreateNode();
                User2    = NodeBuilder.CreateNode();
                Explorer = NodeBuilder.CreateNode();
                NodeBuilder.StartAll();

                var creds = ExtractCredentials(File.ReadAllText(Explorer.Config));
                var conf  = new ExplorerConfiguration();
                conf.DataDir = Path.Combine(directory, "explorer");
                conf.Network = Network.RegTest;
                conf.RPC     = new RPCArgs()
                {
                    User     = creds.Item1,
                    Password = creds.Item2,
                    Url      = Explorer.CreateRPCClient().Address,
                    NoTest   = true
                };
                conf.NodeEndpoint = Explorer.Endpoint;
                conf.Network      = ExplorerConfiguration.CreateNetwork(conf.Network, Explorer.CreateRPCClient().GetBlock(0));

                Runtime = conf.CreateRuntime();

                Runtime.Repository.SetIndexProgress(new BlockLocator()
                {
                    Blocks = { Runtime.RPC.GetBestBlockHash() }
                });

                Runtime.StartNodeListener(conf.StartHeight);
                Host = Runtime.CreateWebHost();
                Host.Start();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
 public ExplorerContentText(ExplorerConfiguration configuration, XmlNode text_node)
     : base(configuration, text_node)
 {
     textContent = text_node.InnerText;
 }
 public ExplorerContentImage(ExplorerConfiguration configuration, XmlNode image_node)
     : base(configuration, image_node)
 {
     bitmapImage = new BitmapImage(getPathUri());
 }