public List<Device> GetDevices() { MinerConfiguration minerConfiguration = new MinerConfiguration() { ExecutablePath = MinerPath.GetPathToInstalledMiner(), DisableGpu = xgminerConfiguration.DisableGpu, DisableUsbProbe = xgminerConfiguration.DisableUsbProbe, ScanArguments = xgminerConfiguration.ScanArguments }; Miner miner = new 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; }
private Process LaunchMinerProcess(MinerConfiguration minerConfiguration, string reason) { minerConfiguration.Priority = this.engineConfiguration.XgminerConfiguration.Priority; Miner miner = new Miner(minerConfiguration); miner.LogLaunch += this.LogProcessLaunch; miner.LaunchFailed += this.ProcessLaunchFailed; miner.AuthenticationFailed += this.ProcessAuthenticationFailed; Process process = miner.Launch(reason); return process; }
private MinerConfiguration CreateMinerConfiguration(int port, string coinSymbol) { CoinConfiguration coinConfiguration = engineConfiguration.CoinConfigurations.Single(c => c.Coin.Symbol.Equals(coinSymbol)); IList<DeviceConfiguration> enabledConfigurations = engineConfiguration.DeviceConfigurations.Where(c => c.Enabled && c.CoinSymbol.Equals(coinSymbol)).ToList(); MinerConfiguration minerConfiguration = new MinerConfiguration(); minerConfiguration.MinerBackend = engineConfiguration.XgminerConfiguration.MinerBackend; minerConfiguration.ExecutablePath = MinerPath.GetPathToInstalledMiner(minerConfiguration.MinerBackend); minerConfiguration.ErupterDriver = engineConfiguration.XgminerConfiguration.ErupterDriver; minerConfiguration.Pools = coinConfiguration.Pools; minerConfiguration.Algorithm = coinConfiguration.Coin.Algorithm; minerConfiguration.ApiPort = port; minerConfiguration.ApiListen = true; minerConfiguration.AllowedApiIps = engineConfiguration.XgminerConfiguration.AllowedApiIps; minerConfiguration.CoinName = coinConfiguration.Coin.Name; minerConfiguration.DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu; int firstGpuIndex = GetIndexOfFirstGpu(); for (int i = 0; i < enabledConfigurations.Count; i++) { DeviceConfiguration enabledConfiguration = enabledConfigurations[i]; //don't actually add stratum device as a device index if (devices[enabledConfiguration.DeviceIndex].Kind != DeviceKind.PXY) { int deviceIndex = enabledConfiguration.DeviceIndex; if (coinConfiguration.Coin.Algorithm == CoinAlgorithm.Scrypt) { //launching bfgminer with --scrypt makes it ignore all USB devices //this wasn't an issue until 3.3.0 where -d? started returning GPUs last //rebase the device index by the number of non-GPU devices before this one deviceIndex = deviceIndex - firstGpuIndex; } minerConfiguration.DeviceIndexes.Add(deviceIndex); } else { //only enable the stratum proxy if these devices contain the PXY device minerConfiguration.StratumProxy = engineConfiguration.XgminerConfiguration.StratumProxy; minerConfiguration.StratumProxyPort = engineConfiguration.XgminerConfiguration.StratumProxyPort; } } string arguments = string.Empty; //apply algorithm-specific parameters if (engineConfiguration.XgminerConfiguration.AlgorithmFlags.ContainsKey(coinConfiguration.Coin.Algorithm)) arguments = String.Format("{0} {1}", arguments, engineConfiguration.XgminerConfiguration.AlgorithmFlags[coinConfiguration.Coin.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"; minerConfiguration.Arguments = arguments; return minerConfiguration; }
private void logProcessClose(DateTime startDate, DateTime endDate, string coinName, string coinSymbol, double priceAtStart, double priceAtEnd, List<int> deviceIndexes, MinerConfiguration minerConfiguration) { if (this.LogProcessClose != null) { LogProcessCloseArgs args = new LogProcessCloseArgs(); args.StartDate = startDate; args.EndDate = endDate; args.CoinName = coinName; args.CoinSymbol = coinSymbol; args.StartPrice = priceAtStart; args.EndPrice = priceAtEnd; args.DeviceIndexes = deviceIndexes; args.MinerConfiguration = minerConfiguration; this.LogProcessClose(this, args); } }
public Miner(MinerConfiguration minerConfig) { this.minerConfiguration = minerConfig; }
private void SetupConfigurationArguments(MinerConfiguration minerConfiguration, CoinConfiguration coinConfiguration) { string arguments = string.Empty; //apply algorithm-specific parameters if (engineConfiguration.XgminerConfiguration.AlgorithmFlags.ContainsKey(coinConfiguration.Coin.Algorithm)) arguments = String.Format("{0} {1}", arguments, engineConfiguration.XgminerConfiguration.AlgorithmFlags[coinConfiguration.Coin.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; }
private List<Device> GetDevices() { MinerConfiguration minerConfiguration = new MinerConfiguration(); minerConfiguration.MinerBackend = engineConfiguration.XgminerConfiguration.MinerBackend; minerConfiguration.ExecutablePath = MinerPath.GetPathToInstalledMiner(minerConfiguration.MinerBackend); minerConfiguration.ErupterDriver = engineConfiguration.XgminerConfiguration.ErupterDriver; minerConfiguration.DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu; Miner miner = new Miner(minerConfiguration); List<Device> detectedDevices = miner.ListDevices(); if ((engineConfiguration.XgminerConfiguration.MinerBackend == MinerBackend.Bfgminer) && engineConfiguration.XgminerConfiguration.StratumProxy) { Device proxyDevice = new Device(); proxyDevice.Kind = DeviceKind.PXY; proxyDevice.Driver = "proxy"; proxyDevice.Name = "Stratum Proxy"; proxyDevice.Identifier = "PXY"; proxyDevice.DeviceIndex = detectedDevices.Count; detectedDevices.Add(proxyDevice); } //sort GPUs first - the output of -d? changed with bfgminer 3.3.0 detectedDevices.Sort((d1, d2) => { int result = 0; result = d1.Kind.CompareTo(d2.Kind); if (result == 0) result = d1.DeviceIndex.CompareTo(d2.DeviceIndex); return result; }); return detectedDevices; }
private void StoreMinerProcess(Process process, MinerConfiguration minerConfiguration, int port) { MinerProcess minerProcess = new MinerProcess(); minerProcess.Process = process; minerProcess.ApiPort = port; minerProcess.MinerConfiguration = minerConfiguration; setupProcessStartInfo(minerProcess); minerProcesses.Add(minerProcess); }
private MinerConfiguration CreateMinerConfiguration(int port, string coinSymbol) { CoinConfiguration coinConfiguration = engineConfiguration.CoinConfigurations.Single(c => c.Coin.Symbol.Equals(coinSymbol)); IEnumerable<DeviceConfiguration> coinGpuConfigurations = engineConfiguration.DeviceConfigurations.Where(c => c.Enabled && c.CoinSymbol.Equals(coinSymbol)); MinerConfiguration minerConfiguration = new MinerConfiguration(); minerConfiguration.MinerBackend = engineConfiguration.XgminerConfiguration.MinerBackend; minerConfiguration.ExecutablePath = MinerPath.GetPathToInstalledMiner(minerConfiguration.MinerBackend); minerConfiguration.Pools = coinConfiguration.Pools; minerConfiguration.Algorithm = coinConfiguration.Coin.Algorithm; minerConfiguration.ApiPort = port; minerConfiguration.ApiListen = true; minerConfiguration.CoinName = coinConfiguration.Coin.Name; minerConfiguration.DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu; foreach (DeviceConfiguration coinGpuConfiguration in coinGpuConfigurations) minerConfiguration.DeviceIndexes.Add(coinGpuConfiguration.DeviceIndex); string arguments = string.Empty; //apply algorithm-specific parameters if (engineConfiguration.XgminerConfiguration.AlgorithmFlags.ContainsKey(coinConfiguration.Coin.Algorithm)) arguments = String.Format("{0} {1}", arguments, engineConfiguration.XgminerConfiguration.AlgorithmFlags[coinConfiguration.Coin.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"; minerConfiguration.Arguments = arguments; return minerConfiguration; }
private void AddDonationPool(string coinSymbol, MinerConfiguration minerConfiguration) { MiningPool donationPool = null; CoinConfiguration donationConfiguration = this.donationConfigurations.SingleOrDefault(dc => dc.Coin.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); } }
private MinerConfiguration CreateMinerConfiguration(int port, string coinSymbol, DeviceKind includeKinds) { CoinConfiguration coinConfiguration = engineConfiguration.CoinConfigurations.Single(c => c.Coin.Symbol.Equals(coinSymbol)); IList<DeviceConfiguration> enabledConfigurations = engineConfiguration.DeviceConfigurations.Where(c => c.Enabled && c.CoinSymbol.Equals(coinSymbol)).ToList(); MinerConfiguration minerConfiguration = new MinerConfiguration(); minerConfiguration.ExecutablePath = MinerPath.GetPathToInstalledMiner(); //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(coinSymbol, minerConfiguration); minerConfiguration.Algorithm = coinConfiguration.Coin.Algorithm; minerConfiguration.ApiPort = port; minerConfiguration.ApiListen = true; minerConfiguration.AllowedApiIps = engineConfiguration.XgminerConfiguration.AllowedApiIps; minerConfiguration.CoinName = coinConfiguration.Coin.Name; minerConfiguration.DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu; int deviceCount = 0; for (int i = 0; i < enabledConfigurations.Count; i++) { DeviceConfiguration enabledConfiguration = enabledConfigurations[i]; Device device = devices.SingleOrDefault(d => d.Equals(enabledConfiguration)); if ((includeKinds & 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; } } if (deviceCount == 0) return null; string arguments = string.Empty; //apply algorithm-specific parameters if (engineConfiguration.XgminerConfiguration.AlgorithmFlags.ContainsKey(coinConfiguration.Coin.Algorithm)) arguments = String.Format("{0} {1}", arguments, engineConfiguration.XgminerConfiguration.AlgorithmFlags[coinConfiguration.Coin.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; return minerConfiguration; }
private MinerProcess StoreMinerProcess(Process process, string coinSymbol, MinerConfiguration 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; }
private void SetupConfigurationPools(MinerConfiguration minerConfiguration, CoinConfiguration 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.Coin.Symbol, minerConfiguration); foreach (MiningPool pool in minerConfiguration.Pools) pool.QuotaEnabled = donationPercent > 0; }
private int SetupConfigurationDevices(MinerConfiguration minerConfiguration, DeviceKind deviceKinds, IList<DeviceConfiguration> deviceConfigurations) { int deviceCount = 0; for (int i = 0; i < deviceConfigurations.Count; i++) { DeviceConfiguration enabledConfiguration = deviceConfigurations[i]; 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; }
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"; MinerBackend minerBackend = MinerBackend.Bfgminer; Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}", executableName, Xgminer.Installer.GetMinerDownloadRoot(minerBackend), executablePath); //download and install bfgminer from the official website Xgminer.Installer.InstallMiner(minerBackend, executablePath); try { //create an instance of Miner with the downloaded executable MinerConfiguration minerConfiguration = new MinerConfiguration() { MinerBackend = minerBackend, ExecutablePath = Path.Combine(executablePath, executableName) }; Miner miner = new Miner(minerConfiguration); //use it to iterate through devices List<Device> deviceList = miner.DeviceList(); 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.Identifier); //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.DeviceIndexes.Add(i); //enable RPC API minerConfiguration.ApiListen = true; minerConfiguration.ApiPort = 4028; Console.WriteLine("Launching {0}", executableName); //start mining miner = new 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.DeviceInformation> deviceInformation = apiContext.GetDeviceInformation(); //output device information foreach (Xgminer.Api.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(); }
private List<Device> GetDevices() { MinerConfiguration minerConfiguration = new MinerConfiguration(); minerConfiguration.MinerBackend = engineConfiguration.XgminerConfiguration.MinerBackend; minerConfiguration.ExecutablePath = MinerPath.GetPathToInstalledMiner(minerConfiguration.MinerBackend); minerConfiguration.DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu; Miner miner = new Miner(minerConfiguration); return miner.DeviceList(); }
private MinerConfiguration CreateMinerConfiguration(int port, string coinSymbol, DeviceKind includeKinds) { CoinConfiguration coinConfiguration = engineConfiguration.CoinConfigurations.Single(c => c.Coin.Symbol.Equals(coinSymbol)); IList<DeviceConfiguration> enabledConfigurations = engineConfiguration.DeviceConfigurations.Where(c => c.Enabled && c.CoinSymbol.Equals(coinSymbol)).ToList(); MinerConfiguration minerConfiguration = new MinerConfiguration() { ExecutablePath = MinerPath.GetPathToInstalledMiner(), Algorithm = coinConfiguration.Coin.Algorithm, ApiPort = port, ApiListen = true, AllowedApiIps = engineConfiguration.XgminerConfiguration.AllowedApiIps, CoinName = coinConfiguration.Coin.Name, DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu }; SetupConfigurationPools(minerConfiguration, coinConfiguration); int deviceCount = SetupConfigurationDevices(minerConfiguration, includeKinds, enabledConfigurations); if (deviceCount == 0) return null; SetupConfigurationArguments(minerConfiguration, coinConfiguration); return minerConfiguration; }