Example #1
0
        public void CanHaveAllServicesTest()
        {
            var nodeSettings = NodeSettings.Default();

            nodeSettings.DataDir = "Stratis.Bitcoin.Tests/TestData/FullNodeBuilderTest/CanHaveAllServicesTest";
            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseConsensus()
                                        .UseBlockStore()
                                        .UseMempool()
                                        .AddRPC()
                                        .Build();

            IServiceProvider serviceProvider = fullNode.Services.ServiceProvider;
            var network           = serviceProvider.GetService <Network>();
            var settings          = serviceProvider.GetService <NodeSettings>();
            var consensusLoop     = serviceProvider.GetService <ConsensusLoop>();
            var consensus         = serviceProvider.GetService <PowConsensusValidator>();
            var chain             = serviceProvider.GetService <NBitcoin.ConcurrentChain>();
            var chainState        = serviceProvider.GetService <ChainState>();
            var blockStoreManager = serviceProvider.GetService <BlockStoreManager>();
            var mempoolManager    = serviceProvider.GetService <MempoolManager>();
            var connectionManager = serviceProvider.GetService <ConnectionManager>();

            Assert.NotNull(fullNode);
            Assert.NotNull(network);
            Assert.NotNull(settings);
            Assert.NotNull(consensusLoop);
            Assert.NotNull(consensus);
            Assert.NotNull(chain);
            Assert.NotNull(chainState);
            Assert.NotNull(blockStoreManager);
            Assert.NotNull(mempoolManager);
        }
        public IFullNode BuildServicedNode(string dir)
        {
            var       nodeSettings    = NodeSettings.FromArguments(new string[] { $"-datadir={dir}" });
            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseConsensus()
                                        .UseBlockStore()
                                        .UseMempool()
                                        .AddRPC()
                                        .Build();

            return(fullNode);
        }
Example #3
0
        public IFullNode BuildServicedNode(string dir)
        {
            var nodeSettings = NodeSettings.Default();

            nodeSettings.DataDir = dir;
            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseConsensus()
                                        .UseBlockStore()
                                        .UseMempool()
                                        .AddRPC()
                                        .Build();

            return(fullNode);
        }
        public void CanHaveAllFullnodeServicesTest()
        {
            // This test is put in the mempool feature because the
            // mempool requires all the features to be a fullnode


            var nodeSettings = NodeSettings.Default();

            nodeSettings.DataDir = "Stratis.Bitcoin.Features.MemoryPool.Tests/TestData/FullNodeBuilderTest/CanHaveAllServicesTest";
            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseConsensus()
                                        .UseBlockStore()
                                        .UseMempool()
                                        .Build();

            IServiceProvider serviceProvider = fullNode.Services.ServiceProvider;
            var network           = serviceProvider.GetService <Network>();
            var settings          = serviceProvider.GetService <NodeSettings>();
            var consensusLoop     = serviceProvider.GetService <IConsensusLoop>() as ConsensusLoop;
            var consensus         = serviceProvider.GetService <IPowConsensusValidator>() as PowConsensusValidator;
            var chain             = serviceProvider.GetService <NBitcoin.ConcurrentChain>();
            var chainState        = serviceProvider.GetService <IChainState>() as ChainState;
            var blockStoreManager = serviceProvider.GetService <BlockStoreManager>();
            var mempoolManager    = serviceProvider.GetService <MempoolManager>();
            var connectionManager = serviceProvider.GetService <IConnectionManager>() as ConnectionManager;

            Assert.NotNull(fullNode);
            Assert.NotNull(network);
            Assert.NotNull(settings);
            Assert.NotNull(consensusLoop);
            Assert.NotNull(consensus);
            Assert.NotNull(chain);
            Assert.NotNull(chainState);
            Assert.NotNull(blockStoreManager);
            Assert.NotNull(mempoolManager);
            Assert.NotNull(connectionManager);
        }
Example #5
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                // Get the API uri.
                var apiUri    = args.GetValueOf("apiuri");
                var isTestNet = args.Contains("-testnet");
                var isStratis = args.Contains("stratis");
                var agent     = "Breeze";

                // This setting is not in NodeSettings yet, so get it directly from the args
                ConfigurationOptionWrapper <string> registrationStoreDirectory = new ConfigurationOptionWrapper <string>("RegistrationStoreDirectory", args.GetValueOf("-storedir"));

                NodeSettings nodeSettings;

                if (isStratis)
                {
                    if (NodeSettings.PrintHelp(args, Network.StratisMain))
                    {
                        return;
                    }

                    Network network = isTestNet ? Network.StratisTest : Network.StratisMain;
                    if (isTestNet)
                    {
                        args = args.Append("-addnode=51.141.28.47").ToArray(); // TODO: fix this temp hack
                    }
                    nodeSettings        = new NodeSettings("stratis", network, ProtocolVersion.ALT_PROTOCOL_VERSION, agent).LoadArguments(args);
                    nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultStratisUri : apiUri);
                }
                else
                {
                    nodeSettings        = new NodeSettings(agent: agent).LoadArguments(args);
                    nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultBitcoinUri : apiUri);
                }

                IFullNodeBuilder fullNodeBuilder = null;

                if (args.Contains("light"))
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseLightWallet()
                                      .UseWatchOnlyWallet()
                                      .UseBlockNotification()
                                      .UseTransactionNotification()
                                      .UseApi();
                }
                else
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings);

                    if (args.Contains("stratis"))
                    {
                        fullNodeBuilder.UseStratisConsensus();
                    }
                    else
                    {
                        fullNodeBuilder.UseConsensus();
                    }

                    fullNodeBuilder.UseBlockStore()
                    .UseMempool()
                    .UseBlockNotification()
                    .UseTransactionNotification()
                    .UseWallet()
                    .UseWatchOnlyWallet()
                    .AddMining()
                    .AddRPC()
                    .UseApi();
                }

                if (args.Contains("registration"))
                {
                    //fullNodeBuilder.UseInterNodeCommunication();
                    fullNodeBuilder.UseRegistration();
                }

                // Need this to happen for both TB and non-TB daemon
                Logs.Configure(new FuncLoggerFactory(i => new DualLogger(i, (a, b) => true, false)));

                // Start NTumbleBit logging to the console
                SetupTumbleBitConsoleLogs(nodeSettings);

                // Add logging to NLog
                //SetupTumbleBitNLogs(nodeSettings);

                // Currently TumbleBit is bitcoin only
                if (args.Contains("-tumblebit"))
                {
                    // We no longer pass the URI in via the command line, the registration feature selects a random one
                    fullNodeBuilder.UseTumbleBit(registrationStoreDirectory);
                }

                IFullNode node = fullNodeBuilder.Build();

                // Start Full Node - this will also start the API.
                await node.RunAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }