/// <summary>
/// Hash of parent transaction.
/// </summary>
- private Hash256 txID = new Hash256();
+ public Hash256 txID = new Hash256();
/// <summary>
/// Parent input number.
/// </summary>
- private uint nInput = 0;
+ public uint n = 0;
/// <summary>
/// First half of script, signatures for the scriptPubKey
/// </summary>
- private byte[] scriptSig;
+ public byte[] scriptSig;
/// <summary>
/// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
/// </summary>
- private uint nSequence = 0xffffffff;
+ public uint nSequence = 0xffffffff;
/// <summary>
/// Initialize new CTxIn instance as copy of another one.
public CTxIn(CTxIn i)
{
txID = i.txID;
- nInput = i.nInput;
+ n = i.n;
scriptSig = i.scriptSig;
nSequence = i.nSequence;
}
/// <summary>
- /// Decode byte sequence and initialize new instance of CTxIn class.
+ /// Initialize an empty instance of CTxIn class
/// </summary>
- /// <param name="bytes">Byte sequence</param>
- public CTxIn (IList<byte> bytes)
- {
- WrappedList<byte> wBytes = new WrappedList<byte>(bytes);
-
- txID = new Hash256(wBytes.GetItems(32));
- nInput = Interop.LEBytesToUInt32(wBytes.GetItems(4));
- int ssLength = (int)VarInt.ReadVarInt(wBytes);
- scriptSig = wBytes.GetItems(ssLength);
- nSequence = Interop.LEBytesToUInt32(wBytes.GetItems(4));
- }
+ public CTxIn()
+ {
+ }
/// <summary>
/// Get raw bytes representation of our input.
List<byte> inputBytes = new List<byte>();
inputBytes.AddRange(txID.hashBytes); // Input transaction id
- inputBytes.AddRange(Interop.LEBytes(nInput)); // Input number
- inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // Scriptsig length
- inputBytes.AddRange(scriptSig); // ScriptSig
+ inputBytes.AddRange(Interop.LEBytes(n)); // Output number
+ inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length
+ inputBytes.AddRange(scriptSig); // scriptSig
inputBytes.AddRange(Interop.LEBytes(nSequence)); // Sequence
return inputBytes;
}
+ public bool IsCoinBase()
+ {
+ return txID.IsZero();
+ }
+
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
- sb.AppendFormat ("CTxIn(txId={0},n={1},scriptSig={2}", nInput, nInput, scriptSig.ToString());
+
+ if (IsCoinBase())
+ {
+ sb.AppendFormat("CTxIn(txId={0},coinbase={2},nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig), nSequence);
+ }
+ else
+ {
+ sb.AppendFormat("CTxIn(txId={0},n={1},scriptSig={2},nSequence={3})", txID.ToString(), n, (new CScript(scriptSig)).ToString(), nSequence);
+ }
return sb.ToString ();
}