/// <summary>
        /// Calculates merkle root for block's trasnactions.
        /// </summary>
        /// <param name="block">Block which transactions are used for calculation.</param>
        /// <param name="mutated"><c>true</c> if block contains repeating sequences of transactions without affecting the merkle root of a block. Otherwise: <c>false</c>.</param>
        /// <returns>Merkle root.</returns>
        public static uint256 BlockMerkleRoot(Block block, out bool mutated)
        {
            var leaves = new List <uint256>(block.Transactions.Count);

            foreach (Transaction tx in block.Transactions)
            {
                leaves.Add(tx.GetHash());
            }

            return(BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates merkle root for witness data.
        /// </summary>
        /// <param name="block">Block which transactions witness data is used for calculation.</param>
        /// <param name="mutated"><c>true</c> if at least one leaf of the merkle tree has the same hash as any subtree. Otherwise: <c>false</c>.</param>
        /// <returns>Merkle root.</returns>
        public uint256 BlockWitnessMerkleRoot(Block block, out bool mutated)
        {
            var leaves = new List <uint256>();

            leaves.Add(uint256.Zero); // The witness hash of the coinbase is 0.
            foreach (Transaction tx in block.Transactions.Skip(1))
            {
                leaves.Add(tx.GetWitHash());
            }

            return(BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated));
        }