public async Task <StatusResponse> GetStatusResponseAsync() { var ts = Tor.State.ToString(); if (_walletJob != null) { var hh = 0; var result = await _walletJob.TryGetHeaderHeightAsync(); var headerHeight = result.Height; if (result.Success) { if (headerHeight.Type == HeightType.Chain) { hh = headerHeight.Value; } } var bh = await _walletJob.GetBestHeightAsync(); var th = 0; if (bh.Type == HeightType.Chain) { th = bh.Value; } var ws = _walletState; var nc = _walletJob.ConnectedNodeCount; var mtxc = _walletJob.MemPoolJob.Transactions.Count; var cb = _changeBump; return(new StatusResponse { HeaderHeight = hh, TrackingHeight = th, ConnectedNodeCount = nc, MemPoolTransactionCount = mtxc, WalletState = ws, TorState = ts, ChangeBump = cb }); } else { return new StatusResponse { HeaderHeight = 0, TrackingHeight = 0, ConnectedNodeCount = 0, MemPoolTransactionCount = 0, WalletState = WalletState.NotStarted.ToString(), TorState = ts, ChangeBump = 0 } }; }
public static async Task ReportAsync(CancellationToken ctsToken, WalletJob walletJob) { while (true) { if (ctsToken.IsCancellationRequested) { return; } try { await Task.Delay(1000, ctsToken).ContinueWith(t => { }); var result = await walletJob.TryGetHeaderHeightAsync(); var currHeaderHeight = result.Height; if (result.Success) { // HEADERCHAIN if (currHeaderHeight.Type == HeightType.Chain && (_prevHeaderHeight == Height.Unknown || currHeaderHeight > _prevHeaderHeight)) { Debug.WriteLine($"HeaderChain height: {currHeaderHeight}"); _prevHeaderHeight = currHeaderHeight; } // TRACKER var currHeight = await walletJob.GetBestHeightAsync(); if (currHeight.Type == HeightType.Chain && (_prevHeight == Height.Unknown || currHeight > _prevHeight)) { Debug.WriteLine($"Tracker height: {currHeight} left: {currHeaderHeight.Value - currHeight.Value}"); _prevHeight = currHeight; } } } catch { // ignored } } }