Exemplo n.º 1
0
        public static UTXOStateResult CreateStates(
            Func <Script[], bool[]> matchScript,
            HashSet <Bookmark> knownUnconfBookmarks, IEnumerable <Transaction> unconfirmed,
            HashSet <Bookmark> knownConfBookmarks, IEnumerable <Transaction> confirmed)
        {
            var utxoState = new UTXOState();

            utxoState.MatchScript = matchScript;

            var knownConf = knownConfBookmarks.Contains(Bookmark.Start) ? new UTXOState() : null;

            foreach (var tx in confirmed)
            {
                if (utxoState.Apply(tx) == ApplyTransactionResult.Conflict)
                {
                    throw new InvalidOperationException("Conflict in UTXOStateResult.CreateStates should never happen");
                }
                if (knownConfBookmarks.Contains(utxoState.CurrentBookmark))
                {
                    knownConf = utxoState.Snapshot();
                }
            }


            var actualConf = utxoState.Snapshot();

            utxoState.ResetEvents();

            var knownUnconf = knownUnconfBookmarks.Contains(Bookmark.Start) ? utxoState.Snapshot() : null;

            foreach (var tx in unconfirmed)
            {
                var txid = tx.GetHash();
                if (utxoState.Apply(tx) == ApplyTransactionResult.Conflict)
                {
                    throw new InvalidOperationException("Conflict in UTXOStateResult.CreateStates should never happen");
                }

                if (knownUnconfBookmarks.Contains(utxoState.CurrentBookmark))
                {
                    knownUnconf = utxoState.Snapshot();
                }
            }

            var actualUnconf = utxoState;

            return(new UTXOStateResult()
            {
                Unconfirmed = new UTXOStates()
                {
                    Known = knownUnconf,
                    Actual = actualUnconf
                },
                Confirmed = new UTXOStates()
                {
                    Known = knownConf,
                    Actual = actualConf,
                }
            });
        }
Exemplo n.º 2
0
        public static UTXOStateResult CreateStates(IEnumerable <TrackedTransaction> unconfirmed, IEnumerable <TrackedTransaction> confirmed)
        {
            var utxoState = new UTXOState();

            foreach (var tx in confirmed)
            {
                if (utxoState.Apply(tx) == ApplyTransactionResult.Conflict)
                {
                    throw new InvalidOperationException("Conflict in UTXOStateResult.CreateStates should never happen");
                }
            }


            var actualConf = utxoState.Snapshot();

            foreach (var tx in unconfirmed)
            {
                if (utxoState.Apply(tx) == ApplyTransactionResult.Conflict)
                {
                    throw new InvalidOperationException("Conflict in UTXOStateResult.CreateStates should never happen");
                }
            }

            var actualUnconf = utxoState;

            return(new UTXOStateResult()
            {
                Unconfirmed = new UTXOStates()
                {
                    Actual = actualUnconf
                },
                Confirmed = new UTXOStates()
                {
                    Actual = actualConf,
                }
            });
        }
Exemplo n.º 3
0
        public static UTXOStateResult CreateStates(
            Func <Script[], bool[]> matchScript,
            uint256 knownUnconfHash, IEnumerable <Transaction> unconfirmed,
            uint256 knownConfHash, IEnumerable <Transaction> confirmed)
        {
            var utxoState = new UTXOState();

            utxoState.MatchScript = matchScript;

            var knownConf = knownConfHash == uint256.Zero ? new UTXOState() : null;

            foreach (var tx in confirmed)
            {
                var applyResult = utxoState.Apply(tx);
                if (applyResult == ApplyTransactionResult.Conflict)
                {
                    Logs.Explorer.LogError("A conflict among confirmed transaction happened, this should be impossible");
                    throw new InvalidOperationException("The impossible happened");
                }

                if (applyResult == ApplyTransactionResult.Passed)
                {
                    if (utxoState.CurrentHash == knownConfHash)
                    {
                        knownConf = utxoState.Snapshot();
                    }
                }
            }


            var actualConf = utxoState.Snapshot();

            utxoState.ResetEvents();

            var knownUnconf = knownUnconfHash == uint256.Zero ? utxoState.Snapshot() : null;

            foreach (var tx in unconfirmed)
            {
                var txid = tx.GetHash();
                if (utxoState.Apply(tx) == ApplyTransactionResult.Passed)
                {
                    if (utxoState.CurrentHash == knownUnconfHash)
                    {
                        knownUnconf = utxoState.Snapshot();
                    }
                }
            }

            var actualUnconf = utxoState;

            return(new UTXOStateResult()
            {
                Unconfirmed = new UTXOStates()
                {
                    Known = knownUnconf,
                    Actual = actualUnconf
                },
                Confirmed = new UTXOStates()
                {
                    Known = knownConf,
                    Actual = actualConf,
                }
            });
        }