Example #1
0
        private INode CommitFullNode(FullNode fullNode, bool rehearsal)
        {
            var virtualChildren = new INode?[FullNode.ChildrenCount];

            for (int i = 0; i < FullNode.ChildrenCount; ++i)
            {
                INode?child = fullNode.Children[i];
                virtualChildren[i] = child is null
                    ? null
                    : Commit(child, rehearsal);
            }

            fullNode = new FullNode(virtualChildren.ToImmutableArray());
            if (fullNode.Serialize().Length <= HashDigest <SHA256> .Size)
            {
                return(fullNode);
            }
            else
            {
                var fullNodeHash = fullNode.Hash();
                if (!rehearsal)
                {
                    KeyValueStore.Set(
                        fullNodeHash.ToByteArray(),
                        fullNode.Serialize());
                }

                return(new HashNode(fullNodeHash));
            }
        }