Commit 33ce56ce authored by Jeremy Bokobza's avatar Jeremy Bokobza

Added logging to the Tracker

parent 8b02cbba
...@@ -7,6 +7,7 @@ using System.Text; ...@@ -7,6 +7,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Breeze.Wallet.Notifications; using Breeze.Wallet.Notifications;
using Microsoft.Extensions.Logging;
using NBitcoin; using NBitcoin;
using Stratis.Bitcoin; using Stratis.Bitcoin;
using Stratis.Bitcoin.Notifications; using Stratis.Bitcoin.Notifications;
...@@ -21,14 +22,16 @@ namespace Breeze.Wallet ...@@ -21,14 +22,16 @@ namespace Breeze.Wallet
private readonly Signals signals; private readonly Signals signals;
private readonly BlockNotification blockNotification; private readonly BlockNotification blockNotification;
private readonly CoinType coinType; private readonly CoinType coinType;
private readonly ILogger logger;
public Tracker(IWalletManager walletManager, ConcurrentChain chain, Signals signals, BlockNotification blockNotification, Network network) public Tracker(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Signals signals, BlockNotification blockNotification, Network network)
{ {
this.walletManager = walletManager as WalletManager; this.walletManager = walletManager as WalletManager;
this.chain = chain; this.chain = chain;
this.signals = signals; this.signals = signals;
this.blockNotification = blockNotification; this.blockNotification = blockNotification;
this.coinType = (CoinType)network.Consensus.CoinType; this.coinType = (CoinType)network.Consensus.CoinType;
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
} }
/// <inheritdoc /> /// <inheritdoc />
...@@ -44,7 +47,9 @@ namespace Breeze.Wallet ...@@ -44,7 +47,9 @@ namespace Breeze.Wallet
txSub.Subscribe(); txSub.Subscribe();
// start syncing blocks // start syncing blocks
this.blockNotification.SyncFrom(this.chain.GetBlock(this.FindBestHeightForSyncing()).HashBlock); var bestHeightForSyncing = this.FindBestHeightForSyncing();
this.SyncFrom(bestHeightForSyncing);
this.logger.LogInformation($"Tracker initialized. Syncing from {bestHeightForSyncing}.");
} }
private int FindBestHeightForSyncing() private int FindBestHeightForSyncing()
...@@ -75,6 +80,7 @@ namespace Breeze.Wallet ...@@ -75,6 +80,7 @@ namespace Breeze.Wallet
// wait until the chain is downloaded. We wait until a block is from an hour ago. // wait until the chain is downloaded. We wait until a block is from an hour ago.
if (this.chain.IsDownloaded()) if (this.chain.IsDownloaded())
{ {
this.logger.LogInformation($"Chain downloaded. Tip height is {this.chain.Tip.Height}.");
cancellationTokenSource.Cancel(); cancellationTokenSource.Cancel();
} }
...@@ -88,21 +94,15 @@ namespace Breeze.Wallet ...@@ -88,21 +94,15 @@ namespace Breeze.Wallet
public void SyncFrom(DateTime date) public void SyncFrom(DateTime date)
{ {
int blockSyncStart = this.chain.GetHeightAtTime(date); int blockSyncStart = this.chain.GetHeightAtTime(date);
// start syncing blocks // start syncing blocks
this.SyncFrom(blockSyncStart); this.SyncFrom(blockSyncStart);
} }
/// <inheritdoc /> /// <inheritdoc />
public void SyncFrom(int height) public void SyncFrom(int height)
{
this.blockNotification.SyncFrom(this.chain.GetBlock(height).HashBlock);
}
private bool BlocksSynced()
{ {
return this.walletManager.Wallets.All(w => w.AccountsRoot.Single(a => a.CoinType == this.coinType).LastBlockSyncedHeight == this.chain.Tip.Height); this.blockNotification.SyncFrom(this.chain.GetBlock(height).HashBlock);
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment