using System; using System.Text; using System.Collections.Generic; namespace Novacoin { /// /// Transaction input. /// public class CTxIn { /// /// Previous input data /// public COutPoint prevout; /// /// First half of script, signatures for the scriptPubKey /// public CScript scriptSig; /// /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default. /// public uint nSequence = uint.MaxValue; /// /// Initialize new CTxIn instance as copy of another one. /// /// CTxIn instance. public CTxIn(CTxIn i) { prevout = new COutPoint(i.prevout); scriptSig = i.scriptSig; nSequence = i.nSequence; } /// /// Initialize an empty instance of CTxIn class /// public CTxIn() { prevout = new COutPoint(); scriptSig = new CScript(); } /// /// Read vin list from byte sequence. /// /// Reference to byte sequence /// Inputs array public static CTxIn[] ReadTxInList(ref WrappedList wBytes) { CTxIn[] vin; // Get amount int nInputs = (int)VarInt.ReadVarInt(ref wBytes); vin = new CTxIn[nInputs]; for (int nIndex = 0; nIndex < nInputs; nIndex++) { // Fill inputs array vin[nIndex] = new CTxIn(); vin[nIndex].prevout = new COutPoint(wBytes.GetItems(36)); vin[nIndex].scriptSig = new CScript(wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes))); vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0); } // Return inputs array return vin; } /// /// Get raw bytes representation of our input. /// /// Byte sequence. public IList Bytes { get { List inputBytes = new List(); inputBytes.AddRange(prevout.Bytes); // prevout List s = new List(scriptSig.Bytes); inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length inputBytes.AddRange(s); // scriptSig inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence return inputBytes; } } public bool IsFinal { get { return (nSequence == uint.MaxValue); } } public override string ToString () { StringBuilder sb = new StringBuilder (); sb.AppendFormat("CTxIn("); sb.Append(prevout.ToString()); if(prevout.IsNull) { sb.AppendFormat(", coinbase={0}", Interop.ToHex(scriptSig.Bytes)); } else { sb.AppendFormat(", scriptsig={0}", scriptSig.ToString()); } if (nSequence != uint.MaxValue) { sb.AppendFormat(", nSequence={0}", nSequence); } sb.Append(")"); return sb.ToString (); } } }