src/Stratis.FederatedSidechains.AdminDashboard/Services/FetchingBackgroundService.cs
/// <summary>
/// Retrieve all node information and store it in IDistributedCache object
/// </summary>
/// <returns></returns>
Retrieve all node information and store it in IDistributedCache object
Retrieve all node information and store it in IDistributedCache object
private async Task BuildCacheAsync()
        {
            #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 stratisWalletBalances = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/FederationWallet/balance");
            ApiResponse stratisWalletHistory = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.StratisNode, "/api/FederationWallet/history?maxEntriesToReturn=10");
            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 sidechainWalletBalances = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/FederationWallet/balance");
            ApiResponse sidechainWalletHistory = await ApiRequester.GetRequestAsync(this.defaultEndpointsSettings.SidechainNode, "/api/FederationWallet/history?maxEntriesToReturn=10");
            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,
                        ConfirmedBalance = (double)stratisWalletBalances.Content.balances[0].amountConfirmed / 100000000,
                        UnconfirmedBalance = (double)stratisWalletBalances.Content.balances[0].amountUnconfirmed / 100000000,
                        CoinTicker = stratisStatus.Content.coinTicker ?? "STRAT"
                    },  
                    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 = sidechainWalletHistory.Content,
                        ConfirmedBalance = (double)sidechainWalletBalances.Content.balances[0].amountConfirmed / 100000000,
                        UnconfirmedBalance = (double)sidechainWalletBalances.Content.balances[0].amountUnconfirmed / 100000000,
                        CoinTicker = sidechainStatus.Content.coinTicker ?? "STRAT"
                    }
                };
            }
            catch
            {
            }
            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));
        }
private async Task BuildCacheAsync ( ) { region  Stratis Node ApiResponse stratisStatus = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . StratisNode , " " ) ; ApiResponse stratisRawmempool = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . StratisNode , " " ) ; ApiResponse stratisBestBlock = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . StratisNode , " " ) ; ApiResponse stratisWalletBalances = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . StratisNode , " " ) ; ApiResponse stratisWalletHistory = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . StratisNode , " " ) ; ApiResponse stratisFederationInfo = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . StratisNode , " " ) ; endregion region  Sidechain Node ApiResponse sidechainStatus = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . SidechainNode , " " ) ; ApiResponse sidechainRawmempool = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . SidechainNode , " " ) ; ApiResponse sidechainBestBlock = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . SidechainNode , " " ) ; ApiResponse sidechainWalletBalances = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . SidechainNode , " " ) ; ApiResponse sidechainWalletHistory = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . SidechainNode , " " ) ; ApiResponse sidechainFederationInfo = await ApiRequester . GetRequestAsync ( this . defaultEndpointsSettings . SidechainNode , " " ) ; 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 , " " ) , SwaggerUrl = string . Concat ( this . defaultEndpointsSettings . StratisNode , " " ) , 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 ?? " " } , SidechainNode = new SidechainNodelModel { WebAPIUrl = string . Concat ( this . defaultEndpointsSettings . SidechainNode , " " ) , SwaggerUrl = string . Concat ( this . defaultEndpointsSettings . SidechainNode , " " ) , 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 ?? " " } } ; } catch { } if ( ! string . IsNullOrEmpty ( this . distributedCache . GetString ( " " ) ) ) { if ( JToken . DeepEquals ( this . distributedCache . GetString ( " " ) , JsonConvert . SerializeObject ( dashboardModel ) ) == false ) { await this . updaterHub . Clients . All . SendAsync ( " " ) ; } } this . distributedCache . SetString ( " " , JsonConvert . SerializeObject ( dashboardModel ) ) ; }
Retrieve all node information and store it in IDistributedCache object
Retrieve all node information and store it in IDistributedCache object
//ignored
None