@@ -2186,17 +2186,45 @@ static void ApproximateBestSubset(std::vector<std::pair<CAmount, std::pair<const
21862186 }
21872187}
21882188
2189-
2190- bool CWallet::StakeableCoins (std::vector<COutput>* pCoins)
2189+ bool CWallet::StakeableCoins (std::vector<CStakeableOutput>* pCoins)
21912190{
2192- const bool fIncludeCold = (sporkManager.IsSporkActive (SPORK_17_COLDSTAKING_ENFORCEMENT) &&
2191+ const bool fIncludeColdStaking = (sporkManager.IsSporkActive (SPORK_17_COLDSTAKING_ENFORCEMENT) &&
21932192 GetBoolArg (" -coldstaking" , DEFAULT_COLDSTAKING));
21942193
2195- return AvailableCoins (pCoins,
2196- nullptr , // coin control
2197- false , // fIncludeDelegated
2198- fIncludeCold , // fIncludeColdStaking
2199- STAKEABLE_COINS); // coin type
2194+ LOCK2 (cs_main, cs_wallet);
2195+ for (const auto & it : mapWallet) {
2196+ const uint256& wtxid = it.first ;
2197+ const CWalletTx* pcoin = &(it).second ;
2198+
2199+ // Check if the tx is selectable
2200+ int nDepth;
2201+ const CBlockIndex* pindex = nullptr ;
2202+ if (!CheckTXAvailability (pcoin, true , false , nDepth, pindex))
2203+ continue ;
2204+
2205+ // Check min depth requirement for stake inputs
2206+ if (nDepth < Params ().GetConsensus ().nStakeMinDepth ) continue ;
2207+
2208+ for (unsigned int index = 0 ; index < pcoin->vout .size (); index++) {
2209+
2210+ auto res = CheckOutputAvailability (
2211+ pcoin->vout [index],
2212+ index,
2213+ wtxid,
2214+ STAKEABLE_COINS,
2215+ nullptr , // coin control
2216+ false , // fIncludeDelegated
2217+ fIncludeColdStaking ,
2218+ false );
2219+
2220+ if (!res.available ) continue ;
2221+
2222+ // found valid coin
2223+ if (!pCoins) return true ;
2224+ pCoins->emplace_back (CStakeableOutput (pcoin, (int ) index, nDepth, res.spendable , res.solvable , pindex));
2225+ }
2226+ }
2227+ return (pCoins && !pCoins->empty ());
22002228}
22012229
22022230bool CWallet::SelectCoinsMinConf (const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*, unsigned int > >& setCoinsRet, CAmount& nValueRet) const
@@ -2704,8 +2732,7 @@ bool CWallet::CreateCoinStake(
27042732 unsigned int nBits,
27052733 CMutableTransaction& txNew,
27062734 int64_t & nTxNewTime,
2707- std::vector<COutput>* availableCoins
2708- )
2735+ std::vector<CStakeableOutput>* availableCoins)
27092736{
27102737
27112738 const Consensus::Params& consensus = Params ().GetConsensus ();
@@ -2727,7 +2754,7 @@ bool CWallet::CreateCoinStake(
27272754 CScript scriptPubKeyKernel;
27282755 bool fKernelFound = false ;
27292756 int nAttempts = 0 ;
2730- for (const COutput & out : *availableCoins) {
2757+ for (const auto & out : *availableCoins) {
27312758 CPivStake stakeInput;
27322759 stakeInput.SetPrevout (out.tx ->vout [out.i ], COutPoint (out.tx ->GetHash (), out.i ));
27332760
0 commit comments