internal bool EnqueueScan(NBXplorerNetwork network, DerivationStrategyBase derivationScheme, ScanUTXOSetOptions options) { var workItem = new ScanUTXOWorkItem(network, derivationScheme) { State = new ScanUTXOInformation() { Status = ScanUTXOStatus.Queued, QueuedAt = DateTimeOffset.UtcNow }, Options = options }; var value = _Progress.AddOrUpdate(workItem.Id, workItem, (k, existing) => existing.Finished ? workItem : existing); if (value != workItem) { return(false); } if (!_Channel.Writer.TryWrite(workItem.Id)) { _Progress.TryRemove(workItem.Id, out var unused); return(false); } CleanProgressList(); return(true); }
private ScannedItems GetScannedItems(ScanUTXOWorkItem workItem, ScanUTXOProgress progress) { var items = new ScannedItems(); var derivationStrategy = workItem.DerivationStrategy; foreach (var feature in workItem.Options.DerivationFeatures) { var path = DerivationStrategyBase.GetKeyPath(feature); var lineDerivation = workItem.DerivationStrategy.DerivationStrategy.GetLineFor(feature); Enumerable.Range(progress.From, progress.Count) .Select(index => { var derivation = lineDerivation.Derive((uint)index); var info = new KeyPathInformation() { ScriptPubKey = derivation.ScriptPubKey, Redeem = derivation.Redeem, TrackedSource = derivationStrategy, DerivationStrategy = derivationStrategy.DerivationStrategy, Feature = feature, KeyPath = path.Derive(index, false) }; items.Descriptors.Add(new ScanTxoutSetObject(ScanTxoutDescriptor.Raw(info.ScriptPubKey))); items.KeyPathInformations.TryAdd(info.ScriptPubKey, info); return(info); }).All(_ => true); } Logs.Explorer.LogInformation($"{workItem.Network.CryptoCode}: Start scanning batch {progress.BatchNumber} of {workItem.DerivationStrategy.ToPrettyString()} from index {progress.From}"); return(items); }
private ScannedItems GetScannedItems(ScanUTXOWorkItem workItem, ScanUTXOProgress progress, NBXplorerNetwork network) { var items = new ScannedItems(); var derivationStrategy = workItem.DerivationStrategy; foreach (var feature in keyPathTemplates.GetSupportedDerivationFeatures()) { var keyPathTemplate = keyPathTemplates.GetKeyPathTemplate(feature); var lineDerivation = workItem.DerivationStrategy.DerivationStrategy.GetLineFor(keyPathTemplate); Enumerable.Range(progress.From, progress.Count) .Select(index => { var derivation = lineDerivation.Derive((uint)index); var info = new KeyPathInformation(derivation, derivationStrategy, feature, keyPathTemplate.GetKeyPath(index, false), network); items.Descriptors.Add(new ScanTxoutSetObject(ScanTxoutDescriptor.Raw(info.ScriptPubKey))); items.KeyPathInformations.TryAdd(info.ScriptPubKey, info); return(info); }).All(_ => true); } Logs.Explorer.LogInformation($"{workItem.Network.CryptoCode}: Start scanning batch {progress.BatchNumber} of {workItem.DerivationStrategy.ToPrettyString()} from index {progress.From}"); return(items); }