3 using System.Collections.Generic;
13 /// Previous input data
15 public COutPoint prevout;
18 /// First half of script, signatures for the scriptPubKey
20 public CScript scriptSig;
23 /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
25 public uint nSequence = uint.MaxValue;
28 /// Initialize new CTxIn instance as copy of another one.
30 /// <param name="i">CTxIn instance.</param>
33 prevout = new COutPoint(i.prevout);
34 scriptSig = i.scriptSig;
35 nSequence = i.nSequence;
39 /// Initialize an empty instance of CTxIn class
43 prevout = new COutPoint();
44 scriptSig = new CScript();
48 /// Read vin list from byte sequence.
50 /// <param name="wBytes">Reference to byte sequence</param>
51 /// <returns>Inputs array</returns>
52 public static CTxIn[] ReadTxInList(ref WrappedList<byte> wBytes)
57 int nInputs = (int)VarInt.ReadVarInt(ref wBytes);
58 vin = new CTxIn[nInputs];
60 for (int nIndex = 0; nIndex < nInputs; nIndex++)
63 vin[nIndex] = new CTxIn();
64 vin[nIndex].prevout = new COutPoint(wBytes.GetItems(36));
65 vin[nIndex].scriptSig = new CScript(wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)));
66 vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
69 // Return inputs array
74 /// Get raw bytes representation of our input.
76 /// <returns>Byte sequence.</returns>
77 public IList<byte> Bytes
81 List<byte> inputBytes = new List<byte>();
83 inputBytes.AddRange(prevout.Bytes); // prevout
85 List<byte> s = new List<byte>(scriptSig.Bytes);
87 inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length
88 inputBytes.AddRange(s); // scriptSig
89 inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
97 get { return (nSequence == uint.MaxValue); }
99 public override string ToString ()
101 StringBuilder sb = new StringBuilder ();
103 sb.AppendFormat("CTxIn(");
104 sb.Append(prevout.ToString());
108 sb.AppendFormat(", coinbase={0}", Interop.ToHex(scriptSig.Bytes));
112 sb.AppendFormat(", scriptsig={0}", scriptSig.ToString());
115 if (nSequence != uint.MaxValue)
117 sb.AppendFormat(", nSequence={0}", nSequence);
123 return sb.ToString ();