public async Task <IActionResult> GetStatus(string cryptoCode) { var network = GetNetwork(cryptoCode, false); var waiter = Waiters.GetWaiter(network); var chain = ChainProvider.GetChain(network); var repo = RepositoryProvider.GetRepository(network); var now = DateTimeOffset.UtcNow; var location = waiter.GetLocation(); var blockchainInfoAsync = waiter.RPCAvailable ? waiter.RPC.GetBlockchainInfoAsyncEx() : null; var networkInfoAsync = waiter.RPCAvailable ? waiter.RPC.GetNetworkInfoAsync() : null; await repo.Ping(); var pingAfter = DateTimeOffset.UtcNow; GetBlockchainInfoResponse blockchainInfo = blockchainInfoAsync == null ? null : await blockchainInfoAsync; GetNetworkInfoResponse networkInfo = networkInfoAsync == null ? null : await networkInfoAsync; var status = new StatusResult() { NetworkType = network.NBitcoinNetwork.NetworkType, CryptoCode = network.CryptoCode, Version = typeof(MainController).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version, SupportedCryptoCodes = Waiters.All().Select(w => w.Network.CryptoCode).ToArray(), RepositoryPingTime = (pingAfter - now).TotalSeconds, IsFullySynched = true }; if (status.RepositoryPingTime > 30) { Logs.Explorer.LogWarning($"Repository ping exceeded 30 seconds ({(int)status.RepositoryPingTime}), please report the issue to NBXplorer developers"); } if (blockchainInfo != null) { status.BitcoinStatus = new BitcoinStatus() { IsSynched = !waiter.IsSynchingCore(blockchainInfo), Blocks = (int)blockchainInfo.Blocks, Headers = (int)blockchainInfo.Headers, VerificationProgress = blockchainInfo.VerificationProgress, MinRelayTxFee = new FeeRate(Money.Coins((decimal)networkInfo.relayfee), 1000), IncrementalRelayFee = new FeeRate(Money.Coins((decimal)networkInfo.incrementalfee), 1000), Capabilities = new NodeCapabilities() { CanScanTxoutSet = waiter.RPC.Capabilities.SupportScanUTXOSet, CanSupportSegwit = waiter.RPC.Capabilities.SupportSegwit } }; status.IsFullySynched &= status.BitcoinStatus.IsSynched; } status.ChainHeight = chain.Height; status.SyncHeight = location == null ? (int?)null : chain.FindFork(location).Height; status.IsFullySynched &= blockchainInfo != null && waiter.State == BitcoinDWaiterState.Ready && status.SyncHeight.HasValue && blockchainInfo.Headers - status.SyncHeight.Value < 3; return(Json(status)); }
public async Task <IActionResult> GetStatus(string cryptoCode) { var network = GetNetwork(cryptoCode, false); var waiter = Waiters.GetWaiter(network); var chain = ChainProvider.GetChain(network); var repo = RepositoryProvider.GetRepository(network); var location = waiter.GetLocation(); GetBlockchainInfoResponse blockchainInfo = null; if (waiter.RPCAvailable) { try { var rpc = waiter.RPC.Clone(); rpc.RequestTimeout = TimeSpan.FromMinutes(1.0); blockchainInfo = await rpc.GetBlockchainInfoAsyncEx(); } catch (OperationCanceledException) // Timeout, can happen if core is really busy { } } var status = new StatusResult() { NetworkType = network.NBitcoinNetwork.NetworkType, CryptoCode = network.CryptoCode, Version = typeof(MainController).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version, SupportedCryptoCodes = Waiters.All().Select(w => w.Network.CryptoCode).ToArray(), IsFullySynched = true }; GetNetworkInfoResponse networkInfo = waiter.NetworkInfo; if (blockchainInfo != null && networkInfo != null) { status.BitcoinStatus = new BitcoinStatus() { IsSynched = !waiter.IsSynchingCore(blockchainInfo), Blocks = (int)blockchainInfo.Blocks, Headers = (int)blockchainInfo.Headers, VerificationProgress = blockchainInfo.VerificationProgress, MinRelayTxFee = networkInfo.GetRelayFee(), IncrementalRelayFee = networkInfo.GetIncrementalFee(), Capabilities = new NodeCapabilities() { CanScanTxoutSet = waiter.RPC.Capabilities.SupportScanUTXOSet, CanSupportSegwit = waiter.RPC.Capabilities.SupportSegwit }, ExternalAddresses = (networkInfo.localaddresses ?? Array.Empty <GetNetworkInfoResponse.LocalAddress>()) .Select(l => $"{l.address}:{l.port}").ToArray() }; status.IsFullySynched &= status.BitcoinStatus.IsSynched; } status.ChainHeight = chain.Height; status.SyncHeight = location == null ? (int?)null : chain.FindFork(location).Height; status.IsFullySynched &= blockchainInfo != null && waiter.State == BitcoinDWaiterState.Ready && status.SyncHeight.HasValue && blockchainInfo.Headers - status.SyncHeight.Value < 3; if (status.IsFullySynched) { var now = DateTimeOffset.UtcNow; await repo.Ping(); var pingAfter = DateTimeOffset.UtcNow; status.RepositoryPingTime = (pingAfter - now).TotalSeconds; if (status.RepositoryPingTime > 30) { Logs.Explorer.LogWarning($"Repository ping exceeded 30 seconds ({(int)status.RepositoryPingTime}), please report the issue to NBXplorer developers"); } } return(Json(status)); }