Removal of ReadVarInt
authorCryptoManiac <balthazar@yandex.ru>
Fri, 21 Aug 2015 19:10:30 +0000 (22:10 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Fri, 21 Aug 2015 19:10:30 +0000 (22:10 +0300)
Novacoin/CBlock.cs
Novacoin/CTransaction.cs
Novacoin/CTxIn.cs
Novacoin/CTxOut.cs
Novacoin/VarInt.cs
Novacoin/WrappedList.cs

index 8f6fb76..82a8b88 100644 (file)
@@ -51,7 +51,7 @@ namespace Novacoin
             vtx = CTransaction.ReadTransactionsList(ref wBytes);
 
             // Read block signature
-            signature = wBytes.Get((int)VarInt.ReadVarInt(ref wBytes));
+            signature = wBytes.Get((int)wBytes.GetVarInt());
                }
 
         public CBlock()
index cd66ada..792c426 100644 (file)
@@ -84,7 +84,7 @@ namespace Novacoin
             nVersion = BitConverter.ToUInt32(wBytes.Get(4), 0);
             nTime = BitConverter.ToUInt32(wBytes.Get(4), 0);
 
-            int nInputs = (int)VarInt.ReadVarInt(ref wBytes);
+            int nInputs = (int)(int)wBytes.GetVarInt();
             vin = new CTxIn[nInputs];
 
             for (int nCurrentInput = 0; nCurrentInput < nInputs; nCurrentInput++)
@@ -94,13 +94,13 @@ namespace Novacoin
                 
                 vin[nCurrentInput].prevout = new COutPoint(wBytes.Get(36));
 
-                int nScriptSigLen = (int)VarInt.ReadVarInt(ref wBytes);
+                int nScriptSigLen = (int)wBytes.GetVarInt();
                 vin[nCurrentInput].scriptSig = new CScript(wBytes.Get(nScriptSigLen));
 
                 vin[nCurrentInput].nSequence = BitConverter.ToUInt32(wBytes.Get(4), 0);
             }
 
-            int nOutputs = (int)VarInt.ReadVarInt(ref wBytes);
+            int nOutputs = (int)wBytes.GetVarInt();
             vout = new CTxOut[nOutputs];
 
             for (int nCurrentOutput = 0; nCurrentOutput < nOutputs; nCurrentOutput++)
@@ -109,7 +109,7 @@ namespace Novacoin
                 vout[nCurrentOutput] = new CTxOut();
                 vout[nCurrentOutput].nValue = BitConverter.ToInt64(wBytes.Get(8), 0);
 
-                int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
+                int nScriptPKLen = (int)wBytes.GetVarInt();
                 vout[nCurrentOutput].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen));
             }
 
@@ -126,7 +126,7 @@ namespace Novacoin
             CTransaction[] tx;
 
             // Read amount of transactions
-            int nTransactions = (int)VarInt.ReadVarInt(ref wTxBytes);
+            int nTransactions = (int)wTxBytes.GetVarInt();
             tx = new CTransaction[nTransactions];
 
             for (int nTx = 0; nTx < nTransactions; nTx++)
index 8cff600..967ae0e 100644 (file)
@@ -54,7 +54,7 @@ namespace Novacoin
             CTxIn[] vin;
 
             // Get amount
-            int nInputs = (int)VarInt.ReadVarInt(ref wBytes);
+            int nInputs = (int)wBytes.GetVarInt();
             vin = new CTxIn[nInputs];
 
             for (int nIndex = 0; nIndex < nInputs; nIndex++)
@@ -62,7 +62,7 @@ namespace Novacoin
                 // Fill inputs array
                 vin[nIndex] = new CTxIn();
                 vin[nIndex].prevout = new COutPoint(wBytes.Get(36));
-                vin[nIndex].scriptSig = new CScript(wBytes.Get((int)VarInt.ReadVarInt(ref wBytes)));
+                vin[nIndex].scriptSig = new CScript(wBytes.Get((int)wBytes.GetVarInt()));
                 vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.Get(4), 0);
             }
 
index 8acab9b..32fa51b 100644 (file)
@@ -44,7 +44,7 @@ namespace Novacoin
         /// <returns>Outputs array</returns>
         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++)
@@ -53,7 +53,7 @@ namespace Novacoin
                 vout[nIndex] = new CTxOut();
                 vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.Get(8), 0);
 
-                int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
+                int nScriptPKLen = (int)wBytes.GetVarInt();
                 vout[nIndex].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen));
             }
 
index 35e8e8a..ea30a58 100644 (file)
@@ -94,30 +94,5 @@ namespace Novacoin
                     return prefix;
             }
         }
-
-        /// <summary>
-        /// Read and decode variable integer from wrapped list object.
-        /// 
-        /// Note: Should be used only if there is some variable integer data at current position. Otherwise you will get undefined behavior, so make sure that you know what you are doing.
-        /// </summary>
-        /// <param name="wBytes"></param>
-        /// <returns></returns>
-        public static ulong ReadVarInt(ref ByteQueue wBytes)
-        {
-            byte prefix = wBytes.Get();
-
-            switch (prefix)
-            {
-                case 0xfd: // ushort
-                    return BitConverter.ToUInt16(wBytes.Get(2), 0);
-                case 0xfe: // uint
-                    return BitConverter.ToUInt32(wBytes.Get(4), 0);
-                case 0xff: // ulong
-                    return BitConverter.ToUInt64(wBytes.Get(8), 0);
-                default:
-                    return prefix;
-            }
-
-        }
     }
 }
index ff50096..b8c1656 100644 (file)
@@ -92,5 +92,22 @@ namespace Novacoin
 
             return result;
         }
+
+        public ulong GetVarInt()
+        {
+            byte prefix = Get();
+
+            switch (prefix)
+            {
+                case 0xfd: // ushort
+                    return BitConverter.ToUInt16(Get(2), 0);
+                case 0xfe: // uint
+                    return BitConverter.ToUInt32(Get(4), 0);
+                case 0xff: // ulong
+                    return BitConverter.ToUInt64(Get(8), 0);
+                default:
+                    return prefix;
+            }
+        }
     }
 }