OP_EVAL implementation
[novacoin.git] / src / base58.h
index cace423..8fc546c 100644 (file)
@@ -18,6 +18,7 @@
 #include <string>
 #include <vector>
 #include "bignum.h"
+#include "key.h"
 
 static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
 
@@ -257,15 +258,20 @@ public:
 class CBitcoinAddress : public CBase58Data
 {
 public:
-    bool SetHash160(const uint160& hash160)
+    void SetHash160(const uint160& hash160)
     {
         SetData(fTestNet ? 111 : 0, &hash160, 20);
-        return true;
     }
 
-    bool SetPubKey(const std::vector<unsigned char>& vchPubKey)
+    void SetPubKey(const std::vector<unsigned char>& vchPubKey)
+    {
+        SetHash160(Hash160(vchPubKey));
+    }
+
+    bool SetScriptHash160(const uint160& hash160)
     {
-        return SetHash160(Hash160(vchPubKey));
+        SetData(fTestNet ? 112 : 1, &hash160, 20);
+        return true;
     }
 
     bool IsValid() const
@@ -275,9 +281,20 @@ public:
         switch(nVersion)
         {
             case 0:
+                nExpectedSize = 20; // Hash of public key
+                fExpectTestNet = false;
+                break;
+            case 1:
+                nExpectedSize = 20; // OP_EVAL, hash of CScript
+                fExpectTestNet = false;
                 break;
 
             case 111:
+                nExpectedSize = 20;
+                fExpectTestNet = true;
+                break;
+            case 112:
+                nExpectedSize = 20;
                 fExpectTestNet = true;
                 break;
 
@@ -286,6 +303,14 @@ public:
         }
         return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize;
     }
+    bool IsScript() const
+    {
+        if (!IsValid())
+            return false;
+        if (fTestNet)
+            return nVersion == 112;
+        return nVersion == 1;
+    }
 
     CBitcoinAddress()
     {
@@ -320,4 +345,49 @@ public:
     }
 };
 
+class CBitcoinSecret : public CBase58Data
+{
+public:
+    void SetSecret(const CSecret& vchSecret)
+    {
+        SetData(fTestNet ? 239 : 128, &vchSecret[0], vchSecret.size());
+    }
+
+    CSecret GetSecret()
+    {
+        CSecret vchSecret;
+        vchSecret.resize(vchData.size());
+        memcpy(&vchSecret[0], &vchData[0], vchData.size());
+        return vchSecret;
+    }
+
+    bool IsValid() const
+    {
+        int nExpectedSize = 32;
+        bool fExpectTestNet = false;
+        switch(nVersion)
+        {
+            case 128:
+                break;
+
+            case 239:
+                fExpectTestNet = true;
+                break;
+
+            default:
+                return false;
+        }
+        return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize;
+    }
+
+    CBitcoinSecret(const CSecret& vchSecret)
+    {
+        SetSecret(vchSecret);
+    }
+
+    CBitcoinSecret()
+    {
+    }
+};
+
 #endif