From: CryptoManiac Date: Wed, 2 Sep 2015 07:16:53 +0000 (+0300) Subject: Redefine uint160.nWidth, uint160.pn, uint256.nWidth and uint256.pn as protected prope... X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=0beeb4bd4e68e4f0d81832370f2f0388d0d76c65 Redefine uint160.nWidth, uint160.pn, uint256.nWidth and uint256.pn as protected properties to make the derivals easier. --- diff --git a/Novacoin/uint160.cs b/Novacoin/uint160.cs index 1417562..595aa1a 100644 --- a/Novacoin/uint160.cs +++ b/Novacoin/uint160.cs @@ -9,24 +9,25 @@ namespace Novacoin { public class uint160 : base_uint { - new protected readonly int nWidth = 5; + new protected int nWidth + { + get { return base.nWidth; } + private set { base.nWidth = value; } + } + new protected uint[] pn + { + get { return base.pn; } + private set { base.pn = value; } + } public uint160() { - base.nWidth = nWidth; + nWidth = 5; pn = new uint[nWidth]; - - for (int i = 0; i < nWidth; i++) - { - pn[i] = 0; - } } - public uint160(uint160 b) + public uint160(uint160 b) : this() { - base.nWidth = nWidth; - pn = new uint[nWidth]; - for (int i = 0; i < nWidth; i++) { pn[i] = b.pn[i]; @@ -34,11 +35,8 @@ namespace Novacoin } - public uint160(ulong n) + public uint160(ulong n) : this() { - base.nWidth = nWidth; - pn = new uint[nWidth]; - pn[0] = (uint)n; pn[1] = (uint)(n >> 32); for (int i = 2; i < nWidth; i++) @@ -47,19 +45,15 @@ namespace Novacoin } } - public uint160(byte[] bytes) + public uint160(byte[] bytes) : this() { Contract.Requires(bytes.Length == 20, "Incorrect array length"); - - base.nWidth = nWidth; pn = Interop.ToUInt32Array(bytes); } - public uint160(string hex) + public uint160(string hex) : this() { 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 09e1a2c..0c451ef 100644 --- a/Novacoin/uint256.cs +++ b/Novacoin/uint256.cs @@ -10,36 +10,31 @@ namespace Novacoin { public class uint256 : base_uint { - new public readonly int nWidth = 8; + new protected int nWidth { + get { return base.nWidth; } + private set { base.nWidth = value; } + } + new protected uint[] pn { + get { return base.pn; } + private set { base.pn = value; } + } public uint256() { - base.nWidth = nWidth; + nWidth = 8; pn = new uint[nWidth]; - - for (int i = 0; i < nWidth; i++) - { - pn[i] = 0; - } } - public uint256(uint256 b) + public uint256(uint256 b) : this() { - base.nWidth = nWidth; - pn = new uint[nWidth]; - for (int i = 0; i < nWidth; i++) { pn[i] = b.pn[i]; } } - - public uint256(ulong n) + public uint256(ulong n) : this() { - base.nWidth = nWidth; - pn = new uint[nWidth]; - pn[0] = (uint)n; pn[1] = (uint)(n >> 32); for (int i = 2; i < nWidth; i++) @@ -48,19 +43,17 @@ namespace Novacoin } } - public uint256(byte[] bytes) + public uint256(byte[] bytes) : this() { Contract.Requires(bytes.Length == 32, "Incorrect array length"); - base.nWidth = nWidth; pn = Interop.ToUInt32Array(bytes); } - public uint256(string hex) + public uint256(string hex) : this() { Contract.Requires(hex.Length == 64, "Incorrect string"); - base.nWidth = nWidth; var bytes = Interop.ReverseBytes(Interop.HexToArray(hex)); pn = Interop.ToUInt32Array(bytes); }