From: miketout Date: Sat, 6 Jun 2020 19:51:38 +0000 (-0700) Subject: Fixes for staking from smart transactions X-Git-Url: https://repo.jachan.dev/VerusCoin.git/commitdiff_plain/adb5cebb2955cc1423824383efed3d702d223c9f?hp=5de26d5d16b7b8def06081b4b8f0cd356a600add Fixes for staking from smart transactions --- diff --git a/src/script/script.cpp b/src/script/script.cpp index 0eab1a1d1..4ebd85adb 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -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; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 43865fc02..410935c02 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -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(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 {