@@ -2695,6 +2695,12 @@ bool CWallet::StakeableCoins(std::vector<CStakeableOutput>* pCoins)
26952695 return (pCoins && !pCoins->empty ());
26962696}
26972697
2698+ void CWallet::StakeableShieldNotes (std::vector<CStakeableShieldNote>* shieldCoins)
2699+ {
2700+ shieldCoins->clear ();
2701+ m_sspk_man->GetStakeableNotes (shieldCoins, Params ().GetConsensus ().nStakeMinDepth );
2702+ }
2703+
26982704bool CWallet::SelectCoinsMinConf (const CAmount& nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*, unsigned int > >& setCoinsRet, CAmount& nValueRet) const
26992705{
27002706 setCoinsRet.clear ();
@@ -3309,12 +3315,13 @@ bool CWallet::CreateCoinstakeOuts(const CPivStake& stakeInput, std::vector<CTxOu
33093315}
33103316
33113317bool CWallet::CreateCoinStake (
3312- const CBlockIndex* pindexPrev,
3313- unsigned int nBits,
3314- CMutableTransaction& txNew,
3315- int64_t & nTxNewTime,
3316- std::vector<CStakeableOutput>* availableCoins,
3317- bool stopOnNewBlock) const
3318+ const CBlockIndex* pindexPrev,
3319+ unsigned int nBits,
3320+ CMutableTransaction& txNew,
3321+ int64_t & nTxNewTime,
3322+ std::vector<CStakeableOutput>* availableCoins,
3323+ std::vector<CStakeableShieldNote>* availableShieldNotes,
3324+ bool stopOnNewBlock) const
33183325{
33193326 // shuffle coins
33203327 if (availableCoins && Params ().IsRegTestNet ()) {
@@ -3336,6 +3343,7 @@ bool CWallet::CreateCoinStake(
33363343 CScript scriptPubKeyKernel;
33373344 bool fKernelFound = false ;
33383345 int nAttempts = 0 ;
3346+ int nShieldAttempts = 0 ;
33393347 for (auto it = availableCoins->begin (); it != availableCoins->end ();) {
33403348 COutPoint outPoint = COutPoint (it->tx ->GetHash (), it->i );
33413349 CPivStake stakeInput (it->tx ->tx ->vout [it->i ],
@@ -3409,9 +3417,36 @@ bool CWallet::CreateCoinStake(
34093417 if (nBytes >= DEFAULT_BLOCK_MAX_SIZE / 5 )
34103418 return error (" %s : exceeded coinstake size limit" , __func__);
34113419
3412- break ;
3420+ LogPrint (BCLog::STAKING, " %s: shield attempted staking %d times\n " , __func__, nShieldAttempts);
3421+ return fKernelFound ;
3422+ }
3423+ LogPrint (BCLog::STAKING, " %s: transparent attempted staking %d times\n " , __func__, nAttempts);
3424+ // Resetting tx values
3425+ txNew.vin .clear ();
3426+ txNew.vout .clear ();
3427+ for (auto it = availableShieldNotes->begin (); it != availableShieldNotes->end ();) {
3428+ CShieldStake noteStake = CShieldStake (it->note .note .value (), it->nullifier );
3429+ // New block came in, move on
3430+ if (stopOnNewBlock && GetLastBlockHeightLockWallet () != pindexPrev->nHeight ) return false ;
3431+
3432+ // Make sure the wallet is unlocked and shutdown hasn't been requested
3433+ if (IsLocked () || ShutdownRequested ()) return false ;
3434+
3435+ // TODO: check that the note IS NOT spent
3436+ nShieldAttempts++;
3437+ nCredit = 0 ;
3438+ bool fKernelFound = false ;
3439+ fKernelFound = Stake (pindexPrev, ¬eStake, nBits, nTxNewTime);
3440+ // update staker status (time, attempts)
3441+ pStakerStatus->SetLastTime (nTxNewTime);
3442+ pStakerStatus->SetLastTries (nAttempts + nShieldAttempts);
3443+
3444+ if (!fKernelFound ) {
3445+ it++;
3446+ continue ;
3447+ }
34133448 }
3414- LogPrint (BCLog::STAKING, " %s: attempted staking %d times\n " , __func__, nAttempts );
3449+ LogPrint (BCLog::STAKING, " %s: shield attempted staking %d times\n " , __func__, nShieldAttempts );
34153450
34163451 return fKernelFound ;
34173452}
0 commit comments