Skip to content

Commit 4d94916

Browse files
committed
Get rid of PendingWalletTx class.
No reason for this class to exist if it doesn't have any code to run in the destructor. e10e1e8 from bitcoin/bitcoin#16208 recently removed code destructor code that would return an unused key if the transaction wasn't committed.
1 parent e5abb59 commit 4d94916

File tree

6 files changed

+33
-55
lines changed

6 files changed

+33
-55
lines changed

src/interfaces/wallet.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,6 @@
3333
namespace interfaces {
3434
namespace {
3535

36-
class PendingWalletTxImpl : public PendingWalletTx
37-
{
38-
public:
39-
explicit PendingWalletTxImpl(CWallet& wallet) : m_wallet(wallet) {}
40-
41-
const CTransaction& get() override { return *m_tx; }
42-
43-
bool commit(WalletValueMap value_map,
44-
WalletOrderForm order_form,
45-
std::string& reject_reason) override
46-
{
47-
auto locked_chain = m_wallet.chain().lock();
48-
LOCK(m_wallet.cs_wallet);
49-
CValidationState state;
50-
if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), state)) {
51-
reject_reason = state.GetRejectReason();
52-
return false;
53-
}
54-
return true;
55-
}
56-
57-
CTransactionRef m_tx;
58-
CWallet& m_wallet;
59-
};
60-
6136
//! Construct wallet tx struct.
6237
WalletTx MakeWalletTx(interfaces::Chain::Lock& locked_chain, CWallet& wallet, const CWalletTx& wtx)
6338
{
@@ -227,7 +202,7 @@ class WalletImpl : public Wallet
227202
LOCK(m_wallet->cs_wallet);
228203
return m_wallet->ListLockedCoins(outputs);
229204
}
230-
std::unique_ptr<PendingWalletTx> createTransaction(const std::vector<CRecipient>& recipients,
205+
CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
231206
const CCoinControl& coin_control,
232207
bool sign,
233208
int& change_pos,
@@ -236,12 +211,26 @@ class WalletImpl : public Wallet
236211
{
237212
auto locked_chain = m_wallet->chain().lock();
238213
LOCK(m_wallet->cs_wallet);
239-
auto pending = MakeUnique<PendingWalletTxImpl>(*m_wallet);
240-
if (!m_wallet->CreateTransaction(*locked_chain, recipients, pending->m_tx, fee, change_pos,
214+
CTransactionRef tx;
215+
if (!m_wallet->CreateTransaction(*locked_chain, recipients, tx, fee, change_pos,
241216
fail_reason, coin_control, sign)) {
242217
return {};
243218
}
244-
return std::move(pending);
219+
return tx;
220+
}
221+
bool commitTransaction(CTransactionRef tx,
222+
WalletValueMap value_map,
223+
WalletOrderForm order_form,
224+
std::string& reject_reason) override
225+
{
226+
auto locked_chain = m_wallet->chain().lock();
227+
LOCK(m_wallet->cs_wallet);
228+
CValidationState state;
229+
if (!m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form), state)) {
230+
reject_reason = state.GetRejectReason();
231+
return false;
232+
}
233+
return true;
245234
}
246235
bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
247236
bool abandonTransaction(const uint256& txid) override

src/interfaces/wallet.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct CRecipient;
3434
namespace interfaces {
3535

3636
class Handler;
37-
class PendingWalletTx;
3837
struct WalletAddress;
3938
struct WalletBalances;
4039
struct WalletTx;
@@ -134,13 +133,19 @@ class Wallet
134133
virtual void listLockedCoins(std::vector<COutPoint>& outputs) = 0;
135134

136135
//! Create transaction.
137-
virtual std::unique_ptr<PendingWalletTx> createTransaction(const std::vector<CRecipient>& recipients,
136+
virtual CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
138137
const CCoinControl& coin_control,
139138
bool sign,
140139
int& change_pos,
141140
CAmount& fee,
142141
std::string& fail_reason) = 0;
143142

143+
//! Commit transaction.
144+
virtual bool commitTransaction(CTransactionRef tx,
145+
WalletValueMap value_map,
146+
WalletOrderForm order_form,
147+
std::string& reject_reason) = 0;
148+
144149
//! Return whether transaction can be abandoned.
145150
virtual bool transactionCanBeAbandoned(const uint256& txid) = 0;
146151

@@ -288,21 +293,6 @@ class Wallet
288293
virtual std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) = 0;
289294
};
290295

291-
//! Tracking object returned by CreateTransaction and passed to CommitTransaction.
292-
class PendingWalletTx
293-
{
294-
public:
295-
virtual ~PendingWalletTx() {}
296-
297-
//! Get transaction data.
298-
virtual const CTransaction& get() = 0;
299-
300-
//! Send pending transaction and commit to wallet.
301-
virtual bool commit(WalletValueMap value_map,
302-
WalletOrderForm order_form,
303-
std::string& reject_reason) = 0;
304-
};
305-
306296
//! Information about one wallet address.
307297
struct WalletAddress
308298
{

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void SendCoinsDialog::on_sendButton_clicked()
392392
accept();
393393
CoinControlDialog::coinControl()->UnSelectAll();
394394
coinControlUpdateLabels();
395-
Q_EMIT coinsSent(currentTransaction.getWtx()->get().GetHash());
395+
Q_EMIT coinsSent(currentTransaction.getWtx()->GetHash());
396396
}
397397
fNewRecipientAllowed = true;
398398
}

src/qt/walletmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
261261

262262
auto& newTx = transaction.getWtx();
263263
std::string rejectReason;
264-
if (!newTx->commit({} /* mapValue */, std::move(vOrderForm), rejectReason))
264+
if (!wallet().commitTransaction(newTx, {} /* mapValue */, std::move(vOrderForm), rejectReason))
265265
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(rejectReason));
266266

267267
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
268-
ssTx << newTx->get();
268+
ssTx << *newTx;
269269
transaction_array.append(&(ssTx[0]), ssTx.size());
270270
}
271271

src/qt/walletmodeltransaction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
2121
return recipients;
2222
}
2323

24-
std::unique_ptr<interfaces::PendingWalletTx>& WalletModelTransaction::getWtx()
24+
CTransactionRef& WalletModelTransaction::getWtx()
2525
{
2626
return wtx;
2727
}
2828

2929
unsigned int WalletModelTransaction::getTransactionSize()
3030
{
31-
return wtx ? GetVirtualTransactionSize(wtx->get()) : 0;
31+
return wtx ? GetVirtualTransactionSize(*wtx) : 0;
3232
}
3333

3434
CAmount WalletModelTransaction::getTransactionFee() const
@@ -43,7 +43,7 @@ void WalletModelTransaction::setTransactionFee(const CAmount& newFee)
4343

4444
void WalletModelTransaction::reassignAmounts(int nChangePosRet)
4545
{
46-
const CTransaction* walletTransaction = &wtx->get();
46+
const CTransaction* walletTransaction = wtx.get();
4747
int i = 0;
4848
for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
4949
{

src/qt/walletmodeltransaction.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class SendCoinsRecipient;
1616

1717
namespace interfaces {
1818
class Node;
19-
class PendingWalletTx;
2019
}
2120

2221
/** Data model for a walletmodel transaction. */
@@ -27,7 +26,7 @@ class WalletModelTransaction
2726

2827
QList<SendCoinsRecipient> getRecipients() const;
2928

30-
std::unique_ptr<interfaces::PendingWalletTx>& getWtx();
29+
CTransactionRef& getWtx();
3130
unsigned int getTransactionSize();
3231

3332
void setTransactionFee(const CAmount& newFee);
@@ -39,7 +38,7 @@ class WalletModelTransaction
3938

4039
private:
4140
QList<SendCoinsRecipient> recipients;
42-
std::unique_ptr<interfaces::PendingWalletTx> wtx;
41+
CTransactionRef wtx;
4342
CAmount fee;
4443
};
4544

0 commit comments

Comments
 (0)