Esempio n. 1
0
 public RootDataResponse(ListTreeNode root, LedgerCloseData ledgerCloseData)
 {
     RootHash = root.Hash;
     LeafCount = root.LeafCount;
     LedgerCloseData = ledgerCloseData;
     Children = new NodeDataEntity[16];
     for (int i = 0; i < 16; i++)
     {
         ListTreeNode LTN = root.Children[i];
         if(LTN != null) Children[i] = new NodeDataEntity(LTN);
     }
 }
Esempio n. 2
0
        public NodeDataEntity(ListTreeNode node)
        {
            NodeHash = node.Hash;
            LeafCount = node.LeafCount;
            AddressNibbles = node.addressNibbles;

            Children = new Hash[16];
            for (int i = 0; i < 16; i++)
            {
                ListTreeNode LTN = node.Children[i];
                if (LTN != null) Children[i] = LTN.Hash;
            }
        }
Esempio n. 3
0
 public ListHashTree()
 {
     Root = new ListTreeNode();
 }
Esempio n. 4
0
        private List<LeafDataType> TraverseTree(ListTreeNode Root, ref long FoundLeafDataCount, ref long FoundNodesCount, LeafDataFetchEventHandler leafDataFetch, long depth)
        {
            List<LeafDataType> foundElements = new List<LeafDataType>();

            // int depth = _depth + 1;

            for (int i = 0; i < 16; i++)
            {
                if (Root.Children[i] != null)
                {
                    /////////////////////////////////////

                    FoundNodesCount++;

                    if (Root.Hash != null)
                    {
                        //DisplayUtils.Display("ID : " + HexUtil.ToString(Root.Hash.Hex) + " : " + depth);
                    }
                    else
                    {
                        //DisplayUtils.Display("ID: NULL --------------- =============== ------------- :");
                    }

                    ////////////////////////////////

                    if (!Root.Children[i].IsLeaf)
                    {
                        //DisplayUtils.Display("Intermediate Traversed : " + Root.Children[i].Hash.ToString() + " : " + depth);

                        TraverseTree(Root.Children[i], ref FoundLeafDataCount, ref FoundNodesCount, leafDataFetch, depth + 1);
                    }
                    else
                    {
                        ListTreeLeafNode Leaf = (ListTreeLeafNode)Root.Children[i];

                        LeafDataType[] ldts = Leaf.GetAllItems();

                        if (leafDataFetch != null)
                            leafDataFetch(ldts);

                        foundElements.AddRange(ldts);

                        // TotalMoney += ((AccountInfo)Leaf.).Money;
                        //DisplayUtils.Display("\nLeaf Node Traversed: " + HexUtil.ToString(Leaf.GetHash().Hex) + " - " +
                        //AccountInfo.CalculateTotalMoney(ldts));

                        /*foreach (LeafDataType ld in ldts)
                        {
                            //DisplayUtils.Display("          --- ID: " + HexUtil.ToString(ld.GetID().Hex) + " - Money " + ((AccountInfo)ld).Money);
                            TotalMoney += ((AccountInfo)ld).Money;
                        }*/

                        FoundLeafDataCount += ldts.Length;
                    }
                }
            }

            return foundElements;
        }
Esempio n. 5
0
        public TraverseResult TraverseToNode(Hash AddressNibbles, out ListTreeNode Leaf)
        {
            ListTreeNode TempRoot = Root;

            int LeafDepth = Constants.HashTree_NodeListDepth;

            byte[] addressNibbles = AddressNibbles.Hex;

            if (addressNibbles.Length <= LeafDepth)
            {
                for (int i = 0; i < AddressNibbles.Hex.Length; i++)
                {
                    byte Nibble = AddressNibbles.Hex[i];

                    if ((i < (LeafDepth - 1)))
                    {
                        if (TempRoot.Children[Nibble] == null)
                        {
                            Leaf = default(ListTreeLeafNode);
                            return TraverseResult.MidwayBreak;
                        }

                        TempRoot = TempRoot.Children[Nibble];
                    }

                    if (i == (addressNibbles.Length - 1)) // ValidateCondition
                    {
                        // Success
                        Leaf = TempRoot;
                        return TraverseResult.Success;
                    }
                }
            }
            else
            {
                Leaf = default(ListTreeLeafNode);
                return TraverseResult.TooLongAddressPath;
            }

            Leaf = default(ListTreeLeafNode);
            return TraverseResult.NodeDoesNotExist;
        }
Esempio n. 6
0
        /// <summary>
        /// This method will give all the leaves under a node
        /// Method is recursive. Set MaxLeaves properly.
        /// </summary>
        /// /// <param name="MaxLeaves"></param>
        /// <param name="Node"></param>
        /// <param name="Leaves"></param>
        /// <returns></returns>
        public void GetAllLeavesUnderNode(long MaxLeaves, ListTreeNode Node, ref List<LeafDataType> Leaves)
        {
            //List<LeafDataType> leaves = new List<LeafDataType>();

            for (int i = 0; i < 16; i++)
            {
                if (Node.Children[i] != null)
                {
                    // Base condition of the recursion
                    if (Node.Children[i].IsLeaf)
                    {
                        ListTreeLeafNode leafNode = (ListTreeLeafNode)Node.Children[i];

                        if ((Leaves.Count + leafNode.Count) > MaxLeaves) break;

                        SortedDictionary<Hash, LeafDataType> val = leafNode.Values;
                        foreach (KeyValuePair<Hash, LeafDataType> v in val)
                        {
                            Leaves.Add(v.Value);
                        }

                        return;
                    } // recusion steps
                    else
                    {
                        GetAllLeavesUnderNode(MaxLeaves, Node.Children[i], ref Leaves);
                    }
                }
            }
        }