public void Recache() { try // read getinfo() based data. { var info = _daemonClient.GetInfo(); // read data. CoinVersion = info.Version; ProtocolVersion = info.ProtocolVersion; WalletVersion = info.WalletVersion; Testnet = info.Testnet; Connections = info.Connections; Errors = info.Errors; // check if our network connection is healthy. Healthy = Connections >= 0 && string.IsNullOrEmpty(Errors); } catch (RpcException e) { _logger.Error("Can not read getinfo(): {0:l}", e.Message); Healthy = false; // set healthy status to false as we couldn't get a reply. } try // read getmininginfo() based data. { var miningInfo = _daemonClient.GetMiningInfo(); // read data. Hashrate = miningInfo.NetworkHashPerSec; Difficulty = miningInfo.Difficulty; Round = miningInfo.Blocks + 1; } catch (RpcException e) { _logger.Error("Can not read getmininginfo(): {0:l}", e.Message); Hashrate = 0; Difficulty = 0; Round = -1; Healthy = false; // set healthy status to false as we couldn't get a reply. } try // read getblocktemplate() based data. { var blockTemplate = _daemonClient.GetBlockTemplate(_poolConfig.Coin.Options.BlockTemplateModeRequired); Reward = (UInt64)blockTemplate.Coinbasevalue / 100000000; // coinbasevalue is in satoshis, convert it to actual coins. } catch (RpcException e) { _logger.Error("Can not read getblocktemplate(): {0:l}", e.Message); Reward = 0; } }
/// <summary> /// Initialize mock objects. /// </summary> public PoolTests() { // factory mockup. _objectFactory = Substitute.For<IObjectFactory>(); // pool-config mockup. _config = Substitute.For<IPoolConfig>(); _config.Daemon.Valid.Returns(true); // daemon client mockup. _daemonClient = _objectFactory.GetDaemonClient(_config.Coin.Name, _config.Daemon); _daemonClient.GetInfo().Returns(new Info()); _daemonClient.GetMiningInfo().Returns(new MiningInfo()); }
/// <summary> /// Initialize mock objects. /// </summary> public PoolTests() { // factory mockup. _objectFactory = Substitute.For <IObjectFactory>(); // pool-config mockup. _config = Substitute.For <IPoolConfig>(); _config.Daemon.Valid.Returns(true); // daemon client mockup. _daemonClient = _objectFactory.GetDaemonClient(_config); _daemonClient.GetInfo().Returns(new Info()); _daemonClient.GetMiningInfo().Returns(new MiningInfo()); }
private void InitDaemon() { if (Config.Daemon == null || Config.Daemon.Valid == false) { _logger.Error("Coin daemon configuration is not valid!"); return; } _daemonClient = _objectFactory.GetDaemonClient(Config); _hashAlgorithm = _objectFactory.GetHashAlgorithm(Config.Coin.Algorithm); try { var info = _daemonClient.GetInfo(); _logger.Information("Coin symbol: {0:l} algorithm: {1:l} " + "Coin version: {2} protocol: {3} wallet: {4} " + "Daemon network: {5:l} peers: {6} blocks: {7} errors: {8:l} ", Config.Coin.Symbol, Config.Coin.Algorithm, info.Version, info.ProtocolVersion, info.WalletVersion, info.Testnet ? "testnet" : "mainnet", info.Connections, info.Blocks, string.IsNullOrEmpty(info.Errors) ? "none" : info.Errors); } catch (RpcException e) { _logger.Error("Can not read getinfo(): {0:l}", e.Message); return; } try { // try reading mininginfo(), some coins may not support it. var miningInfo = _daemonClient.GetMiningInfo(); _logger.Information("Network difficulty: {0:0.00000000} block difficulty: {1:0.00} Network hashrate: {2:l} ", miningInfo.Difficulty, miningInfo.Difficulty * _hashAlgorithm.Multiplier, miningInfo.NetworkHashps.GetReadableHashrate()); } catch (RpcException e) { _logger.Error("Can not read mininginfo() - the coin may not support the request: {0:l}", e.Message); } }
private void ReadCoinData() { try { var miningInfo = _daemonClient.GetMiningInfo(); NetworkHashrate = miningInfo.NetworkHashps; Difficulty = miningInfo.Difficulty; Round = miningInfo.Blocks + 1; } catch (RpcException) { NetworkHashrate = 0; Difficulty = 0; Round = -1; } }
/// <summary> /// Initialize mock objects. /// </summary> public PoolTests() { // factory mockup. _objectFactory = Substitute.For <IObjectFactory>(); // config-manager mockup _configManager = Substitute.For <IConfigManager>(); // pool-config mockup. _config = Substitute.For <IPoolConfig>(); _config.Daemon.Valid.Returns(true); // daemon client mockup. _daemonClient = _objectFactory.GetDaemonClient(_config.Daemon, _config.Coin); _daemonClient.GetInfo().Returns(new Info()); _daemonClient.GetBlockChainInfo().Returns(new Info()); _daemonClient.GetNetworkInfo().Returns(new Info()); _daemonClient.GetWalletInfo().Returns(new Info()); _daemonClient.GetMiningInfo().Returns(new MiningInfo()); }
public void Recache() { try // read getinfo() based data. { var info = _daemonClient.GetInfo(); // read data. CoinVersion = info.Version; ProtocolVersion = info.ProtocolVersion; WalletVersion = info.WalletVersion; Testnet = info.Testnet; Connections = info.Connections; Errors = info.Errors; // check if our network connection is healthy. Healthy = Connections >= 0 && string.IsNullOrEmpty(Errors); } catch (RpcException e) { _logger.Error("Can not read getinfo(): {0:l}", e.Message); Healthy = false; // set healthy status to false as we couldn't get a reply. } try // read mininginfo() based data. { var miningInfo = _daemonClient.GetMiningInfo(); // read data. Hashrate = miningInfo.NetworkHashps; Difficulty = miningInfo.Difficulty; Round = miningInfo.Blocks + 1; } catch (RpcException e) { _logger.Error("Can not read mininginfo() - the coin may not support the request: {0:l}", e.Message); Hashrate = 0; Difficulty = 0; Round = -1; Healthy = false; // set healthy status to false as we couldn't get a reply. } }
public void Recache() { try // read getnetworkinfo() followed by getwalletinfo() based data. { var info = _daemonClient.GetNetworkInfo(); // read Getnetwork CoinVersion = info.Version; ProtocolVersion = info.ProtocolVersion; Connections = info.Connections; Errors = info.Errors; try // read getwalletinfo() based data. { var infoWall = _daemonClient.GetWalletInfo(); // read data WalletVersion = infoWall.WalletVersion; } catch (RpcException e) { _logger.Error("Can not read getwalletinfo(): {0:l}", e.Message); Healthy = false; // set healthy status to false as we couldn't get a reply. } // check if our network connection is healthy. info: based errors are warnings only so ignore. Healthy = Connections >= 0 && (string.IsNullOrEmpty(Errors) || Errors.Contains("Info:")); } catch (RpcException) // catch exception, provide backwards compatability for getinfo() based data. { // do not log this as an actual error, but rather as info only, then proceed to try getinfo(). //_logger.Error("Can not read getnetworkinfo(), trying getinfo() instead: {0:l}", c.Message); // do not log original error, try getinfo() first. try // catch exception, provide backwards compatability for getinfo() based data. { var info = _daemonClient.GetInfo(); // read data. CoinVersion = info.Version; ProtocolVersion = info.ProtocolVersion; WalletVersion = info.WalletVersion; Testnet = info.Testnet; Connections = info.Connections; Errors = info.Errors; // check if our network connection is healthy. info: based errors are warnings only so ignore. Healthy = Connections >= 0 && (string.IsNullOrEmpty(Errors) || Errors.Contains("Info:")); } catch (RpcException ee) { _logger.Error("Can not read getinfo(): {0:l}", ee.Message); Healthy = false; // set healthy status to false as we couldn't get a reply. } } try // read getmininginfo() based data. { var miningInfo = _daemonClient.GetMiningInfo(); // read data. Hashrate = miningInfo.NetworkHashPerSec; Difficulty = miningInfo.Difficulty; Round = miningInfo.Blocks + 1; if (!Testnet) { Testnet = miningInfo.Testnet; } } catch (RpcException e) { _logger.Error("Can not read getmininginfo(): {0:l}", e.Message); Hashrate = 0; Difficulty = 0; Round = -1; Healthy = false; // set healthy status to false as we couldn't get a reply. } try // read getblocktemplate() based data. { var blockTemplate = _daemonClient.GetBlockTemplate(_poolConfig.Coin.Options.BlockTemplateModeRequired); Reward = (UInt64)blockTemplate.Coinbasevalue / 100000000; // coinbasevalue is in satoshis, convert it to actual coins. } catch (RpcException e) { _logger.Error("Can not read getblocktemplate(): {0:l}", e.Message); Reward = 0; } }