Example #1
0
        public Block(Block block, bool thawChildren)
        {
            ContractsCommon.NotNull(block, "block");
            Contract.Ensures(this.Version == block.Version);
            Contract.Ensures(this.PreviousBlockHash == block.PreviousBlockHash);
            Contract.Ensures(this.Timestamp == block.Timestamp);
            Contract.Ensures(this.DifficultyBits == block.DifficultyBits);
            Contract.Ensures(this.Nonce == block.Nonce);
            Contract.Ensures(this.Transactions.SequencedEquals(block.Transactions));
            Contract.Ensures(this.MerkleRoot == block.MerkleRoot);
            ContractsCommon.ChildrenThawed(Transactions, thawChildren);

            this._version           = block._version;
            this._previousBlockHash = block._previousBlockHash;
            this._timestamp         = block._timestamp;
            this._difficultyBits    = block._difficultyBits;
            this._nonce             = block._nonce;
            if (block._merkleTree != null)
            {
                var tree = new ArrayList <Hash256>(block._merkleTree.Count);
                tree.AddAll(block._merkleTree);
                this._merkleTree = new GuardedList <Hash256>(tree);
            }

            var transactions = new HashedArrayList <Transaction>(block.Transactions.Count);

            transactions.AddAll(FreezableExtensions.ThawChildren(block.Transactions, thawChildren));
            transactions.CollectionChanged += InvalidateMerkleTree;
            this.Transactions = transactions;
        }
Example #2
0
        public Transaction(Transaction tx, bool thawChildren)
        {
            ContractsCommon.NotNull(tx, "tx");
            ContractsCommon.ChildrenThawed(TransactionInputs, thawChildren);
            ContractsCommon.ChildrenThawed(TransactionOutputs, thawChildren);

            Version = tx.Version;

            var transactionInputs = new ArrayList <TransactionInput>(tx.TransactionInputs.Count);

            transactionInputs.AddAll(FreezableExtensions.ThawChildren(tx.TransactionInputs, thawChildren));
            transactionInputs.CollectionChanged += InputOutputChanged;
            TransactionInputs = transactionInputs;

            var transactionOutputs = new ArrayList <TransactionOutput>(tx.TransactionOutputs.Count);

            transactionOutputs.AddAll(FreezableExtensions.ThawChildren(tx.TransactionOutputs, thawChildren));
            transactionOutputs.CollectionChanged += InputOutputChanged;
            TransactionOutputs = transactionOutputs;

            LockTime = tx.LockTime;
        }