From: CryptoManiac Date: Fri, 21 Aug 2015 17:08:37 +0000 (+0300) Subject: Simplification of syntax X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=ed406332056a475608c5c2b25725e61dd0194231 Simplification of syntax --- diff --git a/Novacoin/COutPoint.cs b/Novacoin/COutPoint.cs index 4c9f17a..71f2bda 100644 --- a/Novacoin/COutPoint.cs +++ b/Novacoin/COutPoint.cs @@ -38,8 +38,8 @@ namespace Novacoin public COutPoint(IEnumerable 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 diff --git a/Novacoin/Hash.cs b/Novacoin/Hash.cs index e013e8b..4210c28 100644 --- a/Novacoin/Hash.cs +++ b/Novacoin/Hash.cs @@ -1,4 +1,5 @@ -using System.Security.Cryptography; +using 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 /// /// List of bytes - public Hash(IEnumerable bytes) + public Hash(IEnumerable 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) diff --git a/Novacoin/Hash160.cs b/Novacoin/Hash160.cs index 5b23d60..4b99ea0 100644 --- a/Novacoin/Hash160.cs +++ b/Novacoin/Hash160.cs @@ -23,8 +23,8 @@ namespace Novacoin } public Hash160() : base() { } - public Hash160(byte[] bytes) : base(bytes) { } - public Hash160(IEnumerable bytes) : base(bytes) { } + public Hash160(byte[] bytes, int offset = 0) : base(bytes, offset) { } + public Hash160(IEnumerable bytes, int skip = 0) : base(bytes, skip) { } public Hash160(Hash160 h) : base(h) { } public static Hash160 Compute160(IEnumerable inputBytes) diff --git a/Novacoin/Hash256.cs b/Novacoin/Hash256.cs index 132dc40..bad52d7 100644 --- a/Novacoin/Hash256.cs +++ b/Novacoin/Hash256.cs @@ -19,8 +19,8 @@ namespace Novacoin } public Hash256() : base() { } - public Hash256(byte[] bytes) : base(bytes) { } - public Hash256(IEnumerable bytes) : base(bytes) { } + public Hash256(byte[] bytes, int offset=0) : base(bytes, offset) { } + public Hash256(IEnumerable bytes, int skip=0) : base(bytes, skip) { } public Hash256(Hash256 h) : base(h) { } diff --git a/Novacoin/ScryptHash256.cs b/Novacoin/ScryptHash256.cs index ca804fd..c53882f 100644 --- a/Novacoin/ScryptHash256.cs +++ b/Novacoin/ScryptHash256.cs @@ -16,8 +16,8 @@ namespace Novacoin } public ScryptHash256() : base() { } - public ScryptHash256(byte[] bytes) : base(bytes) { } - public ScryptHash256(IEnumerable bytes) : base(bytes) { } + public ScryptHash256(byte[] bytes, int offset = 0) : base(bytes, offset) { } + public ScryptHash256(IEnumerable bytes, int skip = 0) : base(bytes, skip) { } public ScryptHash256(ScryptHash256 h) : base(h) { } /// diff --git a/Novacoin/WrappedList.cs b/Novacoin/WrappedList.cs index 28a79a0..89c5cce 100644 --- a/Novacoin/WrappedList.cs +++ b/Novacoin/WrappedList.cs @@ -62,7 +62,7 @@ namespace Novacoin throw new WrappedListException("Unable to read requested amount of data."); } - T[] result = Elements.Skip(Index).Take(Count).ToArray(); + 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(Index).Take(Count).ToArray(); + 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 result = Elements.Skip(Index).Take(Count); + IEnumerable result = Elements.Skip(Index).Take(Count); Index += Count; return result;