Redefine uint160.nWidth, uint160.pn, uint256.nWidth and uint256.pn as protected prope...
authorCryptoManiac <balthazar.ad@gmail.com>
Wed, 2 Sep 2015 07:16:53 +0000 (10:16 +0300)
committerCryptoManiac <balthazar.ad@gmail.com>
Wed, 2 Sep 2015 07:16:53 +0000 (10:16 +0300)
Novacoin/uint160.cs
Novacoin/uint256.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);
         }
index 09e1a2c..0c451ef 100644 (file)
@@ -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<ArgumentException>(bytes.Length == 32, "Incorrect array length");
 
-            base.nWidth = nWidth;
             pn = Interop.ToUInt32Array(bytes);
         }
 
-        public uint256(string hex)
+        public uint256(string hex) : this()
         {
             Contract.Requires<ArgumentException>(hex.Length == 64, "Incorrect string");
 
-            base.nWidth = nWidth;
             var bytes = Interop.ReverseBytes(Interop.HexToArray(hex));
             pn = Interop.ToUInt32Array(bytes);
         }