Exemplo n.º 1
0
        private void OnShown(object sender, EventArgs e)
        {
            WebSocketHelpers.ClearCanvas();
            MerkleTree tree = new DemoMerkleTree();

            CreateTree(tree, (int)nudNumLeaves.Value);
            DrawTree(tree);
        }
Exemplo n.º 2
0
        private void btnAuditProof_Click(object sender, EventArgs e)
        {
            WebSocketHelpers.ClearCanvas();
            MerkleTree tree = new DemoMerkleTree();

            CreateTree(tree, (int)nudNumLeaves.Value);
            DrawTree(tree);
            int leafNum = (int)nudAuditProofNodeNumber.Value;

            Highlight(tree.RootNode.Leaves().Cast <DemoMerkleNode>().Single(n => n.Text == leafNum.ToString("X")), "Orange");
            DrawAuditProof(leafNum.ToString("X"), tree);
        }
Exemplo n.º 3
0
        private void NumLeavesChanged(object sender, EventArgs e)
        {
            WebSocketHelpers.ClearCanvas();
            MerkleTree tree = new DemoMerkleTree();

            CreateTree(tree, (int)nudNumLeaves.Value);
            DrawTree(tree);

            // Adjust maximums of our "proof" explorers.
            nudAuditProofNodeNumber.Maximum      = nudNumLeaves.Value - 1;
            nudConsistencyProofNumLeaves.Maximum = nudNumLeaves.Value - 1;
        }
Exemplo n.º 4
0
        protected void DrawConnectors(List <Rectangle> shapesLower, List <Rectangle> shapesUpper)
        {
            int n  = 0;
            int n2 = 0;

            foreach (Rectangle rlower in shapesLower)
            {
                Rectangle rupper       = shapesUpper[n2];
                var       topMiddle    = rlower.TopMiddle();
                var       bottomMiddle = rupper.BottomMiddle();
                WebSocketHelpers.DropConnector("DynamicConnectorUD", "", bottomMiddle.X, bottomMiddle.Y, topMiddle.X, topMiddle.Y);
                n++;
                n2 = n2 + ((n % 2) == 0 ? 1 : 0);
            }
        }
Exemplo n.º 5
0
        protected List <Rectangle> DrawLeaves(List <MerkleNode> leaves)
        {
            List <Rectangle> rects = new List <Rectangle>();
            int i = 0;

            foreach (var leaf in leaves.Cast <DemoMerkleNode>())
            {
                var leafRect = new Rectangle(i * X_OFFSET, LEAF_Y, LEAF_WIDTH, NODE_HEIGHT);
                WebSocketHelpers.DropShape("Box", leaf.Text, leafRect, LEAF_COLOR, leaf.Text);
                rects.Add(leafRect);
                leaf.Tag = leafRect;
                ++i;
            }

            return(rects);
        }
Exemplo n.º 6
0
        protected List <Rectangle> DrawParents(IEnumerable <MerkleNode> parents, int level)
        {
            List <Rectangle> rects = new List <Rectangle>();
            int i  = 0;
            int l0 = level - 1;
            int indent;
            int spacing;
            int width = NODE_WIDTH;

            // Leaves and branches have different widths.
            if (level == 1)
            {
                indent  = LEAF_WIDTH / 2 - 5;
                spacing = LEAF_WIDTH * 2 + 10;
            }
            else if (level == 2)
            {
                indent  = ((int)Math.Pow(2, l0) - 1) * LEAF_WIDTH + LEAF_WIDTH / 2;
                spacing = NODE_WIDTH * (int)Math.Pow(2, level) - NODE_WIDTH / 2 - 13;
            }
            else if (level == 3)
            {
                indent  = ((int)Math.Pow(2, l0) - 1) * LEAF_WIDTH + LEAF_WIDTH / 2 + 10;
                spacing = NODE_WIDTH * (int)Math.Pow(2, level) - NODE_WIDTH / 2 - 75;
            }
            else
            {
                indent  = ((int)Math.Pow(2, l0) - 1) * LEAF_WIDTH + LEAF_WIDTH / 2 - 20;
                spacing = NODE_WIDTH * (int)Math.Pow(2, level) - NODE_WIDTH / 2 - 30;
                width   = NODE_WIDTH * 2;
            }

            Color nodeColor = parents.Count() == 1 ? ROOT_COLOR : NODE_COLOR;

            foreach (var node in parents.Cast <DemoMerkleNode>())
            {
                var nodeRect = new Rectangle(indent + i * spacing, LEAF_Y - (V_OFFSET * level), width, NODE_HEIGHT);
                WebSocketHelpers.DropShape("Box", node.Text, nodeRect, nodeColor, node.Text);
                rects.Add(nodeRect);
                node.Tag = nodeRect;
                ++i;
            }

            return(rects);
        }
Exemplo n.º 7
0
        private void btnConsistencyProof_Click(object sender, EventArgs e)
        {
            WebSocketHelpers.ClearCanvas();
            MerkleTree tree = new DemoMerkleTree();

            CreateTree(tree, (int)nudNumLeaves.Value);
            DrawTree(tree);
            int numLeaves = (int)nudConsistencyProofNumLeaves.Value;

            // Reconstruct the old root hash by creating a tree of "m" leaves.
            // We do this because in the demo, we haven't given the user the ability to append trees, so we
            // simulate that process here.
            MerkleTree oldTree = new DemoMerkleTree();

            CreateTree(oldTree, numLeaves);

            // For demo purposes, remove any () that were created by left-only branches.
            ((DemoMerkleNode)oldTree.RootNode).Text = ((DemoMerkleNode)oldTree.RootNode).Text.Replace("(", "").Replace(")", "");

            DrawConsistencyProof(tree, (DemoMerkleNode)oldTree.RootNode, numLeaves, null);
        }
Exemplo n.º 8
0
        protected void Highlight(DemoMerkleNode node, string color = "Yellow")
        {
            Rectangle r = (Rectangle)node.Tag;

            WebSocketHelpers.UpdateProperty(node.Text, "FillColor", color);
        }