public virtual void ReadWrite(BitcoinStream stream)
 {
     if (Key.IsPruned)
     {
         stream.ReadWrite(ref _CoinsData);
     }
     else
     {
         stream.ReadWrite(ref _Transaction);
     }
     stream.ReadWrite(ref _TickCount);
     if (stream.Serializing)
     {
         var match = new TransactionMiniMatch();
         match.Outputs = KnownKeyPathMapping.Select(kv => new TransactionMiniKeyInformation()
         {
             ScriptPubKey = kv.Key, KeyPath = kv.Value
         }).ToArray();
         stream.ReadWrite(ref match);
     }
     else
     {
         var match = new TransactionMiniMatch();
         stream.ReadWrite(ref match);
         KnownKeyPathMapping = new Dictionary <Script, KeyPath>();
         foreach (var kv in match.Inputs.Concat(match.Outputs))
         {
             KnownKeyPathMapping.TryAdd(kv.ScriptPubKey, kv.KeyPath);
         }
     }
     stream.ReadWrite(ref _FirstSeenTickCount);
 }
Beispiel #2
0
 public IEnumerable <MatchedOutput> GetReceivedOutputs()
 {
     return(this.ReceivedCoins
            .Select(o => (Index: (int)o.Outpoint.N,
                          Output: o,
                          KeyPath: KnownKeyPathMapping.TryGet(o.ScriptPubKey)))
            .Where(o => o.KeyPath != null || o.Output.ScriptPubKey == (TrackedSource as IDestination)?.ScriptPubKey)
            .Select(o => new MatchedOutput()
     {
         Index = o.Index,
         Value = o.Output.Amount,
         KeyPath = o.KeyPath,
         ScriptPubKey = o.Output.ScriptPubKey
     }));
 }
Beispiel #3
0
        internal void KnownKeyPathMappingUpdated()
        {
            if (Transaction == null)
            {
                return;
            }
            var scriptPubKey = (TrackedSource as IDestination)?.ScriptPubKey;

            for (int i = 0; i < Transaction.Outputs.Count; i++)
            {
                var output = Transaction.Outputs[i];
                if (KnownKeyPathMapping.ContainsKey(output.ScriptPubKey) || scriptPubKey == output.ScriptPubKey)
                {
                    ReceivedCoins.Add(new Coin(new OutPoint(Key.TxId, i), output));
                }
            }
            SpentOutpoints.AddRange(Transaction.Inputs.Select(input => input.PrevOut));
        }
 public virtual IEnumerable <Coin> GetCoins()
 {
     if (_CoinsData is null)
     {
         int idx = -1;
         foreach (var output in Transaction.Outputs)
         {
             idx++;
             if (KnownKeyPathMapping.ContainsKey(output.ScriptPubKey))
             {
                 yield return(new Coin(new OutPoint(Key.TxId, idx), output));
             }
         }
     }
     else
     {
         foreach (var coinData in _CoinsData)
         {
             yield return(new Coin(new OutPoint(Key.TxId, (int)coinData.Index), coinData.TxOut));
         }
     }
 }