Implementation of new Size property for CScript, CTxIn, CTxOut, CTransaction and...
[NovacoinLibrary.git] / Novacoin / CTxIn.cs
index 4b88d15..937b367 100644 (file)
@@ -87,26 +87,38 @@ namespace Novacoin
         }
 
         /// <summary>
+        /// Serialized size
+        /// </summary>
+        public int Size
+        {
+            get {
+                int nSize = 40; // COutPoint, nSequence
+                nSize += VarInt.GetEncodedSize(scriptSig.Size);
+                nSize += scriptSig.Size;
+
+                return nSize;
+            }
+        }
+
+        /// <summary>
         /// Get raw bytes representation of our input.
         /// </summary>
         /// <returns>Byte sequence.</returns>
-        public IList<byte> Bytes
+        public static implicit operator byte[] (CTxIn input)
         {
-            get
-            {
-                var inputBytes = new List<byte>();
+            var inputBytes = new List<byte>();
 
-                inputBytes.AddRange(prevout.Bytes); // prevout
+            inputBytes.AddRange((byte[])input.prevout); // prevout
 
-                var s = scriptSig.Bytes;
-                inputBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptSig length
-                inputBytes.AddRange(s); // scriptSig
-                inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
+            var s = (byte[])input.scriptSig;
+            inputBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptSig length
+            inputBytes.AddRange(s); // scriptSig
+            inputBytes.AddRange(BitConverter.GetBytes(input.nSequence)); // Sequence
 
-                return inputBytes;
-            }
+            return inputBytes.ToArray();
         }
 
+
         public bool IsFinal
         {
             get { return (nSequence == uint.MaxValue); }
@@ -120,7 +132,7 @@ namespace Novacoin
 
             if(prevout.IsNull)
             {
-                sb.AppendFormat(", coinbase={0}", Interop.ToHex(scriptSig.Bytes));
+                sb.AppendFormat(", coinbase={0}", Interop.ToHex((byte[])scriptSig));
             }
             else
             {