Exemple #1
0
        private UTXOChange SetUTXOChange(UTXOStates states, UTXOState substract = null)
        {
            substract = substract ?? new UTXOState();
            var substractedSpent    = new HashSet <OutPoint>(substract.SpentUTXOs);
            var substractedReceived = new HashSet <OutPoint>(substract.UTXOByOutpoint.Select(u => u.Key));

            UTXOChange change = new UTXOChange();

            change.KnownBookmark = states.Known == null ? null : states.Known.CurrentBookmark;
            change.Bookmark      = states.Actual.CurrentBookmark;

            states.Known = states.Known ?? new UTXOState();

            foreach (var coin in states.Actual.UTXOByOutpoint)
            {
                if (!states.Known.UTXOByOutpoint.ContainsKey(coin.Key) &&
                    !substractedReceived.Contains(coin.Key))
                {
                    change.UTXOs.Add(new UTXO(coin.Value));
                }
            }

            foreach (var outpoint in states.Actual.SpentUTXOs)
            {
                if (!states.Known.SpentUTXOs.Contains(outpoint) &&
                    (states.Known.UTXOByOutpoint.ContainsKey(outpoint) || substractedReceived.Contains(outpoint)) &&
                    !substractedSpent.Contains(outpoint))
                {
                    change.SpentOutpoints.Add(outpoint);
                }
            }
            return(change);
        }
Exemple #2
0
        private UTXOChange SetUTXOChange(UTXOStates states, UTXOState substract = null)
        {
            substract = substract ?? new UTXOState();
            var substractedSpent    = new HashSet <OutPoint>(substract.SpentOutpoints);
            var substractedReceived = new HashSet <OutPoint>(substract.CoinsByOutpoint.Select(u => u.Key));

            UTXOChange change = new UTXOChange();

            change.Reset = states.Known == null;
            change.Hash  = states.Actual.CurrentHash;

            states.Known = states.Known ?? new UTXOState();

            foreach (var coin in states.Actual.CoinsByOutpoint)
            {
                if (!states.Known.CoinsByOutpoint.ContainsKey(coin.Key) &&
                    !substractedReceived.Contains(coin.Key))
                {
                    change.UTXOs.Add(new UTXO()
                    {
                        Outpoint = coin.Key, Output = coin.Value.TxOut
                    });
                }
            }

            foreach (var outpoint in states.Actual.SpentOutpoints)
            {
                if (!states.Known.SpentOutpoints.Contains(outpoint) &&
                    states.Known.CoinsByOutpoint.ContainsKey(outpoint) &&
                    !substractedSpent.Contains(outpoint))
                {
                    change.SpentOutpoints.Add(outpoint);
                }
            }
            return(change);
        }