Skip to content

Commit e78bc45

Browse files
committed
[Wallet] Decouple CInputCoin from CWalletTx
1 parent fd44ac1 commit e78bc45

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *pWal
3030
for (auto& input : tx.vin) {
3131
const auto mi = pWallet->mapWallet.find(input.prevout.hash);
3232
assert(mi != pWallet->mapWallet.end() && input.prevout.n < mi->second.tx->vout.size());
33-
vCoins.emplace_back(&(mi->second), input.prevout.n);
33+
vCoins.emplace_back(CInputCoin(&(mi->second), input.prevout.n));
3434
}
3535
if (!pWallet->DummySignTx(txNew, vCoins)) {
3636
// This should never happen, because IsAllFromMe(ISMINE_SPENDABLE)

src/wallet/wallet.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
20872087
// List of values less than target
20882088
std::pair<CAmount, CInputCoin> coinLowestLarger;
20892089
coinLowestLarger.first = std::numeric_limits<CAmount>::max();
2090-
coinLowestLarger.second.first = NULL;
20912090
std::vector<std::pair<CAmount, CInputCoin> > vValue;
20922091
CAmount nTotalLower = 0;
20932092

@@ -2109,7 +2108,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
21092108
int i = output.i;
21102109
CAmount n = pcoin->tx->vout[i].nValue;
21112110

2112-
std::pair<CAmount,CInputCoin> coin = std::make_pair(n,std::make_pair(pcoin, i));
2111+
std::pair<CAmount,CInputCoin> coin = std::make_pair(n, CInputCoin(pcoin, i));
21132112

21142113
if (n == nTargetValue)
21152114
{
@@ -2140,7 +2139,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
21402139

21412140
if (nTotalLower < nTargetValue)
21422141
{
2143-
if (coinLowestLarger.second.first == NULL)
2142+
if (coinLowestLarger.second.IsNull())
21442143
return false;
21452144
setCoinsRet.insert(coinLowestLarger.second);
21462145
nValueRet += coinLowestLarger.first;
@@ -2159,7 +2158,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
21592158

21602159
// If we have a bigger coin and (either the stochastic approximation didn't find a good solution,
21612160
// or the next bigger coin is closer), return the bigger coin
2162-
if (coinLowestLarger.second.first &&
2161+
if (coinLowestLarger.second.IsNull() &&
21632162
((nBest != nTargetValue && nBest < nTargetValue + MIN_CHANGE) || coinLowestLarger.first <= nBest))
21642163
{
21652164
setCoinsRet.insert(coinLowestLarger.second);
@@ -2199,7 +2198,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
21992198
if (!out.fSpendable)
22002199
continue;
22012200
nValueRet += out.tx->tx->vout[out.i].nValue;
2202-
setCoinsRet.insert(std::make_pair(out.tx, out.i));
2201+
setCoinsRet.insert(CInputCoin(out.tx, out.i));
22032202
}
22042203
return (nValueRet >= nTargetValue);
22052204
}
@@ -2221,15 +2220,15 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
22212220
if (pcoin->tx->vout.size() <= outpoint.n)
22222221
return false;
22232222
nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue;
2224-
setPresetCoins.insert(std::make_pair(pcoin, outpoint.n));
2223+
setPresetCoins.insert(CInputCoin(pcoin, outpoint.n));
22252224
} else
22262225
return false; // TODO: Allow non-wallet inputs
22272226
}
22282227

22292228
// remove preset inputs from vCoins
22302229
for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coinControl && coinControl->HasSelected();)
22312230
{
2232-
if (setPresetCoins.count(std::make_pair(it->tx, it->i)))
2231+
if (setPresetCoins.count(CInputCoin(it->tx, it->i)))
22332232
it = vCoins.erase(it);
22342233
else
22352234
++it;
@@ -2554,7 +2553,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
25542553
// behavior."
25552554
bool rbf = coinControl ? coinControl->signalRbf : fWalletRbf;
25562555
for (const auto& coin : setCoins)
2557-
txNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second,CScript(),
2556+
txNew.vin.push_back(CTxIn(coin.outpoint,CScript(),
25582557
std::numeric_limits<unsigned int>::max() - (rbf ? 2 : 1)));
25592558

25602559
// Fill in dummy signatures for fee calculation.
@@ -2637,10 +2636,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
26372636
int nIn = 0;
26382637
for (const auto& coin : setCoins)
26392638
{
2640-
const CScript& scriptPubKey = coin.first->tx->vout[coin.second].scriptPubKey;
2639+
const CScript& scriptPubKey = coin.txout.scriptPubKey;
26412640
SignatureData sigdata;
26422641

2643-
if (!ProduceSignature(TransactionSignatureCreator(this, &txNewConst, nIn, coin.first->tx->vout[coin.second].nValue, SIGHASH_ALL), scriptPubKey, sigdata))
2642+
if (!ProduceSignature(TransactionSignatureCreator(this, &txNewConst, nIn, coin.txout.nValue, SIGHASH_ALL), scriptPubKey, sigdata))
26442643
{
26452644
strFailReason = _("Signing transaction failed");
26462645
return false;

src/wallet/wallet.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,38 @@ class CWalletTx : public CMerkleTx
475475
};
476476

477477

478-
using CInputCoin = std::pair<const CWalletTx*, unsigned int>;
478+
class CInputCoin {
479+
public:
480+
CInputCoin()
481+
{
482+
}
483+
CInputCoin(const CWalletTx* walletTx, unsigned int i)
484+
{
485+
if (walletTx != nullptr && i < walletTx->tx->vout.size())
486+
{
487+
outpoint = COutPoint(walletTx->GetHash(), i);
488+
txout = walletTx->tx->vout[i];
489+
}
490+
}
491+
bool IsNull() const
492+
{
493+
return outpoint.IsNull() && txout.IsNull();
494+
}
495+
COutPoint outpoint;
496+
CTxOut txout;
497+
498+
bool operator<(const CInputCoin& rhs) const {
499+
return outpoint < rhs.outpoint;
500+
}
501+
502+
bool operator!=(const CInputCoin& rhs) const {
503+
return outpoint != rhs.outpoint;
504+
}
505+
506+
bool operator==(const CInputCoin& rhs) const {
507+
return outpoint == rhs.outpoint;
508+
}
509+
};
479510

480511
class COutput
481512
{
@@ -1132,7 +1163,7 @@ bool CWallet::DummySignTx(CMutableTransaction &txNew, const ContainerType &coins
11321163
int nIn = 0;
11331164
for (const auto& coin : coins)
11341165
{
1135-
const CScript& scriptPubKey = coin.first->tx->vout[coin.second].scriptPubKey;
1166+
const CScript& scriptPubKey = coin.txout.scriptPubKey;
11361167
SignatureData sigdata;
11371168

11381169
if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, sigdata))

0 commit comments

Comments
 (0)