From 5d324d33a73d62756bbb2fedadc9bea85383e4a8 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Mon, 16 Dec 2024 10:30:12 +0400 Subject: [PATCH] Don't split when minting in firod, add option in QT not to split --- src/qt/forms/optionsdialog.ui | 7 +++++++ src/qt/optionsdialog.cpp | 1 + src/qt/optionsmodel.cpp | 10 ++++++++++ src/qt/optionsmodel.h | 3 +++ src/qt/walletmodel.cpp | 2 +- src/spark/sparkwallet.cpp | 16 ++++++++++++---- src/spark/sparkwallet.h | 1 + src/test/evospork_tests.cpp | 2 +- src/test/fixtures.cpp | 2 +- src/wallet/rpcwallet.cpp | 4 ++-- src/wallet/test/spark_tests.cpp | 16 ++++++++-------- src/wallet/wallet.cpp | 6 ++++-- src/wallet/wallet.h | 2 ++ 13 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index a7affffa67..b567badcce 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -189,6 +189,13 @@ + + + + Enable &splitting when minting + + + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 6017558d4f..c7fb7d3df6 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -188,6 +188,7 @@ void OptionsDialog::setMapper() /* Lelantus */ mapper->addMapping(ui->autoAnonymize, OptionsModel::AutoAnonymize); + mapper->addMapping(ui->fSplit, OptionsModel::Split); if (!lelantus::IsLelantusAllowed()) { ui->lelantusPage->setVisible(false); } diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 74d4ea6f03..8569b0cb81 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -85,6 +85,10 @@ void OptionsModel::Init(bool resetSettings) settings.setValue("fAutoAnonymize", false); fAutoAnonymize = settings.value("fAutoAnonymize", false).toBool(); + if (!settings.contains("fSplit")) + settings.setValue("fSplit", true); + fSplit = settings.value("fSplit", true).toBool(); + if (!settings.contains("fLelantusPage")) settings.setValue("fLelantusPage", false); fLelantusPage = settings.value("fLelantusPage", false).toBool(); @@ -279,6 +283,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const return fCoinControlFeatures; case AutoAnonymize: return fAutoAnonymize; + case Split: + return fSplit; case LelantusPage: return fLelantusPage; case DatabaseCache: @@ -429,6 +435,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in settings.setValue("fAutoAnonymize", fAutoAnonymize); Q_EMIT autoAnonymizeChanged(fAutoAnonymize); break; + case Split: + fSplit = value.toBool(); + settings.setValue("fSplit", fSplit); + break; case LelantusPage: fLelantusPage = value.toBool(); settings.setValue("fLelantusPage", fLelantusPage); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 1ff155b86d..7d22dd2494 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -49,6 +49,7 @@ class OptionsModel : public QAbstractListModel Listen, // bool TorSetup, // bool AutoAnonymize, // bool + Split, // bool LelantusPage, // bool enableRapAddresses, // bool OptionIDRowCount, @@ -73,6 +74,7 @@ class OptionsModel : public QAbstractListModel bool getRapAddresses() { return fenableRapAddresses; } const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; } bool getAutoAnonymize() { return fAutoAnonymize; } + bool getfSplit() { return fSplit; } bool getLelantusPage() {return fLelantusPage; } /* Restart flag helper */ @@ -89,6 +91,7 @@ class OptionsModel : public QAbstractListModel QString strThirdPartyTxUrls; bool fCoinControlFeatures; bool fAutoAnonymize; + bool fSplit; bool fLelantusPage; bool fenableRapAddresses; diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index c625cf4b77..470675f6ef 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -1407,7 +1407,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareMintSparkTransaction(std::vecto int nChangePosRet = -1; std::string strFailReason; - bool fCreated = wallet->CreateSparkMintTransactions(outputs, wtxAndFees, nFeeRequired, reservekeys, nChangePosRet, fSubtractFeeFromAmount, strFailReason, coinControl, false); + bool fCreated = wallet->CreateSparkMintTransactions(outputs, wtxAndFees, nFeeRequired, reservekeys, nChangePosRet, fSubtractFeeFromAmount, strFailReason, optionsModel->getfSplit(), coinControl, false); transactions.clear(); transactions.reserve(wtxAndFees.size()); for (auto &wtxAndFee : wtxAndFees) { diff --git a/src/spark/sparkwallet.cpp b/src/spark/sparkwallet.cpp index 9e5e0a49e8..5714303c0f 100644 --- a/src/spark/sparkwallet.cpp +++ b/src/spark/sparkwallet.cpp @@ -762,6 +762,7 @@ bool CSparkWallet::CreateSparkMintTransactions( int& nChangePosInOut, bool subtractFeeFromAmount, std::string& strFailReason, + bool fSplit, const CCoinControl *coinControl, bool autoMintAll) { @@ -790,10 +791,17 @@ bool CSparkWallet::CreateSparkMintTransactions( std::list cacheWtxs; // vector pairs for each transparent address std::vector>> valueAndUTXO; - pwalletMain->AvailableCoinsForLMint(valueAndUTXO, coinControl); - - Shuffle(valueAndUTXO.begin(), valueAndUTXO.end(), FastRandomContext()); - + if (fSplit) { + pwalletMain->AvailableCoinsForLMint(valueAndUTXO, coinControl); + Shuffle(valueAndUTXO.begin(), valueAndUTXO.end(), FastRandomContext()); + } else { + std::vector vAvailableCoins; + pwalletMain->AvailableCoins(vAvailableCoins, true, coinControl); + CAmount balance = 0; + for (auto& coin : vAvailableCoins) + balance += coin.tx->tx->vout[coin.i].nValue; + valueAndUTXO.emplace_back(std::make_pair(balance, vAvailableCoins)); + } while (!valueAndUTXO.empty()) { // initialize diff --git a/src/spark/sparkwallet.h b/src/spark/sparkwallet.h index 8f707a5f94..a300f904a3 100644 --- a/src/spark/sparkwallet.h +++ b/src/spark/sparkwallet.h @@ -122,6 +122,7 @@ class CSparkWallet { int& nChangePosInOut, bool subtractFeeFromAmount, std::string& strFailReason, + bool fSplit, const CCoinControl *coinControl, bool autoMintAll = false); diff --git a/src/test/evospork_tests.cpp b/src/test/evospork_tests.cpp index fb01ac97bc..e2c71c0053 100644 --- a/src/test/evospork_tests.cpp +++ b/src/test/evospork_tests.cpp @@ -604,7 +604,7 @@ BOOST_AUTO_TEST_CASE(limit) for (int i=0; i<10; i++) { std::vector> wtxAndFee; std::vector mints{{address, 50*COIN, ""}}; - std::string error = pwalletMain->MintAndStoreSpark(mints, wtxAndFee, false); + std::string error = pwalletMain->MintAndStoreSpark(mints, wtxAndFee, false, true); BOOST_ASSERT(error.empty()); for (auto &w: wtxAndFee) sparkMints.emplace_back(*w.first.tx); diff --git a/src/test/fixtures.cpp b/src/test/fixtures.cpp index 65b9297a43..50f4d30a75 100644 --- a/src/test/fixtures.cpp +++ b/src/test/fixtures.cpp @@ -369,7 +369,7 @@ std::vector SparkTestingSetup::GenerateMints( data.address = address; outputs.push_back(data); - auto result = pwalletMain->MintAndStoreSpark(outputs, wtxAndFee, false); + auto result = pwalletMain->MintAndStoreSpark(outputs, wtxAndFee, false, true); if (result != "") { throw std::runtime_error(_("Fail to generate mints, ") + result); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9ed20ecbd8..65ea2b2260 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3726,7 +3726,7 @@ UniValue mintspark(const JSONRPCRequest& request) if (request.params.size() > 1) subtractFeeFromAmount = request.params[1].get_bool(); std::vector> wtxAndFee; - std::string strError = pwallet->MintAndStoreSpark(outputs, wtxAndFee, subtractFeeFromAmount); + std::string strError = pwallet->MintAndStoreSpark(outputs, wtxAndFee, subtractFeeFromAmount, false); if (strError != "") throw JSONRPCError(RPC_WALLET_ERROR, strError); @@ -3761,7 +3761,7 @@ UniValue automintspark(const JSONRPCRequest& request) { std::vector> wtxAndFee; std::vector outputs; - std::string strError = pwallet->MintAndStoreSpark(outputs, wtxAndFee, true, true); + std::string strError = pwallet->MintAndStoreSpark(outputs, wtxAndFee, true, true, true); if (strError != "") throw JSONRPCError(RPC_WALLET_ERROR, strError); diff --git a/src/wallet/test/spark_tests.cpp b/src/wallet/test/spark_tests.cpp index 7ed925fb2d..1d05c9e9df 100644 --- a/src/wallet/test/spark_tests.cpp +++ b/src/wallet/test/spark_tests.cpp @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(mint_and_store_spark) std::vector mintedCoins; mintedCoins.push_back(data); - std::string result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, false); + std::string result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, false, true); BOOST_CHECK_EQUAL(result, ""); size_t mintAmount = 0; @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(mint_subtract_fee) std::vector mintedCoins; mintedCoins.push_back(data); - std::string result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, true); + std::string result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, true, true); BOOST_CHECK_EQUAL(result, ""); size_t mintAmount = 0; @@ -207,10 +207,10 @@ BOOST_AUTO_TEST_CASE(spend) mintedCoins.push_back(data); std::vector> wtxAndFee; - std::string result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, false); + std::string result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, false, true); std::vector> wtxAndFee2; - pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee2, false); + pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee2, false, true); BOOST_CHECK_EQUAL("", result); @@ -308,7 +308,7 @@ BOOST_AUTO_TEST_CASE(mintspark_and_mint_all) std::vector mintedCoins; mintedCoins.push_back(data); - auto result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, false); + auto result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, false, true); BOOST_CHECK_EQUAL("", result); BOOST_CHECK_EQUAL(1, wtxAndFee.size()); BOOST_CHECK_EQUAL(10 * COIN, countMintsInBalance(wtxAndFee)); @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(mintspark_and_mint_all) mintedCoins.clear(); mintedCoins.push_back(data); - result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, false); + result = pwalletMain->MintAndStoreSpark(mintedCoins, wtxAndFee, false, true); BOOST_CHECK_EQUAL("", result); BOOST_CHECK_GT(wtxAndFee.size(), 1); BOOST_CHECK_EQUAL(600 * COIN, countMintsInBalance(wtxAndFee)); @@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(mintspark_and_mint_all) auto balance = getAvailableCoinsForMintBalance(); BOOST_CHECK_GT(balance, 0); - result = pwalletMain->MintAndStoreSpark({}, wtxAndFee, false, true); + result = pwalletMain->MintAndStoreSpark({}, wtxAndFee, false, true, true); BOOST_CHECK_EQUAL("", result); BOOST_CHECK_GT(balance, countMintsInBalance(wtxAndFee)); BOOST_CHECK_EQUAL(balance, countMintsInBalance(wtxAndFee, true)); @@ -344,7 +344,7 @@ BOOST_AUTO_TEST_CASE(mintspark_and_mint_all) balance = getAvailableCoinsForMintBalance(); BOOST_CHECK_GT(balance, 0); - result = pwalletMain->MintAndStoreSpark({ }, wtxAndFee, false, true); + result = pwalletMain->MintAndStoreSpark({ }, wtxAndFee, false, true, true); BOOST_CHECK_EQUAL("", result); BOOST_CHECK_GT(balance, countMintsInBalance(wtxAndFee)); BOOST_CHECK_EQUAL(balance, countMintsInBalance(wtxAndFee, true)); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 787a739f0d..c857ce3537 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5658,6 +5658,7 @@ std::string CWallet::MintAndStoreSpark( std::vector>& wtxAndFee, bool subtractFeeFromAmount, bool autoMintAll, + bool fSplit, bool fAskFee, const CCoinControl *coinControl) { std::string strError; @@ -5683,7 +5684,7 @@ std::string CWallet::MintAndStoreSpark( int nChangePosRet = -1; std::list reservekeys; - if (!sparkWallet->CreateSparkMintTransactions(outputs, wtxAndFee, nFeeRequired, reservekeys, nChangePosRet, subtractFeeFromAmount, strError, coinControl, autoMintAll)) { + if (!sparkWallet->CreateSparkMintTransactions(outputs, wtxAndFee, nFeeRequired, reservekeys, nChangePosRet, subtractFeeFromAmount, strError, fSplit, coinControl, autoMintAll)) { return strError; } @@ -8220,10 +8221,11 @@ bool CWallet::CreateSparkMintTransactions( int& nChangePosInOut, bool subtractFeeFromAmount, std::string& strFailReason, + bool fSplit, const CCoinControl *coinControl, bool autoMintAll) { - return sparkWallet->CreateSparkMintTransactions(outputs, wtxAndFee, nAllFeeRet, reservekeys, nChangePosInOut, subtractFeeFromAmount, strFailReason, coinControl, autoMintAll); + return sparkWallet->CreateSparkMintTransactions(outputs, wtxAndFee, nAllFeeRet, reservekeys, nChangePosInOut, subtractFeeFromAmount, strFailReason, fSplit, coinControl, autoMintAll); } std::pair CWallet::GetSparkBalance() diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f1f1d0c6a9..8ac437eb26 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1047,6 +1047,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface int& nChangePosInOut, bool subtractFeeFromAmount, std::string& strFailReason, + bool fSplit, const CCoinControl *coinControl, bool autoMintAll = false); @@ -1093,6 +1094,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface const std::vector& outputs, std::vector>& wtxAndFee, bool subtractFeeFromAmount, + bool fSplit, bool autoMintAll = false, bool fAskFee = false, const CCoinControl *coinControl = NULL);