ReadTxInList, ReadTxOutList and ReadTxList are internal now.
authorCryptoManiac <balthazar@yandex.ru>
Mon, 31 Aug 2015 20:52:23 +0000 (23:52 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Mon, 31 Aug 2015 20:52:23 +0000 (23:52 +0300)
Novacoin/CBlock.cs
Novacoin/CTransaction.cs
Novacoin/CTxIn.cs
Novacoin/CTxOut.cs

index 79d07d4..101d20e 100644 (file)
@@ -88,16 +88,25 @@ namespace Novacoin
                {
             try
             {
-                ByteQueue wBytes = new ByteQueue(ref blockBytes);
+                var stream = new MemoryStream(blockBytes);
+                var reader = new BinaryReader(stream);
 
                 // Fill the block header fields
-                header = new CBlockHeader(wBytes.Get(80));
+                header = new CBlockHeader();
+                header.nVersion = reader.ReadUInt32();
+                header.prevHash = new ScryptHash256(reader.ReadBytes(32));
+                header.merkleRoot = new Hash256(reader.ReadBytes(32));
+                header.nTime = reader.ReadUInt32();
+                header.nBits = reader.ReadUInt32();
+                header.nNonce = reader.ReadUInt32();                
 
                 // Parse transactions list
-                vtx = CTransaction.ReadTransactionsList(ref wBytes);
+                vtx = CTransaction.ReadTransactionsList(ref reader);
 
                 // Read block signature
-                signature = wBytes.Get((int)wBytes.GetVarInt());
+                signature = reader.ReadBytes((int)VarInt.ReadVarInt(ref reader));
+
+                reader.Close();
             }
             catch (Exception e)
             {
index d1cc3dd..e67ed45 100644 (file)
@@ -342,12 +342,12 @@ namespace Novacoin
         /// </summary>
         /// <param name="wTxBytes">Bytes sequence</param>
         /// <returns>Transactions array</returns>
-        public static CTransaction[] ReadTransactionsList(ref ByteQueue wTxBytes)
+        internal static CTransaction[] ReadTransactionsList(ref BinaryReader reader)
         {
             try
             {
                 // Read amount of transactions
-                int nTransactions = (int)wTxBytes.GetVarInt();
+                int nTransactions = (int)VarInt.ReadVarInt(ref reader);
                 var tx = new CTransaction[nTransactions];
 
                 for (int nTx = 0; nTx < nTransactions; nTx++)
@@ -355,16 +355,16 @@ namespace Novacoin
                     // Fill the transactions array
                     tx[nTx] = new CTransaction();
 
-                    tx[nTx].nVersion = BitConverter.ToUInt32(wTxBytes.Get(4), 0);
-                    tx[nTx].nTime = BitConverter.ToUInt32(wTxBytes.Get(4), 0);
+                    tx[nTx].nVersion = reader.ReadUInt32();
+                    tx[nTx].nTime = reader.ReadUInt32();
 
                     // Inputs array
-                    tx[nTx].vin = CTxIn.ReadTxInList(ref wTxBytes);
+                    tx[nTx].vin = CTxIn.ReadTxInList(ref reader);
 
                     // outputs array
-                    tx[nTx].vout = CTxOut.ReadTxOutList(ref wTxBytes);
+                    tx[nTx].vout = CTxOut.ReadTxOutList(ref reader);
 
-                    tx[nTx].nLockTime = BitConverter.ToUInt32(wTxBytes.Get(4), 0);
+                    tx[nTx].nLockTime = reader.ReadUInt32();
                 }
 
                 return tx;
index 067ad46..376f27f 100644 (file)
@@ -84,23 +84,23 @@ namespace Novacoin
         /// <summary>
         /// Read vin list from byte sequence.
         /// </summary>
-        /// <param name="wBytes">Reference to byte sequence</param>
+        /// <param name="wBytes">Reference to binary reader</param>
         /// <returns>Inputs array</returns>
-        public static CTxIn[] ReadTxInList(ref ByteQueue wBytes)
+        internal static CTxIn[] ReadTxInList(ref BinaryReader reader)
         {
             try
             {
                 // Get amount
-                int nInputs = (int)wBytes.GetVarInt();
+                int nInputs = (int)VarInt.ReadVarInt(ref reader);
                 var vin = new CTxIn[nInputs];
 
                 for (int nIndex = 0; nIndex < nInputs; nIndex++)
                 {
                     // Fill inputs array
                     vin[nIndex] = new CTxIn();
-                    vin[nIndex].prevout = new COutPoint(wBytes.Get(36));
-                    vin[nIndex].scriptSig = new CScript(wBytes.Get((int)wBytes.GetVarInt()));
-                    vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.Get(4), 0);
+                    vin[nIndex].prevout = new COutPoint(reader.ReadBytes(36));
+                    vin[nIndex].scriptSig = new CScript(reader.ReadBytes((int)VarInt.ReadVarInt(ref reader)));
+                    vin[nIndex].nSequence = reader.ReadUInt32();
                 }
 
                 // Return inputs array
index eb24845..43c1f63 100644 (file)
@@ -59,21 +59,21 @@ namespace Novacoin
         /// <summary>
         /// Read vout list from byte sequence.
         /// </summary>
-        /// <param name="wBytes">Reference to byte sequence</param>
+        /// <param name="wBytes">Reference to binary reader</param>
         /// <returns>Outputs array</returns>
-        public static CTxOut[] ReadTxOutList(ref ByteQueue wBytes)
+        internal static CTxOut[] ReadTxOutList(ref BinaryReader reader)
         {
-            int nOutputs = (int)wBytes.GetVarInt();
+            int nOutputs = (int)VarInt.ReadVarInt(ref reader);
             var vout =new CTxOut[nOutputs];
 
             for (int nIndex = 0; nIndex < nOutputs; nIndex++)
             {
                 // Fill outputs array
                 vout[nIndex] = new CTxOut();
-                vout[nIndex].nValue = BitConverter.ToUInt64(wBytes.Get(8), 0);
+                vout[nIndex].nValue = reader.ReadUInt64();
 
-                int nScriptPKLen = (int)wBytes.GetVarInt();
-                vout[nIndex].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen));
+                int nScriptPKLen = (int)VarInt.ReadVarInt(ref reader);
+                vout[nIndex].scriptPubKey = new CScript(reader.ReadBytes(nScriptPKLen));
             }
 
             return vout;