Improve empty constructors behavior
[NovacoinLibrary.git] / Novacoin / CTxIn.cs
index 7f6aeee..9983c65 100644 (file)
@@ -12,7 +12,7 @@ namespace Novacoin
                /// <summary>
                /// Hash of parent transaction.
                /// </summary>
-               public Hash256 txID = new Hash256();
+               public Hash256 txID;
 
                /// <summary>
                /// Parent input number.
@@ -22,7 +22,7 @@ namespace Novacoin
                /// <summary>
                /// First half of script, signatures for the scriptPubKey
                /// </summary>
-        public byte[] scriptSig;
+        public CScript scriptSig;
 
                /// <summary>
                /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
@@ -46,6 +46,8 @@ namespace Novacoin
         /// </summary>
         public CTxIn()
         {
+            txID = new Hash256();
+            scriptSig = new CScript();
         }
 
         /// <summary>
@@ -68,7 +70,7 @@ namespace Novacoin
 
                 vin[nIndex].txID = new Hash256(wBytes.GetItems(32));
                 vin[nIndex].n = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
-                vin[nIndex].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
+                vin[nIndex].scriptSig = new CScript(wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)));
                 vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
             }
 
@@ -88,8 +90,11 @@ namespace Novacoin
 
                 inputBytes.AddRange(txID.hashBytes); // Input transaction id
                 inputBytes.AddRange(BitConverter.GetBytes(n)); // Output number
-                inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length
-                inputBytes.AddRange(scriptSig); // scriptSig
+
+                List<byte> s = new List<byte>(scriptSig.Bytes);
+
+                inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length
+                inputBytes.AddRange(s); // scriptSig
                 inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
 
                 return inputBytes;
@@ -107,11 +112,11 @@ namespace Novacoin
 
             if (IsCoinBase)
             {
-                sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig), nSequence);
+                sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig.Bytes), nSequence);
             }
             else
             {
-                sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, (new CScript(scriptSig)).ToString(), nSequence);
+                sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, scriptSig.ToString(), nSequence);
             }
 
                        return sb.ToString ();