Redefine uint160.nWidth, uint160.pn, uint256.nWidth and uint256.pn as protected prope...
[NovacoinLibrary.git] / Novacoin / uint160.cs
index 1417562..595aa1a 100644 (file)
@@ -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<ArgumentException>(bytes.Length == 20, "Incorrect array length");
-
-            base.nWidth = nWidth;
             pn = Interop.ToUInt32Array(bytes);
         }
 
-        public uint160(string hex)
+        public uint160(string hex) : this()
         {
             Contract.Requires<ArgumentException>(hex.Length == 40, "Incorrect string");
-
-            base.nWidth = nWidth;
             var bytes = Interop.ReverseBytes(Interop.HexToArray(hex));
             pn = Interop.ToUInt32Array(bytes);
         }