Skip to content

Commit 354f57a

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#10368: [wallet] Remove helper conversion operator from wallet
5a5e4e9 [wallet] Remove CTransaction&() helper conversion operator from wallet implementation. (Karl-Johan Alm) Pull request description: The `CTransaction&()` operator in `CMerkleTx` makes conversion into `CTransaction`s transparent, but was marked as to-be-removed in favor of explicitly getting the `tx` ivar, presumably as the operator can lead to ambiguous behavior and makes the code harder to follow. This PR removes the operator and adapts callers. This includes some cases of `static_cast<CTransaction>(wtx)` → `*wtx.tx`, which is definitely an improvement. Tree-SHA512: 95856fec7194d6a79615ea1c322abfcd6bcedf6ffd0cfa89bbdd332ce13035fa52dd4b828d20df673072dde1be64b79c513529a6f422dd5f0961ce722a32d56a
1 parent 3bae57a commit 354f57a

File tree

10 files changed

+21
-24
lines changed

10 files changed

+21
-24
lines changed

src/qt/transactiondesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
2626
{
2727
AssertLockHeld(cs_main);
28-
if (!CheckFinalTx(wtx))
28+
if (!CheckFinalTx(*wtx.tx))
2929
{
3030
if (wtx.tx->nLockTime < LOCKTIME_THRESHOLD)
3131
return tr("Open for %n more block(s)", "", wtx.tx->nLockTime - chainActive.Height());

src/qt/transactionrecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx, int chainLockHeight)
285285
status.label = QString::fromStdString(addrBookIt->second.name);
286286
}
287287

288-
if (!CheckFinalTx(wtx))
288+
if (!CheckFinalTx(*wtx.tx))
289289
{
290290
if (wtx.tx->nLockTime < LOCKTIME_THRESHOLD)
291291
{

src/qt/transactiontablemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class TransactionTablePriv
244244
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
245245
if(mi != wallet->mapWallet.end())
246246
{
247-
std::string strHex = EncodeHexTx(static_cast<CTransaction>(mi->second));
247+
std::string strHex = EncodeHexTx(*mi->second.tx);
248248
return QString::fromStdString(strHex);
249249
}
250250
return QString();

src/qt/walletmodeltransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CWalletTx *WalletModelTransaction::getTransaction() const
3333

3434
unsigned int WalletModelTransaction::getTransactionSize()
3535
{
36-
return (!walletTransaction ? 0 : (::GetSerializeSize(walletTransaction->tx, SER_NETWORK, PROTOCOL_VERSION)));
36+
return (!walletTransaction ? 0 : (::GetSerializeSize(*walletTransaction->tx, SER_NETWORK, PROTOCOL_VERSION)));
3737
}
3838

3939
CAmount WalletModelTransaction::getTransactionFee() const

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
341341

342342
LOCK2(cs_main, pwallet->cs_wallet);
343343

344-
if (pwallet->IsMine(wtx)) {
344+
if (pwallet->IsMine(*wtx.tx)) {
345345
pwallet->AddToWallet(wtx, false);
346346
return NullUniValue;
347347
}

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
19971997
ListTransactions(pwallet, wtx, "*", 0, false, details, filter);
19981998
entry.push_back(Pair("details", details));
19991999

2000-
std::string strHex = EncodeHexTx(static_cast<CTransaction>(wtx));
2000+
std::string strHex = EncodeHexTx(*wtx.tx);
20012001
entry.push_back(Pair("hex", strHex));
20022002

20032003
return entry;

src/wallet/test/accounting_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
8383

8484
wtx.mapValue["comment"] = "y";
8585
{
86-
CMutableTransaction tx(wtx);
86+
CMutableTransaction tx(*wtx.tx);
8787
--tx.nLockTime; // Just to change the hash :)
8888
wtx.SetTx(MakeTransactionRef(std::move(tx)));
8989
}
@@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
9393

9494
wtx.mapValue["comment"] = "x";
9595
{
96-
CMutableTransaction tx(wtx);
96+
CMutableTransaction tx(*wtx.tx);
9797
--tx.nLockTime; // Just to change the hash :)
9898
wtx.SetTx(MakeTransactionRef(std::move(tx)));
9999
}

src/wallet/wallet.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,14 +1493,15 @@ int CWallet::GetRealOutpointPrivateSendRounds(const COutPoint& outpoint, int nRo
14931493
uint256 hash = outpoint.hash;
14941494
unsigned int nout = outpoint.n;
14951495

1496+
// TODO wtx should refer to a CWalletTx object, not a pointer, based on surrounding code
14961497
const CWalletTx* wtx = GetWalletTx(hash);
14971498
if(wtx != nullptr)
14981499
{
14991500
std::map<uint256, CMutableTransaction>::const_iterator mdwi = mDenomWtxes.find(hash);
15001501
if (mdwi == mDenomWtxes.end()) {
15011502
// not known yet, let's add it
15021503
LogPrint(BCLog::PRIVATESEND, "GetRealOutpointPrivateSendRounds INSERTING %s\n", hash.ToString());
1503-
mDenomWtxes[hash] = CMutableTransaction(*wtx);
1504+
mDenomWtxes[hash] = CMutableTransaction(*wtx->tx);
15041505
} else if(mDenomWtxes[hash].vout[nout].nRounds != -10) {
15051506
// found and it's not an initial value, just return it
15061507
return mDenomWtxes[hash].vout[nout].nRounds;
@@ -2043,7 +2044,7 @@ bool CWalletTx::RelayWalletTransaction(CConnman* connman)
20432044
LogPrintf("Relaying wtx %s\n", hash.ToString());
20442045

20452046
if (connman) {
2046-
connman->RelayTransaction((CTransaction)*this);
2047+
connman->RelayTransaction(*tx);
20472048
return true;
20482049
}
20492050
}
@@ -2075,7 +2076,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const
20752076
debit += nDebitCached;
20762077
else
20772078
{
2078-
nDebitCached = pwallet->GetDebit(*this, ISMINE_SPENDABLE);
2079+
nDebitCached = pwallet->GetDebit(*tx, ISMINE_SPENDABLE);
20792080
fDebitCached = true;
20802081
debit += nDebitCached;
20812082
}
@@ -2086,7 +2087,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const
20862087
debit += nWatchDebitCached;
20872088
else
20882089
{
2089-
nWatchDebitCached = pwallet->GetDebit(*this, ISMINE_WATCH_ONLY);
2090+
nWatchDebitCached = pwallet->GetDebit(*tx, ISMINE_WATCH_ONLY);
20902091
fWatchDebitCached = true;
20912092
debit += nWatchDebitCached;
20922093
}
@@ -2108,7 +2109,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
21082109
credit += nCreditCached;
21092110
else
21102111
{
2111-
nCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE);
2112+
nCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE);
21122113
fCreditCached = true;
21132114
credit += nCreditCached;
21142115
}
@@ -2119,7 +2120,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
21192120
credit += nWatchCreditCached;
21202121
else
21212122
{
2122-
nWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY);
2123+
nWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY);
21232124
fWatchCreditCached = true;
21242125
credit += nWatchCreditCached;
21252126
}
@@ -2133,7 +2134,7 @@ CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
21332134
{
21342135
if (fUseCache && fImmatureCreditCached)
21352136
return nImmatureCreditCached;
2136-
nImmatureCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE);
2137+
nImmatureCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE);
21372138
fImmatureCreditCached = true;
21382139
return nImmatureCreditCached;
21392140
}
@@ -2177,7 +2178,7 @@ CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool& fUseCache) const
21772178
{
21782179
if (fUseCache && fImmatureWatchCreditCached)
21792180
return nImmatureWatchCreditCached;
2180-
nImmatureWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY);
2181+
nImmatureWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY);
21812182
fImmatureWatchCreditCached = true;
21822183
return nImmatureWatchCreditCached;
21832184
}
@@ -2297,7 +2298,7 @@ CAmount CWalletTx::GetChange() const
22972298
{
22982299
if (fChangeCached)
22992300
return nChangeCached;
2300-
nChangeCached = pwallet->GetChange(*this);
2301+
nChangeCached = pwallet->GetChange(*tx);
23012302
fChangeCached = true;
23022303
return nChangeCached;
23032304
}
@@ -2311,7 +2312,7 @@ bool CWalletTx::InMempool() const
23112312
bool CWalletTx::IsTrusted() const
23122313
{
23132314
// Quick answer in most cases
2314-
if (!CheckFinalTx(*this))
2315+
if (!CheckFinalTx(*tx))
23152316
return false;
23162317
int nDepth = GetDepthInMainChain();
23172318
if (nDepth >= 1)
@@ -2677,7 +2678,7 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
26772678
for (auto pcoin : GetSpendableTXs()) {
26782679
const uint256& wtxid = pcoin->GetHash();
26792680

2680-
if (!CheckFinalTx(*pcoin))
2681+
if (!CheckFinalTx(*pcoin->tx))
26812682
continue;
26822683

26832684
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)

src/wallet/wallet.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ class CMerkleTx
229229
Init();
230230
}
231231

232-
/** Helper conversion operator to allow passing CMerkleTx where CTransaction is expected.
233-
* TODO: adapt callers and remove this operator. */
234-
operator const CTransaction&() const { return *tx; }
235-
236232
void Init()
237233
{
238234
hashBlock = uint256();

src/wallet/walletdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
275275
CWalletTx wtx;
276276
ssValue >> wtx;
277277
CValidationState state;
278-
if (!(CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid()))
278+
if (!(CheckTransaction(*wtx.tx, state) && (wtx.GetHash() == hash) && state.IsValid()))
279279
return false;
280280

281281
// Undo serialize changes in 31600

0 commit comments

Comments
 (0)