Limit duplicity on stake & Process orphans only if there are some.
[NovacoinLibrary.git] / Novacoin / CTxOut.cs
index 43c1f63..36f4817 100644 (file)
@@ -39,6 +39,17 @@ namespace Novacoin
         public CScript scriptPubKey;
 
         /// <summary>
+        /// Initialize new outpoint using provided value and script.
+        /// </summary>
+        /// <param name="nValue">Input value</param>
+        /// <param name="scriptPubKey">Spending instructions.</param>
+        public CTxOut(ulong nValue, CScript scriptPubKey)
+        {
+            this.nValue = nValue;
+            this.scriptPubKey = scriptPubKey;
+        }
+
+        /// <summary>
         /// Initialize new CTxOut instance as a copy of another instance.
         /// </summary>
         /// <param name="o">CTxOut instance.</param>
@@ -80,6 +91,48 @@ namespace Novacoin
         }
 
         /// <summary>
+        /// Deserialize outputs array.
+        /// </summary>
+        /// <param name="outBytes">Byte array</param>
+        /// <returns>Outputs array</returns>
+        public static CTxOut[] DeserializeOutputsArray(byte[] outBytes)
+        {
+            var stream = new MemoryStream(outBytes);
+            var reader = new BinaryReader(stream);
+
+            CTxOut[] result = ReadTxOutList(ref reader);
+
+            reader.Close();
+
+            return result;
+        }
+
+        /// <summary>
+        /// Create serialized representation of outputs array.
+        /// </summary>
+        /// <param name="vout">Outputs array</param>
+        /// <returns>Byte array</returns>
+        public static byte[] SerializeOutputsArray(CTxOut[] vout)
+        {
+            var stream = new MemoryStream();
+            var writer = new BinaryWriter(stream);
+
+            writer.Write(VarInt.EncodeVarInt(vout.Length));
+
+            foreach (var o in vout)
+            {
+                writer.Write(o);
+            }
+
+            var resultBytes = stream.ToArray();
+
+            writer.Close();
+
+            return resultBytes;
+        }
+
+
+        /// <summary>
         /// Get raw bytes representation of our output.
         /// </summary>
         /// <returns>Byte sequence.</returns>
@@ -130,7 +183,7 @@ namespace Novacoin
         /// <summary>
         /// Serialized size
         /// </summary>
-        public int Size
+        public uint Size
         {
             get
             {