コード例 #1
0
        /// <summary>
        /// Remove superflous branches
        /// </summary>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public PartialMerkleTree Trim(params uint256[] matchedTransactions)
        {
            PartialMerkleTree trimmed = new PartialMerkleTree();

            trimmed.TransactionCount = TransactionCount;
            var root = GetMerkleRoot();

            foreach (var leaf in root.GetLeafs())
            {
                MarkToTop(leaf, false);
            }
            BitWriter flags = new BitWriter();

            foreach (var leaf in root.GetLeafs().Where(l => matchedTransactions.Contains(l.Hash)))
            {
                MarkToTop(leaf, true);
            }
            trimmed.BuildCore(root, flags);
            trimmed.Flags = flags.ToBitArray();
            return(trimmed);
        }