Beispiel #1
0
        public static MerkleSibling CreateMerkleBranch(
            MerkleNode merkleTree, int index)
        {
            if (merkleTree == null || index >= merkleTree.Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (merkleTree.IsLeaf)
            {
                return(null);
            }

            int  leftCount = merkleTree.LeftNode.Count;
            bool goLeft    = index < leftCount;

            MerkleNode sibling;
            MerkleNode child;

            if (goLeft)
            {
                sibling = merkleTree.RightNode;
                child   = merkleTree.LeftNode;
            }
            else
            {
                sibling = merkleTree.LeftNode;
                child   = merkleTree.RightNode;
            }

            sbyte[] hash = sibling.Slice();

            if (!goLeft)
            {
                index = index - leftCount;
            }

            MerkleSibling nextSibling = CreateMerkleBranch(child, index);

            return(new MerkleSibling(hash, nextSibling));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="hash"></param>
 /// <param name="nextSibling"></param>
 public MerkleSibling(sbyte[] hash, MerkleSibling nextSibling)
 {
     Hash        = hash;
     NextSibling = nextSibling;
 }