@@ -2695,6 +2695,12 @@ bool CWallet::StakeableCoins(std::vector<CStakeableOutput>* pCoins)
2695
2695
return (pCoins && !pCoins->empty ());
2696
2696
}
2697
2697
2698
+ void CWallet::StakeableShieldNotes (std::vector<CStakeableShieldNote>* shieldCoins)
2699
+ {
2700
+ shieldCoins->clear ();
2701
+ m_sspk_man->GetStakeableNotes (shieldCoins, Params ().GetConsensus ().nStakeMinDepth );
2702
+ }
2703
+
2698
2704
bool 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
2699
2705
{
2700
2706
setCoinsRet.clear ();
@@ -3309,12 +3315,13 @@ bool CWallet::CreateCoinstakeOuts(const CPivStake& stakeInput, std::vector<CTxOu
3309
3315
}
3310
3316
3311
3317
bool 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
3318
3325
{
3319
3326
// shuffle coins
3320
3327
if (availableCoins && Params ().IsRegTestNet ()) {
@@ -3336,6 +3343,7 @@ bool CWallet::CreateCoinStake(
3336
3343
CScript scriptPubKeyKernel;
3337
3344
bool fKernelFound = false ;
3338
3345
int nAttempts = 0 ;
3346
+ int nShieldAttempts = 0 ;
3339
3347
for (auto it = availableCoins->begin (); it != availableCoins->end ();) {
3340
3348
COutPoint outPoint = COutPoint (it->tx ->GetHash (), it->i );
3341
3349
CPivStake stakeInput (it->tx ->tx ->vout [it->i ],
@@ -3409,9 +3417,36 @@ bool CWallet::CreateCoinStake(
3409
3417
if (nBytes >= DEFAULT_BLOCK_MAX_SIZE / 5 )
3410
3418
return error (" %s : exceeded coinstake size limit" , __func__);
3411
3419
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
+ }
3413
3448
}
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 );
3415
3450
3416
3451
return fKernelFound ;
3417
3452
}
0 commit comments