@@ -161,7 +161,7 @@ const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
161
161
LOCK (cs_wallet);
162
162
std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find (hash);
163
163
if (it == mapWallet.end ())
164
- return NULL ;
164
+ return nullptr ;
165
165
return &(it->second );
166
166
}
167
167
@@ -3266,6 +3266,48 @@ int CWallet::GetLastBlockHeightLockWallet() const
3266
3266
return WITH_LOCK (cs_wallet, return m_last_block_processed_height;);
3267
3267
}
3268
3268
3269
+ bool CWallet::CreateCoinstakeOuts (const CPivStake& stakeInput, std::vector<CTxOut>& vout, CAmount nTotal) const
3270
+ {
3271
+ std::vector<valtype> vSolutions;
3272
+ txnouttype whichType;
3273
+ CTxOut stakePrevout;
3274
+ if (!stakeInput.GetTxOutFrom (stakePrevout)) {
3275
+ return error (" %s: failed to get stake input" , __func__);
3276
+ }
3277
+ CScript scriptPubKeyKernel = stakePrevout.scriptPubKey ;
3278
+ if (!Solver (scriptPubKeyKernel, whichType, vSolutions))
3279
+ return error (" %s: failed to parse kernel" , __func__);
3280
+
3281
+ if (whichType != TX_PUBKEY && whichType != TX_PUBKEYHASH && whichType != TX_COLDSTAKE)
3282
+ return error (" %s: type=%d (%s) not supported for scriptPubKeyKernel" , __func__, whichType, GetTxnOutputType (whichType));
3283
+
3284
+ CKey key;
3285
+ if (whichType == TX_PUBKEYHASH || whichType == TX_COLDSTAKE) {
3286
+ // if P2PKH or P2CS check that we have the input private key
3287
+ if (!GetKey (CKeyID (uint160 (vSolutions[0 ])), key))
3288
+ return error (" %s: Unable to get staking private key" , __func__);
3289
+ }
3290
+
3291
+ vout.emplace_back (0 , scriptPubKeyKernel);
3292
+
3293
+ // Calculate if we need to split the output
3294
+ if (nStakeSplitThreshold > 0 ) {
3295
+ int nSplit = static_cast <int >(nTotal / nStakeSplitThreshold);
3296
+ if (nSplit > 1 ) {
3297
+ // if nTotal is twice or more of the threshold; create more outputs
3298
+ int txSizeMax = MAX_STANDARD_TX_SIZE >> 11 ; // limit splits to <10% of the max TX size (/2048)
3299
+ if (nSplit > txSizeMax)
3300
+ nSplit = txSizeMax;
3301
+ for (int i = nSplit; i > 1 ; i--) {
3302
+ LogPrintf (" %s: StakeSplit: nTotal = %d; adding output %d of %d\n " , __func__, nTotal, (nSplit-i)+2 , nSplit);
3303
+ vout.emplace_back (0 , scriptPubKeyKernel);
3304
+ }
3305
+ }
3306
+ }
3307
+
3308
+ return true ;
3309
+ }
3310
+
3269
3311
bool CWallet::CreateCoinStake (
3270
3312
const CBlockIndex* pindexPrev,
3271
3313
unsigned int nBits,
@@ -3335,7 +3377,7 @@ bool CWallet::CreateCoinStake(
3335
3377
3336
3378
// Create the output transaction(s)
3337
3379
std::vector<CTxOut> vout;
3338
- if (!stakeInput. CreateTxOuts ( this , vout, nCredit)) {
3380
+ if (!CreateCoinstakeOuts (stakeInput , vout, nCredit)) {
3339
3381
LogPrintf (" %s : failed to create output\n " , __func__);
3340
3382
it++;
3341
3383
continue ;
0 commit comments