3 using System.Collections.Generic;
13 /// Hash of parent transaction.
15 public Hash256 txID = new Hash256();
18 /// Parent input number.
23 /// First half of script, signatures for the scriptPubKey
25 public CScript scriptSig;
28 /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
30 public uint nSequence = 0xffffffff;
33 /// Initialize new CTxIn instance as copy of another one.
35 /// <param name="i">CTxIn instance.</param>
40 scriptSig = i.scriptSig;
41 nSequence = i.nSequence;
45 /// Initialize an empty instance of CTxIn class
52 /// Read vin list from byte sequence.
54 /// <param name="wBytes">Reference to byte sequence</param>
55 /// <returns>Inputs array</returns>
56 public static CTxIn[] ReadTxInList(ref WrappedList<byte> wBytes)
61 int nInputs = (int)VarInt.ReadVarInt(ref wBytes);
62 vin = new CTxIn[nInputs];
64 for (int nIndex = 0; nIndex < nInputs; nIndex++)
67 vin[nIndex] = new CTxIn();
69 vin[nIndex].txID = new Hash256(wBytes.GetItems(32));
70 vin[nIndex].n = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
71 vin[nIndex].scriptSig = new CScript(wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)));
72 vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
75 // Return inputs array
80 /// Get raw bytes representation of our input.
82 /// <returns>Byte sequence.</returns>
83 public IList<byte> Bytes
87 List<byte> inputBytes = new List<byte>();
89 inputBytes.AddRange(txID.hashBytes); // Input transaction id
90 inputBytes.AddRange(BitConverter.GetBytes(n)); // Output number
92 List<byte> s = new List<byte>(scriptSig.Bytes);
94 inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length
95 inputBytes.AddRange(s); // scriptSig
96 inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
102 public bool IsCoinBase
104 get { return txID.IsZero; }
107 public override string ToString ()
109 StringBuilder sb = new StringBuilder ();
113 sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig.Bytes), nSequence);
117 sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, scriptSig.ToString(), nSequence);
120 return sb.ToString ();