From 9f4f9d3f60f89dcf29fb7b24d60ffd40d7360a7d Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Fri, 21 Aug 2015 19:00:10 +0300 Subject: [PATCH] New constructor for block header class --- Novacoin/CBlock.cs | 9 +-------- Novacoin/CBlockHeader.cs | 11 +++++++++++ Novacoin/CNovacoinAddress.cs | 1 - Novacoin/CPubKey.cs | 1 - Novacoin/CTxIn.cs | 2 +- Novacoin/CTxOut.cs | 3 ++- Novacoin/Hash.cs | 2 +- Novacoin/Hash256.cs | 2 -- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Novacoin/CBlock.cs b/Novacoin/CBlock.cs index 5e47b08..8974cef 100644 --- a/Novacoin/CBlock.cs +++ b/Novacoin/CBlock.cs @@ -42,17 +42,10 @@ namespace Novacoin /// public CBlock (IList blockBytes) { - header = new CBlockHeader(); - WrappedList wBytes = new WrappedList(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); diff --git a/Novacoin/CBlockHeader.cs b/Novacoin/CBlockHeader.cs index e8b257f..8c07cf2 100644 --- a/Novacoin/CBlockHeader.cs +++ b/Novacoin/CBlockHeader.cs @@ -1,4 +1,5 @@ using 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); + } + /// /// Convert current block header instance into sequence of bytes /// diff --git a/Novacoin/CNovacoinAddress.cs b/Novacoin/CNovacoinAddress.cs index 410de44..3b41edd 100644 --- a/Novacoin/CNovacoinAddress.cs +++ b/Novacoin/CNovacoinAddress.cs @@ -67,7 +67,6 @@ namespace Novacoin /// /// Basic sanity checking /// - /// public bool IsValid { get diff --git a/Novacoin/CPubKey.cs b/Novacoin/CPubKey.cs index 0294f1d..7feaf84 100644 --- a/Novacoin/CPubKey.cs +++ b/Novacoin/CPubKey.cs @@ -58,7 +58,6 @@ namespace Novacoin List r = new List(); r.Add((byte)(AddrType.PUBKEY_ADDRESS)); - r.AddRange(PublicBytes); return AddressTools.Base58EncodeCheck(r); diff --git a/Novacoin/CTxIn.cs b/Novacoin/CTxIn.cs index bc80f0f..fad0d7e 100644 --- a/Novacoin/CTxIn.cs +++ b/Novacoin/CTxIn.cs @@ -22,7 +22,7 @@ namespace Novacoin /// /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default. /// - public uint nSequence = 0xffffffff; + public uint nSequence = uint.MaxValue; /// /// Initialize new CTxIn instance as copy of another one. diff --git a/Novacoin/CTxOut.cs b/Novacoin/CTxOut.cs index 4ce6c0d..8c8ad4f 100644 --- a/Novacoin/CTxOut.cs +++ b/Novacoin/CTxOut.cs @@ -87,6 +87,7 @@ namespace Novacoin public void SetNull() { nValue = -1; + scriptPubKey = new CScript(); } /// @@ -95,7 +96,7 @@ namespace Novacoin public void SetEmpty() { nValue = 0; - scriptPubKey.SetNullDestination(); + scriptPubKey = new CScript(); } public bool IsNull diff --git a/Novacoin/Hash.cs b/Novacoin/Hash.cs index fbff17f..e013e8b 100644 --- a/Novacoin/Hash.cs +++ b/Novacoin/Hash.cs @@ -43,7 +43,7 @@ namespace Novacoin /// List of bytes public Hash(IEnumerable bytes) { - _hashBytes = bytes.Take(hashSize).ToArray(); + _hashBytes = bytes.Take(hashSize).ToArray(); } public Hash(byte[] bytes) diff --git a/Novacoin/Hash256.cs b/Novacoin/Hash256.cs index f571f3d..132dc40 100644 --- a/Novacoin/Hash256.cs +++ b/Novacoin/Hash256.cs @@ -5,8 +5,6 @@ using System.Collections.Generic; using System.Security.Cryptography; - - namespace Novacoin { /// -- 1.7.1