@@ -192,14 +192,12 @@ std::optional<CAmount> TryPreviewFee(interfaces::Wallet& wallet,
192192 const std::vector<wallet::CRecipient>& recipients,
193193 const wallet::CCoinControl& coin_control)
194194{
195- int change_position{-1 };
196- CAmount fee{0 };
197- const auto result = wallet.createTransaction (recipients, coin_control, /* sign=*/ false , change_position, fee);
195+ const auto result = wallet.createTransaction (recipients, coin_control, /* sign=*/ false , /* change_pos=*/ std::nullopt );
198196 if (!result) {
199197 return std::nullopt ;
200198 }
201199
202- return fee;
200+ return result-> fee ;
203201}
204202
205203std::optional<std::vector<wallet::CRecipient>> WithLargestRecipientPayingFee (const std::vector<wallet::CRecipient>& recipients)
@@ -1597,25 +1595,24 @@ bool WalletQmlModel::prepareTransactionInternal(std::optional<SecureString> pass
15971595 return false ;
15981596 }
15991597
1600- int nChangePosRet = -1 ;
1601- CAmount nFeeRequired = 0 ;
16021598 const bool sign = !m_wallet->privateKeysDisabled ();
1603- const auto & result = m_wallet->createTransaction (*vec_send, coin_control, sign, nChangePosRet, nFeeRequired );
1599+ const auto & result = m_wallet->createTransaction (*vec_send, coin_control, sign, /* change_pos= */ std:: nullopt );
16041600 if (result) {
16051601 if (m_current_transaction) {
16061602 delete m_current_transaction;
16071603 }
1608- const CTransactionRef& newTx = * result;
1604+ const CTransactionRef& newTx = result-> tx ;
16091605 m_current_transaction = new WalletQmlModelTransaction (m_send_recipients, this );
16101606 m_current_psbt.reset ();
16111607 m_current_transaction_source = CurrentTransactionSource::SendDraft;
16121608 m_current_transaction_can_send = true ;
16131609 m_current_transaction_can_broadcast = false ;
16141610 m_current_transaction_review_message.clear ();
16151611 m_current_transaction->setWtx (newTx);
1616- m_current_transaction->setTransactionFee (nFeeRequired );
1612+ m_current_transaction->setTransactionFee (result-> fee );
16171613 if (subtract_fee_from_amount) {
1618- m_current_transaction->reassignAmounts (nChangePosRet);
1614+ m_current_transaction->reassignAmounts (
1615+ result->change_pos ? static_cast <int >(*result->change_pos ) : -1 );
16191616 }
16201617 m_current_transaction->setDisplayUnit (m_display_unit);
16211618 relock_guard.relock ();
@@ -1642,7 +1639,8 @@ void WalletQmlModel::approveExternalSignerTransaction()
16421639 }
16431640
16441641 try {
1645- PartiallySignedTransaction psbtx;
1642+ CMutableTransaction empty_tx;
1643+ PartiallySignedTransaction psbtx{empty_tx};
16461644 if (m_current_psbt) {
16471645 psbtx = *m_current_psbt;
16481646 } else {
@@ -1652,7 +1650,7 @@ void WalletQmlModel::approveExternalSignerTransaction()
16521650 }
16531651
16541652 bool complete{false };
1655- const auto draft_err = m_wallet->fillPSBT (std:: nullopt , /* sign= */ false , /* bip32derivs= */ true ,
1653+ const auto draft_err = m_wallet->fillPSBT ({. sign = false , . bip32_derivs = true } ,
16561654 /* n_signed=*/ nullptr , psbtx, complete);
16571655 if (draft_err) {
16581656 Q_EMIT externalSignerApprovalFailed (
@@ -1662,7 +1660,7 @@ void WalletQmlModel::approveExternalSignerTransaction()
16621660 }
16631661
16641662 if (!complete) {
1665- const auto sign_err = m_wallet->fillPSBT (std:: nullopt , /* sign= */ true , /* bip32derivs= */ true ,
1663+ const auto sign_err = m_wallet->fillPSBT ({. sign = true , . bip32_derivs = true } ,
16661664 /* n_signed=*/ nullptr , psbtx, complete);
16671665 if (sign_err) {
16681666 const bool signer_not_found = *sign_err == common::PSBTError::EXTERNAL_SIGNER_NOT_FOUND ;
@@ -1813,7 +1811,7 @@ bool WalletQmlModel::sendTransactionInternal(std::optional<SecureString> passphr
18131811
18141812 size_t signed_inputs{0 };
18151813 const std::optional<common::PSBTError> fill_error{
1816- m_wallet->fillPSBT (std:: nullopt , /* sign= */ true , /* bip32derivs= */ true , &signed_inputs, psbt, complete)};
1814+ m_wallet->fillPSBT ({. sign = true , . bip32_derivs = true } , &signed_inputs, psbt, complete)};
18171815 if (fill_error) {
18181816 setTransactionStatus (PsbtQmlModel::PsbtErrorText (*fill_error));
18191817 return false ;
@@ -1876,15 +1874,17 @@ WalletQmlModel::PsbtImportResult WalletQmlModel::importPsbtFromFile(const QStrin
18761874 return PsbtImportResult::PsbtUnsupported;
18771875 }
18781876
1879- PartiallySignedTransaction psbt;
1877+ CMutableTransaction empty_tx;
1878+ PartiallySignedTransaction psbt{empty_tx};
18801879 const QString load_err{PsbtQmlModel::LoadPsbtFromFile (path, psbt)};
18811880 if (!load_err.isEmpty ()) {
18821881 m_imported_psbt_model->setError (load_err);
18831882 return PsbtImportResult::PsbtUnsupported;
18841883 }
18851884
1886- if (m_wallet && psbt.tx ) {
1887- const Txid psbt_txid{psbt.tx ->GetHash ()};
1885+ const auto unsigned_tx{psbt.GetUnsignedTx ()};
1886+ if (m_wallet && unsigned_tx) {
1887+ const Txid psbt_txid{unsigned_tx->GetHash ()};
18881888 interfaces::WalletTxStatus tx_status;
18891889 int num_blocks{0 };
18901890 int64_t block_time{0 };
@@ -1915,7 +1915,8 @@ QString WalletQmlModel::saveCurrentTransactionAsPsbt(const QString& path)
19151915 return tr (" No transaction is prepared." );
19161916 }
19171917
1918- PartiallySignedTransaction psbtx;
1918+ CMutableTransaction empty_tx;
1919+ PartiallySignedTransaction psbtx{empty_tx};
19191920 try {
19201921 if (m_current_psbt) {
19211922 psbtx = *m_current_psbt;
@@ -1932,7 +1933,7 @@ QString WalletQmlModel::saveCurrentTransactionAsPsbt(const QString& path)
19321933 }
19331934
19341935 bool complete{false };
1935- const auto err{m_wallet->fillPSBT (std:: nullopt , /* sign= */ false , /* bip32derivs= */ true ,
1936+ const auto err{m_wallet->fillPSBT ({. sign = false , . bip32_derivs = true } ,
19361937 /* n_signed=*/ nullptr , psbtx, complete)};
19371938 if (err) {
19381939 return PsbtQmlModel::PsbtErrorText (*err);
@@ -1950,33 +1951,39 @@ bool WalletQmlModel::tryImportPsbtToReview(const PartiallySignedTransaction& psb
19501951 reason = tr (" No wallet is loaded." );
19511952 return false ;
19521953 }
1953- if (!psbt.tx ) {
1954+ const auto unsigned_tx{psbt.GetUnsignedTx ()};
1955+ if (!unsigned_tx) {
19541956 reason = tr (" The PSBT does not contain an unsigned transaction." );
19551957 return false ;
19561958 }
1957- if (psbt. tx ->vin .empty () || psbt. tx ->vout .empty ()) {
1959+ if (unsigned_tx ->vin .empty () || unsigned_tx ->vout .empty ()) {
19581960 reason = tr (" The PSBT has no inputs or outputs." );
19591961 return false ;
19601962 }
1961- if (psbt.inputs .size () != psbt. tx ->vin .size () || psbt.outputs .size () != psbt. tx ->vout .size ()) {
1963+ if (psbt.inputs .size () != unsigned_tx ->vin .size () || psbt.outputs .size () != unsigned_tx ->vout .size ()) {
19621964 reason = tr (" The PSBT is malformed." );
19631965 return false ;
19641966 }
19651967
1966- const bool spends_only_wallet_inputs{std::all_of (psbt. tx ->vin .begin (), psbt. tx ->vin .end (), [this ](const CTxIn& input) {
1968+ const bool spends_only_wallet_inputs{std::all_of (unsigned_tx ->vin .begin (), unsigned_tx ->vin .end (), [this ](const CTxIn& input) {
19671969 return m_wallet->txinIsMine (input);
19681970 })};
19691971
19701972 PartiallySignedTransaction analysis_psbt{psbt};
19711973 bool complete{FinalizePSBT (analysis_psbt)};
19721974 size_t could_sign{0 };
19731975 const std::optional<common::PSBTError> fill_error{
1974- m_wallet->fillPSBT (std:: nullopt , /* sign= */ false , /* bip32derivs= */ false , &could_sign, analysis_psbt, complete)};
1976+ m_wallet->fillPSBT ({. sign = false , . bip32_derivs = false } , &could_sign, analysis_psbt, complete)};
19751977 if (fill_error) {
19761978 reason = PsbtQmlModel::PsbtErrorText (*fill_error);
19771979 return false ;
19781980 }
19791981 complete = FinalizePSBT (analysis_psbt);
1982+ const auto analysis_tx{analysis_psbt.GetUnsignedTx ()};
1983+ if (!analysis_tx) {
1984+ reason = tr (" The PSBT does not contain an unsigned transaction." );
1985+ return false ;
1986+ }
19801987 std::optional<std::pair<int , int >> multisig_sig_info;
19811988 if (!complete) {
19821989 for (size_t i{0 }; i < analysis_psbt.inputs .size (); ++i) {
@@ -2009,7 +2016,7 @@ bool WalletQmlModel::tryImportPsbtToReview(const PartiallySignedTransaction& psb
20092016 };
20102017 std::vector<DraftRecipient> draft_recipients;
20112018 CAmount recipient_total{0 };
2012- for (const CTxOut& output : analysis_psbt. tx ->vout ) {
2019+ for (const CTxOut& output : analysis_tx ->vout ) {
20132020 CTxDestination destination;
20142021 if (!ExtractDestination (output.scriptPubKey , destination)) {
20152022 if (output.nValue == 0 && output.scriptPubKey .IsUnspendable ()) {
@@ -2056,7 +2063,7 @@ bool WalletQmlModel::tryImportPsbtToReview(const PartiallySignedTransaction& psb
20562063 delete m_current_transaction;
20572064 }
20582065 m_current_transaction = new WalletQmlModelTransaction (m_send_recipients, this );
2059- m_current_transaction->setWtx (MakeTransactionRef (*analysis_psbt. tx ));
2066+ m_current_transaction->setWtx (MakeTransactionRef (*analysis_tx ));
20602067 if (analysis.fee ) {
20612068 m_current_transaction->setTransactionFee (*analysis.fee );
20622069 }
0 commit comments