mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 11:32:46 +01:00
merge bitcoin#16415: Get rid of PendingWalletTx class
Co-authored-by: PastaPastaPasta <PastaPastaPasta@users.noreply.github.com>
This commit is contained in:
parent
e51c4c41c0
commit
1e11a7ad03
@ -42,32 +42,6 @@
|
||||
namespace interfaces {
|
||||
namespace {
|
||||
|
||||
class PendingWalletTxImpl : public PendingWalletTx
|
||||
{
|
||||
public:
|
||||
explicit PendingWalletTxImpl(CWallet& wallet) : m_wallet(wallet), m_key(&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();
|
||||
LOCK2(mempool.cs, m_wallet.cs_wallet);
|
||||
CValidationState state;
|
||||
if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), m_key, state)) {
|
||||
reject_reason = state.GetRejectReason();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CTransactionRef m_tx;
|
||||
CWallet& m_wallet;
|
||||
CReserveKey m_key;
|
||||
};
|
||||
|
||||
//! Construct wallet tx struct.
|
||||
WalletTx MakeWalletTx(interfaces::Chain::Lock& locked_chain, CWallet& wallet, const CWalletTx& wtx)
|
||||
{
|
||||
@ -308,7 +282,7 @@ public:
|
||||
LOCK2(cs_main, m_wallet->cs_wallet);
|
||||
return m_wallet->ListProTxCoins(outputs);
|
||||
}
|
||||
std::unique_ptr<PendingWalletTx> createTransaction(const std::vector<CRecipient>& recipients,
|
||||
CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
|
||||
const CCoinControl& coin_control,
|
||||
bool sign,
|
||||
int& change_pos,
|
||||
@ -317,12 +291,28 @@ public:
|
||||
{
|
||||
auto locked_chain = m_wallet->chain().lock();
|
||||
LOCK2(mempool.cs, m_wallet->cs_wallet);
|
||||
auto pending = MakeUnique<PendingWalletTxImpl>(*m_wallet);
|
||||
if (!m_wallet->CreateTransaction(*locked_chain, recipients, pending->m_tx, pending->m_key, fee, change_pos,
|
||||
CReserveKey m_key(m_wallet.get());
|
||||
CTransactionRef tx;
|
||||
if (!m_wallet->CreateTransaction(*locked_chain, recipients, tx, m_key, fee, change_pos,
|
||||
fail_reason, coin_control, sign)) {
|
||||
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();
|
||||
LOCK2(mempool.cs, m_wallet->cs_wallet);
|
||||
CReserveKey m_key(m_wallet.get());
|
||||
CValidationState state;
|
||||
if (!m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form), m_key, state)) {
|
||||
reject_reason = state.GetRejectReason();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
|
||||
bool abandonTransaction(const uint256& txid) override
|
||||
|
@ -32,7 +32,6 @@ struct CRecipient;
|
||||
namespace interfaces {
|
||||
|
||||
class Handler;
|
||||
class PendingWalletTx;
|
||||
struct WalletAddress;
|
||||
struct WalletBalances;
|
||||
struct WalletTx;
|
||||
@ -159,13 +158,19 @@ public:
|
||||
virtual void listProTxCoins(std::vector<COutPoint>& vOutpts) = 0;
|
||||
|
||||
//! 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,
|
||||
bool sign,
|
||||
int& change_pos,
|
||||
CAmount& fee,
|
||||
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.
|
||||
virtual bool transactionCanBeAbandoned(const uint256& txid) = 0;
|
||||
|
||||
@ -313,21 +318,6 @@ public:
|
||||
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.
|
||||
struct WalletAddress
|
||||
{
|
||||
|
@ -411,7 +411,7 @@ void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients)
|
||||
if (m_coin_control->IsUsingCoinJoin()) {
|
||||
// append number of inputs
|
||||
questionString.append("<hr />");
|
||||
int nInputs = currentTransaction.getWtx()->get().vin.size();
|
||||
int nInputs = currentTransaction.getWtx()->vin.size();
|
||||
questionString.append(tr("This transaction will consume %n input(s)", "", nInputs));
|
||||
|
||||
// warn about potential privacy issues when spending too many inputs at once
|
||||
@ -464,7 +464,7 @@ void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients)
|
||||
accept();
|
||||
m_coin_control->UnSelectAll();
|
||||
coinControlUpdateLabels();
|
||||
Q_EMIT coinsSent(currentTransaction.getWtx()->get().GetHash());
|
||||
Q_EMIT coinsSent(currentTransaction.getWtx()->GetHash());
|
||||
}
|
||||
fNewRecipientAllowed = true;
|
||||
}
|
||||
|
@ -312,11 +312,11 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
|
||||
|
||||
auto& newTx = transaction.getWtx();
|
||||
std::string rejectReason;
|
||||
if (!newTx->commit(std::move(mapValue), std::move(vOrderForm), rejectReason))
|
||||
if (!wallet().commitTransaction(newTx, std::move(mapValue), std::move(vOrderForm), rejectReason))
|
||||
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(rejectReason));
|
||||
|
||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssTx << newTx->get();
|
||||
ssTx << *newTx;
|
||||
transaction_array.append(ssTx.data(), ssTx.size());
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,14 @@ QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
|
||||
return recipients;
|
||||
}
|
||||
|
||||
std::unique_ptr<interfaces::PendingWalletTx>& WalletModelTransaction::getWtx()
|
||||
CTransactionRef& WalletModelTransaction::getWtx()
|
||||
{
|
||||
return wtx;
|
||||
}
|
||||
|
||||
unsigned int WalletModelTransaction::getTransactionSize()
|
||||
{
|
||||
return wtx ? ::GetSerializeSize(wtx->get(), SER_NETWORK, PROTOCOL_VERSION) : 0;
|
||||
return wtx != nullptr ? ::GetSerializeSize(*wtx, SER_NETWORK, PROTOCOL_VERSION) : 0;
|
||||
}
|
||||
|
||||
CAmount WalletModelTransaction::getTransactionFee() const
|
||||
@ -60,7 +60,7 @@ void WalletModelTransaction::reassignAmounts()
|
||||
if (out.amount() <= 0) continue;
|
||||
const unsigned char* scriptStr = (const unsigned char*)out.script().data();
|
||||
CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
|
||||
for (const auto& txout : wtx->get().vout) {
|
||||
for (const auto& txout : wtx.get()->vout) {
|
||||
if (txout.scriptPubKey == scriptPubKey) {
|
||||
subtotal += txout.nValue;
|
||||
break;
|
||||
@ -72,7 +72,7 @@ void WalletModelTransaction::reassignAmounts()
|
||||
else // normal recipient (no payment request)
|
||||
#endif
|
||||
{
|
||||
for (const auto& txout : wtx->get().vout) {
|
||||
for (const auto& txout : wtx.get()->vout) {
|
||||
CScript scriptPubKey = GetScriptForDestination(DecodeDestination(rcp.address.toStdString()));
|
||||
if (txout.scriptPubKey == scriptPubKey) {
|
||||
rcp.amount = txout.nValue;
|
||||
|
@ -16,7 +16,6 @@ class SendCoinsRecipient;
|
||||
|
||||
namespace interfaces {
|
||||
class Node;
|
||||
class PendingWalletTx;
|
||||
}
|
||||
|
||||
/** Data model for a walletmodel transaction. */
|
||||
@ -27,7 +26,7 @@ public:
|
||||
|
||||
QList<SendCoinsRecipient> getRecipients() const;
|
||||
|
||||
std::unique_ptr<interfaces::PendingWalletTx>& getWtx();
|
||||
CTransactionRef& getWtx();
|
||||
unsigned int getTransactionSize();
|
||||
|
||||
void setTransactionFee(const CAmount& newFee);
|
||||
@ -39,7 +38,7 @@ public:
|
||||
|
||||
private:
|
||||
QList<SendCoinsRecipient> recipients;
|
||||
std::unique_ptr<interfaces::PendingWalletTx> wtx;
|
||||
CTransactionRef wtx;
|
||||
CAmount fee;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user