From 80b9c15a0c2d1b87180824a36948e37894cebaca Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Tue, 1 Sep 2015 22:06:48 +0300 Subject: [PATCH] HACK: initialize base.nWidth to resolve comparison issues. --- Novacoin/base_uint.cs | 2 +- Novacoin/uint160.cs | 5 +++++ Novacoin/uint256.cs | 5 +++++ NovacoinTest/Program.cs | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Novacoin/base_uint.cs b/Novacoin/base_uint.cs index 3ec7d7b..83ef1ed 100644 --- a/Novacoin/base_uint.cs +++ b/Novacoin/base_uint.cs @@ -27,7 +27,7 @@ namespace Novacoin /// public class base_uint : IComparable, IEquatable { - protected readonly int nWidth; + protected int nWidth; protected uint[] pn; public double getDouble() diff --git a/Novacoin/uint160.cs b/Novacoin/uint160.cs index 9a89c3d..1417562 100644 --- a/Novacoin/uint160.cs +++ b/Novacoin/uint160.cs @@ -13,6 +13,7 @@ namespace Novacoin public uint160() { + base.nWidth = nWidth; pn = new uint[nWidth]; for (int i = 0; i < nWidth; i++) @@ -23,6 +24,7 @@ namespace Novacoin public uint160(uint160 b) { + base.nWidth = nWidth; pn = new uint[nWidth]; for (int i = 0; i < nWidth; i++) @@ -34,6 +36,7 @@ namespace Novacoin public uint160(ulong n) { + base.nWidth = nWidth; pn = new uint[nWidth]; pn[0] = (uint)n; @@ -48,6 +51,7 @@ namespace Novacoin { Contract.Requires(bytes.Length == 20, "Incorrect array length"); + base.nWidth = nWidth; pn = Interop.ToUInt32Array(bytes); } @@ -55,6 +59,7 @@ namespace Novacoin { Contract.Requires(hex.Length == 40, "Incorrect string"); + base.nWidth = nWidth; var bytes = Interop.ReverseBytes(Interop.HexToArray(hex)); pn = Interop.ToUInt32Array(bytes); } diff --git a/Novacoin/uint256.cs b/Novacoin/uint256.cs index 15a9931..e54b2be 100644 --- a/Novacoin/uint256.cs +++ b/Novacoin/uint256.cs @@ -13,6 +13,7 @@ namespace Novacoin public uint256() { + base.nWidth = nWidth; pn = new uint[nWidth]; for (int i = 0; i < nWidth; i++) @@ -23,6 +24,7 @@ namespace Novacoin public uint256(uint256 b) { + base.nWidth = nWidth; pn = new uint[nWidth]; for (int i = 0; i < nWidth; i++) @@ -34,6 +36,7 @@ namespace Novacoin public uint256(ulong n) { + base.nWidth = nWidth; pn = new uint[nWidth]; pn[0] = (uint)n; @@ -48,6 +51,7 @@ namespace Novacoin { Contract.Requires(bytes.Length == 32, "Incorrect array length"); + base.nWidth = nWidth; pn = Interop.ToUInt32Array(bytes); } @@ -55,6 +59,7 @@ namespace Novacoin { Contract.Requires(hex.Length == 64, "Incorrect string"); + base.nWidth = nWidth; var bytes = Interop.ReverseBytes(Interop.HexToArray(hex)); pn = Interop.ToUInt32Array(bytes); } diff --git a/NovacoinTest/Program.cs b/NovacoinTest/Program.cs index 5a44468..126d501 100644 --- a/NovacoinTest/Program.cs +++ b/NovacoinTest/Program.cs @@ -311,10 +311,10 @@ namespace NovacoinTest Output: + True False False True - False 0000000000021173331e7742b51afe6c853158a8881f7ad871f4391a7ddcfa4d 0000000000021173331e7742b51afe6c853158a8881f7ad871f4391a7ddcfa4f 00021173331e7742b51afe6c853158a8881f7ad871f4391a7ddcfa4e00000000 -- 1.7.1