Use implicit type casting operator for serialization.
[NovacoinLibrary.git] / Novacoin / CTxIn.cs
index 4b88d15..a33606a 100644 (file)
@@ -90,23 +90,21 @@ namespace Novacoin
         /// 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 +118,7 @@ namespace Novacoin
 
             if(prevout.IsNull)
             {
-                sb.AppendFormat(", coinbase={0}", Interop.ToHex(scriptSig.Bytes));
+                sb.AppendFormat(", coinbase={0}", Interop.ToHex((byte[])scriptSig));
             }
             else
             {