New constructor for block header class
authorCryptoManiac <balthazar@yandex.ru>
Fri, 21 Aug 2015 16:00:10 +0000 (19:00 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Fri, 21 Aug 2015 16:00:10 +0000 (19:00 +0300)
Novacoin/CBlock.cs
Novacoin/CBlockHeader.cs
Novacoin/CNovacoinAddress.cs
Novacoin/CPubKey.cs
Novacoin/CTxIn.cs
Novacoin/CTxOut.cs
Novacoin/Hash.cs
Novacoin/Hash256.cs

index 5e47b08..8974cef 100644 (file)
@@ -42,17 +42,10 @@ namespace Novacoin
         /// <param name="blockBytes"></param>
                public CBlock (IList<byte> blockBytes)
                {
-            header = new CBlockHeader();
-
             WrappedList<byte> wBytes = new WrappedList<byte>(blockBytes);
 
             // Fill the block header fields
-            header.nVersion = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
-            header.prevHash = new Hash256(wBytes.GetItems(32));
-            header.merkleRoot = new Hash256(wBytes.GetItems(32));
-            header.nTime = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
-            header.nBits = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
-            header.nNonce = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
+            header = new CBlockHeader(wBytes.GetItems(80));
 
             // Parse transactions list
             vtx = CTransaction.ReadTransactionsList(ref wBytes);
index e8b257f..8c07cf2 100644 (file)
@@ -1,4 +1,5 @@
 \feffusing System;
+using System.Linq;
 using System.Text;
 using System.Collections.Generic;
 
@@ -56,6 +57,16 @@ namespace Novacoin
             nNonce = h.nNonce;
         }
 
+        public CBlockHeader(byte[] bytes)
+        {
+            nVersion = BitConverter.ToUInt32(bytes, 0);
+            prevHash = new Hash256(bytes.Skip(4).Take(32).ToArray());
+            merkleRoot = new Hash256(bytes.Skip(36).Take(32).ToArray());
+            nTime = BitConverter.ToUInt32(bytes, 68);
+            nBits = BitConverter.ToUInt32(bytes, 72);
+            nNonce = BitConverter.ToUInt32(bytes, 76);
+        }
+
         /// <summary>
         /// Convert current block header instance into sequence of bytes
         /// </summary>
index 410de44..3b41edd 100644 (file)
@@ -67,7 +67,6 @@ namespace Novacoin
         /// <summary>
         /// Basic sanity checking
         /// </summary>
-        /// <returns></returns>
         public bool IsValid
         {
             get
index 0294f1d..7feaf84 100644 (file)
@@ -58,7 +58,6 @@ namespace Novacoin
             List<byte> r = new List<byte>();
 
             r.Add((byte)(AddrType.PUBKEY_ADDRESS));
-
             r.AddRange(PublicBytes);
 
             return AddressTools.Base58EncodeCheck(r);
index bc80f0f..fad0d7e 100644 (file)
@@ -22,7 +22,7 @@ namespace Novacoin
                /// <summary>
                /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
                /// </summary>
-        public uint nSequence = 0xffffffff;
+        public uint nSequence = uint.MaxValue;
 
         /// <summary>
         /// Initialize new CTxIn instance as copy of another one.
index 4ce6c0d..8c8ad4f 100644 (file)
@@ -87,6 +87,7 @@ namespace Novacoin
         public void SetNull()
         {
             nValue = -1;
+            scriptPubKey = new CScript();
         }
 
         /// <summary>
@@ -95,7 +96,7 @@ namespace Novacoin
         public void SetEmpty()
         {
             nValue = 0;
-            scriptPubKey.SetNullDestination();
+            scriptPubKey = new CScript();
         }
 
         public bool IsNull
index fbff17f..e013e8b 100644 (file)
@@ -43,7 +43,7 @@ namespace Novacoin
         /// <param name="bytesList">List of bytes</param>
         public Hash(IEnumerable<byte> bytes)
         {
-            _hashBytes = bytes.Take<byte>(hashSize).ToArray<byte>();
+            _hashBytes = bytes.Take(hashSize).ToArray();
         }
 
         public Hash(byte[] bytes)
index f571f3d..132dc40 100644 (file)
@@ -5,8 +5,6 @@ using System.Collections.Generic;
 
 using System.Security.Cryptography;
 
-
-
 namespace Novacoin
 {
        /// <summary>