Example #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());
        }
Example #2
0
        public Hash256 SigningHash()
        {
            Hash256.HalfSha512 signing = Hash256.Prefixed256(HashPrefix.TxSign);
            ToBytesSink(signing, new IsSigningFieldFilter());

            return(signing.Finish());
        }
Example #3
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());
        }
Example #4
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);
        }
Example #5
0
        public void Prepare(IKeyPair keyPair, Amount fee, UInt32 sequence, UInt32 lastLedgerSequence)
        {
            // This won't always be specified
            if (lastLedgerSequence != null)
            {
                Txn.Add(UInt32.LastLedgerSequence, lastLedgerSequence);
            }

            Txn.Add(UInt32.Sequence, sequence);
            Txn.Add(Amount.Fee, fee);
            Txn.Add(VariableLength.SigningPubKey, keyPair.PubBytes());

            if (Transaction.CanonicalFlagDeployed)
            {
                Txn.SetCanonicalSignatureFlag();
            }

            SigningHash = Txn.SigningHash();
            if (PreviousSigningHash != null && SigningHash.Equals(PreviousSigningHash))
            {
                return;
            }

            try
            {
                byte[] signature = keyPair.Sign(SigningHash.Bytes);
                Txn.Add(VariableLength.TxnSignature, signature);

                var blob = new BytesList();
                Hash256.HalfSha512 id = Hash256.Prefixed256(HashPrefix.TransactionId);

                Txn.ToBytesSink(new MultiSink(blob, id));
                TxBlob = blob.BytesHex();
                Hash   = id.Finish();
            }
            catch (Exception e)
            {
                // electric paranoia
                PreviousSigningHash = null;
                throw new ApplicationException("Something went wrong.", e);
            }

            PreviousSigningHash = SigningHash;
        }
Example #6
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);
        }