@@ -2245,7 +2245,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
2245
2245
CAmount nValue = 0 ;
2246
2246
int nChangePosRequest = nChangePosInOut;
2247
2247
unsigned int nSubtractFeeFromAmount = 0 ;
2248
- BOOST_FOREACH (const CRecipient & recipient, vecSend)
2248
+ for (const auto & recipient : vecSend)
2249
2249
{
2250
2250
if (nValue < 0 || recipient.nAmount < 0 )
2251
2251
{
@@ -2300,6 +2300,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
2300
2300
assert (txNew.nLockTime < LOCKTIME_THRESHOLD);
2301
2301
2302
2302
{
2303
+ set<pair<const CWalletTx*,unsigned int > > setCoins;
2303
2304
LOCK2 (cs_main, cs_wallet);
2304
2305
{
2305
2306
std::vector<COutput> vAvailableCoins;
@@ -2320,7 +2321,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
2320
2321
nValueToSelect += nFeeRet;
2321
2322
double dPriority = 0 ;
2322
2323
// vouts to the payees
2323
- BOOST_FOREACH (const CRecipient & recipient, vecSend)
2324
+ for (const auto & recipient : vecSend)
2324
2325
{
2325
2326
CTxOut txout (recipient.nAmount , recipient.scriptPubKey );
2326
2327
@@ -2352,14 +2353,14 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
2352
2353
}
2353
2354
2354
2355
// Choose coins to use
2355
- set<pair<const CWalletTx*,unsigned int > > setCoins;
2356
2356
CAmount nValueIn = 0 ;
2357
+ setCoins.clear ();
2357
2358
if (!SelectCoins (vAvailableCoins, nValueToSelect, setCoins, nValueIn, coinControl))
2358
2359
{
2359
2360
strFailReason = _ (" Insufficient funds" );
2360
2361
return false ;
2361
2362
}
2362
- BOOST_FOREACH ( PAIRTYPE ( const CWalletTx*, unsigned int ) pcoin, setCoins)
2363
+ for ( const auto & pcoin : setCoins)
2363
2364
{
2364
2365
CAmount nCredit = pcoin.first ->tx ->vout [pcoin.second ].nValue ;
2365
2366
// The coin age after the next block (depth+1) is used instead of the current,
@@ -2470,24 +2471,18 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
2470
2471
// to avoid conflicting with other possible uses of nSequence,
2471
2472
// and in the spirit of "smallest posible change from prior
2472
2473
// behavior."
2473
- BOOST_FOREACH ( const PAIRTYPE (const CWalletTx*, unsigned int ) & coin, setCoins)
2474
+ for (const auto & coin : setCoins)
2474
2475
txNew.vin .push_back (CTxIn (coin.first ->GetHash (),coin.second ,CScript (),
2475
2476
std::numeric_limits<unsigned int >::max () - (fWalletRbf ? 2 : 1 )));
2476
2477
2477
- // Sign
2478
+ // Fill in dummy signatures for fee calculation.
2478
2479
int nIn = 0 ;
2479
- CTransaction txNewConst (txNew);
2480
- BOOST_FOREACH (const PAIRTYPE (const CWalletTx*,unsigned int )& coin, setCoins)
2480
+ for (const auto & coin : setCoins)
2481
2481
{
2482
- bool signSuccess;
2483
2482
const CScript& scriptPubKey = coin.first ->tx ->vout [coin.second ].scriptPubKey ;
2484
2483
SignatureData sigdata;
2485
- if (sign)
2486
- signSuccess = ProduceSignature (TransactionSignatureCreator (this , &txNewConst, nIn, coin.first ->tx ->vout [coin.second ].nValue , SIGHASH_ALL), scriptPubKey, sigdata);
2487
- else
2488
- signSuccess = ProduceSignature (DummySignatureCreator (this ), scriptPubKey, sigdata);
2489
2484
2490
- if (!signSuccess )
2485
+ if (!ProduceSignature ( DummySignatureCreator ( this ), scriptPubKey, sigdata) )
2491
2486
{
2492
2487
strFailReason = _ (" Signing transaction failed" );
2493
2488
return false ;
@@ -2500,26 +2495,15 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
2500
2495
2501
2496
unsigned int nBytes = GetVirtualTransactionSize (txNew);
2502
2497
2503
- // Remove scriptSigs if we used dummy signatures for fee calculation
2504
- if (!sign) {
2505
- BOOST_FOREACH (CTxIn& vin, txNew.vin ) {
2506
- vin.scriptSig = CScript ();
2507
- vin.scriptWitness .SetNull ();
2508
- }
2509
- }
2510
-
2511
- // Embed the constructed transaction data in wtxNew.
2512
- wtxNew.SetTx (MakeTransactionRef (std::move (txNew)));
2498
+ CTransaction txNewConst (txNew);
2499
+ dPriority = txNewConst.ComputePriority (dPriority, nBytes);
2513
2500
2514
- // Limit size
2515
- if (GetTransactionWeight (wtxNew) >= MAX_STANDARD_TX_WEIGHT)
2516
- {
2517
- strFailReason = _ (" Transaction too large" );
2518
- return false ;
2501
+ // Remove scriptSigs to eliminate the fee calculation dummy signatures
2502
+ for (auto & vin : txNew.vin ) {
2503
+ vin.scriptSig = CScript ();
2504
+ vin.scriptWitness .SetNull ();
2519
2505
}
2520
2506
2521
- dPriority = wtxNew.tx ->ComputePriority (dPriority, nBytes);
2522
-
2523
2507
// Allow to override the default confirmation target over the CoinControl instance
2524
2508
int currentConfirmationTarget = nTxConfirmTarget;
2525
2509
if (coinControl && coinControl->nConfirmTarget > 0 )
@@ -2558,6 +2542,37 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
2558
2542
continue ;
2559
2543
}
2560
2544
}
2545
+
2546
+ if (sign)
2547
+ {
2548
+ CTransaction txNewConst (txNew);
2549
+ int nIn = 0 ;
2550
+ for (const auto & coin : setCoins)
2551
+ {
2552
+ const CScript& scriptPubKey = coin.first ->tx ->vout [coin.second ].scriptPubKey ;
2553
+ SignatureData sigdata;
2554
+
2555
+ if (!ProduceSignature (TransactionSignatureCreator (this , &txNewConst, nIn, coin.first ->tx ->vout [coin.second ].nValue , SIGHASH_ALL), scriptPubKey, sigdata))
2556
+ {
2557
+ strFailReason = _ (" Signing transaction failed" );
2558
+ return false ;
2559
+ } else {
2560
+ UpdateTransaction (txNew, nIn, sigdata);
2561
+ }
2562
+
2563
+ nIn++;
2564
+ }
2565
+ }
2566
+
2567
+ // Embed the constructed transaction data in wtxNew.
2568
+ wtxNew.SetTx (MakeTransactionRef (std::move (txNew)));
2569
+
2570
+ // Limit size
2571
+ if (GetTransactionWeight (wtxNew) >= MAX_STANDARD_TX_WEIGHT)
2572
+ {
2573
+ strFailReason = _ (" Transaction too large" );
2574
+ return false ;
2575
+ }
2561
2576
}
2562
2577
2563
2578
if (GetBoolArg (" -walletrejectlongchains" , DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
0 commit comments