Skip to content

Commit 77ba4bf

Browse files
committed
Merge #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
2 parents ef3758d + 5a5e4e9 commit 77ba4bf

11 files changed

+22
-26
lines changed

src/qt/transactiondesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
2525
{
2626
AssertLockHeld(cs_main);
27-
if (!CheckFinalTx(wtx))
27+
if (!CheckFinalTx(*wtx.tx))
2828
{
2929
if (wtx.tx->nLockTime < LOCKTIME_THRESHOLD)
3030
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
@@ -182,7 +182,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
182182
status.depth = wtx.GetDepthInMainChain();
183183
status.cur_num_blocks = chainActive.Height();
184184

185-
if (!CheckFinalTx(wtx))
185+
if (!CheckFinalTx(*wtx.tx))
186186
{
187187
if (wtx.tx->nLockTime < LOCKTIME_THRESHOLD)
188188
{

src/qt/transactiontablemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class TransactionTablePriv
230230
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
231231
if(mi != wallet->mapWallet.end())
232232
{
233-
std::string strHex = EncodeHexTx(static_cast<CTransaction>(mi->second));
233+
std::string strHex = EncodeHexTx(*mi->second.tx);
234234
return QString::fromStdString(strHex);
235235
}
236236
return QString();

src/qt/walletmodeltransaction.cpp

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

3535
unsigned int WalletModelTransaction::getTransactionSize()
3636
{
37-
return (!walletTransaction ? 0 : ::GetVirtualTransactionSize(*walletTransaction));
37+
return (!walletTransaction ? 0 : ::GetVirtualTransactionSize(*walletTransaction->tx));
3838
}
3939

4040
CAmount WalletModelTransaction::getTransactionFee() const

src/wallet/feebumper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoin
8989
return;
9090
}
9191

92-
if (!SignalsOptInRBF(wtx)) {
92+
if (!SignalsOptInRBF(*wtx.tx)) {
9393
vErrors.push_back("Transaction is not BIP 125 replaceable");
9494
currentResult = BumpFeeResult::WALLET_ERROR;
9595
return;
@@ -103,7 +103,7 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoin
103103

104104
// check that original tx consists entirely of our inputs
105105
// if not, we can't bump the fee, because the wallet has no way of knowing the value of the other inputs (thus the fee)
106-
if (!pWallet->IsAllFromMe(wtx, ISMINE_SPENDABLE)) {
106+
if (!pWallet->IsAllFromMe(*wtx.tx, ISMINE_SPENDABLE)) {
107107
vErrors.push_back("Transaction contains inputs that don't belong to this wallet");
108108
currentResult = BumpFeeResult::WALLET_ERROR;
109109
return;

src/wallet/rpcdump.cpp

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

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

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

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
108108
std::string rbfStatus = "no";
109109
if (confirms <= 0) {
110110
LOCK(mempool.cs);
111-
RBFTransactionState rbfState = IsRBFOptIn(wtx, mempool);
111+
RBFTransactionState rbfState = IsRBFOptIn(*wtx.tx, mempool);
112112
if (rbfState == RBF_TRANSACTIONSTATE_UNKNOWN)
113113
rbfStatus = "unknown";
114114
else if (rbfState == RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125)
@@ -2051,7 +2051,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
20512051
ListTransactions(pwallet, wtx, "*", 0, false, details, filter);
20522052
entry.push_back(Pair("details", details));
20532053

2054-
std::string strHex = EncodeHexTx(static_cast<CTransaction>(wtx), RPCSerializationFlags());
2054+
std::string strHex = EncodeHexTx(*wtx.tx, RPCSerializationFlags());
20552055
entry.push_back(Pair("hex", strHex));
20562056

20572057
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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const
17181718
debit += nDebitCached;
17191719
else
17201720
{
1721-
nDebitCached = pwallet->GetDebit(*this, ISMINE_SPENDABLE);
1721+
nDebitCached = pwallet->GetDebit(*tx, ISMINE_SPENDABLE);
17221722
fDebitCached = true;
17231723
debit += nDebitCached;
17241724
}
@@ -1729,7 +1729,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const
17291729
debit += nWatchDebitCached;
17301730
else
17311731
{
1732-
nWatchDebitCached = pwallet->GetDebit(*this, ISMINE_WATCH_ONLY);
1732+
nWatchDebitCached = pwallet->GetDebit(*tx, ISMINE_WATCH_ONLY);
17331733
fWatchDebitCached = true;
17341734
debit += nWatchDebitCached;
17351735
}
@@ -1751,7 +1751,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
17511751
credit += nCreditCached;
17521752
else
17531753
{
1754-
nCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE);
1754+
nCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE);
17551755
fCreditCached = true;
17561756
credit += nCreditCached;
17571757
}
@@ -1762,7 +1762,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
17621762
credit += nWatchCreditCached;
17631763
else
17641764
{
1765-
nWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY);
1765+
nWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY);
17661766
fWatchCreditCached = true;
17671767
credit += nWatchCreditCached;
17681768
}
@@ -1776,7 +1776,7 @@ CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
17761776
{
17771777
if (fUseCache && fImmatureCreditCached)
17781778
return nImmatureCreditCached;
1779-
nImmatureCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE);
1779+
nImmatureCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE);
17801780
fImmatureCreditCached = true;
17811781
return nImmatureCreditCached;
17821782
}
@@ -1820,7 +1820,7 @@ CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool& fUseCache) const
18201820
{
18211821
if (fUseCache && fImmatureWatchCreditCached)
18221822
return nImmatureWatchCreditCached;
1823-
nImmatureWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY);
1823+
nImmatureWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY);
18241824
fImmatureWatchCreditCached = true;
18251825
return nImmatureWatchCreditCached;
18261826
}
@@ -1861,7 +1861,7 @@ CAmount CWalletTx::GetChange() const
18611861
{
18621862
if (fChangeCached)
18631863
return nChangeCached;
1864-
nChangeCached = pwallet->GetChange(*this);
1864+
nChangeCached = pwallet->GetChange(*tx);
18651865
fChangeCached = true;
18661866
return nChangeCached;
18671867
}
@@ -1875,7 +1875,7 @@ bool CWalletTx::InMempool() const
18751875
bool CWalletTx::IsTrusted() const
18761876
{
18771877
// Quick answer in most cases
1878-
if (!CheckFinalTx(*this))
1878+
if (!CheckFinalTx(*tx))
18791879
return false;
18801880
int nDepth = GetDepthInMainChain();
18811881
if (nDepth >= 1)
@@ -2133,7 +2133,7 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
21332133
const uint256& wtxid = it->first;
21342134
const CWalletTx* pcoin = &(*it).second;
21352135

2136-
if (!CheckFinalTx(*pcoin))
2136+
if (!CheckFinalTx(*pcoin->tx))
21372137
continue;
21382138

21392139
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
@@ -2915,7 +2915,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
29152915
wtxNew.SetTx(MakeTransactionRef(std::move(txNew)));
29162916

29172917
// Limit size
2918-
if (GetTransactionWeight(wtxNew) >= MAX_STANDARD_TX_WEIGHT)
2918+
if (GetTransactionWeight(*wtxNew.tx) >= MAX_STANDARD_TX_WEIGHT)
29192919
{
29202920
strFailReason = _("Transaction too large");
29212921
return false;

src/wallet/wallet.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,6 @@ class CMerkleTx
214214
Init();
215215
}
216216

217-
/** Helper conversion operator to allow passing CMerkleTx where CTransaction is expected.
218-
* TODO: adapt callers and remove this operator. */
219-
operator const CTransaction&() const { return *tx; }
220-
221217
void Init()
222218
{
223219
hashBlock = uint256();

0 commit comments

Comments
 (0)