3 using System.Collections.Generic;
13 /// Hash of parent transaction.
15 private Hash256 txID = new Hash256();
18 /// Parent input number.
20 private uint nInput = 0;
23 /// First half of script, signatures for the scriptPubKey
25 private byte[] scriptSig;
28 /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
30 private 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 /// Decode byte sequence and initialize new instance of CTxIn class.
47 /// <param name="bytes">Byte sequence</param>
48 public CTxIn (IList<byte> bytes)
50 WrappedList<byte> wBytes = new WrappedList<byte>(bytes);
52 txID = new Hash256(wBytes.GetItems(32));
53 nInput = Interop.LEBytesToUInt32(wBytes.GetItems(4));
54 int ssLength = (int)VarInt.ReadVarInt(wBytes);
55 scriptSig = wBytes.GetItems(ssLength);
56 nSequence = Interop.LEBytesToUInt32(wBytes.GetItems(4));
60 /// Get raw bytes representation of our input.
62 /// <returns>Byte sequence.</returns>
63 public IList<byte> ToBytes()
65 List<byte> inputBytes = new List<byte>();
67 inputBytes.AddRange(txID.hashBytes); // Input transaction id
68 inputBytes.AddRange(Interop.LEBytes(nInput)); // Input number
69 inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // Scriptsig length
70 inputBytes.AddRange(scriptSig); // ScriptSig
71 inputBytes.AddRange(Interop.LEBytes(nSequence)); // Sequence
76 public override string ToString ()
78 StringBuilder sb = new StringBuilder ();
79 sb.AppendFormat ("CTxIn(txId={0},n={1},scriptSig={2}", nInput, nInput, scriptSig.ToString());
81 return sb.ToString ();