예제 #1
0
        /// <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());
        }
예제 #2
0
        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;
            }
        }