ToInt64 -> ToUInt64
[NovacoinLibrary.git] / Novacoin / CTransaction.cs
index d8572eb..343968a 100644 (file)
@@ -30,12 +30,12 @@ namespace Novacoin
         /// <summary>
         /// Version of transaction schema.
         /// </summary>
-        public uint nVersion = 1;
+        public uint nVersion;
 
         /// <summary>
         /// Transaction timestamp.
         /// </summary>
-        public uint nTime = 0;
+        public uint nTime;
 
         /// <summary>
         /// Array of transaction inputs
@@ -50,7 +50,7 @@ namespace Novacoin
         /// <summary>
         /// Block height or timestamp when transaction is final
         /// </summary>
-        public uint nLockTime = 0;
+        public uint nLockTime;
 
         /// <summary>
         /// Initialize an empty instance
@@ -60,8 +60,11 @@ namespace Novacoin
             // Initialize empty input and output arrays. Please note that such 
             // configuration is not valid for real transaction, you have to supply 
             // at least one input and one output.
+            nVersion = 1;
+            nTime = 0;
             vin = new CTxIn[0];
             vout = new CTxOut[0];
+            nLockTime = 0;
         }
 
         /// <summary>
@@ -102,7 +105,7 @@ namespace Novacoin
             nVersion = BitConverter.ToUInt32(wBytes.Get(4), 0);
             nTime = BitConverter.ToUInt32(wBytes.Get(4), 0);
 
-            int nInputs = (int)(int)wBytes.GetVarInt();
+            int nInputs = (int)wBytes.GetVarInt();
             vin = new CTxIn[nInputs];
 
             for (int nCurrentInput = 0; nCurrentInput < nInputs; nCurrentInput++)
@@ -125,7 +128,7 @@ namespace Novacoin
             {
                 // Fill outputs array
                 vout[nCurrentOutput] = new CTxOut();
-                vout[nCurrentOutput].nValue = BitConverter.ToInt64(wBytes.Get(8), 0);
+                vout[nCurrentOutput].nValue = BitConverter.ToUInt64(wBytes.Get(8), 0);
 
                 int nScriptPKLen = (int)wBytes.GetVarInt();
                 vout[nCurrentOutput].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen));
@@ -135,6 +138,32 @@ namespace Novacoin
         }
 
         /// <summary>
+        /// Serialized size
+        /// </summary>
+        public int Size
+        {
+            get
+            {
+                int nSize = 12; // nVersion, nTime, nLockLime
+
+                nSize += VarInt.GetEncodedSize(vin.Length);
+                nSize += VarInt.GetEncodedSize(vout.Length);
+
+                foreach (var input in vin)
+                {
+                    nSize += input.Size;
+                }
+
+                foreach (var output in vout)
+                {
+                    nSize += output.Size;
+                }
+
+                return nSize;
+            }
+        }
+
+        /// <summary>
         /// Read transactions array which is encoded in the block body.
         /// </summary>
         /// <param name="wTxBytes">Bytes sequence</param>