Add CMutableTransaction and make CTransaction immutable.
In addition, introduce a cached hash inside CTransaction, to prevent recalculating it over and over again.
This commit is contained in:
@@ -1245,6 +1245,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
}
|
||||
|
||||
wtxNew.BindWallet(this);
|
||||
CMutableTransaction txNew;
|
||||
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
@@ -1252,8 +1253,8 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
nFeeRet = payTxFee.GetFeePerK();
|
||||
while (true)
|
||||
{
|
||||
wtxNew.vin.clear();
|
||||
wtxNew.vout.clear();
|
||||
txNew.vin.clear();
|
||||
txNew.vout.clear();
|
||||
wtxNew.fFromMe = true;
|
||||
|
||||
int64_t nTotalValue = nValue + nFeeRet;
|
||||
@@ -1267,7 +1268,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
strFailReason = _("Transaction amount too small");
|
||||
return false;
|
||||
}
|
||||
wtxNew.vout.push_back(txout);
|
||||
txNew.vout.push_back(txout);
|
||||
}
|
||||
|
||||
// Choose coins to use
|
||||
@@ -1331,8 +1332,8 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
else
|
||||
{
|
||||
// Insert change txn at random position:
|
||||
vector<CTxOut>::iterator position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size()+1);
|
||||
wtxNew.vout.insert(position, newTxOut);
|
||||
vector<CTxOut>::iterator position = txNew.vout.begin()+GetRandInt(txNew.vout.size()+1);
|
||||
txNew.vout.insert(position, newTxOut);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1340,17 +1341,20 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
|
||||
// Fill vin
|
||||
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
|
||||
wtxNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second));
|
||||
txNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second));
|
||||
|
||||
// Sign
|
||||
int nIn = 0;
|
||||
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
|
||||
if (!SignSignature(*this, *coin.first, wtxNew, nIn++))
|
||||
if (!SignSignature(*this, *coin.first, txNew, nIn++))
|
||||
{
|
||||
strFailReason = _("Signing transaction failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Embed the constructed transaction data in wtxNew.
|
||||
*static_cast<CTransaction*>(&wtxNew) = CTransaction(txNew);
|
||||
|
||||
// Limit size
|
||||
unsigned int nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK, PROTOCOL_VERSION);
|
||||
if (nBytes >= MAX_STANDARD_TX_SIZE)
|
||||
|
||||
Reference in New Issue
Block a user