Beispiel #1
0
        public async Task <IActionResult> ResyncCrosschainTransactionsAsync()
        {
            //TODO: implement this method
            ApiResponse stopNodeRequest = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Node/status");

            return(stopNodeRequest.IsSuccess ? (IActionResult)Ok() : BadRequest());
        }
        public async Task <IActionResult> CheckFederationAsync()
        {
            ApiResponse getMainchainFederationInfo = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/FederationGateway/info");

            if (getMainchainFederationInfo.IsSuccess)
            {
                return(Json(getMainchainFederationInfo.Content.active));
            }
            return(Json(true));
        }
Beispiel #3
0
        public async Task <IActionResult> ResyncAsync(string value)
        {
            bool isHeight = int.TryParse(value, out int height);

            if (isHeight)
            {
                ApiResponse getblockhashRequest = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, $"/api/Consensus/getblockhash?height={value}");

                ApiResponse syncRequest = await ApiRequester.PostRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Wallet/sync", new { hash = ((string)getblockhashRequest.Content) });

                return(syncRequest.IsSuccess ? (IActionResult)Ok() : BadRequest());
            }
            else
            {
                ApiResponse syncRequest = await ApiRequester.PostRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Wallet/sync", new { hash = value });

                return(syncRequest.IsSuccess ? (IActionResult)Ok() : BadRequest());
            }
        }
Beispiel #4
0
        /// <summary>
        /// Retrieve all node information and store it in IDistributedCache object
        /// </summary>
        private async Task BuildCacheAsync()
        {
            this.logger.LogInformation($"Refresh the Dashboard Data");

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

            ApiResponse stratisLogRules = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Node/logrules");

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

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

            ApiResponse stratisWalletBalances = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/FederationWallet/balance");

            ApiResponse stratisWalletHistory = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/FederationWallet/history", "maxEntriesToReturn=30");

            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 sidechainLogRules = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/Node/logrules");

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

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

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

            ApiResponse sidechainWalletHistory = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/FederationWallet/history", "maxEntriesToReturn=30");

            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>();

            try
            {
                this.ParsePeers(stratisStatus, stratisFederationInfo, ref stratisPeers, ref stratisFederationMembers);
                this.ParsePeers(sidechainStatus, sidechainFederationInfo, ref sidechainPeers, ref sidechainFederationMembers);
            }
            catch (Exception e)
            {
                this.logger.LogError(e, "Unable to parse feeds");
            }

            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          = UriHelper.BuildUri(this.defaultEndpointsSettings.StratisNode, "/api").ToString(),
                        SwaggerUrl         = UriHelper.BuildUri(this.defaultEndpointsSettings.StratisNode, "/swagger").ToString(),
                        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,
                        ConfirmedBalance   = (double)stratisWalletBalances.Content.balances[0].amountConfirmed / 100000000,
                        UnconfirmedBalance = (double)stratisWalletBalances.Content.balances[0].amountUnconfirmed / 100000000,
                        CoinTicker         = stratisStatus.Content.coinTicker ?? "STRAT",
                        LogRules           = stratisLogRules.Content
                    },
                    SidechainNode = new SidechainNodelModel
                    {
                        WebAPIUrl          = UriHelper.BuildUri(this.defaultEndpointsSettings.SidechainNode, "/api").ToString(),
                        SwaggerUrl         = UriHelper.BuildUri(this.defaultEndpointsSettings.SidechainNode, "/swagger").ToString(),
                        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            = sidechainWalletHistory.Content,
                        ConfirmedBalance   = (double)sidechainWalletBalances.Content.balances[0].amountConfirmed / 100000000,
                        UnconfirmedBalance = (double)sidechainWalletBalances.Content.balances[0].amountUnconfirmed / 100000000,
                        CoinTicker         = sidechainStatus.Content.coinTicker ?? "STRAT",
                        LogRules           = sidechainLogRules.Content
                    }
                };
            }
            catch (Exception e)
            {
                this.logger.LogError(e, "Unable to fetch feeds.");
            }

            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));
        }