Beispiel #1
0
        /// <summary>
        /// Deserializes the given byte array starting from the specified offset. The return value indicates success.
        /// </summary>
        /// <param name="data">Byte array containing an <see cref="TxIn"/>.</param>
        /// <param name="offset">The offset inside the <paramref name="data"/> to start from.</param>
        /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure).</param>
        /// <returns>True if deserialization was successful, false if otherwise.</returns>
        public bool TryDeserialize(byte[] data, ref int offset, out string error)
        {
            if (offset < 0)
            {
                error = "Offset can not be negative.";
                return(false);
            }
            if (data == null || data.Length - offset < MinSize)
            {
                error = "Data length is not valid.";
                return(false);
            }
            // TODO: Outpoint and SigScript could be null, perform a check?

            if (!Outpoint.TryDeserialize(data, ref offset, out error))
            {
                return(false);
            }

            if (!SigScript.TryDeserialize(data, ref offset, out error))
            {
                return(false);
            }

            Sequence = data.SubArray(offset, sizeof(uint)).ToUInt32(false);
            offset  += sizeof(uint);

            error = null;
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public byte[] ForBlkHash()
        {
            var payload = new List <byte>();

            payload.AddRange(ToBytes());                       // txOut.PublicKeyScript.Length
            payload.AddRange(BitConverter.GetBytes(Sequence)); // 4 bytes
            payload.AddRange(PublicKey);                       // 32 bytes
            payload.AddRange(SigScript.HexToByteArray());      // 4 bytes
            return(payload.ToArray());
        }
Beispiel #3
0
        /// <summary>
        /// Converts this instance into its byte array representation.
        /// </summary>
        /// <exception cref="ArgumentNullException"/>
        /// <returns>An array of bytes</returns>
        public byte[] Serialize()
        {
            if (Outpoint == null)
            {
                throw new ArgumentNullException(nameof(Outpoint), "Outpoint can not be null.");
            }
            if (SigScript == null)
            {
                throw new ArgumentNullException(nameof(SigScript), "Signature script can not be null!");
            }


            return(ByteArray.ConcatArrays(
                       Outpoint.Serialize(),
                       SigScript.Serialize(),
                       Sequence.ToByteArray(false)
                       ));
        }