示例#1
0
        public override MerkleNode AppendLeaf(MerkleNode node)
        {
            if (CurrentLeaf == null) // Meaning we have an even number of nodes (or zero)
            {
                // There were an even number of Leaves, including zero
                if (CurrentParent == null)
                {
                    EventMerkleTree.OutputWriter($"New tree, first append - left leaf");
                    // This is the first node
                    CurrentParent = CreateNode(node, null);
                    CurrentLeaf   = node;
                }
                else
                {
                    EventMerkleTree.OutputWriter($"Append left leaf");
                    CurrentParent = ((EventMerkleNode)CurrentParent).AppendMerkleNode(node);
                    CurrentLeaf   = node;
                }
            }
            else
            {
                EventMerkleTree.OutputWriter($"Append right leaf");
                CurrentParent = ((EventMerkleNode)CurrentParent).AppendMerkleNode(node);
                CurrentLeaf   = null;
            }

            return(node);
        }
示例#2
0
 public MerkleNode AppendMerkleNode(MerkleNode node)
 {
     if (RightNode == null)
     {
         SetRightNode(node);
         EventMerkleTree.Output($"Node {((EventMerkleNode)node).Text} set as right node on {this.Text}");
         MergeText();
         return(this);
     }
     if (Parent == null)
     {
         EventMerkleTree.Output($"Parent of {this} was null on {((EventMerkleNode)node).Text}, will create new parent.");
         var newParent = new EventMerkleNode((EventMerkleNode)node, null);
         new EventMerkleNode(this, newParent);
         return(newParent);
     }
     else // Parent exists
     {
         EventMerkleTree.Output($"Parent of {this} was NOT null:{((EventMerkleNode)Parent).Text} on {((EventMerkleNode)node).Text}");
         var newParent = new EventMerkleNode((EventMerkleNode)node, null);
         ((EventMerkleNode)Parent).AppendMerkleNode(newParent);
         return(newParent);
     }
 }
示例#3
0
 }                                // Useful for diagramming.
 public EventMerkleNode(EventMerkleNode left, EventMerkleNode right = null) : base(left, right)
 {
     MergeText(left, right);
     EventMerkleTree.Output($"New node:{Text}, L:{left.Text}, R:{right?.Text}");
 }
示例#4
0
 protected void MergeText()
 {
     EventMerkleTree.Output($"Updating Text from L:{((EventMerkleNode)LeftNode).Text}, R:{((EventMerkleNode)RightNode)?.Text}");
     MergeText(LeftNode, RightNode);
     ((EventMerkleNode)Parent)?.MergeText();
 }