3 using System.Collections.Generic;
13 /// Hash of parent transaction.
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
50 scriptSig = new CScript();
54 /// Read vin list from byte sequence.
56 /// <param name="wBytes">Reference to byte sequence</param>
57 /// <returns>Inputs array</returns>
58 public static CTxIn[] ReadTxInList(ref WrappedList<byte> wBytes)
63 int nInputs = (int)VarInt.ReadVarInt(ref wBytes);
64 vin = new CTxIn[nInputs];
66 for (int nIndex = 0; nIndex < nInputs; nIndex++)
69 vin[nIndex] = new CTxIn();
71 vin[nIndex].txID = new Hash256(wBytes.GetItems(32));
72 vin[nIndex].n = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
73 vin[nIndex].scriptSig = new CScript(wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)));
74 vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
77 // Return inputs array
82 /// Get raw bytes representation of our input.
84 /// <returns>Byte sequence.</returns>
85 public IList<byte> Bytes
89 List<byte> inputBytes = new List<byte>();
91 inputBytes.AddRange(txID.hashBytes); // Input transaction id
92 inputBytes.AddRange(BitConverter.GetBytes(n)); // Output number
94 List<byte> s = new List<byte>(scriptSig.Bytes);
96 inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length
97 inputBytes.AddRange(s); // scriptSig
98 inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
104 public bool IsCoinBase
106 get { return txID.IsZero; }
109 public override string ToString ()
111 StringBuilder sb = new StringBuilder ();
115 sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig.Bytes), nSequence);
119 sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, scriptSig.ToString(), nSequence);
122 return sb.ToString ();