Esempio n. 1
0
        public static async Task Main(string[] args)
        {
            try
            {
                string chain = args
                               .DefaultIfEmpty("--chain=BTC")
                               .Where(arg => arg.StartsWith("--chain", ignoreCase: true, CultureInfo.InvariantCulture))
                               .Select(arg => arg.Replace("--chain=", string.Empty, ignoreCase: true, CultureInfo.InvariantCulture))
                               .FirstOrDefault();

                NodeSettings     nodeSettings = NetworkSelector.Create(chain, args);
                IFullNodeBuilder nodeBuilder  = NodeBuilder.Create(chain, nodeSettings);

                IFullNode node = nodeBuilder.Build();

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex);
            }
        }
Esempio n. 2
0
        public static async Task Main(string[] args)
        {
            try
            {
                var nodeSettings = new NodeSettings(networksSelector: Networks.x42, args: args);

                IFullNodeBuilder nodeBuilder = new FullNodeBuilder()
                                               .UseNodeSettings(nodeSettings)
                                               .UseBlockStore()
                                               .UsePosConsensus()
                                               .UseMempool()
                                               .UseColdStakingWallet()
                                               .AddPowPosMining()
                                               .UseNodeHost()
                                               .AddRPC()
                                               .UseDiagnosticFeature();

                IFullNode node = nodeBuilder.Build();

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex);
            }
        }
Esempio n. 3
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                bool isMainchainNode = args.FirstOrDefault(a => a.ToLower() == MainchainArgument) != null;
                bool isSidechainNode = args.FirstOrDefault(a => a.ToLower() == SidechainArgument) != null;

                if (isSidechainNode == isMainchainNode)
                {
                    throw new ArgumentException($"Gateway node needs to be started specifying either a {SidechainArgument} or a {MainchainArgument} argument");
                }

                // set the console window title to identify which node this is (for clarity when running Strax and Cirrus on the same machine)
                Console.Title = isMainchainNode ? "Strax Full Node" : "Cirrus Full Node";

                IFullNode node = isMainchainNode ? GetStraxNode(args) : GetCirrusMiningNode(args);

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 4
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                var nodeSettings = new NodeSettings(networksSelector: CirrusNetwork.NetworksSelector,
                                                    protocolVersion: ProtocolVersion.CIRRUS_VERSION, args: args)
                {
                    MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
                };

                bool enableFedKicking = nodeSettings.ConfigReader.GetOrDefault("enablefedkicking", true);
                ((PoAConsensusOptions)nodeSettings.Network.Consensus.Options).AutoKickIdleMembers = enableFedKicking;

                IFullNode node = GetSideChainFullNode(nodeSettings);

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 5
0
        public void GetStakingInfo_StakingEnabled()
        {
            using (var dir = TestDirectory.Create())
            {
                IFullNode fullNode        = PurpleBitcoinPosRunner.BuildStakingNode(dir.FolderName);
                var       fullNodeRunTask = fullNode.RunAsync();

                INodeLifetime nodeLifetime = fullNode.NodeService <INodeLifetime>();
                nodeLifetime.ApplicationStarted.WaitHandle.WaitOne();
                MiningRPCController controller = fullNode.Services.ServiceProvider.GetService <MiningRPCController>();

                Assert.NotNull(fullNode.NodeService <IPosMinting>(true));

                GetStakingInfoModel info = controller.GetStakingInfo();

                Assert.NotNull(info);
                Assert.True(info.Enabled);
                Assert.False(info.Staking);

                nodeLifetime.StopApplication();
                nodeLifetime.ApplicationStopped.WaitHandle.WaitOne();
                fullNode.Dispose();

                Assert.False(fullNodeRunTask.IsFaulted);
            }
        }
Esempio n. 6
0
        public static async Task RunFederationGatewayAsync(string[] args)
        {
            try
            {
                var isMainchainNode = args.FirstOrDefault(a => a.ToLower() == MainchainArgument) != null;
                var isSidechainNode = args.FirstOrDefault(a => a.ToLower() == SidechainArgument) != null;

                if (isSidechainNode == isMainchainNode)
                {
                    throw new ArgumentException($"Gateway node needs to be started specifying either a {SidechainArgument} or a {MainchainArgument} argument");
                }

                IFullNode node = isMainchainNode
                    ? GetMainchainFullNode(args)
                    : GetSidechainFullNode(args);

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 7
0
        public void GetStakingInfo_StakingEnabled()
        {
            string    dir             = AssureEmptyDir("TestData/GetStakingInfoActionTests/GetStakingInfo_StakingEnabled");
            IFullNode fullNode        = this.BuildStakingNode(dir);
            var       fullNodeRunTask = fullNode.RunAsync();

            INodeLifetime nodeLifetime = fullNode.NodeService <INodeLifetime>();

            nodeLifetime.ApplicationStarted.WaitHandle.WaitOne();
            MiningRPCController controller = fullNode.Services.ServiceProvider.GetService <MiningRPCController>();

            Assert.NotNull(fullNode.NodeService <PosMinting>(true));

            GetStakingInfoModel info = controller.GetStakingInfo();

            Assert.NotNull(info);
            Assert.True(info.Enabled);
            Assert.False(info.Staking);

            nodeLifetime.StopApplication();
            nodeLifetime.ApplicationStopped.WaitHandle.WaitOne();
            fullNode.Dispose();

            Assert.False(fullNodeRunTask.IsFaulted);
        }
Esempio n. 8
0
#pragma warning disable IDE1006 // Naming Styles

        public static async Task Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
        {
            try
            {
                var nodeSettings = new NodeSettings(networksSelector: Networks.Stratis,
                                                    protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args)
                {
                    MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
                };

                IFullNodeBuilder nodeBuilder = new FullNodeBuilder()
                                               .UseNodeSettings(nodeSettings)
                                               .UseBlockStore()
                                               .UsePosConsensus()
                                               .UseMempool()
                                               .UseColdStakingWallet()
                                               .AddPowPosMining()
                                               .UseNodeHost()
                                               .AddRPC()
                                               .UseDiagnosticFeature();

                IFullNode node = nodeBuilder.Build();

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.ToString());
            }
        }
Esempio n. 9
0
        public static async Task Main(string[] args)
        {
            try
            {
                bool isStratis = args.Contains("stratis");

                NodeSettings nodeSettings;

                IFullNodeBuilder fullNodeBuilder = null;

                if (!args.Any(a => a.Contains("datadirroot")))
                {
                    args = args.Concat(new[] { "-datadirroot=StratisBreeze" }).ToArray();
                }

                if (isStratis)
                {
                    nodeSettings = new NodeSettings(networksSelector: Networks.Stratis, protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, agent: "Breeze", args: args)
                    {
                        MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
                    };

                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseApi()
                                      .UseBlockStore()
                                      .UsePosConsensus()
                                      .UseLightWallet()
                                      .AddSQLiteWalletRepository()
                                      .UseBlockNotification()
                                      .UseTransactionNotification();
                }
                else
                {
                    nodeSettings = new NodeSettings(networksSelector: Networks.Bitcoin, agent: "Breeze", args: args);

                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseApi()
                                      .UseBlockStore()
                                      .UsePowConsensus()
                                      .UseLightWallet()
                                      .AddSQLiteWalletRepository()
                                      .UseBlockNotification()
                                      .UseTransactionNotification();
                }

                IFullNode node = fullNodeBuilder.Build();

                await node.RunAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"There was a problem initializing the node: '{ex}'");
            }
        }
Esempio n. 10
0
        public static async Task Main(string[] args)
        {
            // IConfiguration configuration = BuildConfiguration();
            // SetupApplicationInsightsLogging(configuration["Azure:ApplicationInsights:InstrumentationKey"]);

            var isLaunchedWithDevMode = args.Any(a => a.Contains($"-{NodeSettings.DevModeParam}", StringComparison.InvariantCultureIgnoreCase));

            IFullNode fullNode = BuildCirrusLiveNode(args);

            await fullNode.RunAsync();
        }
        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";

                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 = new FullNodeBuilder()
                                                   .UseNodeSettings(nodeSettings)
                                                   .UseLightWallet()
                                                   .UseBlockNotification()
                                                   .UseTransactionNotification()
                                                   .UseApi();

                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);
            }
        }
Esempio n. 12
0
        public static void Main(string[] args)
        {
            try
            {
                var nodeSettings = new NodeSettings(networksSelector: Blockcore.Networks.Xds.Networks.Xds, args: args);

                IFullNodeBuilder nodeBuilder = new FullNodeBuilder()
                                               .UseNodeSettings(nodeSettings)
                                               .UseBlockStore()
                                               .UsePosConsensus()
                                               .UseMempool()
                                               .UseColdStakingWallet()
                                               .AddPowPosMining()
                                               .UseNodeHost()
                                               .AddRPC();

                var window = new WebWindow("Blockcore");
                window.NavigateToString("<h1>Blockcore node loading....</h1> ");
                WriteResourceToFile("Xds-ui.favicon.ico", "Xds-ui.favicon.ico");
                window.SetIconFile("Xds-ui.favicon.ico");

                IFullNode node     = null;
                Task      nodeTask = null;

                Task.Run(() =>
                {
                    try
                    {
                        node     = nodeBuilder.Build();
                        nodeTask = node.RunAsync();
                    }
                    catch (Exception ex)
                    {
                        window.NavigateToString("There was a problem initializing the node. <br> see the log file " + nodeSettings.DataFolder.LogPath + " " + ex.ToString());
                        return;
                    }

                    window.Title = node.Network.CoinTicker + " Node";
                    window.NavigateToUrl(node.NodeService <NodeHostSettings>().ApiUri.ToString());
                });

                window.WaitForExit();
                nodeTask.Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.ToString());
            }
        }
Esempio n. 13
0
        public static async Task Main(string[] args)
        {
            try
            {
                // Get the API uri.
                bool isTestNet = args.Contains("-testnet");
                bool isStratis = args.Contains("stratis");

                string agent = "Breeze";

                NodeSettings nodeSettings;

                if (isStratis)
                {
                    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(network, ProtocolVersion.ALT_PROTOCOL_VERSION, agent, args: args);
                }
                else
                {
                    nodeSettings = new NodeSettings(agent: agent, args: args);
                }

                IFullNodeBuilder fullNodeBuilder = new FullNodeBuilder()
                                                   .UseNodeSettings(nodeSettings)
                                                   .UseLightWallet()
                                                   .UseBlockNotification()
                                                   .UseTransactionNotification()
                                                   .UseApi();

                IFullNode node = fullNodeBuilder.Build();

                // Start Full Node - this will also start the API.
                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 14
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                // Get the API uri.
                var isTestNet = args.Contains("-testnet");
                var isImpleum = args.Contains("impleum");

                var agent = "Impleum Privacy";

                NodeSettings nodeSettings;

                if (isImpleum)
                {
                    Network network = isTestNet ? Network.ImpleumTest : Network.ImpleumMain;
                    if (isTestNet)
                    {
                        args = args.Append("-addnode=94.131.240.45").ToArray(); // TODO: fix this temp hack
                    }
                    nodeSettings = new NodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, agent, args: args, loadConfiguration: false);
                }
                else
                {
                    nodeSettings = new NodeSettings(agent: agent, args: args, loadConfiguration: false);
                }

                IFullNodeBuilder fullNodeBuilder = new FullNodeBuilder()
                                                   .UseNodeSettings(nodeSettings)
                                                   .UseLightWallet()
                                                   .UseBlockNotification()
                                                   .UseTransactionNotification()
                                                   .UseApi();

                IFullNode node = fullNodeBuilder.Build();

                // Start Full Node - this will also start the API.
                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 15
0
        public static async Task Main(string[] args)
        {
            IFullNodeBuilder fullNodeBuilder = null;

            // Get the API uri.
            var apiUri    = args.GetValueOf("apiuri");
            var isTestNet = args.Contains("-testnet");
            var isStratis = args.Contains("stratis");
            var agent     = "Breeze";

            NodeSettings nodeSettings;

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

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

            fullNodeBuilder = new FullNodeBuilder()
                              .UseNodeSettings(nodeSettings)
                              .UseLightWallet()
                              .UseBlockNotification()
                              .UseTransactionNotification()
                              .UseApi();

            IFullNode node = fullNodeBuilder.Build();

            // Start Full Node - this will also start the API.
            await node.RunAsync();
        }
Esempio n. 16
0
        public static async Task Main(string[] args)
        {
            try
            {
                List <string> arguments = new List <string>(args);

                // If now override of dbtype is specified, we'll default to rocksdb and not the normal leveldb.
                if (!arguments.Any(a => a.ToLower().StartsWith("-dbtype")))
                {
                    arguments.Add("-dbtype=rocksdb");
                }

                string chain = arguments
                               .DefaultIfEmpty("--chain=BTC")
                               .Where(arg => arg.StartsWith("--chain", ignoreCase: true, CultureInfo.InvariantCulture))
                               .Select(arg => arg.Replace("--chain=", string.Empty, ignoreCase: true, CultureInfo.InvariantCulture))
                               .FirstOrDefault();

                if (string.IsNullOrWhiteSpace(chain))
                {
                    chain = "BTC";
                }

                NodeSettings nodeSettings = NetworkSelector.Create(chain, arguments.ToArray());

                if (nodeSettings == null)
                {
                    Console.WriteLine($"Please check your specified chain argument, it is currently not supported: {chain}. Exiting...");
                    return;
                }

                IFullNodeBuilder nodeBuilder = NodeBuilder.Create(chain, nodeSettings);

                IFullNode node = nodeBuilder.Build();

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex);
            }
        }
Esempio n. 17
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                var nodeSettings = new NodeSettings(networksSelector: FederatedPegNetwork.NetworksSelector, protocolVersion: ProtocolVersion.ALT_PROTOCOL_VERSION, args: args);

                IFullNode node = GetFederatedPegFullNode(nodeSettings);

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 18
0
        public void GetStakingInfo_StartStaking()
        {
            using (var dir = TestDirectory.Create())
            {
                IFullNode fullNode = StratisBitcoinPosRunner.BuildStakingNode(dir.FolderName, false);
                var       node     = fullNode as FullNode;

                var fullNodeRunTask = fullNode.RunAsync();

                INodeLifetime nodeLifetime = fullNode.NodeService <INodeLifetime>();
                nodeLifetime.ApplicationStarted.WaitHandle.WaitOne();
                MiningRPCController controller = fullNode.Services.ServiceProvider.GetService <MiningRPCController>();

                WalletManager walletManager = node.NodeService <IWalletManager>() as WalletManager;

                var password = "******";

                // create the wallet
                var mnemonic = walletManager.CreateWallet(password, "test");


                Assert.NotNull(fullNode.NodeService <PosMinting>(true));

                GetStakingInfoModel info = controller.GetStakingInfo();

                Assert.NotNull(info);
                Assert.False(info.Enabled);
                Assert.False(info.Staking);

                controller.StartStaking("test", "test");

                info = controller.GetStakingInfo();

                Assert.NotNull(info);
                Assert.True(info.Enabled);
                Assert.False(info.Staking);

                nodeLifetime.StopApplication();
                nodeLifetime.ApplicationStopped.WaitHandle.WaitOne();
                fullNode.Dispose();

                Assert.False(fullNodeRunTask.IsFaulted);
            }
        }
Esempio n. 19
0
        public static async Task Main(string[] args)
        {
            try
            {
                var nodeSettings = new NodeSettings(networksSelector: Networks.Strax, protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args)
                {
                    MinProtocolVersion = ProtocolVersion.PROVEN_HEADER_VERSION
                };

                // Set the console window title to identify this as a Strax full node (for clarity when running Strax and Cirrus on the same machine).
                Console.Title = $"Strax Full Node {nodeSettings.Network.NetworkType}";

                DbType dbType = nodeSettings.GetDbType();

                IFullNodeBuilder nodeBuilder = new FullNodeBuilder()
                                               .UseNodeSettings(nodeSettings, dbType)
                                               .UseBlockStore(dbType)
                                               .UsePosConsensus(dbType)
                                               .UseMempool()
                                               .UseColdStakingWallet()
                                               .AddSQLiteWalletRepository()
                                               .AddPowPosMining(true)
                                               .UseApi()
                                               .UseUnity3dApi()
                                               .AddRPC()
                                               .AddSignalR(options =>
                {
                    DaemonConfiguration.ConfigureSignalRForStrax(options);
                })
                                               .UseDiagnosticFeature()
                                               .AddExternalApi();

                IFullNode node = nodeBuilder.Build();

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex);
            }
        }
Esempio n. 20
0
        /// <summary>
        ///     Installs handlers for graceful shutdown in the console, starts a full node and waits until it terminates.
        /// </summary>
        /// <param name="node">Full node to run.</param>
        public static async Task RunAsync(this IFullNode node)
        {
            var done = new ManualResetEventSlim(false);

            using (var cts = new CancellationTokenSource())
            {
                Action shutdown = () =>
                {
                    if (!cts.IsCancellationRequested)
                    {
                        Console.WriteLine("Application is shutting down...");
                        try
                        {
                            cts.Cancel();
                        }
                        catch (ObjectDisposedException exception)
                        {
                            Console.WriteLine(exception.Message);
                        }
                    }

                    done.Wait();
                };

                var assemblyLoadContext = AssemblyLoadContext.GetLoadContext(typeof(FullNode).GetTypeInfo().Assembly);
                assemblyLoadContext.Unloading += context => shutdown();

                Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    shutdown();
                    // Don't terminate the process immediately, wait for the Main thread to exit gracefully.
                    eventArgs.Cancel = true;
                };

                try
                {
                    await node.RunAsync(cts.Token).ConfigureAwait(false);
                }
                finally
                {
                    done.Set();
                }
            }
        }
Esempio n. 21
0
        public void GetStakingInfo_StartStaking()
        {
            string    dir      = AssureEmptyDir("TestData/GetStakingInfoActionTests/GetStakingInfo_StartStaking");
            IFullNode fullNode = this.BuildStakingNode(dir, false);
            var       node     = fullNode as FullNode;

            var fullNodeRunTask = fullNode.RunAsync();

            INodeLifetime nodeLifetime = fullNode.NodeService <INodeLifetime>();

            nodeLifetime.ApplicationStarted.WaitHandle.WaitOne();
            MiningRPCController controller = fullNode.Services.ServiceProvider.GetService <MiningRPCController>();

            WalletManager walletManager = node.NodeService <IWalletManager>() as WalletManager;

            var password = "******";

            // create the wallet
            var mnemonic = walletManager.CreateWallet(password, "test");


            Assert.NotNull(fullNode.NodeService <PosMinting>(true));

            GetStakingInfoModel info = controller.GetStakingInfo();

            Assert.NotNull(info);
            Assert.False(info.Enabled);
            Assert.False(info.Staking);

            controller.StartStaking("test", "test");

            info = controller.GetStakingInfo();

            Assert.NotNull(info);
            Assert.True(info.Enabled);
            Assert.False(info.Staking);

            nodeLifetime.StopApplication();
            nodeLifetime.ApplicationStopped.WaitHandle.WaitOne();
            fullNode.Dispose();

            Assert.False(fullNodeRunTask.IsFaulted);
        }
Esempio n. 22
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                // Get the API uri.
                var isTestNet  = args.Contains("-testnet");
                var isDeStream = args.Contains("destream");

                var agent = "Breeze";

                DeStreamNodeSettings nodeSettings;

                if (isDeStream)
                {
                    Network network = isTestNet ? Network.DeStreamTest : Network.DeStreamMain;
                    nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, agent, args: args, loadConfiguration: false);
                }
                else
                {
                    nodeSettings = new DeStreamNodeSettings(agent: agent, args: args, loadConfiguration: false);
                }

                IFullNodeBuilder fullNodeBuilder = new FullNodeBuilder()
                                                   .UseNodeSettings(nodeSettings)
                                                   .UseLightWallet()
                                                   .UseBlockNotification()
                                                   .UseTransactionNotification()
                                                   .UseApi();

                IFullNode node = fullNodeBuilder.Build();

                // Start Full Node - this will also start the API.
                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
        public void GetStakingInfo_StartStaking()
        {
            IFullNode fullNode = StratisBitcoinPosRunner.BuildStakingNode(TestBase.CreateTestDir(this), false);
            var       node     = fullNode as FullNode;

            Task fullNodeRunTask = fullNode.RunAsync();

            var nodeLifetime = fullNode.NodeService <INodeLifetime>();

            nodeLifetime.ApplicationStarted.WaitHandle.WaitOne();
            var controller = fullNode.NodeController <StakingRpcController>();

            var walletManager = node.NodeService <IWalletManager>() as WalletManager;

            string password   = "******";
            string passphrase = "passphrase";

            // create the wallet
            walletManager.CreateWallet(password, "test", passphrase);

            Assert.NotNull(fullNode.NodeService <IPosMinting>(true));

            GetStakingInfoModel info = controller.GetStakingInfo();

            Assert.NotNull(info);
            Assert.False(info.Enabled);
            Assert.False(info.Staking);

            controller.StartStaking("test", "test");

            info = controller.GetStakingInfo();

            Assert.NotNull(info);
            Assert.True(info.Enabled);
            Assert.False(info.Staking);

            nodeLifetime.StopApplication();
            nodeLifetime.ApplicationStopped.WaitHandle.WaitOne();
            fullNode.Dispose();

            Assert.False(fullNodeRunTask.IsFaulted);
        }
Esempio n. 24
0
        /// <summary>
        /// Installs handlers for graceful shutdown in the console, starts a full node and waits until it terminates.
        /// </summary>
        /// <param name="node">Full node to run.</param>
        /// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
        async Task RunAsync(IFullNode node)
        {
            var done = new ManualResetEventSlim(false);

            using (var cts = new CancellationTokenSource())
            {
                Action shutdown = () =>
                {
                    if (!cts.IsCancellationRequested)
                    {
                        Console.WriteLine(@"Application is shutting down.");
                        try
                        {
                            cts.Cancel();
                        }
                        catch (ObjectDisposedException exception)
                        {
                            Console.WriteLine(exception.Message);
                        }
                    }

                    done.Wait();
                };

                FullNodeStopRequested += (sender, eventArgs) =>
                {
                    shutdown();
                };

                try
                {
                    await node.RunAsync(cts.Token).ConfigureAwait(false);
                }
                finally
                {
                    done.Set();
                    _fullNode = null;
                }
            }
        }
Esempio n. 25
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                if (!args.Any(a => a.Contains("apiport")))
                {
                    args = args.Concat(new[] { "apiport=38225" }).ToArray();
                }

                NodeSettings nodeSettings = new NodeSettings(networksSelector: FederatedPegNetwork.NetworksSelector, protocolVersion: ProtocolVersion.ALT_PROTOCOL_VERSION, args: args);

                IFullNode node = GetFederatedPegFullNode(nodeSettings);

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 26
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                // set the console window title to identify this as a Cirrus full node (for clarity when running Strax and Cirrus on the same machine)
                Console.Title = "Cirrus Full Node";
                var nodeSettings = new NodeSettings(networksSelector: CirrusNetwork.NetworksSelector, protocolVersion: ProtocolVersion.CIRRUS_VERSION, args: args)
                {
                    MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
                };

                IFullNode node = GetSideChainFullNode(nodeSettings);

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 27
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                bool isMainchainNode = args.FirstOrDefault(a => a.ToLower() == MainchainArgument) != null;
                bool isSidechainNode = args.FirstOrDefault(a => a.ToLower() == SidechainArgument) != null;
                bool startInDevMode  = args.Any(a => a.ToLower().Contains($"-{NodeSettings.DevModeParam}"));

                IFullNode fullNode = null;

                if (startInDevMode)
                {
                    fullNode = BuildDevCirrusMiningNode(args);
                }
                else
                {
                    if (isSidechainNode == isMainchainNode)
                    {
                        throw new ArgumentException($"Gateway node needs to be started specifying either a {SidechainArgument} or a {MainchainArgument} argument");
                    }

                    fullNode = isMainchainNode ? BuildStraxNode(args) : BuildCirrusMiningNode(args);

                    // set the console window title to identify which node this is (for clarity when running Strax and Cirrus on the same machine)
                    Console.Title = isMainchainNode ? $"Strax Full Node {fullNode.Network.NetworkType}" : $"Cirrus Full Node {fullNode.Network.NetworkType}";
                }

                if (fullNode != null)
                {
                    await fullNode.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
        public void GetStakingInfo_StakingEnabled()
        {
            IFullNode fullNode        = StratisBitcoinPosRunner.BuildStakingNode(TestBase.CreateTestDir(this));
            Task      fullNodeRunTask = fullNode.RunAsync();

            var nodeLifetime = fullNode.NodeService <INodeLifetime>();

            nodeLifetime.ApplicationStarted.WaitHandle.WaitOne();
            var controller = fullNode.NodeController <StakingRpcController>();

            Assert.NotNull(fullNode.NodeService <IPosMinting>(true));

            GetStakingInfoModel info = controller.GetStakingInfo();

            Assert.NotNull(info);
            Assert.True(info.Enabled);
            Assert.False(info.Staking);

            nodeLifetime.StopApplication();
            nodeLifetime.ApplicationStopped.WaitHandle.WaitOne();
            fullNode.Dispose();

            Assert.False(fullNodeRunTask.IsFaulted);
        }
        public static async Task MainAsync(string[] args)
        {
            try
            {
                var nodeSettings = new NodeSettings(
                    network: CirrusNetwork.NetworksSelector.Testnet(),
                    protocolVersion: ProtocolVersion.CIRRUS_VERSION,
                    args: args)
                {
                    MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
                };

                IFullNode node = GetSideChainFullNode(nodeSettings);

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Esempio n. 30
0
        static async Task MainAsync(string[] args)
        {
            try
            {
                var nodeSettings = GetPatchedNodeSettings(args);

                var builder = new FullNodeBuilder()
                              .UseNodeSettings(nodeSettings)
                              .UseBlockStore()
                              .UsePosConsensus()
                              .UseMempool()
                              .UseX1Wallet()
                              .UseX1WalletApi()
                              .UseSecureApiHost();

                FullNode = builder.Build();

                Init.PrintWelcomeMessage(nodeSettings, FullNode);

                cancellationTokenSource = Init.RunIfDebugModeDelayed(FullNode);

                await FullNode.RunAsync();
            }
            catch (Exception e)
            {
                var message = $"Critical error in {Init.GetName()}: {e.Message}";
                try
                {
                    FullNode.NodeService <ILoggerFactory>().CreateLogger(typeof(Program).Name).LogCritical(message);
                }
                catch (Exception)
                {
                    Console.WriteLine(message);
                }
            }
        }