Пример #1
0
        public async Task StartAsync()
        {
            var config = new NodeConfigParameters
            {
                { "regtest", "1" },
                { "regtest.rest", "1" },
                { "regtest.listenonion", "0" },
                { "regtest.server", "1" },
                { "regtest.txindex", "1" },
                { "regtest.rpcuser", Creds.UserName },
                { "regtest.rpcpassword", Creds.Password },
                { "regtest.whitebind", "127.0.0.1:" + P2pPort.ToString() },
                { "regtest.rpcport", RpcPort.ToString() },
                { "regtest.printtoconsole", "0" },               // Set it to one if do not mind loud debug logs
                { "regtest.keypool", "10" },
                { "regtest.pid", "bitcoind.pid" }
            };

            config.Import(ConfigParameters);
            File.WriteAllText(Config, config.ToString());
            using (await KillerLock.LockAsync())
            {
                Process = Process.Start(new FileInfo(Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + DataDir + " -debug=1");
                State   = CoreNodeState.Starting;
                string pidFile = Path.Combine(DataDir, "regtest", "bitcoind.pid");
                if (!File.Exists(pidFile))
                {
                    Directory.CreateDirectory(Path.Combine(DataDir, "regtest"));
                    File.WriteAllText(pidFile, Process.Id.ToString());
                }
            }
            while (true)
            {
                try
                {
                    await CreateRpcClient().GetBlockHashAsync(0);

                    State = CoreNodeState.Running;
                    break;
                }
                catch
                {
                }
                if (Process is null || Process.HasExited)
                {
                    break;
                }
            }
        }
Пример #2
0
        private CoreNode(string folder, NodeBuilder builder)
        {
            _Builder = builder;
            Folder   = folder;
            State    = CoreNodeState.Stopped;
            DataDir  = Path.Combine(folder, "data");
            Directory.CreateDirectory(DataDir);
            var pass = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20));

            Creds  = new NetworkCredential(pass, pass);
            Config = Path.Combine(DataDir, "bitcoin.conf");
            ConfigParameters.Import(builder.ConfigParameters);
            _ports = new int[2];
            FindPorts(_ports);
        }
Пример #3
0
        private CoreNode(string folder, NodeBuilder builder)
        {
            Builder = builder;
            Folder  = folder;
            State   = CoreNodeState.Stopped;
            DataDir = Path.Combine(folder, "data");
            Directory.CreateDirectory(DataDir);
            var pass = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20));

            Creds  = new NetworkCredential(pass, pass);
            Config = Path.Combine(DataDir, "bitcoin.conf");
            ConfigParameters.Import(builder.ConfigParameters);

            var portArray = new int[2];
            var i         = 0;

            while (i < portArray.Length)
            {
                var port = RandomUtils.GetUInt32() % 4000;
                port += 10000;
                if (portArray.Any(p => p == port))
                {
                    continue;
                }

                try
                {
                    var listener = new TcpListener(IPAddress.Loopback, (int)port);
                    listener.Start();
                    listener.Stop();
                    portArray[i] = (int)port;
                    i++;
                }
                catch (SocketException)
                {
                }
            }

            P2pPort     = portArray[0];
            RpcPort     = portArray[1];
            P2pEndPoint = new IPEndPoint(IPAddress.Loopback, P2pPort);
            RpcEndPoint = new IPEndPoint(IPAddress.Loopback, RpcPort);
        }
Пример #4
0
        public async Task StartAsync()
        {
            var config = new NodeConfigParameters
            {
                { "regtest", "1" },
                { "regtest.rest", "1" },
                { "regtest.listenonion", "0" },
                { "regtest.server", "1" },
                { "regtest.txindex", "1" },
                { "regtest.rpcuser", Creds.UserName },
                { "regtest.rpcpassword", Creds.Password },
                { "regtest.whitebind", "127.0.0.1:" + _ports[0].ToString() },
                { "regtest.rpcport", _ports[1].ToString() },
                { "regtest.printtoconsole", "0" },               // Set it to one if don't mind loud debug logs
                { "regtest.keypool", "10" }
            };

            config.Import(ConfigParameters);
            File.WriteAllText(Config, config.ToString());
            lock (_l)
            {
                _process = Process.Start(new FileInfo(_Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + DataDir + " -debug=1");
                State    = CoreNodeState.Starting;
            }
            while (true)
            {
                try
                {
                    await CreateRpcClient().GetBlockHashAsync(0);

                    State = CoreNodeState.Running;
                    break;
                }
                catch
                {
                }
                if (_process is null || _process.HasExited)
                {
                    break;
                }
            }
        }