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 byte[] 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 = 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
91 inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length
92 inputBytes.AddRange(scriptSig); // scriptSig
93 inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
99 public bool IsCoinBase
101 get { return txID.IsZero; }
104 public override string ToString ()
106 StringBuilder sb = new StringBuilder ();
110 sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig), nSequence);
114 sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, (new CScript(scriptSig)).ToString(), nSequence);
117 return sb.ToString ();