Get rid of PendingWalletTx class.
No reason for this class to exist if it doesn't have any code to run in the
destructor. e10e1e8db0
from
https://github.com/bitcoin/bitcoin/pull/16208 recently removed code destructor
code that would return an unused key if the transaction wasn't committed.
This commit is contained in:
parent
e5abb59a9a
commit
4d94916f0d
6 changed files with 33 additions and 55 deletions
|
@ -33,31 +33,6 @@
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class PendingWalletTxImpl : public PendingWalletTx
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit PendingWalletTxImpl(CWallet& wallet) : m_wallet(wallet) {}
|
|
||||||
|
|
||||||
const CTransaction& get() override { return *m_tx; }
|
|
||||||
|
|
||||||
bool commit(WalletValueMap value_map,
|
|
||||||
WalletOrderForm order_form,
|
|
||||||
std::string& reject_reason) override
|
|
||||||
{
|
|
||||||
auto locked_chain = m_wallet.chain().lock();
|
|
||||||
LOCK(m_wallet.cs_wallet);
|
|
||||||
CValidationState state;
|
|
||||||
if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), state)) {
|
|
||||||
reject_reason = state.GetRejectReason();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
CTransactionRef m_tx;
|
|
||||||
CWallet& m_wallet;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Construct wallet tx struct.
|
//! Construct wallet tx struct.
|
||||||
WalletTx MakeWalletTx(interfaces::Chain::Lock& locked_chain, CWallet& wallet, const CWalletTx& wtx)
|
WalletTx MakeWalletTx(interfaces::Chain::Lock& locked_chain, CWallet& wallet, const CWalletTx& wtx)
|
||||||
{
|
{
|
||||||
|
@ -227,7 +202,7 @@ public:
|
||||||
LOCK(m_wallet->cs_wallet);
|
LOCK(m_wallet->cs_wallet);
|
||||||
return m_wallet->ListLockedCoins(outputs);
|
return m_wallet->ListLockedCoins(outputs);
|
||||||
}
|
}
|
||||||
std::unique_ptr<PendingWalletTx> createTransaction(const std::vector<CRecipient>& recipients,
|
CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
|
||||||
const CCoinControl& coin_control,
|
const CCoinControl& coin_control,
|
||||||
bool sign,
|
bool sign,
|
||||||
int& change_pos,
|
int& change_pos,
|
||||||
|
@ -236,12 +211,26 @@ public:
|
||||||
{
|
{
|
||||||
auto locked_chain = m_wallet->chain().lock();
|
auto locked_chain = m_wallet->chain().lock();
|
||||||
LOCK(m_wallet->cs_wallet);
|
LOCK(m_wallet->cs_wallet);
|
||||||
auto pending = MakeUnique<PendingWalletTxImpl>(*m_wallet);
|
CTransactionRef tx;
|
||||||
if (!m_wallet->CreateTransaction(*locked_chain, recipients, pending->m_tx, fee, change_pos,
|
if (!m_wallet->CreateTransaction(*locked_chain, recipients, tx, fee, change_pos,
|
||||||
fail_reason, coin_control, sign)) {
|
fail_reason, coin_control, sign)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return std::move(pending);
|
return tx;
|
||||||
|
}
|
||||||
|
bool commitTransaction(CTransactionRef tx,
|
||||||
|
WalletValueMap value_map,
|
||||||
|
WalletOrderForm order_form,
|
||||||
|
std::string& reject_reason) override
|
||||||
|
{
|
||||||
|
auto locked_chain = m_wallet->chain().lock();
|
||||||
|
LOCK(m_wallet->cs_wallet);
|
||||||
|
CValidationState state;
|
||||||
|
if (!m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form), state)) {
|
||||||
|
reject_reason = state.GetRejectReason();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
|
bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
|
||||||
bool abandonTransaction(const uint256& txid) override
|
bool abandonTransaction(const uint256& txid) override
|
||||||
|
|
|
@ -34,7 +34,6 @@ struct CRecipient;
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
|
|
||||||
class Handler;
|
class Handler;
|
||||||
class PendingWalletTx;
|
|
||||||
struct WalletAddress;
|
struct WalletAddress;
|
||||||
struct WalletBalances;
|
struct WalletBalances;
|
||||||
struct WalletTx;
|
struct WalletTx;
|
||||||
|
@ -134,13 +133,19 @@ public:
|
||||||
virtual void listLockedCoins(std::vector<COutPoint>& outputs) = 0;
|
virtual void listLockedCoins(std::vector<COutPoint>& outputs) = 0;
|
||||||
|
|
||||||
//! Create transaction.
|
//! Create transaction.
|
||||||
virtual std::unique_ptr<PendingWalletTx> createTransaction(const std::vector<CRecipient>& recipients,
|
virtual CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
|
||||||
const CCoinControl& coin_control,
|
const CCoinControl& coin_control,
|
||||||
bool sign,
|
bool sign,
|
||||||
int& change_pos,
|
int& change_pos,
|
||||||
CAmount& fee,
|
CAmount& fee,
|
||||||
std::string& fail_reason) = 0;
|
std::string& fail_reason) = 0;
|
||||||
|
|
||||||
|
//! Commit transaction.
|
||||||
|
virtual bool commitTransaction(CTransactionRef tx,
|
||||||
|
WalletValueMap value_map,
|
||||||
|
WalletOrderForm order_form,
|
||||||
|
std::string& reject_reason) = 0;
|
||||||
|
|
||||||
//! Return whether transaction can be abandoned.
|
//! Return whether transaction can be abandoned.
|
||||||
virtual bool transactionCanBeAbandoned(const uint256& txid) = 0;
|
virtual bool transactionCanBeAbandoned(const uint256& txid) = 0;
|
||||||
|
|
||||||
|
@ -288,21 +293,6 @@ public:
|
||||||
virtual std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) = 0;
|
virtual std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Tracking object returned by CreateTransaction and passed to CommitTransaction.
|
|
||||||
class PendingWalletTx
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~PendingWalletTx() {}
|
|
||||||
|
|
||||||
//! Get transaction data.
|
|
||||||
virtual const CTransaction& get() = 0;
|
|
||||||
|
|
||||||
//! Send pending transaction and commit to wallet.
|
|
||||||
virtual bool commit(WalletValueMap value_map,
|
|
||||||
WalletOrderForm order_form,
|
|
||||||
std::string& reject_reason) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Information about one wallet address.
|
//! Information about one wallet address.
|
||||||
struct WalletAddress
|
struct WalletAddress
|
||||||
{
|
{
|
||||||
|
|
|
@ -392,7 +392,7 @@ void SendCoinsDialog::on_sendButton_clicked()
|
||||||
accept();
|
accept();
|
||||||
CoinControlDialog::coinControl()->UnSelectAll();
|
CoinControlDialog::coinControl()->UnSelectAll();
|
||||||
coinControlUpdateLabels();
|
coinControlUpdateLabels();
|
||||||
Q_EMIT coinsSent(currentTransaction.getWtx()->get().GetHash());
|
Q_EMIT coinsSent(currentTransaction.getWtx()->GetHash());
|
||||||
}
|
}
|
||||||
fNewRecipientAllowed = true;
|
fNewRecipientAllowed = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,11 +261,11 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
|
||||||
|
|
||||||
auto& newTx = transaction.getWtx();
|
auto& newTx = transaction.getWtx();
|
||||||
std::string rejectReason;
|
std::string rejectReason;
|
||||||
if (!newTx->commit({} /* mapValue */, std::move(vOrderForm), rejectReason))
|
if (!wallet().commitTransaction(newTx, {} /* mapValue */, std::move(vOrderForm), rejectReason))
|
||||||
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(rejectReason));
|
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(rejectReason));
|
||||||
|
|
||||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
ssTx << newTx->get();
|
ssTx << *newTx;
|
||||||
transaction_array.append(&(ssTx[0]), ssTx.size());
|
transaction_array.append(&(ssTx[0]), ssTx.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,14 @@ QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
|
||||||
return recipients;
|
return recipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<interfaces::PendingWalletTx>& WalletModelTransaction::getWtx()
|
CTransactionRef& WalletModelTransaction::getWtx()
|
||||||
{
|
{
|
||||||
return wtx;
|
return wtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int WalletModelTransaction::getTransactionSize()
|
unsigned int WalletModelTransaction::getTransactionSize()
|
||||||
{
|
{
|
||||||
return wtx ? GetVirtualTransactionSize(wtx->get()) : 0;
|
return wtx ? GetVirtualTransactionSize(*wtx) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CAmount WalletModelTransaction::getTransactionFee() const
|
CAmount WalletModelTransaction::getTransactionFee() const
|
||||||
|
@ -43,7 +43,7 @@ void WalletModelTransaction::setTransactionFee(const CAmount& newFee)
|
||||||
|
|
||||||
void WalletModelTransaction::reassignAmounts(int nChangePosRet)
|
void WalletModelTransaction::reassignAmounts(int nChangePosRet)
|
||||||
{
|
{
|
||||||
const CTransaction* walletTransaction = &wtx->get();
|
const CTransaction* walletTransaction = wtx.get();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
|
for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,6 @@ class SendCoinsRecipient;
|
||||||
|
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
class Node;
|
class Node;
|
||||||
class PendingWalletTx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Data model for a walletmodel transaction. */
|
/** Data model for a walletmodel transaction. */
|
||||||
|
@ -27,7 +26,7 @@ public:
|
||||||
|
|
||||||
QList<SendCoinsRecipient> getRecipients() const;
|
QList<SendCoinsRecipient> getRecipients() const;
|
||||||
|
|
||||||
std::unique_ptr<interfaces::PendingWalletTx>& getWtx();
|
CTransactionRef& getWtx();
|
||||||
unsigned int getTransactionSize();
|
unsigned int getTransactionSize();
|
||||||
|
|
||||||
void setTransactionFee(const CAmount& newFee);
|
void setTransactionFee(const CAmount& newFee);
|
||||||
|
@ -39,7 +38,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<SendCoinsRecipient> recipients;
|
QList<SendCoinsRecipient> recipients;
|
||||||
std::unique_ptr<interfaces::PendingWalletTx> wtx;
|
CTransactionRef wtx;
|
||||||
CAmount fee;
|
CAmount fee;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue