Ejemplo n.º 1
0
        /// <summary>
        /// Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is removed from the returned data.
        /// </summary>
        /// <exception cref="AddressFormatException">If the input is not base 58 or the checksum does not validate.</exception>
        public byte[] DecodeChecked(string input)
        {
            var tmp = Decode(input);

            if (tmp.Length < 4)
            {
                throw new AddressFormatException("Input too short");
            }

            var checksum = new byte[4];

            Array.Copy(tmp, tmp.Length - 4, checksum, 0, 4);

            var bytes = new byte[tmp.Length - 4];

            Array.Copy(tmp, 0, bytes, 0, tmp.Length - 4);

            tmp = DoubleDigestSha256Helper.DoubleDigest(bytes);
            var hash = new byte[4];

            Array.Copy(tmp, 0, hash, 0, 4);
            if (!hash.SequenceEqual(checksum))
            {
                throw new AddressFormatException("Checksum does not validate");
            }
            return(bytes);
        }
Ejemplo n.º 2
0
        /////throws ClassNotFoundException, IOException
        //private void readObject(ObjectInputStream ois)
        //{
        //	ois.defaultReadObject();
        //	// This code is not actually necessary, as transient fields are initialized to the default value which is in
        //	// this case null. However it clears out a FindBugs warning and makes it explicit what we're doing.
        //	hash = null;
        //}

        private void parseHeader()
        {
            if (headerParsed)
            {
                return;
            }

            Cursor            = Offset;
            Version           = ReadUint32();
            PreviousBlockHash = ReadHash();
            MerkleRoot        = ReadHash();
            TimeSeconds       = ReadUint32();
            difficultyTarget  = ReadUint32();
            nonce             = ReadUint32();

            hash = new Sha256Hash(DoubleDigestSha256Helper.DoubleDigest(Bytes, Offset, Cursor).ReverseBytes());

            headerParsed     = true;
            headerBytesValid = ParseRetain;
        }