mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Merge pull request #1154 from andreabonel/master-fix_issue_1151
Elements-qt: Correctly display the amount in the sender's wallet after using Send button
This commit is contained in:
commit
03b646930f
6 changed files with 28 additions and 18 deletions
|
|
@ -36,6 +36,7 @@ struct PartiallySignedTransaction;
|
|||
struct WalletContext;
|
||||
struct bilingual_str;
|
||||
typedef uint8_t isminefilter;
|
||||
struct BlindDetails;
|
||||
|
||||
namespace interfaces {
|
||||
|
||||
|
|
@ -140,13 +141,14 @@ public:
|
|||
bool sign,
|
||||
int& change_pos,
|
||||
CAmount& fee,
|
||||
std::vector<CAmount>& out_amounts,
|
||||
BlindDetails* blind_details,
|
||||
bilingual_str& fail_reason) = 0;
|
||||
|
||||
//! Commit transaction.
|
||||
virtual void commitTransaction(CTransactionRef tx,
|
||||
WalletValueMap value_map,
|
||||
WalletOrderForm order_form) = 0;
|
||||
WalletOrderForm order_form,
|
||||
BlindDetails* blind_details) = 0;
|
||||
|
||||
//! Return whether transaction can be abandoned.
|
||||
virtual bool transactionCanBeAbandoned(const uint256& txid) = 0;
|
||||
|
|
|
|||
|
|
@ -281,11 +281,13 @@ bool SendCoinsDialog::PrepareSendText(QString& question_string, QString& informa
|
|||
|
||||
// prepare transaction for getting txFee earlier
|
||||
m_current_transaction = std::make_unique<WalletModelTransaction>(recipients);
|
||||
if (g_con_elementsmode)
|
||||
m_current_blind_details = std::make_unique<BlindDetails>();
|
||||
WalletModel::SendCoinsReturn prepareStatus;
|
||||
|
||||
updateCoinControlState();
|
||||
|
||||
prepareStatus = model->prepareTransaction(*m_current_transaction, *m_coin_control);
|
||||
prepareStatus = model->prepareTransaction(*m_current_transaction, m_current_blind_details.get(), *m_coin_control);
|
||||
|
||||
// process prepareStatus and on error generate message shown to user
|
||||
processSendCoinsReturn(prepareStatus,
|
||||
|
|
@ -403,6 +405,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
|||
QString question_string, informative_text, detailed_text;
|
||||
if (!PrepareSendText(question_string, informative_text, detailed_text)) return;
|
||||
assert(m_current_transaction);
|
||||
assert(!g_con_elementsmode || m_current_blind_details);
|
||||
|
||||
const QString confirmation = model->wallet().privateKeysDisabled() && !model->wallet().hasExternalSigner() ? tr("Confirm transaction proposal") : tr("Confirm send coins");
|
||||
const QString confirmButtonText = model->wallet().privateKeysDisabled() && !model->wallet().hasExternalSigner() ? tr("Create Unsigned") : tr("Sign and send");
|
||||
|
|
@ -461,7 +464,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
|||
if (complete) {
|
||||
const CTransactionRef tx = MakeTransactionRef(mtx);
|
||||
m_current_transaction->setWtx(tx);
|
||||
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(*m_current_transaction);
|
||||
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(*m_current_transaction, m_current_blind_details.get());
|
||||
// process sendStatus and on error generate message shown to user
|
||||
processSendCoinsReturn(sendStatus);
|
||||
|
||||
|
|
@ -520,7 +523,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
|||
} // msgBox.exec()
|
||||
} else {
|
||||
// now send the prepared transaction
|
||||
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(*m_current_transaction);
|
||||
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(*m_current_transaction, m_current_blind_details.get());
|
||||
// process sendStatus and on error generate message shown to user
|
||||
processSendCoinsReturn(sendStatus);
|
||||
|
||||
|
|
@ -537,11 +540,13 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
|||
}
|
||||
fNewRecipientAllowed = true;
|
||||
m_current_transaction.reset();
|
||||
m_current_blind_details.reset();
|
||||
}
|
||||
|
||||
void SendCoinsDialog::clear()
|
||||
{
|
||||
m_current_transaction.reset();
|
||||
m_current_blind_details.reset();
|
||||
|
||||
// Clear coin control settings
|
||||
m_coin_control->UnSelectAll();
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ private:
|
|||
WalletModel *model;
|
||||
std::unique_ptr<CCoinControl> m_coin_control;
|
||||
std::unique_ptr<WalletModelTransaction> m_current_transaction;
|
||||
std::unique_ptr<BlindDetails> m_current_blind_details;
|
||||
bool fNewRecipientAllowed;
|
||||
bool fFeeMinimized;
|
||||
const PlatformStyle *platformStyle;
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ bool WalletModel::validateAddress(const QString &address)
|
|||
return IsValidDestinationString(address.toStdString());
|
||||
}
|
||||
|
||||
WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl)
|
||||
WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, BlindDetails *blind_details, const CCoinControl& coinControl)
|
||||
{
|
||||
CAmountMap total;
|
||||
bool fSubtractFeeFromAmount = false;
|
||||
|
|
@ -236,10 +236,13 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
|
|||
|
||||
auto& newTx = transaction.getWtx();
|
||||
std::vector<CAmount> out_amounts;
|
||||
newTx = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, out_amounts, error);
|
||||
newTx = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, blind_details, error);
|
||||
transaction.setTransactionFee(nFeeRequired);
|
||||
if (fSubtractFeeFromAmount && newTx) {
|
||||
assert(out_amounts.size() == newTx->vout.size());
|
||||
if(blind_details) {
|
||||
out_amounts = blind_details->o_amounts;
|
||||
assert(out_amounts.size() == newTx->vout.size());
|
||||
}
|
||||
transaction.reassignAmounts(out_amounts, nChangePosRet);
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +269,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
|
|||
return SendCoinsReturn(OK);
|
||||
}
|
||||
|
||||
WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &transaction)
|
||||
WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &transaction, BlindDetails *blind_details)
|
||||
{
|
||||
QByteArray transaction_array; /* store serialized transaction */
|
||||
|
||||
|
|
@ -279,7 +282,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
|
|||
}
|
||||
|
||||
auto& newTx = transaction.getWtx();
|
||||
wallet().commitTransaction(newTx, {} /* mapValue */, std::move(vOrderForm));
|
||||
wallet().commitTransaction(newTx, {} /* mapValue */, std::move(vOrderForm), blind_details);
|
||||
|
||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssTx << *newTx;
|
||||
|
|
|
|||
|
|
@ -100,10 +100,10 @@ public:
|
|||
};
|
||||
|
||||
// prepare transaction for getting txfee before sending coins
|
||||
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl);
|
||||
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, BlindDetails *blind_details, const CCoinControl& coinControl);
|
||||
|
||||
// Send coins to a list of recipients
|
||||
SendCoinsReturn sendCoins(WalletModelTransaction &transaction);
|
||||
SendCoinsReturn sendCoins(WalletModelTransaction &transaction, BlindDetails *blind_details);
|
||||
|
||||
// Wallet encryption
|
||||
bool setWalletEncrypted(const SecureString& passphrase);
|
||||
|
|
|
|||
|
|
@ -248,26 +248,25 @@ public:
|
|||
bool sign,
|
||||
int& change_pos,
|
||||
CAmount& fee,
|
||||
std::vector<CAmount>& out_amounts,
|
||||
BlindDetails* blind_details,
|
||||
bilingual_str& fail_reason) override
|
||||
{
|
||||
LOCK(m_wallet->cs_wallet);
|
||||
CTransactionRef tx;
|
||||
FeeCalculation fee_calc_out;
|
||||
BlindDetails blind_details;
|
||||
if (!m_wallet->CreateTransaction(recipients, tx, fee, change_pos,
|
||||
fail_reason, coin_control, fee_calc_out, sign, gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode) ? &blind_details : nullptr)) {
|
||||
fail_reason, coin_control, fee_calc_out, sign, blind_details)) {
|
||||
return {};
|
||||
}
|
||||
out_amounts = blind_details.o_amounts;
|
||||
return tx;
|
||||
}
|
||||
void commitTransaction(CTransactionRef tx,
|
||||
WalletValueMap value_map,
|
||||
WalletOrderForm order_form) override
|
||||
WalletOrderForm order_form,
|
||||
BlindDetails* blind_details) override
|
||||
{
|
||||
LOCK(m_wallet->cs_wallet);
|
||||
m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
|
||||
m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form), blind_details);
|
||||
}
|
||||
bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
|
||||
bool abandonTransaction(const uint256& txid) override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue