|
22 | 22 | #include <psbt.h>
|
23 | 23 | #include <util/translation.h>
|
24 | 24 | #include <wallet/coincontrol.h>
|
| 25 | +#include <wallet/types.h> |
25 | 26 | #include <wallet/wallet.h> // for CRecipient
|
26 | 27 |
|
27 | 28 | #include <stdint.h>
|
@@ -153,6 +154,8 @@ bool WalletModel::validateAddress(const QString& address) const
|
153 | 154 |
|
154 | 155 | WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl)
|
155 | 156 | {
|
| 157 | + transaction.getWtx() = nullptr; // reset tx output |
| 158 | + |
156 | 159 | CAmount total = 0;
|
157 | 160 | bool fSubtractFeeFromAmount = false;
|
158 | 161 | QList<SendCoinsRecipient> recipients = transaction.getRecipients();
|
@@ -204,22 +207,21 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
|
204 | 207 | }
|
205 | 208 |
|
206 | 209 | try {
|
207 |
| - CAmount nFeeRequired = 0; |
208 |
| - int nChangePosRet = -1; |
209 |
| - |
210 | 210 | auto& newTx = transaction.getWtx();
|
211 |
| - const auto& res = m_wallet->createTransaction(vecSend, coinControl, /*sign=*/!wallet().privateKeysDisabled(), nChangePosRet, nFeeRequired); |
212 |
| - newTx = res ? *res : nullptr; |
213 |
| - transaction.setTransactionFee(nFeeRequired); |
214 |
| - if (fSubtractFeeFromAmount && newTx) |
215 |
| - transaction.reassignAmounts(nChangePosRet); |
216 |
| - |
217 |
| - if (!newTx) { |
| 211 | + const auto& res = m_wallet->createTransaction(vecSend, coinControl, /*sign=*/!wallet().privateKeysDisabled(), /*change_pos=*/std::nullopt); |
| 212 | + if (!res) { |
218 | 213 | Q_EMIT message(tr("Send Coins"), QString::fromStdString(util::ErrorString(res).translated),
|
219 |
| - CClientUIInterface::MSG_ERROR); |
| 214 | + CClientUIInterface::MSG_ERROR); |
220 | 215 | return TransactionCreationFailed;
|
221 | 216 | }
|
222 | 217 |
|
| 218 | + newTx = res->tx; |
| 219 | + CAmount nFeeRequired = res->fee; |
| 220 | + transaction.setTransactionFee(nFeeRequired); |
| 221 | + if (fSubtractFeeFromAmount && newTx) { |
| 222 | + transaction.reassignAmounts(res->change_pos ? int(*res->change_pos) : -1); |
| 223 | + } |
| 224 | + |
223 | 225 | // Reject absurdly high fee. (This can never happen because the
|
224 | 226 | // wallet never creates transactions with fee greater than
|
225 | 227 | // m_default_max_tx_fee. This merely a belt-and-suspenders check).
|
|
0 commit comments