From da30da3d4b1b97712e2a72b1c052e7bb14b2f7d4 Mon Sep 17 00:00:00 2001 From: Peter Shugalev Date: Fri, 1 Mar 2024 12:56:55 +0100 Subject: [PATCH] Changed signature of CreateTransaction() function --- src/qt/walletmodel.cpp | 2 +- src/rpc/rpcevo.cpp | 2 +- src/wallet/rpcwallet.cpp | 4 +- src/wallet/test/createtransaction_tests.cpp | 89 +++++++++++---------- src/wallet/wallet.cpp | 11 +-- src/wallet/wallet.h | 4 +- 6 files changed, 55 insertions(+), 57 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index b514edcdc6..e6908f973d 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -335,7 +335,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact CWalletTx *newTx = transaction.getTransaction(); CReserveKey *keyChange = transaction.getPossibleKeyChange(); - bool fCreated = wallet->CreateTransaction(vecSend, *newTx, keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl); + bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl); transaction.setTransactionFee(nFeeRequired); if (fSubtractFeeFromAmount && fCreated) transaction.reassignAmounts(nChangePosRet); diff --git a/src/rpc/rpcevo.cpp b/src/rpc/rpcevo.cpp index 716aaf163f..6037b4835f 100644 --- a/src/rpc/rpcevo.cpp +++ b/src/rpc/rpcevo.cpp @@ -213,7 +213,7 @@ static void FundSpecialTx(CWallet* pwallet, CMutableTransaction& tx, const Speci int nChangePos = -1; std::string strFailReason; - if (!pwallet->CreateTransaction(vecSend, wtx, &reservekey, nFee, nChangePos, strFailReason, &coinControl, false, tx.vExtraPayload.size())) { + if (!pwallet->CreateTransaction(vecSend, wtx, reservekey, nFee, nChangePos, strFailReason, &coinControl, false, tx.vExtraPayload.size())) { throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 284b7d8dcf..3357bbac11 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -509,7 +509,7 @@ static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CA int nChangePosRet = -1; CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; vecSend.push_back(recipient); - if (!pwallet->CreateTransaction(vecSend, wtxNew, &reservekey, nFeeRequired, nChangePosRet, strError)) { + if (!pwallet->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError)) { if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) strError = strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired)); throw JSONRPCError(RPC_WALLET_ERROR, strError); @@ -1266,7 +1266,7 @@ UniValue sendmany(const JSONRPCRequest& request) CAmount nFeeRequired = 0; int nChangePosRet = -1; std::string strFailReason; - bool fCreated = pwallet->CreateTransaction(vecSend, wtx, &keyChange, nFeeRequired, nChangePosRet, strFailReason); + bool fCreated = pwallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason); if (!fCreated) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); CValidationState state; diff --git a/src/wallet/test/createtransaction_tests.cpp b/src/wallet/test/createtransaction_tests.cpp index b527362ff3..30bdf35ced 100644 --- a/src/wallet/test/createtransaction_tests.cpp +++ b/src/wallet/test/createtransaction_tests.cpp @@ -151,7 +151,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -177,7 +177,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -206,7 +206,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -229,7 +229,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); BOOST_ASSERT(nChangePosInOut == -1); @@ -257,7 +257,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -283,7 +283,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -298,7 +298,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -329,7 +329,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -344,7 +344,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -371,7 +371,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); @@ -403,7 +403,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); @@ -436,7 +436,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -451,7 +451,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); @@ -472,7 +472,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, false, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -494,7 +494,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -520,7 +520,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -546,7 +546,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -572,7 +572,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); BOOST_ASSERT(nChangePosInOut == -1); @@ -587,7 +587,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); BOOST_ASSERT(nChangePosInOut == -1); @@ -612,7 +612,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); BOOST_ASSERT(strFailReason == "Insufficient funds"); @@ -628,7 +628,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.fAllowWatchOnly = true; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, false, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -650,7 +650,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.fAllowWatchOnly = true; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Signing transaction failed"); @@ -671,7 +671,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, nullptr, true, 0, true, vTxouts); @@ -688,7 +688,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nCoinType = CoinType::ONLY_1000; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); @@ -714,7 +714,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) fMasternodeMode = false; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("fMasternode must be enabled to use CoinType::ONLY_NONDENOMINATED_NOT1000IFMN"); @@ -735,7 +735,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) fMasternodeMode = true; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); @@ -759,7 +759,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) fMasternodeMode = true; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); @@ -786,7 +786,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nCoinType = CoinType::WITH_1000; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); @@ -811,7 +811,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nCoinType = CoinType::WITH_1000; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -828,7 +828,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.fAllowOtherInputs = true; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Some coin control inputs could not be selected."); @@ -852,7 +852,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nMaxInputs = 2; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -869,7 +869,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nMaxInputs = 3; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); @@ -903,7 +903,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nMaxInputs = 3; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); @@ -936,7 +936,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nMaxSize = n3TxSize - 1; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); @@ -964,7 +964,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nMaxSize = n2TxSize - 1; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -986,7 +986,8 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.destChange = GetRandomDest(); - pwalletMain->CreateTransaction(vRecipients, wtx, nullptr, nFeeRet, nChangePosInOut, strFailReason, + CReserveKey reservekey(nullptr); + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -1015,7 +1016,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nMinimumTotalFee = 1 << 13; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -1037,7 +1038,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nMinimumTotalFee = 1 << 20; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -1053,7 +1054,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nMinimumTotalFee = 100; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -1084,7 +1085,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nConfirmTarget = 5; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_FAILURE("Insufficient funds"); @@ -1102,7 +1103,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.nConfirmTarget = 5; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -1133,7 +1134,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.Select(vTxouts.at(1).GetOutpoint()); CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -1158,7 +1159,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) coinControl.Select(vTxouts.at(1).GetOutpoint()); CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); ASSERT_SUCCESS(); @@ -1189,7 +1190,7 @@ BOOST_FIXTURE_TEST_SUITE(createtransaction_tests, WalletTestingSetup) std::string strFailReason; CReserveKey reservekey(pwalletMain); - pwalletMain->CreateTransaction(vRecipients, wtx, &reservekey, nFeeRet, nChangePosInOut, + pwalletMain->CreateTransaction(vRecipients, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, true, 0, true, vTxouts); if (nOurs >= n) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a71201fa15..3f142aaf8a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4487,7 +4487,7 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool ov CReserveKey reservekey(this); CWalletTx wtx; - if (!CreateTransaction(vecSend, wtx, &reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, nExtraPayloadSize)) + if (!CreateTransaction(vecSend, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, nExtraPayloadSize)) return false; if (nChangePosInOut != -1) @@ -4706,7 +4706,7 @@ void CWallet::CheckTransparentTransactionSanity(CMutableTransaction& tx, // true, the wallet must be unlocked. nExtraPayloadSize should be set to the number of extra bytes in the transaction // outside inputs/outputs (ie. LLMQ-related things). If fUseInstantSend is true, we will consider both locked and // confirmed UTXOs to be eligible for input; if it is not, only confirmed UTXOs will be used as inputs. -bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey* reservekey, +bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, const CCoinControl* coinControl, bool sign, int nExtraPayloadSize, bool fUseInstantSend) { @@ -4717,16 +4717,13 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT nExtraPayloadSize, fUseInstantSend, vTransparentTxouts); } -bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey* reservekey, +bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, const CCoinControl* coinControl, bool sign, int nExtraPayloadSize, bool fUseInstantSend, const std::vector& vTransparentTxouts) { LOCK(mempool.cs); AssertLockHeld(cs_main); - if (!coinControl || coinControl->destChange.which() == 0) - assert(reservekey); - nFeeRet = -1; strFailReason = ""; @@ -4810,7 +4807,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT scriptChange = GetScriptForDestination(coinControl->destChange); } else { CPubKey changeKey; - if (!reservekey->GetReservedKey(changeKey)) { + if (!reservekey.GetReservedKey(changeKey)) { strFailReason = _("Keypool ran out, please call keypoolrefill first"); nChangePosInOut = -1; nFeeRet = -1; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 7a9bcc9526..3b63048262 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1094,12 +1094,12 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface void CheckTransparentTransactionSanity(CMutableTransaction& tx, const std::vector& vInputTxs, const CCoinControl* coinControl, CAmount nFee, bool fSign); - bool CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey* reservekey, + bool CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, const CCoinControl* coinControl, bool sign, int nExtraPayloadSize, bool fUseInstantSend, const std::vector& vTransparentTxouts); - bool CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey* reservekey, + bool CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, const CCoinControl* coinControl = NULL, bool sign = true, int nExtraPayloadSize = 0, bool fUseInstantSend = false);