Simplification of syntax
authorCryptoManiac <balthazar@yandex.ru>
Fri, 21 Aug 2015 17:08:37 +0000 (20:08 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Fri, 21 Aug 2015 17:08:37 +0000 (20:08 +0300)
Novacoin/COutPoint.cs
Novacoin/Hash.cs
Novacoin/Hash160.cs
Novacoin/Hash256.cs
Novacoin/ScryptHash256.cs
Novacoin/WrappedList.cs

index 4c9f17a..71f2bda 100644 (file)
@@ -38,8 +38,8 @@ namespace Novacoin
 
         public COutPoint(IEnumerable<byte> bytes)
         {
-            hash = new Hash256(bytes.Take(32));
-            n = BitConverter.ToUInt32(bytes.Skip(32).Take(4).ToArray(), 0);
+            hash = new Hash256(bytes);
+            n = BitConverter.ToUInt32(bytes.ToArray(), 32);
         }
 
         public bool IsNull
index e013e8b..4210c28 100644 (file)
@@ -1,4 +1,5 @@
-\feffusing System.Security.Cryptography;
+\feffusing System;
+using System.Security.Cryptography;
 using System.Collections.Generic;
 using System.Linq;
 
@@ -41,14 +42,15 @@ namespace Novacoin
         /// Initializes a new instance of Hash class with first 20 bytes from supplied list
         /// </summary>
         /// <param name="bytesList">List of bytes</param>
-        public Hash(IEnumerable<byte> bytes)
+        public Hash(IEnumerable<byte> bytes, int skip = 0)
         {
-            _hashBytes = bytes.Take(hashSize).ToArray();
+            _hashBytes = bytes.Skip(skip).Take(hashSize).ToArray();
         }
 
-        public Hash(byte[] bytes)
+        public Hash(byte[] bytes, int offset = 0)
         {
-            _hashBytes = bytes;
+            _hashBytes = new byte[hashSize];
+            Array.Copy(bytes, offset, _hashBytes, 0, hashSize);
         }
 
         public Hash(Hash h)
index 5b23d60..4b99ea0 100644 (file)
@@ -23,8 +23,8 @@ namespace Novacoin
         }
 
         public Hash160() : base() { }
-        public Hash160(byte[] bytes) : base(bytes) { }
-        public Hash160(IEnumerable<byte> bytes) : base(bytes) { }
+        public Hash160(byte[] bytes, int offset = 0) : base(bytes, offset) { }
+        public Hash160(IEnumerable<byte> bytes, int skip = 0) : base(bytes, skip) { }
         public Hash160(Hash160 h) : base(h) { }
 
         public static Hash160 Compute160(IEnumerable<byte> inputBytes)
index 132dc40..bad52d7 100644 (file)
@@ -19,8 +19,8 @@ namespace Novacoin
         }
 
         public Hash256() : base() { }
-        public Hash256(byte[] bytes) : base(bytes) { }
-        public Hash256(IEnumerable<byte> bytes) : base(bytes) { }
+        public Hash256(byte[] bytes, int offset=0) : base(bytes, offset) { }
+        public Hash256(IEnumerable<byte> bytes, int skip=0) : base(bytes, skip) { }
         public Hash256(Hash256 h) : base(h) { }
 
 
index ca804fd..c53882f 100644 (file)
@@ -16,8 +16,8 @@ namespace Novacoin
         }
 
         public ScryptHash256() : base() { }
-        public ScryptHash256(byte[] bytes) : base(bytes) { }
-        public ScryptHash256(IEnumerable<byte> bytes) : base(bytes) { }
+        public ScryptHash256(byte[] bytes, int offset = 0) : base(bytes, offset) { }
+        public ScryptHash256(IEnumerable<byte> bytes, int skip = 0) : base(bytes, skip) { }
         public ScryptHash256(ScryptHash256 h) : base(h) { }
 
         /// <summary>
index 28a79a0..89c5cce 100644 (file)
@@ -62,7 +62,7 @@ namespace Novacoin
                 throw new WrappedListException("Unable to read requested amount of data.");
             }
 
-            T[] result = Elements.Skip<T>(Index).Take<T>(Count).ToArray<T>();
+            T[] result = Elements.Skip(Index).Take(Count).ToArray();
             Index += Count;
 
             return result;
@@ -75,7 +75,7 @@ namespace Novacoin
                 throw new WrappedListException("Unable to read requested amount of data.");
             }
 
-            T[] result = Elements.Skip<T>(Index).Take<T>(Count).ToArray<T>();
+            T[] result = Elements.Skip(Index).Take(Count).ToArray();
 
             return result;
         }
@@ -87,7 +87,7 @@ namespace Novacoin
                 throw new WrappedListException("Unable to read requested amount of data.");
             }
 
-            IEnumerable<T> result = Elements.Skip<T>(Index).Take<T>(Count);
+            IEnumerable<T> result = Elements.Skip(Index).Take(Count);
             Index += Count;
 
             return result;