Add license header.
[NovacoinLibrary.git] / Novacoin / CTxOut.cs
index 920fcd5..2d4d756 100644 (file)
@@ -1,4 +1,22 @@
-\feffusing System;
+\feff/**
+ *  Novacoin classes library
+ *  Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com)
+
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Affero General Public License as
+ *  published by the Free Software Foundation, either version 3 of the
+ *  License, or (at your option) any later version.
+
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Affero General Public License for more details.
+
+ *  You should have received a copy of the GNU Affero General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using System;
 using System.Text;
 using System.Collections.Generic;
 
@@ -12,7 +30,7 @@ namespace Novacoin
                /// <summary>
                /// Input value.
                /// </summary>
-        public ulong nValue;
+        public long nValue = -1;
 
                /// <summary>
                /// Second half of script which contains spending instructions.
@@ -34,7 +52,7 @@ namespace Novacoin
         /// </summary>
         public CTxOut()
         {
-            scriptPubKey = new CScript();
+            SetEmpty();
         }
 
         /// <summary>
@@ -42,19 +60,19 @@ namespace Novacoin
         /// </summary>
         /// <param name="wBytes">Reference to byte sequence</param>
         /// <returns>Outputs array</returns>
-        public static CTxOut[] ReadTxOutList(ref WrappedList<byte> wBytes)
+        public static CTxOut[] ReadTxOutList(ref ByteQueue wBytes)
         {
-            int nOutputs = (int)VarInt.ReadVarInt(ref wBytes);
+            int nOutputs = (int)wBytes.GetVarInt();
             CTxOut[] vout =new CTxOut[nOutputs];
 
             for (int nIndex = 0; nIndex < nOutputs; nIndex++)
             {
                 // Fill outputs array
                 vout[nIndex] = new CTxOut();
-                vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.GetItems(8), 0);
+                vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.Get(8), 0);
 
-                int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
-                vout[nIndex].scriptPubKey = new CScript(wBytes.GetItems(nScriptPKLen));
+                int nScriptPKLen = (int)wBytes.GetVarInt();
+                vout[nIndex].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen));
             }
 
             return vout;
@@ -81,6 +99,34 @@ namespace Novacoin
             }
         }
 
+        /// <summary>
+        /// Null prevouts have -1 value
+        /// </summary>
+        public void SetNull()
+        {
+            nValue = -1;
+            scriptPubKey = new CScript();
+        }
+
+        /// <summary>
+        /// Empty outputs have zero value and empty scriptPubKey
+        /// </summary>
+        public void SetEmpty()
+        {
+            nValue = 0;
+            scriptPubKey = new CScript();
+        }
+
+        public bool IsNull
+        {
+            get { return (nValue == -1); }
+        }
+
+        public bool IsEmpty
+        {
+           get { return nValue == 0 && scriptPubKey.IsNull; }
+        }
+
                public override string ToString ()
                {
                        StringBuilder sb = new StringBuilder ();