public GetInfoModel GetInfo()
        {
            var model = new GetInfoModel
            {
                version         = this.FullNode?.Version.ToUint() ?? 0,
                protocolversion = (uint)(this.Settings?.ProtocolVersion ?? NodeSettings.SupportedProtocolVersion),
                blocks          = this.ChainState?.ConsensusTip?.Height ?? 0,
                timeoffset      = this.ConnectionManager?.ConnectedNodes?.GetMedianTimeOffset() ?? 0,
                connections     = this.ConnectionManager?.ConnectedNodes?.Count(),
                proxy           = string.Empty,
                difficulty      = this.GetNetworkDifficulty()?.Difficulty ?? 0,
                testnet         = this.Network.IsTest(),
                relayfee        = this.Settings.MinRelayTxFeeRate.FeePerK.ToUnit(MoneyUnit.BTC),
                errors          = string.Empty,

                //TODO: Wallet related infos: walletversion, balance, keypoololdest, keypoolsize, unlocked_until, paytxfee
                walletversion  = null,
                balance        = null,
                keypoololdest  = null,
                keypoolsize    = null,
                unlocked_until = null,
                paytxfee       = null
            };


            return(model);
        }
Beispiel #2
0
        public void CallWithDependencies()
        {
            string             dir        = CreateTestDir(this);
            IFullNode          fullNode   = this.BuildServicedNode(dir);
            FullNodeController controller = fullNode.Services.ServiceProvider.GetService <FullNodeController>();

            Assert.NotNull(fullNode.NodeService <INetworkDifficulty>(true));

            GetInfoModel info = controller.GetInfo();

            NodeSettings nodeSettings            = NodeSettings.Default();
            uint         expectedProtocolVersion = (uint)nodeSettings.ProtocolVersion;
            var          expectedRelayFee        = nodeSettings.MinRelayTxFeeRate.FeePerK.ToUnit(NBitcoin.MoneyUnit.BTC);

            Assert.NotNull(info);
            Assert.Equal(0, info.Blocks);
            Assert.NotEqual <uint>(0, info.Version);
            Assert.Equal(expectedProtocolVersion, info.ProtocolVersion);
            Assert.Equal(0, info.TimeOffset);
            Assert.Equal(0, info.Connections);
            Assert.NotNull(info.Proxy);
            Assert.Equal(0, info.Difficulty);
            Assert.False(info.Testnet);
            Assert.Equal(expectedRelayFee, info.RelayFee);
            Assert.Empty(info.Errors);
        }
Beispiel #3
0
        public GetInfoModel GetInfo()
        {
            var model = new GetInfoModel
            {
                Version         = this.FullNode?.Version?.ToUint() ?? 0,
                ProtocolVersion = (uint)(this.Settings?.ProtocolVersion ?? NodeSettings.SupportedProtocolVersion),
                Blocks          = this.ChainState?.ConsensusTip?.Height ?? 0,
                TimeOffset      = this.ConnectionManager?.ConnectedPeers?.GetMedianTimeOffset() ?? 0,
                Connections     = this.ConnectionManager?.ConnectedPeers?.Count(),
                Proxy           = string.Empty,
                Difficulty      = this.GetNetworkDifficulty()?.Difficulty ?? 0,
                Testnet         = this.Network.IsTest(),
                RelayFee        = this.Settings?.MinRelayTxFeeRate?.FeePerK?.ToUnit(MoneyUnit.BTC) ?? 0,
                Errors          = string.Empty,

                //TODO: Wallet related infos: walletversion, balance, keypNetwoololdest, keypoolsize, unlocked_until, paytxfee
                WalletVersion = null,
                Balance       = null,
                KeypoolOldest = null,
                KeypoolSize   = null,
                UnlockedUntil = null,
                PayTxFee      = null
            };

            return(model);
        }
        public GetInfoModel GetInfo()
        {
            var model = new GetInfoModel()
            {
                version         = this._FullNode?.Version.ToUint() ?? 0,
                protocolversion = (uint)(this._Settings?.ProtocolVersion ?? NodeSettings.SupportedProtocolVersion),
                blocks          = this._ChainState?.HighestValidatedPoW?.Height ?? 0,
                timeoffset      = 0, // TODO: Calculate median time offset of connected nodes
                connections     = this._ConnectionManager?.ConnectedNodes?.Count(),
                proxy           = string.Empty,
                difficulty      = GetNetworkDifficulty()?.Difficulty ?? 0,
                testnet         = this._Network == NBitcoin.Network.TestNet,
                relayfee        = MempoolValidator.MinRelayTxFee.FeePerK.ToUnit(MoneyUnit.BTC),
                errors          = string.Empty,

                //TODO: Wallet related infos: walletversion, balance, keypoololdest, keypoolsize, unlocked_until, paytxfee
                walletversion  = null,
                balance        = null,
                keypoololdest  = null,
                keypoolsize    = null,
                unlocked_until = null,
                paytxfee       = null
            };


            return(model);
        }
Beispiel #5
0
        public void CallWithDependencies()
        {
            string             dir        = AssureEmptyDir("TestData/GetInfoActionTests/CallWithDependencies");
            IFullNode          fullNode   = this.BuildServicedNode(dir);
            FullNodeController controller = fullNode.Services.ServiceProvider.GetService <FullNodeController>();

            Assert.NotNull(fullNode.NodeService <INetworkDifficulty>(true));

            GetInfoModel info = controller.GetInfo();

            uint expectedProtocolVersion = (uint)NodeSettings.Default().ProtocolVersion;
            var  expectedRelayFee        = MempoolValidator.MinRelayTxFee.FeePerK.ToUnit(NBitcoin.MoneyUnit.BTC);

            Assert.NotNull(info);
            Assert.Equal(0, info.blocks);
            Assert.NotEqual <uint>(0, info.version);
            Assert.Equal(expectedProtocolVersion, info.protocolversion);
            Assert.Equal(0, info.timeoffset);
            Assert.Equal(0, info.connections);
            Assert.NotNull(info.proxy);
            Assert.Equal(0, info.difficulty);
            Assert.False(info.testnet);
            Assert.Equal(expectedRelayFee, info.relayfee);
            Assert.Empty(info.errors);
        }
        public void GetInfo_NoNetworkDifficulty_ReturnsModel()
        {
            this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, null,
                                                     this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object);
            GetInfoModel model = this.controller.GetInfo();

            Assert.Equal(0, model.Difficulty);
        }
        public void GetInfo_MainNet_ReturnsInfoModel()
        {
            this.network = KnownNetworks.Main;

            this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object,
                                                     this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object);
            GetInfoModel model = this.controller.GetInfo();

            Assert.False(model.Testnet);
        }
        public void GetInfo_NoSettings_ReturnsModel()
        {
            this.nodeSettings = null;
            this.controller   = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object,
                                                       this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object);
            GetInfoModel model = this.controller.GetInfo();

            Assert.Equal((uint)NodeSettings.SupportedProtocolVersion, model.ProtocolVersion);
            Assert.Equal(0, model.RelayFee);
        }
        public void GetInfo_NoChainState_ReturnsModel()
        {
            IChainState chainState = null;

            this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object,
                                                     this.fullNode.Object, this.nodeSettings, this.network, this.chain, chainState, this.connectionManager.Object);
            GetInfoModel model = this.controller.GetInfo();

            Assert.Equal(0, model.Blocks);
        }
        public void GetInfo_NoVersion_ReturnsModel()
        {
            this.fullNode.Setup(f => f.Version)
            .Returns((Version)null);

            this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object,
                                                     this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object);
            GetInfoModel model = this.controller.GetInfo();

            Assert.Equal((uint)0, model.Version);
        }
        public void GetInfo_NoChainTip_ReturnsModel()
        {
            this.chainState.Setup(c => c.ConsensusTip)
            .Returns((ChainedHeader)null);

            this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object,
                                                     this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object);
            GetInfoModel model = this.controller.GetInfo();

            Assert.Equal(0, model.Blocks);
        }
        public async Task <IActionResult> Index()
        {
            var model  = new GetInfoModel();
            var result = await _teacherService.GetTeachers(new GetTeachersInput());

            if (result.IsSuccessed)
            {
                model.Value = result.Value;
            }
            return(View(model));
        }
        public void GetInfo_NoConnectionManager_ReturnsModel()
        {
            IConnectionManager connectionManager = null;

            this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object,
                                                     this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, connectionManager);
            GetInfoModel model = this.controller.GetInfo();

            Assert.Equal(0, model.TimeOffset);
            Assert.Null(model.Connections);
        }
Beispiel #14
0
        public void GetInfoSerializeSparseTest()
        {
            string[] expectedOrderedPropertyNames = RequiredPropertyNames;
            var      info = new GetInfoModel();

            JObject obj = JObject.FromObject(info);

            Assert.True(obj.HasValues);
            IEnumerable <string> actualOrderedPropertyNames = obj.Children().Select(o => (o as JProperty)?.Name);

            Assert.Equal(expectedOrderedPropertyNames, actualOrderedPropertyNames);
        }
        public void GetInfoSerializeSparseTest()
        {
            var expectedOrderedPropertyNames = RequiredPropertyNames;
            var info = new GetInfoModel();

            JObject obj = ModelToJObject(info);

            Assert.True(obj.HasValues);
            var actualOrderedPropertyNames = obj.Children().Select(o => (o as JProperty)?.Name);

            Assert.Equal(expectedOrderedPropertyNames, actualOrderedPropertyNames);
        }
Beispiel #16
0
        /// <summary>
        /// Get info about account. Returns model object of Getinfo method.
        /// </summary>
        /// <returns>
        /// GetInfoModel
        /// </returns>
        public GetInfoModel GetInfo()
        {
            if (!IsPrivateAPIPossible())
            {
                throw new ArgumentException("This method need key and secret (key and id)");
            }
            IRestRequest req = new RestRequest();

            req = addMandatoryParameters(req, "account", "info");
            string       resp    = client.Execute(req).Content;
            GetInfoModel getinfo = JsonConvert.DeserializeObject <GetInfoModel>(resp);

            return(getinfo);
        }
        public void GetInfoDeserializeFullTest()
        {
            IOrderedEnumerable <string> expectedSortedPropertyNames = AllPropertyNames.OrderBy(name => name);
            string json = "{\n" +
                          "     \"version\": 1010000,\n" +
                          "     \"protocolversion\": 70012,\n" +
                          "     \"walletversion\": 60000,\n" +
                          "     \"balance\": 0.00000002,\n" +
                          "     \"blocks\": 460828,\n" +
                          "     \"timeoffset\": 0,\n" +
                          "     \"connections\": 44,\n" +
                          "     \"proxy\": \"\",\n" +
                          "     \"difficulty\": 499635929816.6675,\n" +
                          "     \"testnet\": false,\n" +
                          "     \"keypoololdest\": 1437418454,\n" +
                          "     \"keypoolsize\": 101,\n" +
                          "     \"unlocked_until\": 0,\n" +
                          "     \"paytxfee\": 0.00010000,\n" +
                          "     \"relayfee\": 0.00001000,\n" +
                          "     \"errors\": \"URGENT: Alert key compromised, upgrade required\"\n" +
                          "   }\n";

            JObject obj = JObject.Parse(json);
            IOrderedEnumerable <string> actualSortedPropertyNames = obj.Children().Select(o => (o as JProperty)?.Name).OrderBy(name => name);
            GetInfoModel model = Newtonsoft.Json.JsonConvert.DeserializeObject <GetInfoModel>(json);

            Assert.Equal(expectedSortedPropertyNames, actualSortedPropertyNames);
            Assert.Equal(1010000u, model.version);
            Assert.Equal(70012u, model.protocolversion);
            Assert.Equal(Money.Satoshis(2).ToUnit(MoneyUnit.BTC), model.balance);
            Assert.Equal(460828, model.blocks);
            Assert.Equal(0, model.timeoffset);
            Assert.Equal(44, model.connections);
            Assert.Empty(model.proxy);
            Assert.Equal(499635929816.6675, model.difficulty, 3);
            Assert.False(model.testnet);
            Assert.Equal(1437418454, model.keypoololdest);
            Assert.Equal(101, model.keypoolsize);
            Assert.Equal(0u, model.unlocked_until);
            Assert.Equal(Money.Satoshis(10000).ToUnit(MoneyUnit.BTC), model.paytxfee);
            Assert.Equal(Money.Satoshis(1000).ToUnit(MoneyUnit.BTC), model.relayfee);
            Assert.Equal("URGENT: Alert key compromised, upgrade required", model.errors);
        }
        public void GetInfoSerializeFullTest()
        {
            var expectedOrderedPropertyNames = AllPropertyNames;
            var info = new GetInfoModel
            {
                Connections   = 0,
                WalletVersion = default(uint),
                Balance       = default(decimal),
                KeypoolOldest = default(long),
                KeypoolSize   = default(int),
                UnlockedUntil = default(uint),
                PayTxFee      = default(decimal),
            };

            JObject obj = ModelToJObject(info);

            Assert.True(obj.HasValues);
            var actualOrderedPropertyNames = obj.Children().Select(o => (o as JProperty)?.Name);

            Assert.Equal(expectedOrderedPropertyNames, actualOrderedPropertyNames);
        }
        public void GetInfoSerializeFullTest()
        {
            var expectedOrderedPropertyNames = AllPropertyNames;
            var info = new GetInfoModel()
            {
                connections    = 0,
                walletversion  = default(uint),
                balance        = default(decimal),
                keypoololdest  = default(long),
                keypoolsize    = default(int),
                unlocked_until = default(uint),
                paytxfee       = default(decimal),
            };

            JObject obj = ModelToJObject(info);

            Assert.True(obj.HasValues);
            var actualOrderedPropertyNames = obj.Children().Select(o => (o as JProperty)?.Name);

            Assert.Equal(expectedOrderedPropertyNames, actualOrderedPropertyNames);
        }
        public void GetInfo_TestNet_ReturnsInfoModel()
        {
            this.nodeSettings = new NodeSettings(protocolVersion: ProtocolVersion.NO_BLOOM_VERSION, args: new[] { "-minrelaytxfeerate=1000" });
            this.controller   = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object,
                                                       this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object);

            this.fullNode.Setup(f => f.Version)
            .Returns(new Version(15, 0));
            this.networkDifficulty.Setup(n => n.GetNetworkDifficulty())
            .Returns(new Target(121221121212));

            this.chainState.Setup(c => c.ConsensusTip)
            .Returns(this.chain.Tip);

            this.connectionManager.Setup(c => c.ConnectedPeers)
            .Returns(new TestReadOnlyNetworkPeerCollection());

            GetInfoModel model = this.controller.GetInfo();

            Assert.Equal((uint)14999899, model.Version);
            Assert.Equal((uint)ProtocolVersion.NO_BLOOM_VERSION, model.ProtocolVersion);
            Assert.Equal(3, model.Blocks);
            Assert.Equal(0, model.TimeOffset);
            Assert.Equal(0, model.Connections);
            Assert.Empty(model.Proxy);
            Assert.Equal(new Target(121221121212).Difficulty, model.Difficulty);
            Assert.True(model.Testnet);
            Assert.Equal(0.00001m, model.RelayFee);
            Assert.Empty(model.Errors);

            Assert.Null(model.WalletVersion);
            Assert.Null(model.Balance);
            Assert.Null(model.KeypoolOldest);
            Assert.Null(model.KeypoolSize);
            Assert.Null(model.UnlockedUntil);
            Assert.Null(model.PayTxFee);
        }
        public void CallWithoutDependencies()
        {
            var controller = new FullNodeController();

            GetInfoModel info = controller.GetInfo();

            Assert.NotNull(info);
            Assert.NotNull(info.version);
            Assert.NotNull(info.protocolversion);
            Assert.NotNull(info.blocks);
            Assert.NotNull(info.timeoffset);
            Assert.Null(info.connections);
            Assert.NotNull(info.proxy);
            Assert.NotNull(info.difficulty);
            Assert.NotNull(info.testnet);
            Assert.NotNull(info.relayfee);
            Assert.NotNull(info.errors);
            Assert.Null(info.walletversion);
            Assert.Null(info.balance);
            Assert.Null(info.keypoololdest);
            Assert.Null(info.keypoolsize);
            Assert.Null(info.unlocked_until);
            Assert.Null(info.paytxfee);
        }
Beispiel #22
0
        //[Authorize(AuthenticationSchemes = "jwt")]
        public APIResult GetInfo([FromBody] GetSingleArgs args)
        {
            var shopModel = db.Query <Shop>()
                            .Where(m => m.Flag == args.Flag)
                            .Select(m => new GetSingleModel()
            {
                AddIp        = m.AddIp,
                AddTime      = m.AddTime,
                AddUser      = m.AddUser,
                Flag         = m.Flag,
                Id           = m.Id,
                Address      = m.Address,
                AddressGuide = m.AddressGuide,
                Detail       = m.Detail,
                IsDel        = m.IsDel,
                Latitude     = m.Latitude,
                Longitude    = m.Longitude,
                Name         = m.Name,
                OpenTime     = m.OpenTime,
                ScoreValue   = m.ScoreValue,
                Tel          = m.Tel,
                UsePerUser   = m.UsePerUser,
                Cover        = m.Cover,
                IsSelfHelp   = m.IsSelfHelp,
                Logo         = m.Logo,
            })
                            .FirstOrDefault();


            if (shopModel == null)
            {
                throw new Exception("记录不存在");
            }


            shopModel.CurrentVersion = db.Query <ShopWechatOpenAuthorizer>()
                                       .Where(m => !m.IsDel)
                                       .Where(m => m.ShopId == shopModel.Id)
                                       .FirstOrDefault()?.CurrentTemplateUserVersion;

            if (shopModel.IsSelfHelp) //自助点餐
            {
                shopModel.DiningWay          = 0;
                shopModel.HasSelfHelpTakeout = true;  //当前默认都有外带
                ShopSelfHelpInfo selfHelpInfo = db.Query <ShopSelfHelpInfo>()
                                                .Where(m => !m.IsDel && m.ShopId == shopModel.Id)
                                                .FirstOrDefault();
                if (selfHelpInfo != null && selfHelpInfo.HasBoxFee)
                {
                    shopModel.SelfHelpBoxFee = selfHelpInfo.BoxFee;
                }
                //shopModel.HasSelfHelpTakeout = db.Query<ShopSelfHelpInfo>()
                //    .Where(m => !m.IsDel && m.ShopId == shopModel.Id)
                //    .FirstOrDefault()?
                //    .HasTakeOut ?? false;
            }
            else
            {
                shopModel.DiningWay = 1;
            }
            var shopMemberSet = db.Query <ShopMemberSet>()
                                .FirstOrDefault(m => !m.IsDel && m.ShopId == shopModel.Id);

            if (shopMemberSet == null)
            {
                shopModel.IsTopUpDiscount = false;
            }
            else
            {
                shopModel.IsTopUpDiscount = shopMemberSet.IsTopUpDiscount;
            }

            var viewModel = new GetInfoModel()
            {
                ShopInfo    = shopModel,
                BannerModel = Utils.ExBannerModels.GetBannerList(db, args.Flag)
            };

            viewModel.TakeOutInfo = db.Query <ShopTakeOutInfo>()
                                    .Where(m => !m.IsDel && m.ShopId == shopModel.Id)
                                    .Select(m => new TakeOutInfo()
            {
                IsUseTakeOut = m.IsUseTakeOut,
                BoxFee       = m.BoxFee / 100m,
                DeliveryFee  = m.DeliveryFee / 100m,
                IsOpen       = m.IsOpen,
                MinAmount    = m.MinAmount / 100m,
                StartTime    = m.StartTime == null ? " " : m.StartTime.Value.ToString("HH:mm"),
                EndTime      = m.EndTime == null ? " " : m.EndTime.Value.ToString("HH:mm")
            })
                                    .FirstOrDefault();

            if (shopModel.Latitude.HasValue && shopModel.Longitude.HasValue)
            {
                var TxCoordinate = BaiduMapUtil.CoverCoordinateToTX(shopModel.Latitude.Value, shopModel.Longitude.Value);
                shopModel.Latitude  = TxCoordinate.lati;
                shopModel.Longitude = TxCoordinate.logi;
            }

            //shopMember信息
            //try
            //{
            //    var memberId = GetMemberId();
            //    viewModel.ShopMember = db.Query<ShopMember>()
            //        .Where(m => !m.IsDel && m.MemberId == memberId && m.ShopId == shopModel.Id)
            //        .FirstOrDefault();
            //}
            //catch (Exception)
            //{

            //}

            return(Success(viewModel));
        }