Additional CNovacoinAddress verification.
authorCryptoManiac <balthazar@yandex.ru>
Tue, 18 Aug 2015 19:07:00 +0000 (22:07 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Tue, 18 Aug 2015 19:07:00 +0000 (22:07 +0300)
Novacoin/CNovacoinAddress.cs
NovacoinTest/Program.cs

index 6f4e595..d66555e 100644 (file)
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
 
 namespace Novacoin
 {
+    /// <summary>
+    /// Available address types
+    /// </summary>
     public enum AddrType
     {
         PUBKEY_ADDRESS = 8,
@@ -14,31 +17,52 @@ namespace Novacoin
         SCRIPT_ADDRESS_TEST = 196
     };
 
+    /// <summary>
+    /// Represents novacoin address
+    /// </summary>
     public class CNovacoinAddress
     {
         private byte nVersion;
         private List<byte> addrData;
 
+        /// <summary>
+        /// Initialize with custom data and version
+        /// </summary>
+        /// <param name="nVersionIn"></param>
+        /// <param name="addrDataIn"></param>
         public CNovacoinAddress(byte nVersionIn, IEnumerable<byte> addrDataIn)
         {
             nVersion = nVersionIn;
             addrData = addrDataIn.ToList();
         }
 
+        /// <summary>
+        /// Initialize new instance of PUBKEY_ADDRESS
+        /// </summary>
+        /// <param name="keyID">CKeyID instance</param>
         public CNovacoinAddress(CKeyID keyID)
         {
             nVersion = (byte)AddrType.PUBKEY_ADDRESS;
             addrData = new List<byte>(keyID.hashBytes);
         }
 
+        /// <summary>
+        /// Initialize new instance of SCRIPT_ADDRESS
+        /// </summary>
+        /// <param name="keyID">CScriptID instance</param>
         public CNovacoinAddress(CScriptID scriptID)
         {
             nVersion = (byte)AddrType.SCRIPT_ADDRESS;
             addrData = new List<byte>(scriptID.hashBytes);
         }
 
+        /// <summary>
+        /// Basic sanity checking
+        /// </summary>
+        /// <returns></returns>
         public bool IsValid()
         {
+            // Address data is normally generated by RIPEMD-160 hash function
             int nExpectedSize = 20;
 
             switch ((AddrType) nVersion)
@@ -62,6 +86,10 @@ namespace Novacoin
             return addrData.Count == nExpectedSize;
         }
 
+        /// <summary>
+        /// Generate base58 serialized representation of novacoin address
+        /// </summary>
+        /// <returns>Base58(data + checksum)</returns>
         public override string ToString()
         {
             List<byte> r = new List<byte>();
index 592f7ff..dfd1ed8 100644 (file)
@@ -55,10 +55,6 @@ namespace NovacoinTest
             Console.WriteLine("Key ID: {0}", Interop.ToHex(keyID.hashBytes));
             Console.WriteLine("Novacoin address: {0}\n", keyID.ToString());
 
-            string strPubKeyTest = "029780fac8b85b4a47a616acb4e19d7958eaf02acc5123f65e7824ce720b1ae788";
-            CPubKey pubKeyTest = new CPubKey(Interop.ParseHex(strPubKeyTest));
-            Console.WriteLine("Donations may be sent to: {0}\n", pubKeyTest.GetKeyID().ToString());
-
             /// ECDSA keypair signing test
 
             string data = "Превед!";
@@ -69,6 +65,15 @@ namespace NovacoinTest
             Console.WriteLine("Signature is OK: {0} (CKeyPair)", keyPair1.VerifySignature(dataBytes, signature));
             Console.WriteLine("Signature is OK: {0} (CPubKey)", pubKey.VerifySignature(dataBytes, signature));
 
+            /// Donation address
+
+            string strPubKeyTest = "029780fac8b85b4a47a616acb4e19d7958eaf02acc5123f65e7824ce720b1ae788";
+            CPubKey pubKeyTest = new CPubKey(Interop.ParseHex(strPubKeyTest));
+            string strDonationAddress = pubKeyTest.GetKeyID().ToString();
+            Console.WriteLine("\nDonations may be sent to: {0}", strDonationAddress);
+            Console.WriteLine("Address generation is OK: {0}", strDonationAddress == "4T2t8uiDtyHceMwMjMHPn88TyJB3trCg3o");
+
+
             Console.ReadLine();
         }
     }