2 * Novacoin classes library
3 * Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
26 /// Transaction input.
31 /// Previous input data
33 public COutPoint prevout;
36 /// First half of script, signatures for the scriptPubKey
38 public CScript scriptSig;
41 /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
43 public uint nSequence = uint.MaxValue;
46 /// Initialize new CTxIn instance as copy of another one.
48 /// <param name="i">CTxIn instance.</param>
51 prevout = new COutPoint(i.prevout);
52 scriptSig = i.scriptSig;
53 nSequence = i.nSequence;
57 /// Initialize an empty instance of CTxIn class
61 prevout = new COutPoint();
62 scriptSig = new CScript();
66 /// Read vin list from byte sequence.
68 /// <param name="wBytes">Reference to byte sequence</param>
69 /// <returns>Inputs array</returns>
70 public static CTxIn[] ReadTxInList(ref ByteQueue wBytes)
75 int nInputs = (int)wBytes.GetVarInt();
76 vin = new CTxIn[nInputs];
78 for (int nIndex = 0; nIndex < nInputs; nIndex++)
81 vin[nIndex] = new CTxIn();
82 vin[nIndex].prevout = new COutPoint(wBytes.Get(36));
83 vin[nIndex].scriptSig = new CScript(wBytes.Get((int)wBytes.GetVarInt()));
84 vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.Get(4), 0);
87 // Return inputs array
92 /// Get raw bytes representation of our input.
94 /// <returns>Byte sequence.</returns>
95 public IList<byte> Bytes
99 List<byte> inputBytes = new List<byte>();
101 inputBytes.AddRange(prevout.Bytes); // prevout
103 List<byte> s = new List<byte>(scriptSig.Bytes);
105 inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length
106 inputBytes.AddRange(s); // scriptSig
107 inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
115 get { return (nSequence == uint.MaxValue); }
117 public override string ToString ()
119 StringBuilder sb = new StringBuilder ();
121 sb.AppendFormat("CTxIn(");
122 sb.Append(prevout.ToString());
126 sb.AppendFormat(", coinbase={0}", Interop.ToHex(scriptSig.Bytes));
130 sb.AppendFormat(", scriptsig={0}", scriptSig.ToString());
133 if (nSequence != uint.MaxValue)
135 sb.AppendFormat(", nSequence={0}", nSequence);
141 return sb.ToString ();