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
51 public static CTxIn[] ReadTxInList(ref WrappedList<byte> wBytes)
56 int nInputs = (int)VarInt.ReadVarInt(ref wBytes);
57 vin = new CTxIn[nInputs];
59 for (int nIndex = 0; nIndex < nInputs; nIndex++)
62 vin[nIndex] = new CTxIn();
64 vin[nIndex].txID = new Hash256(wBytes.GetItems(32));
65 vin[nIndex].n = Interop.LEBytesToUInt32(wBytes.GetItems(4));
66 vin[nIndex].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
67 vin[nIndex].nSequence = Interop.LEBytesToUInt32(wBytes.GetItems(4));
70 // Return inputs array
75 /// Get raw bytes representation of our input.
77 /// <returns>Byte sequence.</returns>
78 public IList<byte> ToBytes()
80 List<byte> inputBytes = new List<byte>();
82 inputBytes.AddRange(txID.hashBytes); // Input transaction id
83 inputBytes.AddRange(Interop.LEBytes(n)); // Output number
84 inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length
85 inputBytes.AddRange(scriptSig); // scriptSig
86 inputBytes.AddRange(Interop.LEBytes(nSequence)); // Sequence
91 public bool IsCoinBase()
96 public override string ToString ()
98 StringBuilder sb = new StringBuilder ();
102 sb.AppendFormat("CTxIn(txId={0},coinbase={2},nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig), nSequence);
106 sb.AppendFormat("CTxIn(txId={0},n={1},scriptSig={2},nSequence={3})", txID.ToString(), n, (new CScript(scriptSig)).ToString(), nSequence);
109 return sb.ToString ();