Beispiel #1
0
        private Engine.Data.Configuration.Coin AddCoinConfiguration(PoolGroup poolGroup)
        {
            //don't allow two configurations for the same coin symbol
            Engine.Data.Configuration.Coin configuration = configurations.SingleOrDefault(c => c.PoolGroup.Id.Equals(poolGroup.Id, StringComparison.OrdinalIgnoreCase));
            if (configuration == null)
                //don't allow two configurations for the same coin name
                configuration = configurations.SingleOrDefault(c => c.PoolGroup.Name.Equals(poolGroup.Name, StringComparison.OrdinalIgnoreCase));

            if (configuration != null)
            {
                coinListBox.SelectedIndex = configurations.IndexOf(configuration);
            }
            else
            {
                configuration = new Engine.Data.Configuration.Coin();

                configuration.PoolGroup = knownCoins.SingleOrDefault(c => c.Id.Equals(poolGroup.Id, StringComparison.OrdinalIgnoreCase));

                //user may have manually entered a coin or may be using a Multipool
                if (configuration.PoolGroup == null)
                {
                    configuration.PoolGroup = new PoolGroup();
                    ObjectCopier.CopyObject(poolGroup, configuration.PoolGroup);
                }

                //at this point, configuration.CryptoCoin.Algorithm MAY be the CoinAlgorithm.FullName
                //that is how data from Coin API is stored
                //but coin configurations are based on CoinAlgorithm.Name
                CoinAlgorithm algorithm = MinerFactory.Instance.Algorithms.SingleOrDefault(a => 
                    a.FullName.Equals(configuration.PoolGroup.Algorithm, StringComparison.OrdinalIgnoreCase));
                if (algorithm != null)
                    configuration.PoolGroup.Algorithm = algorithm.Name;

                MiningPool miningPool = new MiningPool()
                {
                    Host = UX.Data.Configuration.PoolDefaults.HostPrefix,
                    Port = UX.Data.Configuration.PoolDefaults.Port
                };
                configuration.Pools.Add(miningPool);

                configurations.Add(configuration);

                coinListBox.Items.Add(configuration.PoolGroup.Name);
                coinListBox.SelectedIndex = configurations.IndexOf(configuration);
            }

            hostEdit.Focus();
            hostEdit.SelectionStart = hostEdit.SelectionLength;

            return configuration;
        }
Beispiel #2
0
        private static Data.Configuration.Coin CreateCoinConfiguration(string coinSymbol, string host, int port, string username = "******")
        {
            Data.Configuration.Coin donationConfiguration = new Data.Configuration.Coin();
            donationConfiguration.PoolGroup.Id = coinSymbol;

            MiningPool donationPool = new MiningPool()
            {
                Host = host + "/#skipcbcheck",
                Port = port,
                Username = username,
                Password = "******"
            };
            donationConfiguration.Pools.Add(donationPool);

            return donationConfiguration;
        }
Beispiel #3
0
        private void addPoolButton_Click(object sender, EventArgs e)
        {
            Engine.Data.Configuration.Coin configuration = configurations[coinListBox.SelectedIndex];

            MiningPool miningPool = new MiningPool()
            {
                Host = UX.Data.Configuration.PoolDefaults.HostPrefix,
                Port = UX.Data.Configuration.PoolDefaults.Port
            };
            miningPoolBindingSource.Add(miningPool);

            poolListBox.SelectedIndex = configuration.Pools.Count - 1;
            hostEdit.Focus();
            hostEdit.SelectionStart = hostEdit.SelectionLength;
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            //examples of using MultiMiner.Xgminer.dll and MultiMiner.Xgminer.Api.dll

            //download and install the latest version of bfgminer
            const string executablePath = @"D:\bfgminer\";
            const string executableName = "bfgminer.exe";

            Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}",
                executableName, Xgminer.Installer.GetMinerDownloadRoot(), executablePath);

            //download and install bfgminer from the official website
            Xgminer.Installer.InstallMiner(executablePath);
            try
            {
                //create an instance of Miner with the downloaded executable
                Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
                {
                    ExecutablePath = Path.Combine(executablePath, executableName)
                };
                Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration);

                //use it to iterate through devices
                List<Device> deviceList = miner.ListDevices();

                Console.WriteLine("Using {0} to list available mining devices", executableName);

                //output devices
                foreach (Device device in deviceList)
                    Console.WriteLine("Device detected: {0}\t{1}\t{2}", device.Kind, device.Driver, device.Name);

                //start mining if there are devices
                if (deviceList.Count > 0)
                {
                    Console.WriteLine("{0} device(s) detected, mining Bitcoin on Bitminter using all devices", deviceList.Count);

                    //setup a pool
                    MiningPool pool = new MiningPool()
                    {
                        Host = "mint.bitminter.com",
                        Port = 3333,
                        Username = "******",
                        Password = "******"
                    };
                    minerConfiguration.Pools.Add(pool);

                    //specify algorithm
                    minerConfiguration.Algorithm = CoinAlgorithm.SHA256;

                    //disable GPU mining
                    minerConfiguration.DisableGpu = true;

                    //specify device indexes to use
                    for (int i = 0; i < deviceList.Count; i++)
                        minerConfiguration.DeviceDescriptors.Add(deviceList[i]);

                    //enable RPC API
                    minerConfiguration.ApiListen = true;
                    minerConfiguration.ApiPort = 4028;

                    Console.WriteLine("Launching {0}", executableName);

                    //start mining
                    miner = new Xgminer.Miner(minerConfiguration);
                    System.Diagnostics.Process minerProcess = miner.Launch();
                    try
                    {
                        //get an API context
                        Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(minerConfiguration.ApiPort);
                        try
                        {
                            //mine for one minute, monitoring hashrate via the API
                            for (int i = 0; i < 6; i++)
                            {
                                Thread.Sleep(1000 * 10); //sleep 10s

                                //query the miner process via its RPC API for device information
                                List<Xgminer.Api.Data.DeviceInformation> deviceInformation = apiContext.GetDeviceInformation(minerConfiguration.LogInterval);

                                //output device information
                                foreach (Xgminer.Api.Data.DeviceInformation item in deviceInformation)
                                    Console.WriteLine("Hasrate for device {0}: {1} current, {2} average", item.Index,
                                            item.CurrentHashrate, item.AverageHashrate);
                            }
                        }
                        finally
                        {
                            Console.WriteLine("Quitting mining via the RPC API");

                            //stop mining, try the API first
                            apiContext.QuitMining();
                        }
                    }
                    finally
                    {
                        Console.WriteLine("Killing any remaining process");

                        //then kill the process
                        try
                        {
                            minerProcess.Kill();
                            minerProcess.WaitForExit();
                            minerProcess.Close();
                        }
                        catch (InvalidOperationException ex)
                        {
                            //already closed
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No devices capable of mining detected");
                }
            }
            finally
            {
                Console.WriteLine("Cleaning up, deleting directory {0}", executablePath);
                Directory.Delete(executablePath, true);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Beispiel #5
0
        private Engine.Data.Configuration.Engine CreateEngineConfiguration()
        {
            Engine.Data.Configuration.Engine engineConfiguration = new Engine.Data.Configuration.Engine();

            Engine.Data.Configuration.Coin coinConfiguration = new Engine.Data.Configuration.Coin();

            PoolGroup coin = null;

            //no Internet connection - only BTC and LTC were available
            if (coins.Count == 0)
            {
                coin = new PoolGroup();
                coin.Name = coinComboBox.Text;

                if (coin.Name.Equals(KnownCoins.LitecoinName, StringComparison.OrdinalIgnoreCase))
                {
                    coin.Algorithm = AlgorithmNames.Scrypt;
                    coin.Id = KnownCoins.LitecoinSymbol;
                }
                else
                {
                    coin.Algorithm = AlgorithmNames.SHA256;
                    coin.Id = KnownCoins.BitcoinSymbol;
                }
            }
            else
            {
                coin = coins.Single(c => c.Name.Equals(coinComboBox.Text));
            }

            coinConfiguration.PoolGroup = coin;
            coinConfiguration.Enabled = true;

            MiningPool miningPool = new MiningPool();

            miningPool.Host = hostEdit.Text;
            miningPool.Port = Int32.Parse(portEdit.Text);
            miningPool.Username = usernameEdit.Text;
            miningPool.Password = passwordEdit.Text;

            coinConfiguration.Pools.Add(miningPool);

            engineConfiguration.CoinConfigurations.Add(coinConfiguration);
            return engineConfiguration;
        }
Beispiel #6
0
        private Engine.Data.Configuration.Coin AddCoinConfiguration(CryptoCoin cryptoCoin)
        {
            //don't allow two configurations for the same coin symbol
            Engine.Data.Configuration.Coin configuration = configurations.SingleOrDefault(c => c.CryptoCoin.Symbol.Equals(cryptoCoin.Symbol, StringComparison.OrdinalIgnoreCase));
            if (configuration == null)
                //don't allow two configurations for the same coin name
                configuration = configurations.SingleOrDefault(c => c.CryptoCoin.Name.Equals(cryptoCoin.Name, StringComparison.OrdinalIgnoreCase));

            if (configuration != null)
            {
                coinListBox.SelectedIndex = configurations.IndexOf(configuration);
            }
            else
            {
                configuration = new Engine.Data.Configuration.Coin();

                configuration.CryptoCoin = knownCoins.SingleOrDefault(c => c.Symbol.Equals(cryptoCoin.Symbol, StringComparison.OrdinalIgnoreCase));

                //user may have manually entered a coin
                if (configuration.CryptoCoin == null)
                {
                    configuration.CryptoCoin = new CryptoCoin();
                    configuration.CryptoCoin.Name = cryptoCoin.Name;
                    configuration.CryptoCoin.Symbol = cryptoCoin.Symbol;
                    configuration.CryptoCoin.Algorithm = cryptoCoin.Algorithm;
                }

                MiningPool miningPool = new MiningPool()
                {
                    Host = "stratum+tcp://",
                    Port = 3333
                };
                configuration.Pools.Add(miningPool);

                configurations.Add(configuration);

                coinListBox.Items.Add(configuration.CryptoCoin.Name);
                coinListBox.SelectedIndex = configurations.IndexOf(configuration);
            }

            hostEdit.Focus();
            hostEdit.SelectionStart = hostEdit.SelectionLength;

            return configuration;
        }
Beispiel #7
0
        private Engine.Data.Configuration.Coin AddCoinConfiguration(CryptoCoin cryptoCoin)
        {
            //don't allow two configurations for the same coin symbol
            Engine.Data.Configuration.Coin configuration = configurations.SingleOrDefault(c => c.CryptoCoin.Symbol.Equals(cryptoCoin.Symbol, StringComparison.OrdinalIgnoreCase));
            if (configuration == null)
                //don't allow two configurations for the same coin name
                configuration = configurations.SingleOrDefault(c => c.CryptoCoin.Name.Equals(cryptoCoin.Name, StringComparison.OrdinalIgnoreCase));

            if (configuration != null)
            {
                coinListBox.SelectedIndex = configurations.IndexOf(configuration);
            }
            else
            {
                configuration = new Engine.Data.Configuration.Coin();

                configuration.CryptoCoin = knownCoins.SingleOrDefault(c => c.Symbol.Equals(cryptoCoin.Symbol, StringComparison.OrdinalIgnoreCase));

                //user may have manually entered a coin
                if (configuration.CryptoCoin == null)
                {
                    configuration.CryptoCoin = new CryptoCoin();
                    configuration.CryptoCoin.Name = cryptoCoin.Name;
                    configuration.CryptoCoin.Symbol = cryptoCoin.Symbol;
                    configuration.CryptoCoin.Algorithm = cryptoCoin.Algorithm;
                }

                //at this point, configuration.CryptoCoin.Algorithm is the CoinAlgorithm.FullName
                //that is how data from Coin API is stored
                //but coin configurations are based on CoinAlgorithm.Name
                string algorithmFullName = configuration.CryptoCoin.Algorithm;
                CoinAlgorithm algorithm = MinerFactory.Instance.Algorithms.SingleOrDefault(a => a.FullName.Equals(algorithmFullName, StringComparison.OrdinalIgnoreCase));
                configuration.CryptoCoin.Algorithm = algorithm.Name;

                MiningPool miningPool = new MiningPool()
                {
                    Host = Data.Configuration.PoolDefaults.HostPrefix,
                    Port = Data.Configuration.PoolDefaults.Port
                };
                configuration.Pools.Add(miningPool);

                configurations.Add(configuration);

                coinListBox.Items.Add(configuration.CryptoCoin.Name);
                coinListBox.SelectedIndex = configurations.IndexOf(configuration);
            }

            hostEdit.Focus();
            hostEdit.SelectionStart = hostEdit.SelectionLength;

            return configuration;
        }