Esempio n. 1
0
 /// <inheritdoc />
 public void SyncFrom(int height)
 {
     // before we start syncing we need to make sure that the chain is at a certain level.
     // if the chain is behind the height from which we want to sync, we wait for it to catch up, and then we start syncing.
     // if the chain is already past the height we want to sync from, we don't wait, even though the chain might  not be fully downloaded.
     if (this.chain.Tip.Height < height)
     {
         AsyncLoop.RunUntil("WalletFeature.DownloadChain", this.nodeLifetime.ApplicationStopping,
                            () => this.chain.Tip.Height >= height,
                            () => this.StartSync(height),
                            (ex) =>
         {
             // in case of an exception while waiting for the chain to be at a certain height, we just cut our losses and
             // sync from the current height.
             this.logger.LogError($"Exception occurred while waiting for chain to download: {ex.Message}");
             this.StartSync(this.chain.Tip.Height);
         },
                            TimeSpans.FiveSeconds);
     }
     else
     {
         this.StartSync(height);
     }
 }
 /// <inheritdoc />
 public void SyncFrom(DateTime date)
 {
     // before we start syncing we need to make sure that the chain is at a certain level.
     // if the chain is behind the date from which we want to sync, we wait for it to catch up, and then we start syncing.
     // if the chain is already past the date we want to sync from, we don't wait, even though the chain might not be fully downloaded.
     if (this.chain.Tip.Header.BlockTime.LocalDateTime < date)
     {
         AsyncLoop.RunUntil("WalletFeature.DownloadChain", this.cancellationProvider.Cancellation.Token,
                            () => this.chain.Tip.Header.BlockTime.LocalDateTime >= date,
                            () => this.StartSync(this.chain.GetHeightAtTime(date)),
                            (ex) =>
         {
             // in case of an exception while waiting for the chain to be at a certain height, we just cut our losses and
             // sync from the current height.
             this.logger.LogError($"Exception occurred while waiting for chain to download: {ex.Message}");
             this.StartSync(this.chain.Tip.Height);
         },
                            TimeSpans.FiveSeconds);
     }
     else
     {
         this.StartSync(this.chain.GetHeightAtTime(date));
     }
 }