Ejemplo n.º 1
0
        public override Hash256 Hash()
        {
            var        half = new Hash256.HalfSha512();
            HashPrefix prefix;

            switch (this.Type)
            {
            case NodeType.tnTRANSACTION_MD:
                prefix = HashPrefix.TxNode;
                break;

            case NodeType.tnACCOUNT_STATE:
                prefix = HashPrefix.LeafNode;
                break;

            default:
                throw new InvalidOperationException("No support for " + this.Type);
            }

            half.Update(prefix.Bytes);
            half.Update(this.Blob.Bytes);
            half.Update(this.index);

            return(half.Finish());
        }
Ejemplo n.º 2
0
        public override Hash256 Hash()
        {
            var half = new Hash256.HalfSha512();

            half.Update(HashPrefix.LeafNode);
            this.sle.ToBytesSink(half);
            half.Update(this.Index);
            return(half.Finish());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// All data stored is keyed by the hash of it's contents.
        /// Ripple uses the first 256 bits of a sha512 as it's 33 percent
        /// faster than using sha256.
        /// </summary>
        /// <param name="content"></param>
        /// <returns>
        /// `key` used to store the content.
        /// </returns>
        private Hash256 StoreContent(byte[] content)
        {
            var hasher = new Hash256.HalfSha512();

            hasher.Update(content);
            Hash256 key = hasher.Finish();

            this.StoreHashKeyedContent(key, content);
            return(key);
        }
Ejemplo n.º 4
0
        public override Hash256 Hash()
        {
            if (!this.NeedsHashing)
            {
                return(this.hash);
            }

            if (this.Empty)
            {
                return(ZERO_256);
            }

            var hasher = new Hash256.HalfSha512();

            hasher.Update(this.HashingPrefix);

            int fullBranches = 0;

            foreach (var node in this.branches)
            {
                if (node != null)
                {
                    var hsh = node.Hash();
                    hasher.Update(hsh);
                    fullBranches++;
                }
                else
                {
                    hasher.Update(ZERO_256);
                }
            }

            this.hash = hasher.Finish();
            this.OnHash(this.hash, fullBranches);
            return(this.hash);
        }