]> Git Repo - VerusCoin.git/blobdiff - src/cc/StakeGuard.cpp
PBaaS - bulk of non-activated PBaaS changes for testing
[VerusCoin.git] / src / cc / StakeGuard.cpp
index dbc14ebdee6c3b8a32e9120dca0ef96d27652f66..3c0e12166d2b75df5959430bed9e9fc33638b7f1 100644 (file)
@@ -13,6 +13,7 @@
 #include "script/script.h"
 #include "main.h"
 #include "hash.h"
+#include "key_io.h"
 
 #include "streams.h"
 
@@ -192,9 +193,9 @@ bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxO
     // destination address or a properly signed stake transaction of the same utxo on a fork
     vout = MakeCC1of2vout(EVAL_STAKEGUARD, value, dest, ccAddress);
 
-    std::vector<CPubKey> vPubKeys = std::vector<CPubKey>();
-    vPubKeys.push_back(dest);
-    vPubKeys.push_back(ccAddress);
+    std::vector<CTxDestination> vKeys;
+    vKeys.push_back(dest);
+    vKeys.push_back(ccAddress);
     
     std::vector<std::vector<unsigned char>> vData = std::vector<std::vector<unsigned char>>();
 
@@ -218,7 +219,7 @@ bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxO
         }
         vData.push_back(height);
 
-        COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_STAKEGUARD, 1, 2, vPubKeys, vData);
+        COptCCParams ccp = COptCCParams(COptCCParams::VERSION_V1, EVAL_STAKEGUARD, 1, 2, vKeys, vData);
 
         vout.scriptPubKey << ccp.AsVector() << OP_DROP;
         return true;
@@ -288,7 +289,7 @@ bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTr
 bool MakeCheatEvidence(CMutableTransaction &mtx, const CTransaction &ccTx, uint32_t voutNum, const CTransaction &cheatTx)
 {
     std::vector<unsigned char> vch;
-    CDataStream s = CDataStream(SER_DISK, CLIENT_VERSION);
+    CDataStream s = CDataStream(SER_DISK, PROTOCOL_VERSION);
     bool isCheater = false;
 
     if (ValidateMatchingStake(ccTx, voutNum, cheatTx, isCheater) && isCheater)
@@ -397,27 +398,42 @@ bool StakeGuardValidate(struct CCcontract_info *cp, Eval* eval, const CTransacti
             if (ccp.IsValid() && ccp.m == 1 && ccp.n == 2 && ccp.vKeys.size() == 2)
             {
                 std::vector<uint32_t> vc = {0, 0};
-                ccFulfillmentCheck fc = {ccp.vKeys, vc};
 
-                signedByFirstKey = (IsCCFulfilled(cc, &fc) != 0);
-
-                if ((!signedByFirstKey && ccp.evalCode == EVAL_STAKEGUARD && ccp.vKeys.size() == 2 && ccp.version == COptCCParams::VERSION) &&
-                    params.size() == 2 && params[0].size() > 0 && params[0][0] == OPRETTYPE_STAKECHEAT)
+                std::vector<CPubKey> keys;
+                for (auto pk : ccp.vKeys)
                 {
-                    CDataStream s = CDataStream(std::vector<unsigned char>(params[1].begin(), params[1].end()), SER_DISK, CLIENT_VERSION);
-                    bool checkOK = false;
-                    CTransaction cheatTx;
-                    try
-                    {
-                        cheatTx.Unserialize(s);
-                        checkOK = true;
-                    }
-                    catch (...)
+                    uint160 keyID = GetDestinationID(pk);
+                    std::vector<unsigned char> vkch = GetDestinationBytes(pk);
+                    if (vkch.size() == 33)
                     {
+                        keys.push_back(CPubKey(vkch));
                     }
-                    if (checkOK && !ValidateMatchingStake(txOut, tx.vin[0].prevout.n, cheatTx, validCheat))
+                }
+
+                if (keys.size() == 2)
+                {
+                    ccFulfillmentCheck fc = {keys, vc};
+
+                    signedByFirstKey = (IsCCFulfilled(cc, &fc) != 0);
+
+                    if ((!signedByFirstKey && ccp.evalCode == EVAL_STAKEGUARD && ccp.vKeys.size() == 2 && ccp.version == COptCCParams::VERSION_V1) &&
+                        params.size() == 2 && params[0].size() > 0 && params[0][0] == OPRETTYPE_STAKECHEAT)
                     {
-                        validCheat = false;
+                        CDataStream s = CDataStream(std::vector<unsigned char>(params[1].begin(), params[1].end()), SER_DISK, PROTOCOL_VERSION);
+                        bool checkOK = false;
+                        CTransaction cheatTx;
+                        try
+                        {
+                            cheatTx.Unserialize(s);
+                            checkOK = true;
+                        }
+                        catch (...)
+                        {
+                        }
+                        if (checkOK && !ValidateMatchingStake(txOut, tx.vin[0].prevout.n, cheatTx, validCheat))
+                        {
+                            validCheat = false;
+                        }
                     }
                 }
             }
This page took 0.027499 seconds and 4 git commands to generate.