Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,16 @@ bool SendCoinsDialog::PrepareSendText(QString& question_string, QString& informa
}

// prepare transaction for getting txFee earlier
// Create unsigned transaction to support creating unsigned PSBTs.
// Signing is deferred until the user clicks "Send".
m_current_transaction = std::make_unique<WalletModelTransaction>(recipients);
WalletModel::SendCoinsReturn prepareStatus;

updateCoinControlState();

CCoinControl coin_control = *m_coin_control;
coin_control.m_allow_other_inputs = !coin_control.HasSelected(); // future, could introduce a checkbox to customize this value.
prepareStatus = model->prepareTransaction(*m_current_transaction, coin_control);
prepareStatus = model->prepareTransaction(*m_current_transaction, coin_control, /*sign=*/false);

// process prepareStatus and on error generate message shown to user
processSendCoinsReturn(prepareStatus,
Expand Down Expand Up @@ -540,6 +542,24 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
presentPSBT(psbtx);
}
}
} else {
// Sign the transaction now that the user has confirmed they want to send.
CMutableTransaction mtx = CMutableTransaction{*(m_current_transaction->getWtx())};
PartiallySignedTransaction psbtx(mtx);
bool complete = false;
// Fill and sign the PSBT
const auto err{model->wallet().fillPSBT(std::nullopt, /*sign=*/true, /*bip32derivs=*/false, /*n_signed=*/nullptr, psbtx, complete)};
if (err || !complete) {
Q_EMIT message(tr("Send Coins"), tr("Failed to sign transaction."),
CClientUIInterface::MSG_ERROR);
send_failure = true;
broadcast = false;
} else {
// Extract the signed transaction
CHECK_NONFATAL(FinalizeAndExtractPSBT(psbtx, mtx));
const CTransactionRef tx = MakeTransactionRef(mtx);
m_current_transaction->setWtx(tx);
}
}

// Broadcast the transaction, unless an external signer was used and it
Expand Down
6 changes: 4 additions & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool WalletModel::validateAddress(const QString& address) const
return IsValidDestinationString(address.toStdString());
}

WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl)
WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl, bool sign)
{
CAmount total = 0;
bool fSubtractFeeFromAmount = false;
Expand Down Expand Up @@ -203,7 +203,9 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
int nChangePosRet = -1;

auto& newTx = transaction.getWtx();
const auto& res = m_wallet->createTransaction(vecSend, coinControl, /*sign=*/!wallet().privateKeysDisabled(), nChangePosRet, nFeeRequired);
// Only sign if explicitly requested via the sign parameter.
const bool should_sign = sign && !wallet().privateKeysDisabled();
const auto& res = m_wallet->createTransaction(vecSend, coinControl, should_sign, nChangePosRet, nFeeRequired);
newTx = res ? *res : nullptr;
transaction.setTransactionFee(nFeeRequired);
if (fSubtractFeeFromAmount && newTx)
Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class WalletModel : public QObject
};

// prepare transaction for getting txfee before sending coins
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl& coinControl);
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl& coinControl, bool sign = false);

// Send coins to a list of recipients
void sendCoins(WalletModelTransaction& transaction);
Expand Down
Loading