Example #1
0
        public List <Device> GetDevices(string executablePath)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath  = executablePath,
                DisableGpu      = xgminerConfiguration.DisableGpu,
                DisableUsbProbe = xgminerConfiguration.DisableUsbProbe,
                ScanArguments   = xgminerConfiguration.ScanArguments
            };

            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration);

            Version       minerVersion    = new Version(Xgminer.Installer.GetInstalledMinerVersion(executablePath));
            List <Device> detectedDevices = miner.ListDevices(true, minerVersion);

            if (xgminerConfiguration.StratumProxy)
            {
                detectedDevices.Add(new Device()
                {
                    Kind   = DeviceKind.PXY,
                    Driver = "proxy",
                    Name   = "Stratum Proxy"
                });
            }

            SortDevices(detectedDevices);

            return(detectedDevices);
        }
Example #2
0
        public List<Device> GetDevices(string executablePath)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath = executablePath,
                DisableGpu = xgminerConfiguration.DisableGpu,
                DisableUsbProbe = xgminerConfiguration.DisableUsbProbe,
                ScanArguments = xgminerConfiguration.ScanArguments
            };

            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration);

            string minerPath = MultiMiner.Engine.MinerPath.GetPathToInstalledMiner();
            Version minerVersion = new Version(Xgminer.Installer.GetInstalledMinerVersion(minerPath));
            List<Device> detectedDevices = miner.ListDevices(true, minerVersion);

            if (xgminerConfiguration.StratumProxy)
            {
                detectedDevices.Add(new Device()
                {
                    Kind = DeviceKind.PXY,
                    Driver = "proxy",
                    Name = "Stratum Proxy"
                });
            }

            SortDevices(detectedDevices);

            return detectedDevices;
        }
Example #3
0
        private Xgminer.Data.Configuration.Miner CreateMinerConfiguration(int apiPort, string coinSymbol, DeviceKind deviceKind)
        {
            Data.Configuration.Coin coinConfiguration = engineConfiguration.CoinConfigurations.Single(c => c.PoolGroup.Id.Equals(coinSymbol));
            if (coinConfiguration.Pools.Count == 0)
            {
                // no pools configured
                return(null);
            }

            MinerDescriptor miner = MinerFactory.Instance.GetMiner(deviceKind, coinConfiguration.PoolGroup.Algorithm, engineConfiguration.XgminerConfiguration.AlgorithmMiners);

            if (miner == null)
            {
                //no miner configured for the algorithm / custom algorithm
                throw new Xgminer.MinerLaunchException(String.Format("No miner defined for algorithm {0}.", coinConfiguration.PoolGroup.Algorithm));
            }

            Xgminer.Data.Configuration.Miner minerConfiguration = CreateBasicConfiguration(miner, coinConfiguration, apiPort);

            IList <Engine.Data.Configuration.Device> enabledConfigurations =
                engineConfiguration.DeviceConfigurations
                .Where(c => c.Enabled && c.CoinSymbol.Equals(coinSymbol)).ToList();

            int deviceCount = SetupConfigurationDevices(minerConfiguration, deviceKind, enabledConfigurations);

            if (deviceCount == 0)
            {
                return(null);
            }

            return(minerConfiguration);
        }
Example #4
0
        private Xgminer.Data.Configuration.Miner CreateMinerConfiguration(int port, string coinSymbol, DeviceKind includeKinds)
        {
            Data.Configuration.Coin coinConfiguration = engineConfiguration.CoinConfigurations.Single(c => c.CryptoCoin.Symbol.Equals(coinSymbol));

            IList <Engine.Data.Configuration.Device> enabledConfigurations = engineConfiguration.DeviceConfigurations.Where(c => c.Enabled && c.CoinSymbol.Equals(coinSymbol)).ToList();

            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath = MinerPath.GetPathToInstalledMiner(),
                Algorithm      = coinConfiguration.CryptoCoin.Algorithm,
                ApiPort        = port,
                ApiListen      = true,
                AllowedApiIps  = engineConfiguration.XgminerConfiguration.AllowedApiIps,
                CoinName       = coinConfiguration.CryptoCoin.Name,
                DisableGpu     = engineConfiguration.XgminerConfiguration.DisableGpu
            };

            SetupConfigurationPools(minerConfiguration, coinConfiguration);

            int deviceCount = SetupConfigurationDevices(minerConfiguration, includeKinds, enabledConfigurations);

            if (deviceCount == 0)
            {
                return(null);
            }

            SetupConfigurationArguments(minerConfiguration, coinConfiguration);

            return(minerConfiguration);
        }
        public List<Device> GetDevices(string executablePath)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath = executablePath,
                DisableGpu = xgminerConfiguration.DisableGpu,
                DisableUsbProbe = xgminerConfiguration.DisableUsbProbe,
                ScanArguments = xgminerConfiguration.ScanArguments
            };

            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration);

            List<Device> detectedDevices = miner.ListDevices(true);

            if (xgminerConfiguration.StratumProxy)
            {
                detectedDevices.Add(new Device()
                {
                    Kind = DeviceKind.PXY,
                    Driver = "proxy",
                    Name = "Stratum Proxy"
                });
            }

            SortDevices(detectedDevices);

            return detectedDevices;
        }
Example #6
0
        private Xgminer.Data.Configuration.Miner CreateMinerConfiguration(int apiPort, string coinSymbol, DeviceKind deviceKind)
        {
            Data.Configuration.Coin coinConfiguration = engineConfiguration.CoinConfigurations.Single(c => c.CryptoCoin.Symbol.Equals(coinSymbol));
            if (coinConfiguration.Pools.Count == 0)
            {
                // no pools configured
                return(null);
            }

            MinerDescriptor miner = MinerFactory.Instance.GetMiner(deviceKind, coinConfiguration.CryptoCoin.Algorithm, engineConfiguration.XgminerConfiguration.AlgorithmMiners);

            Xgminer.Data.Configuration.Miner minerConfiguration = CreateBasicConfiguration(miner, coinConfiguration, apiPort);

            IList <Engine.Data.Configuration.Device> enabledConfigurations =
                engineConfiguration.DeviceConfigurations
                .Where(c => c.Enabled && c.CoinSymbol.Equals(coinSymbol)).ToList();

            int deviceCount = SetupConfigurationDevices(minerConfiguration, deviceKind, enabledConfigurations);

            if (deviceCount == 0)
            {
                return(null);
            }

            return(minerConfiguration);
        }
Example #7
0
        private int SetupConfigurationDevices(Xgminer.Data.Configuration.Miner minerConfiguration, DeviceKind deviceKinds, IList <Engine.Data.Configuration.Device> deviceConfigurations)
        {
            int deviceCount = 0;

            for (int i = 0; i < deviceConfigurations.Count; i++)
            {
                Engine.Data.Configuration.Device enabledConfiguration = deviceConfigurations[i];

                Xgminer.Data.Device device = devices.SingleOrDefault(d => d.Equals(enabledConfiguration));

                if ((deviceKinds & device.Kind) == 0)
                {
                    continue;
                }

                deviceCount++;

                //don't actually add stratum device as a device index
                if (device.Kind != DeviceKind.PXY)
                {
                    minerConfiguration.DeviceDescriptors.Add(device);
                }
                else
                {
                    //only enable the stratum proxy if these devices contain the PXY device
                    minerConfiguration.StratumProxy            = engineConfiguration.XgminerConfiguration.StratumProxy;
                    minerConfiguration.StratumProxyPort        = engineConfiguration.XgminerConfiguration.StratumProxyPort;
                    minerConfiguration.StratumProxyStratumPort = engineConfiguration.XgminerConfiguration.StratumProxyStratumPort;
                }
            }
            return(deviceCount);
        }
Example #8
0
        private void SetupConfigurationArguments(Xgminer.Data.Configuration.Miner minerConfiguration, Data.Configuration.Coin coinConfiguration)
        {
            string arguments = string.Empty;

            //apply algorithm-specific parameters
            if (engineConfiguration.XgminerConfiguration.AlgorithmFlags.ContainsKey(coinConfiguration.CryptoCoin.Algorithm))
            {
                arguments = String.Format("{0} {1}", arguments,
                                          engineConfiguration.XgminerConfiguration.AlgorithmFlags[coinConfiguration.CryptoCoin.Algorithm]);
            }

            //apply coin-specific parameters
            if (!string.IsNullOrEmpty(coinConfiguration.MinerFlags))
            {
                arguments = string.Format("{0} {1}", arguments, coinConfiguration.MinerFlags);
            }

            if (engineConfiguration.XgminerConfiguration.DesktopMode)
            {
                arguments = arguments + " -I D";
            }

            if (donationPercent > 0)
            {
                arguments = arguments + " --load-balance";
            }

            minerConfiguration.LaunchArguments = arguments;
        }
Example #9
0
        private Process LaunchMinerProcess(Xgminer.Data.Configuration.Miner minerConfiguration, string reason)
        {
            minerConfiguration.Priority = this.engineConfiguration.XgminerConfiguration.Priority;
            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration);
            miner.LogLaunch            += this.LogProcessLaunch;
            miner.LaunchFailed         += this.ProcessLaunchFailed;
            miner.AuthenticationFailed += this.ProcessAuthenticationFailed;
            Process process = miner.Launch(reason);

            return(process);
        }
Example #10
0
        private void LaunchProxyMiners(int apiPort)
        {
            IEnumerable <Xgminer.Data.Device> proxyDevices = devices.Where(d => d.Kind == DeviceKind.PXY);

            foreach (Xgminer.Data.Device proxyDevice in proxyDevices)
            {
                Data.Configuration.Device deviceConfiguration = engineConfiguration.DeviceConfigurations.Single(d => d.Equals(proxyDevice));

                //proxy is disabled
                if (!deviceConfiguration.Enabled)
                {
                    continue;
                }

                //no coin assigned
                if (String.IsNullOrEmpty(deviceConfiguration.CoinSymbol))
                {
                    continue;
                }

                Xgminer.Data.Configuration.Miner minerConfiguration = CreateProxyConfiguration(apiPort, deviceConfiguration.CoinSymbol);
                //null if no pools configured
                if (minerConfiguration != null)
                {
                    minerConfiguration.DeviceDescriptors.Add(proxyDevice);

                    minerConfiguration.StratumProxy = engineConfiguration.XgminerConfiguration.StratumProxy;

                    int index = Math.Max(0, proxyDevice.RelativeIndex);

                    if ((donationPercent == 0) && (index > 0))
                    {
                        throw new Exception(AdvancedProxiesRequirePerksMessage);
                    }

                    MultiMiner.Engine.Data.Configuration.Xgminer.ProxyDescriptor proxyDescriptor = engineConfiguration.XgminerConfiguration.StratumProxies[index];

                    minerConfiguration.StratumProxyPort        = proxyDescriptor.GetworkPort;
                    minerConfiguration.StratumProxyStratumPort = proxyDescriptor.StratumPort;

                    Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");
                    if (!process.HasExited)
                    {
                        StoreMinerProcess(process, MinerFactory.Instance.GetDefaultMiner(), deviceConfiguration.CoinSymbol, minerConfiguration, apiPort);
                    }

                    apiPort++;
                }
            }
        }
Example #11
0
        private MinerProcess StoreMinerProcess(Process process, string coinSymbol, Xgminer.Data.Configuration.Miner minerConfiguration, int port)
        {
            MinerProcess minerProcess = new MinerProcess();

            minerProcess.Process            = process;
            minerProcess.ApiPort            = port;
            minerProcess.MinerConfiguration = minerConfiguration;
            minerProcess.CoinSymbol         = coinSymbol;

            setupProcessStartInfo(minerProcess);

            minerProcesses.Add(minerProcess);

            return(minerProcess);
        }
Example #12
0
        private Process LaunchMinerProcess(Xgminer.Data.Configuration.Miner minerConfiguration, string reason)
        {
            minerConfiguration.Priority = this.engineConfiguration.XgminerConfiguration.Priority;

            //we launch 1 process per device kind now
            DeviceKind deviceKind = minerConfiguration.DeviceDescriptors.First().Kind;

            MinerDescriptor descriptor = MinerFactory.Instance.GetMiner(deviceKind, minerConfiguration.Algorithm, engineConfiguration.XgminerConfiguration.AlgorithmMiners);

            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration, descriptor.LegacyApi);
            miner.LogLaunch            += this.LogProcessLaunch;
            miner.LaunchFailed         += this.ProcessLaunchFailed;
            miner.AuthenticationFailed += this.ProcessAuthenticationFailed;
            Process process = miner.Launch(reason);

            return(process);
        }
Example #13
0
        private void LaunchMiners(ref int apiPort, string coinSymbol, DeviceKind deviceKind, bool terminateProcess)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = CreateMinerConfiguration(apiPort, coinSymbol, deviceKind);


            //null if no pools configured
            if (minerConfiguration != null)
            {
                Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");
                if (!process.HasExited)
                {
                    MinerDescriptor miner        = MinerFactory.Instance.GetMiner(deviceKind, minerConfiguration.Algorithm, engineConfiguration.XgminerConfiguration.AlgorithmMiners);
                    MinerProcess    minerProcess = StoreMinerProcess(process, miner, coinSymbol, minerConfiguration, apiPort);
                    minerProcess.TerminateProcess = terminateProcess;
                }

                apiPort++;
            }
        }
Example #14
0
        public List<Device> GetDevices(string executablePath)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath = executablePath,
                DisableGpu = xgminerConfiguration.DisableGpu,
                DisableUsbProbe = xgminerConfiguration.DisableUsbProbe,
                ScanArguments = xgminerConfiguration.ScanArguments
            };

            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration, false);

            Version minerVersion = new Version(MinerInstaller.GetInstalledMinerVersion(executablePath, false));
            List<Device> detectedDevices = miner.ListDevices(true, minerVersion, logging: true);

            SortDevices(detectedDevices);

            return detectedDevices;
        }
Example #15
0
        public List <Device> GetDevices(string executablePath)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath  = executablePath,
                DisableGpu      = xgminerConfiguration.DisableGpu,
                DisableUsbProbe = xgminerConfiguration.DisableUsbProbe,
                ScanArguments   = xgminerConfiguration.ScanArguments
            };

            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration, false);

            Version       minerVersion    = new Version(MinerInstaller.GetInstalledMinerVersion(executablePath, false));
            List <Device> detectedDevices = miner.ListDevices(true, minerVersion, logging: true);

            SortDevices(detectedDevices);

            return(detectedDevices);
        }
Example #16
0
        private void SetupConfigurationPools(Xgminer.Data.Configuration.Miner minerConfiguration, Data.Configuration.Coin coinConfiguration)
        {
            //minerConfiguration.Pools = coinConfiguration.Pools;
            foreach (MiningPool pool in coinConfiguration.Pools)
            {
                pool.Quota = 0;
                minerConfiguration.Pools.Add(pool);
            }

            //using bfgminer quotas for failover, that way we can augment for donations
            minerConfiguration.Pools.First().Quota = 100 - donationPercent;
            if (donationPercent > 0)
            {
                AddDonationPool(coinConfiguration.CryptoCoin.Symbol, minerConfiguration);
            }

            foreach (MiningPool pool in minerConfiguration.Pools)
            {
                pool.QuotaEnabled = donationPercent > 0;
            }
        }
Example #17
0
        private int SetupConfigurationDevices(Xgminer.Data.Configuration.Miner minerConfiguration, DeviceKind deviceKind, IList <Engine.Data.Configuration.Device> deviceConfigurations)
        {
            int deviceCount = 0;

            for (int i = 0; i < deviceConfigurations.Count; i++)
            {
                Engine.Data.Configuration.Device enabledConfiguration = deviceConfigurations[i];

                Xgminer.Data.Device device = devices.SingleOrDefault(d => d.Equals(enabledConfiguration));

                if (deviceKind != device.Kind)
                {
                    continue;
                }

                deviceCount++;

                minerConfiguration.DeviceDescriptors.Add(device);
            }
            return(deviceCount);
        }
Example #18
0
        private void StartMining()
        {
            IEnumerable <string> coinSymbols = engineConfiguration.DeviceConfigurations
                                               .Where(c => c.Enabled && !string.IsNullOrEmpty(c.CoinSymbol))
                                               .Select(c => c.CoinSymbol)
                                               .Distinct();

            int port = engineConfiguration.XgminerConfiguration.StartingApiPort;

            foreach (string coinSymbol in coinSymbols)
            {
                //launch separate processes for CPU & GPU vs USB & PXY (for stability)
                Xgminer.Data.Configuration.Miner minerConfiguration = CreateMinerConfiguration(port, coinSymbol, DeviceKind.CPU | DeviceKind.GPU);
                if (minerConfiguration != null)
                {
                    Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");
                    if (!process.HasExited)
                    {
                        MinerProcess minerProcess = StoreMinerProcess(process, coinSymbol, minerConfiguration, port);
                        minerProcess.TerminateProcess = engineConfiguration.XgminerConfiguration.TerminateGpuMiners;
                    }

                    port++;
                }

                minerConfiguration = CreateMinerConfiguration(port, coinSymbol, DeviceKind.PXY | DeviceKind.USB);
                if (minerConfiguration != null)
                {
                    Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");
                    if (!process.HasExited)
                    {
                        StoreMinerProcess(process, coinSymbol, minerConfiguration, port);
                    }

                    port++;
                }
            }

            mining = true;
        }
Example #19
0
        private Xgminer.Data.Configuration.Miner CreateBasicConfiguration(
            MinerDescriptor miner,
            Data.Configuration.Coin coinConfiguration,
            int apiPort)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath = MinerPath.GetPathToInstalledMiner(miner),
                Algorithm      = coinConfiguration.CryptoCoin.Algorithm,
                ApiPort        = apiPort,
                ApiListen      = true,
                AllowedApiIps  = engineConfiguration.XgminerConfiguration.AllowedApiIps,
                CoinName       = coinConfiguration.CryptoCoin.Name,
                DisableGpu     = engineConfiguration.XgminerConfiguration.DisableGpu
            };

            SetupConfigurationPools(minerConfiguration, coinConfiguration);

            SetupConfigurationArguments(minerConfiguration, coinConfiguration);

            return(minerConfiguration);
        }
Example #20
0
        private readonly Random random = new Random(Guid.NewGuid().GetHashCode()); //seed so we don't keep getting the same indexes
        private void AddDonationPool(string coinSymbol, Xgminer.Data.Configuration.Miner minerConfiguration)
        {
            MiningPool donationPool = null;

            Data.Configuration.Coin donationConfiguration = this.donationConfigurations.SingleOrDefault(dc => dc.CryptoCoin.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            if (donationConfiguration != null)
            {
                //inclusive lower, exclusive upper
                //int index = random.Next(0, donationConfiguration.Pools.Count);

                //for now just use the first pool, too many donors is *not* an issue
                //if it becomes an issue we can revert to the above
                int index = 0;
                donationPool = donationConfiguration.Pools[index];
            }

            if (donationPool != null)
            {
                donationPool.Quota = donationPercent;
                minerConfiguration.Pools.Add(donationPool);
            }
        }
Example #21
0
        public List <Device> GetDevices(MinerDescriptor minerDescriptor, string executablePath)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath  = executablePath,
                DisableGpu      = xgminerConfiguration.DisableGpu,
                DisableUsbProbe = xgminerConfiguration.DisableUsbProbe,
                ScanArguments   = xgminerConfiguration.ScanArguments
            };

            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration, false);

            Version       minerVersion    = new Version(MinerInstaller.GetInstalledMinerVersion(minerDescriptor, executablePath, false));
            List <Device> detectedDevices = miner.ListDevices(true, minerVersion);

            if (xgminerConfiguration.StratumProxy)
            {
                for (int i = 0; i < xgminerConfiguration.StratumProxies.Count; i++)
                {
                    MultiMiner.Engine.Data.Configuration.Xgminer.ProxyDescriptor proxy = xgminerConfiguration.StratumProxies[i];
                    detectedDevices.Add(new Device()
                    {
                        Kind   = DeviceKind.PXY,
                        Driver = "proxy",
                        Name   = String.Format("Stratum Proxy #{0}", (i + 1)),
                        //we want the path in the ViewModel for Remoting
                        //can't rely on having the Stratum Proxy settings
                        Path          = String.Format("{0}:{1}", proxy.GetworkPort, proxy.StratumPort),
                        RelativeIndex = i
                    });
                }
            }

            SortDevices(detectedDevices);

            return(detectedDevices);
        }
        public List<Device> GetDevices(MinerDescriptor minerDescriptor, string executablePath)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath = executablePath,
                DisableGpu = xgminerConfiguration.DisableGpu,
                DisableUsbProbe = xgminerConfiguration.DisableUsbProbe,
                ScanArguments = xgminerConfiguration.ScanArguments
            };

            Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration, false);

            Version minerVersion = new Version(MinerInstaller.GetInstalledMinerVersion(executablePath, false));
            List<Device> detectedDevices = miner.ListDevices(true, minerVersion);

            if (xgminerConfiguration.StratumProxy)
            {
                for (int i = 0; i < xgminerConfiguration.StratumProxies.Count; i++)
                {
                    MultiMiner.Engine.Data.Configuration.Xgminer.ProxyDescriptor proxy = xgminerConfiguration.StratumProxies[i];
                    detectedDevices.Add(new Device()
                    {
                        Kind = DeviceKind.PXY,
                        Driver = "proxy",
                        Name = String.Format("Stratum Proxy #{0}", (i + 1)),
                        //we want the path in the ViewModel for Remoting
                        //can't rely on having the Stratum Proxy settings
                        Path = String.Format("{0}:{1}", proxy.GetworkPort, proxy.StratumPort),
                        RelativeIndex = i
                    });
                }
            }

            SortDevices(detectedDevices);

            return detectedDevices;
        }
Example #23
0
        private Xgminer.Data.Configuration.Miner CreateBasicConfiguration(
            MinerDescriptor miner, 
            Data.Configuration.Coin coinConfiguration, 
            int apiPort)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
            {
                ExecutablePath = MinerPath.GetPathToInstalledMiner(miner),
                Algorithm = coinConfiguration.CryptoCoin.Algorithm,
                ApiPort = apiPort,
                ApiListen = true,
                AllowedApiIps = engineConfiguration.XgminerConfiguration.AllowedApiIps,
                CoinName = coinConfiguration.CryptoCoin.Name,
                DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu
            };

            SetupConfigurationPools(minerConfiguration, coinConfiguration);

            SetupConfigurationArguments(minerConfiguration, coinConfiguration);

            return minerConfiguration;
        }
Example #24
0
        static void Main(string[] args)
        {
            //examples of using MultiMiner.Xgminer.dll and MultiMiner.Xgminer.Api.dll

            //download and install the latest version of Gateless Gate
            const string executablePath = @"D:\gatelessgate\";
            const string executableName = "gatlessgate.exe";
            const string userAgent      = "MultiMiner/V3-Example";

            //download and install bfgminer from MultiMinerApp.com
            List <AvailableMiner> availableMiners = AvailableMiners.GetAvailableMiners(userAgent);
            AvailableMiner        gatelessgate    = availableMiners.Single(am => am.Name.Equals(MinerNames.GatelessGate, StringComparison.OrdinalIgnoreCase));

            Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}",
                              executableName, new Uri(gatelessgate.Url).Authority, executablePath);

            MinerInstaller.InstallMiner(userAgent, gatelessgate, 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, false);

                //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 = MinerFactory.Instance.GetAlgorithm(AlgorithmNames.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, false);
                    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();

                                //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)
                        {
                            //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();
        }
Example #25
0
        private MinerProcess StoreMinerProcess(Process process, MinerDescriptor miner, string coinSymbol, Xgminer.Data.Configuration.Miner minerConfiguration, int apiPort)
        {
            MinerProcess minerProcess = new MinerProcess()
            {
                Process            = process,
                Miner              = miner,
                ApiPort            = apiPort,
                MinerConfiguration = minerConfiguration,
                CoinSymbol         = coinSymbol
            };

            setupProcessStartInfo(minerProcess);

            minerProcesses.Add(minerProcess);

            return(minerProcess);
        }
Example #26
0
        private Xgminer.Data.Configuration.Miner CreateMinerConfiguration(int port, string coinSymbol, DeviceKind includeKinds)
        {
            Data.Configuration.Coin coinConfiguration = engineConfiguration.CoinConfigurations.Single(c => c.CryptoCoin.Symbol.Equals(coinSymbol));
            if (coinConfiguration.Pools.Count == 0)
                // no pools configured
                return null;

            IList<Engine.Data.Configuration.Device> enabledConfigurations = engineConfiguration.DeviceConfigurations.Where(c => c.Enabled && c.CoinSymbol.Equals(coinSymbol)).ToList();

            Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner() 
            { 
                ExecutablePath = MinerPath.GetPathToInstalledMiner(), 
                Algorithm = coinConfiguration.CryptoCoin.Algorithm, 
                ApiPort = port, 
                ApiListen = true, 
                AllowedApiIps = engineConfiguration.XgminerConfiguration.AllowedApiIps, 
                CoinName = coinConfiguration.CryptoCoin.Name, 
                DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu 
            };
            
            SetupConfigurationPools(minerConfiguration, coinConfiguration);

            int deviceCount = SetupConfigurationDevices(minerConfiguration, includeKinds, enabledConfigurations);
            if (deviceCount == 0)
                return null;

            SetupConfigurationArguments(minerConfiguration, coinConfiguration);

            return minerConfiguration;
        }
Example #27
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();
        }