@@ -2447,6 +2447,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
24472447 wtxNew.fTimeReceivedIsTxTime = true ;
24482448 wtxNew.BindWallet (this );
24492449 CMutableTransaction txNew;
2450+ CScript scriptChange;
24502451
24512452 {
24522453 LOCK2 (cs_main, cs_wallet);
@@ -2529,7 +2530,6 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
25292530 // Fill a vout to ourself
25302531 // TODO: pass in scriptChange instead of reservekey so
25312532 // change transaction isn't always pay-to-pivx-address
2532- CScript scriptChange;
25332533 bool combineChange = false ;
25342534
25352535 // coin control: send change to custom address
@@ -2558,14 +2558,14 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
25582558 // rediscover unknown transactions that were written with keys of ours to recover
25592559 // post-backup change.
25602560
2561- // Reserve a new key pair from key pool
2561+ // Reserve a new key pair from key pool. If it fails, provide a dummy
25622562 CPubKey vchPubKey;
25632563 if (!reservekey.GetReservedKey (vchPubKey, true )) {
25642564 strFailReason = _ (" Can't generate a change-address key. Please call keypoolrefill first." );
2565- return false ;
2565+ scriptChange = CScript ();
2566+ } else {
2567+ scriptChange = GetScriptForDestination (vchPubKey.GetID ());
25662568 }
2567-
2568- scriptChange = GetScriptForDestination (vchPubKey.GetID ());
25692569 }
25702570
25712571 if (!combineChange) {
@@ -2658,6 +2658,11 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
26582658 nFeeRet = nFeeNeeded;
26592659 continue ;
26602660 }
2661+
2662+ // Give up if change keypool ran out and we failed to find a solution without change:
2663+ if (scriptChange.empty () && nChangePosRet != -1 ) {
2664+ return false ;
2665+ }
26612666 }
26622667 }
26632668 return true ;
0 commit comments