Пример #1
0
        protected async Task <NodeStatus> UpdateNodeStatus()
        {
            NodeStatus nodeStatus = new NodeStatus();

            try
            {
                StatusResponse = await _apiRequester.GetRequestAsync(_endpoint, "/api/Node/status");

                nodeStatus.BlockStoreHeight = StatusResponse.Content.blockStoreHeight;
                nodeStatus.ConsensusHeight  = StatusResponse.Content.consensusHeight;
                string upTimeLargePrecion = StatusResponse.Content.runningTime;
                nodeStatus.Uptime = upTimeLargePrecion.Split('.')[0];
                nodeStatus.State  = StatusResponse.Content.state;
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Failed to update node status");
            }

            return(nodeStatus);
        }
        /// <summary>
        /// Retrieve all node information and store it in IDistributedCache object
        /// </summary>
        /// <returns></returns>
        private async Task BuildCacheAsync()
        {
            string walletName = "clintm";

            #region Stratis Node
            ApiResponse stratisStatus = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Node/status");

            ApiResponse stratisRawmempool = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Mempool/getrawmempool");

            ApiResponse stratisBestBlock = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Consensus/getbestblockhash");

            ApiResponse stratisWalletHistory = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, $"/api/Wallet/history?WalletName={walletName}&AccountName=account%200");

            ApiResponse stratisWalletBalances = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, $"/api/Wallet/balance?WalletName={walletName}&AccountName=account%200");

            ApiResponse stratisFederationInfo = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/FederationGateway/info");

            #endregion

            #region Sidechain Node
            ApiResponse sidechainStatus = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/Node/status");

            ApiResponse sidechainRawmempool = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/Mempool/getrawmempool");

            ApiResponse sidechainBestBlock = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/Consensus/getbestblockhash");

            ApiResponse sidechainWalletHistory = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, $"/api/Wallet/history?WalletName={walletName}&AccountName=account%200");

            ApiResponse sidechainWalletBalances = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, $"/api/FederationWallet/balance");

            ApiResponse sidechainFederationInfo = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/FederationGateway/info");

            #endregion

            var stratisPeers               = new List <Peer>();
            var stratisFederationMembers   = new List <Peer>();
            var sidechainPeers             = new List <Peer>();
            var sidechainFederationMembers = new List <Peer>();

            this.ParsePeers(stratisStatus, stratisFederationInfo, ref stratisPeers, ref stratisFederationMembers);
            this.ParsePeers(sidechainStatus, sidechainFederationInfo, ref sidechainPeers, ref sidechainFederationMembers);

            var dashboardModel = new DashboardModel();
            try
            {
                dashboardModel = new DashboardModel
                {
                    Status                 = true,
                    IsCacheBuilt           = true,
                    MainchainWalletAddress = stratisFederationInfo.Content.multisigAddress,
                    SidechainWalletAddress = sidechainFederationInfo.Content.multisigAddress,
                    MiningPublicKeys       = stratisFederationInfo.Content.federationMultisigPubKeys,
                    StratisNode            = new StratisNodeModel
                    {
                        WebAPIUrl          = string.Concat(this.defaultEndpointsSettings.StratisNode, "/api"),
                        SwaggerUrl         = string.Concat(this.defaultEndpointsSettings.StratisNode, "/swagger"),
                        SyncingStatus      = stratisStatus.Content.consensusHeight > 0 ? (stratisStatus.Content.blockStoreHeight / stratisStatus.Content.consensusHeight) * 100 : 0,
                        Peers              = stratisPeers,
                        FederationMembers  = stratisFederationMembers,
                        BlockHash          = stratisBestBlock.Content,
                        BlockHeight        = stratisStatus.Content.blockStoreHeight,
                        MempoolSize        = stratisRawmempool.Content.Count,
                        History            = stratisWalletHistory.Content.history[0].transactionsHistory,
                        ConfirmedBalance   = (double)stratisWalletBalances.Content.balances[0].amountConfirmed / 100000000,
                        UnconfirmedBalance = (double)stratisWalletBalances.Content.balances[0].amountUnconfirmed / 100000000
                    },
                    SidechainNode = new SidechainNodelModel
                    {
                        WebAPIUrl          = string.Concat(this.defaultEndpointsSettings.SidechainNode, "/api"),
                        SwaggerUrl         = string.Concat(this.defaultEndpointsSettings.SidechainNode, "/swagger"),
                        SyncingStatus      = sidechainStatus.Content.consensusHeight > 0 ? (sidechainStatus.Content.blockStoreHeight / sidechainStatus.Content.consensusHeight) * 100 : 0,
                        Peers              = sidechainPeers,
                        FederationMembers  = sidechainFederationMembers,
                        BlockHash          = sidechainBestBlock.Content,
                        BlockHeight        = sidechainStatus.Content.blockStoreHeight,
                        MempoolSize        = sidechainRawmempool.Content.Count,
                        History            = new object[] {},
                        ConfirmedBalance   = (double)sidechainWalletBalances.Content.balances[0].amountConfirmed / 100000000,
                        UnconfirmedBalance = (double)sidechainWalletBalances.Content.balances[0].amountUnconfirmed / 100000000
                    }
                };
            }
            catch (Exception e)
            {
                //ignored
            }

            if (!string.IsNullOrEmpty(this.distributedCache.GetString("DashboardData")))
            {
                if (JToken.DeepEquals(this.distributedCache.GetString("DashboardData"), JsonConvert.SerializeObject(dashboardModel)) == false)
                {
                    await this.updaterHub.Clients.All.SendAsync("CacheIsDifferent");
                }
            }
            this.distributedCache.SetString("DashboardData", JsonConvert.SerializeObject(dashboardModel));
        }
        /// <summary>
        /// Retrieve all node information and store it in IDistributedCache object
        /// </summary>
        /// <returns></returns>
        private async Task BuildCacheAsync()
        {
            var walletName = "clintm";

            #region Stratis Node
            var stratisStatus = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Node/status");

            var stratisRawmempool = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Mempool/getrawmempool");

            var stratisBestBlock = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Consensus/getbestblockhash");

            var stratisWalletHistory = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, $"/api/Wallet/history?WalletName={walletName}&AccountName=account%200");

            var stratisWalletBalances = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, $"/api/Wallet/balance?WalletName={walletName}&AccountName=account%200");

            #endregion

            #region Sidechain Node
            var sidechainStatus = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/Node/status");

            var sidechainRawmempool = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/Mempool/getrawmempool");

            var sidechainBestBlock = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/Consensus/getbestblockhash");

            var sidechainWalletHistory = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, $"/api/Wallet/history?WalletName={walletName}&AccountName=account%200");

            var sidechainWalletBalances = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, $"/api/FederationWallet/balance");

            #endregion

            var dashboardModel = new DashboardModel
            {
                Status                 = true,
                IsCacheBuilt           = true,
                MainchainWalletAddress = "31EBX8oNk6GoPufm755yuFtbBgEPmjPvdK",
                SidechainWalletAddress = "pTEBX8oNk6GoPufm755yuFtbBgEPmjPvdK ",
                MiningPublicKeys       = new string[] { "02446dfcecfcbef1878d906ffd023258a129e9471dba90a1845f15063397ada335", "02446dfcecfcbef1878d906ffd023258a129e9471dba90a1845f15063397ada335", "02446dfcecfcbef1878d906ffd023258a129e9471dba90a1845f15063397ada335" },
                StratisNode            = new StratisNodeModel
                {
                    WebAPIUrl          = string.Concat(this.defaultEndpointsSettings.StratisNode, "/api"),
                    SwaggerUrl         = string.Concat(this.defaultEndpointsSettings.StratisNode, "/swagger"),
                    SyncingStatus      = stratisStatus.Content.consensusHeight > 0 ? (stratisStatus.Content.blockStoreHeight / stratisStatus.Content.consensusHeight) * 100 : 0,
                    Peers              = stratisStatus.Content.outboundPeers,
                    BlockHash          = stratisBestBlock.Content,
                    BlockHeight        = stratisStatus.Content.blockStoreHeight,
                    MempoolSize        = stratisRawmempool.Content.Count,
                    FederationMembers  = new object[] {},
                    History            = stratisWalletHistory.Content.history[0].transactionsHistory,
                    ConfirmedBalance   = (double)stratisWalletBalances.Content.balances[0].amountConfirmed / 100000000,
                    UnconfirmedBalance = (double)stratisWalletBalances.Content.balances[0].amountUnconfirmed / 100000000
                },
                SidechainNode = new SidechainNodelModel
                {
                    WebAPIUrl          = string.Concat(this.defaultEndpointsSettings.SidechainNode, "/api"),
                    SwaggerUrl         = string.Concat(this.defaultEndpointsSettings.SidechainNode, "/swagger"),
                    SyncingStatus      = sidechainStatus.Content.consensusHeight > 0 ? (sidechainStatus.Content.blockStoreHeight / sidechainStatus.Content.consensusHeight) * 100 : 0,
                    Peers              = sidechainStatus.Content.outboundPeers,
                    BlockHash          = sidechainBestBlock.Content,
                    BlockHeight        = sidechainStatus.Content.blockStoreHeight,
                    MempoolSize        = sidechainRawmempool.Content.Count,
                    FederationMembers  = new object[] {},
                    History            = new object[] {},
                    ConfirmedBalance   = (double)sidechainWalletBalances.Content.balances[0].amountConfirmed / 100000000,
                    UnconfirmedBalance = (double)sidechainWalletBalances.Content.balances[0].amountUnconfirmed / 100000000
                }
            };

            if (!string.IsNullOrEmpty(this.distributedCache.GetString("DashboardData")))
            {
                if (JToken.DeepEquals(this.distributedCache.GetString("DashboardData"), JsonConvert.SerializeObject(dashboardModel)) == false)
                {
                    await this.updaterHub.Clients.All.SendAsync("CacheIsDifferent");
                }
            }
            this.distributedCache.SetString("DashboardData", JsonConvert.SerializeObject(dashboardModel));
        }