]> Git Repo - VerusCoin.git/commitdiff
Fixes for staking from smart transactions
authormiketout <[email protected]>
Sat, 6 Jun 2020 19:51:38 +0000 (12:51 -0700)
committermiketout <[email protected]>
Sat, 6 Jun 2020 19:51:38 +0000 (12:51 -0700)
src/script/script.cpp
src/wallet/wallet.cpp

index 0eab1a1d1bb48247ec6864afc1926aa322440af4..4ebd85adb85fbc22582b6ecf9346c3af49a3c3fa 100644 (file)
@@ -596,6 +596,11 @@ bool CScript::IsSpendableOutputType(const COptCCParams &p) const
         case EVAL_RESERVE_TRANSFER:
         case EVAL_RESERVE_EXCHANGE:
         case EVAL_CROSSCHAIN_IMPORT:
+        case EVAL_IDENTITY_COMMITMENT:
+        case EVAL_IDENTITY_PRIMARY:
+        case EVAL_IDENTITY_REVOKE:
+        case EVAL_IDENTITY_RECOVER:
+        case EVAL_IDENTITY_RESERVATION:
         {
             isSpendable = false;
             break;
index 43865fc0239345b81e732a235cd49ea4eba69fab..410935c02f2a02a6a2f8cd766b8c68c41dfc2b1a 100644 (file)
@@ -1905,8 +1905,7 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe
 
     bnTarget = lwmaGetNextPOSRequired(tipindex, Params().GetConsensus());
 
-    if (!VerusSelectStakeOutput(pBlock, hashResult, stakeSource, voutNum, stakeHeight, bnTarget) ||
-        !Solver(stakeSource.vout[voutNum].scriptPubKey, whichType, vSolutions))
+    if (!VerusSelectStakeOutput(pBlock, hashResult, stakeSource, voutNum, stakeHeight, bnTarget))
     {
         //LogPrintf("Searched for eligible staking transactions, no winners found\n");
         return 0;
@@ -1924,26 +1923,44 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe
     txNew.vin[0].prevout.hash = stakeSource.GetHash();
     txNew.vin[0].prevout.n = voutNum;
 
-    if (whichType == TX_PUBKEY)
-    {
-        txNew.vout[0].scriptPubKey << ToByteVector(vSolutions[0]) << OP_CHECKSIG;
-        if (!pk.IsValid())
-            pk = CPubKey(vSolutions[0]);
-    }
-    else if (whichType == TX_PUBKEYHASH)
+    COptCCParams p;
+    if (stakeSource.vout[voutNum].scriptPubKey.IsPayToCryptoCondition(p) && p.IsValid())
     {
-        txNew.vout[0].scriptPubKey << OP_DUP << OP_HASH160 << ToByteVector(vSolutions[0]) << OP_EQUALVERIFY << OP_CHECKSIG;
-        if (saplingStake && !pk.IsValid())
+        // send output to same destination as source, convert stakeguard into normal output, since
+        // that is a spendable output that only works in coinbases. preserve all recipients and
+        // min sigs
+        if (p.evalCode == EVAL_STAKEGUARD)
         {
-            // we need a pubkey, so try to get one from the key ID, if not there, fail
-            if (!keystore.GetPubKey(CKeyID(uint160(vSolutions[0])), pk))
-                return 0;
+            txNew.vout[0].scriptPubKey = MakeMofNCCScript(CConditionObj<CIdentity>(0, p.vKeys, p.m));
+        }
+        else
+        {
+            txNew.vout[0].scriptPubKey = stakeSource.vout[voutNum].scriptPubKey;
         }
     }
-    else if (whichType == TX_CRYPTOCONDITION)
+    else if (Solver(stakeSource.vout[voutNum].scriptPubKey, whichType, vSolutions))
     {
-        // same output as stake
-        txNew.vout[0].scriptPubKey = stakeSource.vout[voutNum].scriptPubKey;
+        if (whichType == TX_PUBKEY)
+        {
+            txNew.vout[0].scriptPubKey << ToByteVector(vSolutions[0]) << OP_CHECKSIG;
+            if (!pk.IsValid())
+                pk = CPubKey(vSolutions[0]);
+        }
+        else if (whichType == TX_PUBKEYHASH)
+        {
+            txNew.vout[0].scriptPubKey << OP_DUP << OP_HASH160 << ToByteVector(vSolutions[0]) << OP_EQUALVERIFY << OP_CHECKSIG;
+            if (saplingStake && !pk.IsValid())
+            {
+                // we need a pubkey, so try to get one from the key ID, if not there, fail
+                if (!keystore.GetPubKey(CKeyID(uint160(vSolutions[0])), pk))
+                    return 0;
+            }
+        }
+        else
+        {
+            LogPrintf("%s: Please report - found stake source that is not valid\n");
+            return 0;
+        }
     }
     else
     {
This page took 0.036575 seconds and 4 git commands to generate.