Exemplo n.º 1
0
        public void GetStakingInfo_StakingEnabled()
        {
            string    dir      = AssureEmptyDir("TestData/GetStakingInfoActionTests/GetStakingInfo_StakingEnabled");
            IFullNode fullNode = this.BuildStakingNode(dir);

            Task.Run(() =>
            {
                fullNode.Run();
            });

            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();
        }
Exemplo n.º 2
0
        public void GetStakingInfo_StartStaking()
        {
            string    dir      = AssureEmptyDir("TestData/GetStakingInfoActionTests/GetStakingInfo_StartStaking");
            IFullNode fullNode = this.BuildStakingNode(dir, false);
            var       node     = fullNode as FullNode;

            Task.Run(() =>
            {
                fullNode.Run();
            });

            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();
        }
Exemplo n.º 3
0
        public static void 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");

            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);
                nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultStratisUri : apiUri);
            }
            else
            {
                nodeSettings        = NodeSettings.FromArguments(args);
                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.
            node.Run();
        }
        /// <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 void Run(this IFullNode node)
        {
            var done = new ManualResetEventSlim(false);

            using (CancellationTokenSource 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();
                };
#if !NOASSEMBLYCONTEXT
                var assemblyLoadContext = AssemblyLoadContext.GetLoadContext(typeof(FullNode).GetTypeInfo().Assembly);
                assemblyLoadContext.Unloading += context => shutdown();
#endif
                Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    shutdown();
                    // Don't terminate the process immediately, wait for the Main thread to exit gracefully.
                    eventArgs.Cancel = true;
                };

                node.Run(cts.Token, "Application started. Press Ctrl+C to shut down.", "Application stopped.");
                done.Set();
            }
        }