From c49c6e1db097b3c117fdd9f3ae738582d9c583c7 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 15 Mar 2023 13:54:12 +0800 Subject: [PATCH 1/8] Support optional bool args, support coin select defaults on defid --- src/init.cpp | 1 + src/masternodes/coinselect.h | 27 +++++++++++++++++++-------- src/util/system.cpp | 10 ++++++++-- src/util/system.h | 9 +++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 7aa21f25db..fbd478d971 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -642,6 +642,7 @@ void SetupServerArgs() hidden_args.emplace_back("-daemon"); #endif + RPCMetadata::SetupArgs(gArgs); // Add the hidden options gArgs.AddHiddenArgs(hidden_args); } diff --git a/src/masternodes/coinselect.h b/src/masternodes/coinselect.h index 5c852124a6..a1469340d3 100644 --- a/src/masternodes/coinselect.h +++ b/src/masternodes/coinselect.h @@ -7,6 +7,7 @@ #define DEFI_MASTERNODES_COINSELECT_H #include +#include /** Default for skipping IsSolvable and return on first valid auth */ static const bool DEFAULT_COIN_SELECT_FAST_SELECT = false; @@ -21,9 +22,9 @@ static const std::string& ARG_STR_WALLET_COIN_OPT_EAGER_SELECT = "-walletcoinopt struct CoinSelectionOptions { public: - bool fastSelect{}; - bool skipSolvable{}; - bool eagerSelect{}; + std::optional fastSelect{}; + std::optional skipSolvable{}; + std::optional eagerSelect{}; static void SetupArgs(ArgsManager& args) { args.AddArg(ARG_STR_WALLET_FAST_SELECT, strprintf("Faster coin select - Enables walletcoinoptskipsolvable and walletcoinopteagerselect. This ends up in faster selection but has the disadvantage of not being able to pick complex input scripts (default: %u)", DEFAULT_COIN_SELECT_FAST_SELECT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); @@ -39,7 +40,7 @@ struct CoinSelectionOptions { static void FromArgs(CoinSelectionOptions& m, ArgsManager& args) { struct V { - bool& target; + std::optional& target; const std::string& arg; const bool& def; }; @@ -48,13 +49,18 @@ struct CoinSelectionOptions { V { m.skipSolvable, ARG_STR_WALLET_COIN_OPT_SKIP_SOLVABLE, DEFAULT_COIN_SELECT_SKIP_SOLVABLE}, V { m.eagerSelect, ARG_STR_WALLET_COIN_OPT_EAGER_SELECT, DEFAULT_COIN_SELECT_EAGER_SELECT}, }) { + // Use a static way to detect DEFI_CLI or DEFID compilation. + // If it's defid, respond with defaults. + // If it's defi-cli, just skip init unless it's provided, + // so we just directly call GetOptionalArgs v = args.GetBoolArg(str, def); + v = args.GetOptionalBoolArg(str); } } static void FromHTTPHeader(CoinSelectionOptions &m, const HTTPHeaderQueryFunc headerFunc) { struct V { - bool& target; + std::optional& target; const std::string& arg; }; for (auto &[v, str]: { @@ -63,13 +69,17 @@ struct CoinSelectionOptions { V { m.eagerSelect, ARG_STR_WALLET_COIN_OPT_EAGER_SELECT}, }) { const auto &[present, val] = headerFunc("x" + str); - if (present) v = val == "1" ? true : false; + if (present) { + v = val == "1" ? true : false; + } else { + v = {}; + } } } static void ToHTTPHeader(const CoinSelectionOptions& m, const HTTPHeaderWriterFunc writer) { struct V { - const bool& val; + const std::optional& val; const std::string& arg; }; for (auto &[v, str]: { @@ -77,7 +87,8 @@ struct CoinSelectionOptions { V { m.skipSolvable, ARG_STR_WALLET_COIN_OPT_SKIP_SOLVABLE}, V { m.eagerSelect, ARG_STR_WALLET_COIN_OPT_EAGER_SELECT}, }) { - writer("x" + str, v ? "1" : "0"); + if (!v) continue; + writer("x" + str, *v ? "1" : "0"); } } }; diff --git a/src/util/system.cpp b/src/util/system.cpp index 072b7738a5..a987a397a1 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -510,12 +510,18 @@ int64_t ArgsManager::GetArg(const std::string& strArg, int64_t nDefault) const return nDefault; } -bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const +std::optional ArgsManager::GetOptionalBoolArg(const std::string& strArg) const { if (IsArgNegated(strArg)) return false; std::pair found_res = ArgsManagerHelper::GetArg(*this, strArg); if (found_res.first) return InterpretBool(found_res.second); - return fDefault; + return {}; +} + +bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const +{ + auto res = ArgsManager::GetOptionalBoolArg(strArg); + return res ? *res : fDefault; } bool ArgsManager::SoftSetArg(const std::string& strArg, const std::string& strValue) diff --git a/src/util/system.h b/src/util/system.h index f409b953ca..c96e1121e1 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -31,6 +31,7 @@ #include #include #include +#include // Application startup time (used for uptime calculation) int64_t GetStartupTime(); @@ -244,6 +245,14 @@ class ArgsManager */ bool GetBoolArg(const std::string& strArg, bool fDefault) const; + /** + * Return boolean argument if present or empty + * + * @param strArg Argument to get (e.g. "-foo") + * @return command-line argument or null value + */ + std::optional GetOptionalBoolArg(const std::string& strArg) const; + /** * Set an argument if it doesn't already have a value * From 59028815bd2abb9d9ca582dacae76d93d676f363 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 15 Mar 2023 14:17:44 +0800 Subject: [PATCH 2/8] Switch FromHeader to no overwrite --- src/masternodes/coinselect.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/masternodes/coinselect.h b/src/masternodes/coinselect.h index a1469340d3..bc9b96f2b2 100644 --- a/src/masternodes/coinselect.h +++ b/src/masternodes/coinselect.h @@ -69,11 +69,7 @@ struct CoinSelectionOptions { V { m.eagerSelect, ARG_STR_WALLET_COIN_OPT_EAGER_SELECT}, }) { const auto &[present, val] = headerFunc("x" + str); - if (present) { - v = val == "1" ? true : false; - } else { - v = {}; - } + if (present) v = val == "1" ? true : false; } } From a95ecfb7aa9760d24ca9c176fa3bb49917d3ed4c Mon Sep 17 00:00:00 2001 From: jouzo Date: Wed, 15 Mar 2023 12:28:35 +0100 Subject: [PATCH 3/8] Use compiler flag to determine if running defi-cli or defid --- src/Makefile.am | 3 ++- src/masternodes/coinselect.h | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 00ab4a3f88..62e2dc5fe7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -181,7 +181,7 @@ DEFI_CORE_H = \ masternodes/proposals.h \ masternodes/tokens.h \ masternodes/threadpool.h \ - masternodes/coinselect.h \ + masternodes/coinselect.h \ masternodes/undo.h \ masternodes/undos.h \ masternodes/validation.h \ @@ -707,6 +707,7 @@ defid_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS # defi-cli binary # defi_cli_SOURCES = defi-cli.cpp defi_cli_CPPFLAGS = $(AM_CPPFLAGS) $(DEFI_INCLUDES) $(EVENT_CFLAGS) +defi_cli_CPPFLAGS += -DDEFI_CLI defi_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) defi_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) diff --git a/src/masternodes/coinselect.h b/src/masternodes/coinselect.h index bc9b96f2b2..4ab78be96b 100644 --- a/src/masternodes/coinselect.h +++ b/src/masternodes/coinselect.h @@ -52,9 +52,12 @@ struct CoinSelectionOptions { // Use a static way to detect DEFI_CLI or DEFID compilation. // If it's defid, respond with defaults. // If it's defi-cli, just skip init unless it's provided, - // so we just directly call GetOptionalArgs - v = args.GetBoolArg(str, def); - v = args.GetOptionalBoolArg(str); + // so we just directly call GetOptionalArgs + #ifdef DEFI_CLI + v = args.GetOptionalBoolArg(str); + #else + v = args.GetBoolArg(str, def); + #endif } } From c8f77940a269bb85c05a6509cc2f44998b16f7df Mon Sep 17 00:00:00 2001 From: jouzo Date: Wed, 15 Mar 2023 12:29:09 +0100 Subject: [PATCH 4/8] Fix coinSelectOpts logic for optional bool --- src/wallet/wallet.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f87bab139f..2aa59ec628 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2500,9 +2500,9 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector< const int min_depth = {coinControl ? coinControl->m_min_depth : DEFAULT_MIN_DEPTH}; const int max_depth = {coinControl ? coinControl->m_max_depth : DEFAULT_MAX_DEPTH}; - bool skipSolvable = coinSelectOpts.skipSolvable; - if (!skipSolvable) { - skipSolvable = coinSelectOpts.fastSelect; + bool skipSolvable = coinSelectOpts.skipSolvable && *coinSelectOpts.skipSolvable; + if (!skipSolvable && coinSelectOpts.fastSelect) { + skipSolvable = *coinSelectOpts.fastSelect; } for (const auto& wtx : mapWallet.get()) @@ -3021,9 +3021,9 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std nSubtractFeeFromAmount++; } - bool eagerSelect = coinSelectOpts.eagerSelect; - if (!eagerSelect) { - eagerSelect = coinSelectOpts.fastSelect; + bool eagerSelect = coinSelectOpts.eagerSelect && *coinSelectOpts.eagerSelect; + if (!eagerSelect && coinSelectOpts.fastSelect) { + eagerSelect = *coinSelectOpts.fastSelect; } const auto sumAmountToSelect = eagerSelect ? nValue + DEFAULT_TRANSACTION_MAXFEE : MAX_MONEY; From 9a0be972ddc79feff342b418ff6de422e568b406 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 16 Mar 2023 23:41:50 +0800 Subject: [PATCH 5/8] Simplify access logic --- src/masternodes/coinselect.h | 8 ++++++-- src/wallet/wallet.cpp | 11 +++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/masternodes/coinselect.h b/src/masternodes/coinselect.h index 4ab78be96b..79265b4fc1 100644 --- a/src/masternodes/coinselect.h +++ b/src/masternodes/coinselect.h @@ -26,6 +26,10 @@ struct CoinSelectionOptions { std::optional skipSolvable{}; std::optional eagerSelect{}; + bool IsFastSelectEnabled() const { return fastSelect.value_or(false); } + bool IsSkipSolvableEnabled() const { return skipSolvable.value_or(false); } + bool IsEagerSelectEnabled() const { return eagerSelect.value_or(false); } + static void SetupArgs(ArgsManager& args) { args.AddArg(ARG_STR_WALLET_FAST_SELECT, strprintf("Faster coin select - Enables walletcoinoptskipsolvable and walletcoinopteagerselect. This ends up in faster selection but has the disadvantage of not being able to pick complex input scripts (default: %u)", DEFAULT_COIN_SELECT_FAST_SELECT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); args.AddArg(ARG_STR_WALLET_COIN_OPT_SKIP_SOLVABLE, strprintf("Coin select option: Skips IsSolvable signable UTXO check (default: %u)", DEFAULT_COIN_SELECT_SKIP_SOLVABLE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); @@ -38,6 +42,7 @@ struct CoinSelectionOptions { return opts; } + static void FromArgs(CoinSelectionOptions& m, ArgsManager& args) { struct V { std::optional& target; @@ -49,10 +54,9 @@ struct CoinSelectionOptions { V { m.skipSolvable, ARG_STR_WALLET_COIN_OPT_SKIP_SOLVABLE, DEFAULT_COIN_SELECT_SKIP_SOLVABLE}, V { m.eagerSelect, ARG_STR_WALLET_COIN_OPT_EAGER_SELECT, DEFAULT_COIN_SELECT_EAGER_SELECT}, }) { - // Use a static way to detect DEFI_CLI or DEFID compilation. // If it's defid, respond with defaults. // If it's defi-cli, just skip init unless it's provided, - // so we just directly call GetOptionalArgs + // so we just directly call GetOptionalBoolArg #ifdef DEFI_CLI v = args.GetOptionalBoolArg(str); #else diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 2aa59ec628..d3523ad5c8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2500,10 +2500,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector< const int min_depth = {coinControl ? coinControl->m_min_depth : DEFAULT_MIN_DEPTH}; const int max_depth = {coinControl ? coinControl->m_max_depth : DEFAULT_MAX_DEPTH}; - bool skipSolvable = coinSelectOpts.skipSolvable && *coinSelectOpts.skipSolvable; - if (!skipSolvable && coinSelectOpts.fastSelect) { - skipSolvable = *coinSelectOpts.fastSelect; - } + bool skipSolvable = coinSelectOpts.IsSkipSolvableEnabled() || coinSelectOpts.IsFastSelectEnabled(); for (const auto& wtx : mapWallet.get()) { @@ -3021,10 +3018,8 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std nSubtractFeeFromAmount++; } - bool eagerSelect = coinSelectOpts.eagerSelect && *coinSelectOpts.eagerSelect; - if (!eagerSelect && coinSelectOpts.fastSelect) { - eagerSelect = *coinSelectOpts.fastSelect; - } + bool eagerSelect = coinSelectOpts.IsEagerSelectEnabled() || coinSelectOpts.IsFastSelectEnabled(); + const auto sumAmountToSelect = eagerSelect ? nValue + DEFAULT_TRANSACTION_MAXFEE : MAX_MONEY; if (vecSend.empty()) From 00a1c73e4dae02ebb9f926a164b4d1ef78d78be8 Mon Sep 17 00:00:00 2001 From: jouzo Date: Thu, 16 Mar 2023 21:10:35 +0100 Subject: [PATCH 6/8] Add metadata default in JSONRPCRequest initialization list --- src/rpc/request.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/request.h b/src/rpc/request.h index a02be8512d..afdf23642f 100644 --- a/src/rpc/request.h +++ b/src/rpc/request.h @@ -66,7 +66,7 @@ class JSONRPCRequest std::string peerAddr; RPCMetadata metadata; - JSONRPCRequest() : id(NullUniValue), params(NullUniValue), fHelp(false) {} + JSONRPCRequest() : id(NullUniValue), params(NullUniValue), fHelp(false), metadata(RPCMetadata::CreateDefault()) {} void parse(const UniValue& valRequest); }; From 62abe58f04b139faeb09a833f983260516074b0c Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Fri, 17 Mar 2023 08:12:00 +0800 Subject: [PATCH 7/8] Pass coin select opts all the way through --- src/masternodes/mn_rpc.cpp | 24 ++++++++++------- src/masternodes/rpc_accounts.cpp | 28 +++++++++---------- src/masternodes/rpc_icxorderbook.cpp | 28 +++++++++---------- src/masternodes/rpc_loan.cpp | 40 ++++++++++++++-------------- src/masternodes/rpc_masternodes.cpp | 12 ++++----- src/masternodes/rpc_oracles.cpp | 16 +++++------ src/masternodes/rpc_poolpair.cpp | 24 ++++++++--------- src/masternodes/rpc_proposals.cpp | 17 +++++------- src/masternodes/rpc_tokens.cpp | 20 +++++++------- src/masternodes/rpc_vault.cpp | 24 ++++++++--------- 10 files changed, 116 insertions(+), 117 deletions(-) diff --git a/src/masternodes/mn_rpc.cpp b/src/masternodes/mn_rpc.cpp index 52ebe59e81..5ccd5e01c2 100644 --- a/src/masternodes/mn_rpc.cpp +++ b/src/masternodes/mn_rpc.cpp @@ -316,7 +316,11 @@ static std::optional GetAuthInputOnly(CWalletCoinsUnlocker& pwallet, CTxD return txin; } -static CTransactionRef CreateAuthTx(CWalletCoinsUnlocker& pwallet, std::set const & auths, int32_t txVersion) { +static CTransactionRef CreateAuthTx(CWalletCoinsUnlocker& pwallet, + std::set const & auths, + int32_t txVersion, + const CoinSelectionOptions &coinSelectOpts) { + CMutableTransaction mtx(txVersion); CCoinControl coinControl; @@ -337,7 +341,7 @@ static CTransactionRef CreateAuthTx(CWalletCoinsUnlocker& pwallet, std::set GetAnyFoundationAuthInput(CWalletCoinsUnlocker& pwallet) { @@ -428,7 +432,7 @@ std::vector GetAuthInputsSmart(CWalletCoinsUnlocker& pwallet, int32_t txV // at last, create additional tx for missed if (!notFoundYet.empty()) { try { - optAuthTx = CreateAuthTx(pwallet, notFoundYet, txVersion); // success or throw + optAuthTx = CreateAuthTx(pwallet, notFoundYet, txVersion, coinSelectOpts); // success or throw } catch (const UniValue& objError) { throw JSONRPCError(objError["code"].get_int(), "Add-on auth TX failed: " + objError["message"].getValStr()); } @@ -593,7 +597,7 @@ UniValue setgov(const JSONRPCRequest& request) { UniValue const & txInputs = request.params[1]; CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -606,7 +610,7 @@ UniValue setgov(const JSONRPCRequest& request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -685,7 +689,7 @@ UniValue unsetgov(const JSONRPCRequest& request) { UniValue const & txInputs = request.params[1]; CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -698,7 +702,7 @@ UniValue unsetgov(const JSONRPCRequest& request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -807,7 +811,7 @@ UniValue setgovheight(const JSONRPCRequest& request) { UniValue const & txInputs = request.params[2]; CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -820,7 +824,7 @@ UniValue setgovheight(const JSONRPCRequest& request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); diff --git a/src/masternodes/rpc_accounts.cpp b/src/masternodes/rpc_accounts.cpp index 538a14e2e4..068e899821 100644 --- a/src/masternodes/rpc_accounts.cpp +++ b/src/masternodes/rpc_accounts.cpp @@ -663,7 +663,7 @@ UniValue utxostoaccount(const JSONRPCRequest& request) { } // fund - fund(rawTx, pwallet, {}); + fund(rawTx, pwallet, {}, nullptr, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight); @@ -806,7 +806,7 @@ UniValue accounttoaccount(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{msg.from}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -818,7 +818,7 @@ UniValue accounttoaccount(const JSONRPCRequest& request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -911,7 +911,7 @@ UniValue accounttoutxos(const JSONRPCRequest& request) { const UniValue &txInputs = request.params[2]; CTransactionRef optAuthTx; std::set auths{msg.from}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -923,7 +923,7 @@ UniValue accounttoutxos(const JSONRPCRequest& request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // re-encode with filled mintingOutputsStart { @@ -1909,7 +1909,7 @@ UniValue sendtokenstoaddress(const JSONRPCRequest& request) { auths.emplace(acc.first); } CTransactionRef optAuthTx; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -1923,7 +1923,7 @@ UniValue sendtokenstoaddress(const JSONRPCRequest& request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -2192,7 +2192,7 @@ UniValue HandleSendDFIP2201DFIInput(const JSONRPCRequest& request, CWalletCoinsU coinControl.matchDestination = dest; // fund - fund(rawTx, pwallet, {}, &coinControl); + fund(rawTx, pwallet, {}, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight); @@ -2230,14 +2230,14 @@ UniValue HandleSendDFIP2201BTCInput(const JSONRPCRequest& request, CWalletCoinsU CTransactionRef optAuthTx; std::set auth{script}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auth, false, optAuthTx, request.params[3]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auth, false, optAuthTx, request.params[3], request.metadata.coinSelectOpts); // Set change address CCoinControl coinControl; coinControl.destChange = dest; // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -2379,14 +2379,14 @@ UniValue futureswap(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auth{msg.owner}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auth, false, optAuthTx, request.params[3]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auth, false, optAuthTx, request.params[3], request.metadata.coinSelectOpts); // Set change address CCoinControl coinControl; coinControl.destChange = dest; // Fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // Check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -2470,14 +2470,14 @@ UniValue withdrawfutureswap(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auth{msg.owner}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auth, false, optAuthTx, request.params[3]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auth, false, optAuthTx, request.params[3], request.metadata.coinSelectOpts); // Set change address CCoinControl coinControl; coinControl.destChange = dest; // Fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // Check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); diff --git a/src/masternodes/rpc_icxorderbook.cpp b/src/masternodes/rpc_icxorderbook.cpp index d48f4bddbd..a9c677a8dc 100644 --- a/src/masternodes/rpc_icxorderbook.cpp +++ b/src/masternodes/rpc_icxorderbook.cpp @@ -323,7 +323,7 @@ UniValue icxcreateorder(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{order.ownerAddress}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -335,7 +335,7 @@ UniValue icxcreateorder(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -465,7 +465,7 @@ UniValue icxmakeoffer(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{makeoffer.ownerAddress}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -477,7 +477,7 @@ UniValue icxmakeoffer(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx,&coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -607,7 +607,7 @@ UniValue icxsubmitdfchtlc(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{authScript}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -619,7 +619,7 @@ UniValue icxsubmitdfchtlc(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -753,7 +753,7 @@ UniValue icxsubmitexthtlc(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{authScript}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -767,7 +767,7 @@ UniValue icxsubmitexthtlc(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx,&coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -857,7 +857,7 @@ UniValue icxclaimdfchtlc(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -869,7 +869,7 @@ UniValue icxclaimdfchtlc(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -953,7 +953,7 @@ UniValue icxcloseorder(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{authScript}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -965,7 +965,7 @@ UniValue icxcloseorder(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx,&coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -1050,7 +1050,7 @@ UniValue icxcloseoffer(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{authScript}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -1062,7 +1062,7 @@ UniValue icxcloseoffer(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx,&coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); diff --git a/src/masternodes/rpc_loan.cpp b/src/masternodes/rpc_loan.cpp index f024f3e414..1f03e1e939 100644 --- a/src/masternodes/rpc_loan.cpp +++ b/src/masternodes/rpc_loan.cpp @@ -155,7 +155,7 @@ UniValue setcollateraltoken(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -167,7 +167,7 @@ UniValue setcollateraltoken(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -360,7 +360,7 @@ UniValue setloantoken(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -372,7 +372,7 @@ UniValue setloantoken(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -481,7 +481,7 @@ UniValue updateloantoken(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(0, scriptMeta)); @@ -493,7 +493,7 @@ UniValue updateloantoken(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -648,7 +648,7 @@ UniValue createloanscheme(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, request.params[3]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, request.params[3], request.metadata.coinSelectOpts); rawTx.vout.emplace_back(0, scriptMeta); @@ -661,7 +661,7 @@ UniValue createloanscheme(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -735,7 +735,7 @@ UniValue updateloanscheme(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, request.params[4]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, request.params[4], request.metadata.coinSelectOpts); rawTx.vout.emplace_back(0, scriptMeta); @@ -748,7 +748,7 @@ UniValue updateloanscheme(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -811,7 +811,7 @@ UniValue setdefaultloanscheme(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, request.params[1]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, request.params[1], request.metadata.coinSelectOpts); rawTx.vout.emplace_back(0, scriptMeta); @@ -823,7 +823,7 @@ UniValue setdefaultloanscheme(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -890,7 +890,7 @@ UniValue destroyloanscheme(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, request.params[2]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, request.params[2], request.metadata.coinSelectOpts); rawTx.vout.emplace_back(0, scriptMeta); @@ -902,7 +902,7 @@ UniValue destroyloanscheme(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -1103,7 +1103,7 @@ UniValue takeloan(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{ownerAddress}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.emplace_back(0, scriptMeta); @@ -1115,7 +1115,7 @@ UniValue takeloan(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -1287,7 +1287,7 @@ UniValue paybackloan(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{from}; const UniValue &txInputs = request.params[1]; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.emplace_back(0, scriptMeta); @@ -1299,7 +1299,7 @@ UniValue paybackloan(const JSONRPCRequest& request) { if (IsValidDestination(dest)) coinControl.destChange = dest; - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -1604,7 +1604,7 @@ UniValue paybackwithcollateral(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{ownerAddress}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -1615,7 +1615,7 @@ UniValue paybackwithcollateral(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); diff --git a/src/masternodes/rpc_masternodes.cpp b/src/masternodes/rpc_masternodes.cpp index 39e22d47ca..40a0635ae5 100644 --- a/src/masternodes/rpc_masternodes.cpp +++ b/src/masternodes/rpc_masternodes.cpp @@ -186,7 +186,7 @@ UniValue createmasternode(const JSONRPCRequest& request) CTransactionRef optAuthTx; auto scriptOwner = GetScriptForDestination(ownerDest); std::set auths{scriptOwner}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[2]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[2], request.metadata.coinSelectOpts); // Return change to owner address CCoinControl coinControl; @@ -197,7 +197,7 @@ UniValue createmasternode(const JSONRPCRequest& request) rawTx.vout.push_back(CTxOut(EstimateMnCreationFee(targetHeight), scriptMeta)); rawTx.vout.push_back(CTxOut(GetMnCollateralAmount(targetHeight), scriptOwner)); - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -277,7 +277,7 @@ UniValue resignmasternode(const JSONRPCRequest& request) if (collateralDest.index() != 0) { auths.insert(GetScriptForDestination(collateralDest)); } - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[1]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[1], request.metadata.coinSelectOpts); // Return change to owner address CCoinControl coinControl; @@ -294,7 +294,7 @@ UniValue resignmasternode(const JSONRPCRequest& request) rawTx.vout.push_back(CTxOut(0, scriptMeta)); - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -395,7 +395,7 @@ UniValue updatemasternode(const JSONRPCRequest& request) CTransactionRef optAuthTx; std::set auths{GetScriptForDestination(ownerDest)}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[2]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[2], request.metadata.coinSelectOpts); // Return change to owner address CCoinControl coinControl; @@ -442,7 +442,7 @@ UniValue updatemasternode(const JSONRPCRequest& request) } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); diff --git a/src/masternodes/rpc_oracles.cpp b/src/masternodes/rpc_oracles.cpp index 9a3defc9f1..125c7f90dd 100644 --- a/src/masternodes/rpc_oracles.cpp +++ b/src/masternodes/rpc_oracles.cpp @@ -152,7 +152,7 @@ UniValue appointoracle(const JSONRPCRequest &request) { UniValue const &txInputs = request.params[3]; CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -165,7 +165,7 @@ UniValue appointoracle(const JSONRPCRequest &request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -267,7 +267,7 @@ UniValue updateoracle(const JSONRPCRequest& request) { UniValue const &txInputs = request.params[4]; CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl;// std::string oracles; @@ -280,7 +280,7 @@ UniValue updateoracle(const JSONRPCRequest& request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -347,7 +347,7 @@ UniValue removeoracle(const JSONRPCRequest& request) { UniValue const &txInputs = request.params[1]; CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -361,7 +361,7 @@ UniValue removeoracle(const JSONRPCRequest& request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -509,7 +509,7 @@ UniValue setoracledata(const JSONRPCRequest &request) { std::set auths{oracleAddress}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -522,7 +522,7 @@ UniValue setoracledata(const JSONRPCRequest &request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); diff --git a/src/masternodes/rpc_poolpair.cpp b/src/masternodes/rpc_poolpair.cpp index 5b735f6f88..43540c1353 100644 --- a/src/masternodes/rpc_poolpair.cpp +++ b/src/masternodes/rpc_poolpair.cpp @@ -423,7 +423,7 @@ UniValue addpoolliquidity(const JSONRPCRequest &request) { } const UniValue &txInputs = request.params[2]; CTransactionRef optAuthTx; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -437,7 +437,7 @@ UniValue addpoolliquidity(const JSONRPCRequest &request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -511,7 +511,7 @@ UniValue removepoolliquidity(const JSONRPCRequest &request) { CTransactionRef optAuthTx; std::set auths{msg.from}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -523,7 +523,7 @@ UniValue removepoolliquidity(const JSONRPCRequest &request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -687,7 +687,7 @@ UniValue createpoolpair(const JSONRPCRequest &request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -699,7 +699,7 @@ UniValue createpoolpair(const JSONRPCRequest &request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -821,7 +821,7 @@ UniValue updatepoolpair(const JSONRPCRequest &request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION); metadata << static_cast(CustomTxType::UpdatePoolPair) @@ -846,7 +846,7 @@ UniValue updatepoolpair(const JSONRPCRequest &request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -946,7 +946,7 @@ UniValue poolswap(const JSONRPCRequest &request) { const UniValue &txInputs = request.params[1]; CTransactionRef optAuthTx; std::set auths{poolSwapMsg.from}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -958,7 +958,7 @@ UniValue poolswap(const JSONRPCRequest &request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -1089,7 +1089,7 @@ UniValue compositeswap(const JSONRPCRequest &request) { const UniValue &txInputs = request.params[1]; CTransactionRef optAuthTx; std::set auths{poolSwapMsg.from}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -1101,7 +1101,7 @@ UniValue compositeswap(const JSONRPCRequest &request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); diff --git a/src/masternodes/rpc_proposals.cpp b/src/masternodes/rpc_proposals.cpp index be376e650a..dce091328b 100644 --- a/src/masternodes/rpc_proposals.cpp +++ b/src/masternodes/rpc_proposals.cpp @@ -282,7 +282,7 @@ UniValue creategovcfp(const JSONRPCRequest &request) { CTransactionRef optAuthTx; std::set auths{pm.address}; rawTx.vin = - GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, request.params[1]); + GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[1], request.metadata.coinSelectOpts); auto cfpFee = GetProposalCreationFee(targetHeight, *pcustomcsview, pm); rawTx.vout.emplace_back(CTxOut(cfpFee, scriptMeta)); @@ -297,7 +297,7 @@ UniValue creategovcfp(const JSONRPCRequest &request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -419,7 +419,7 @@ UniValue creategovvoc(const JSONRPCRequest &request) { CTransactionRef optAuthTx; std::set auths; rawTx.vin = - GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, request.params[1]); + GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[1], request.metadata.coinSelectOpts); auto vocFee = GetProposalCreationFee(targetHeight, *pcustomcsview, pm); rawTx.vout.emplace_back(CTxOut(vocFee, scriptMeta)); @@ -434,7 +434,7 @@ UniValue creategovvoc(const JSONRPCRequest &request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -564,7 +564,7 @@ UniValue votegov(const JSONRPCRequest &request) { CTransactionRef optAuthTx; std::set auths = {GetScriptForDestination(ownerDest)}; rawTx.vin = - GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, request.params[3], request.metadata.coinSelectOpts); + GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[3], request.metadata.coinSelectOpts); rawTx.vout.emplace_back(CTxOut(0, scriptMeta)); @@ -720,12 +720,7 @@ UniValue votegovbatch(const JSONRPCRequest &request) { CTransactionRef optAuthTx; std::set auths = {GetScriptForDestination(ownerDest)}; - rawTx.vin = GetAuthInputsSmart(pwallet, - rawTx.nVersion, - auths, false /*needFoundersAuth*/, - optAuthTx, - {}, - request.metadata.coinSelectOpts); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, {}, request.metadata.coinSelectOpts); rawTx.vout.emplace_back(0, scriptMeta); CCoinControl coinControl; diff --git a/src/masternodes/rpc_tokens.cpp b/src/masternodes/rpc_tokens.cpp index 2d7ed94eae..392085553b 100644 --- a/src/masternodes/rpc_tokens.cpp +++ b/src/masternodes/rpc_tokens.cpp @@ -112,7 +112,7 @@ UniValue createtoken(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, metaObj["isDAT"].getBool() /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, metaObj["isDAT"].getBool(), optAuthTx, txInputs, request.metadata.coinSelectOpts); rawTx.vout.push_back(CTxOut(GetTokenCreationFee(targetHeight), scriptMeta)); rawTx.vout.push_back(CTxOut(GetTokenCollateralAmount(), GetScriptForDestination(collateralDest))); @@ -128,7 +128,7 @@ UniValue createtoken(const JSONRPCRequest& request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -274,7 +274,7 @@ UniValue updatetoken(const JSONRPCRequest& request) { } // before BayfrontHeight it needs only founders auth - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths /*auths*/, true /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); } else { // post-bayfront auth @@ -289,11 +289,11 @@ UniValue updatetoken(const JSONRPCRequest& request) { Params().GetConsensus().foundationMembers.find(owner) != Params().GetConsensus().foundationMembers.end(); if (isFoundersToken) { // need any founder's auth - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths /*auths*/, true /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, true, optAuthTx, txInputs, request.metadata.coinSelectOpts); } else {// "common" auth auths.insert(owner); - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); } } @@ -323,7 +323,7 @@ UniValue updatetoken(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -764,7 +764,7 @@ UniValue minttokens(const JSONRPCRequest& request) { } } - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, needFoundersAuth, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, needFoundersAuth, optAuthTx, txInputs, request.metadata.coinSelectOpts); CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION); metadata << static_cast(CustomTxType::MintToken) << mintTokensMessage; @@ -786,7 +786,7 @@ UniValue minttokens(const JSONRPCRequest& request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -888,7 +888,7 @@ UniValue burntokens(const JSONRPCRequest& request) { CMutableTransaction rawTx(txVersion); CTransactionRef optAuthTx; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION); metadata << static_cast(CustomTxType::BurnToken) @@ -911,7 +911,7 @@ UniValue burntokens(const JSONRPCRequest& request) { } // fund - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); diff --git a/src/masternodes/rpc_vault.cpp b/src/masternodes/rpc_vault.cpp index 39511bba73..409861b92c 100644 --- a/src/masternodes/rpc_vault.cpp +++ b/src/masternodes/rpc_vault.cpp @@ -327,7 +327,7 @@ UniValue createvault(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[2]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[2], request.metadata.coinSelectOpts); rawTx.vout.emplace_back(Params().GetConsensus().vaultCreationFee, scriptMeta); @@ -342,7 +342,7 @@ UniValue createvault(const JSONRPCRequest& request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -419,7 +419,7 @@ UniValue closevault(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{ownerAddress}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[2]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[2], request.metadata.coinSelectOpts); rawTx.vout.emplace_back(0, scriptMeta); @@ -432,7 +432,7 @@ UniValue closevault(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -733,7 +733,7 @@ UniValue updatevault(const JSONRPCRequest& request) { UniValue const &txInputs = request.params[2]; CTransactionRef optAuthTx; std::set auths{vault.ownerAddress}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -746,7 +746,7 @@ UniValue updatevault(const JSONRPCRequest& request) { } } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -821,7 +821,7 @@ UniValue deposittovault(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{from}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -832,7 +832,7 @@ UniValue deposittovault(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -919,7 +919,7 @@ UniValue withdrawfromvault(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{ownerAddress}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, txInputs); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, txInputs, request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -930,7 +930,7 @@ UniValue withdrawfromvault(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); @@ -1021,7 +1021,7 @@ UniValue placeauctionbid(const JSONRPCRequest& request) { CTransactionRef optAuthTx; std::set auths{from}; - rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, request.params[4]); + rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false, optAuthTx, request.params[4], request.metadata.coinSelectOpts); CCoinControl coinControl; @@ -1032,7 +1032,7 @@ UniValue placeauctionbid(const JSONRPCRequest& request) { coinControl.destChange = dest; } - fund(rawTx, pwallet, optAuthTx, &coinControl); + fund(rawTx, pwallet, optAuthTx, &coinControl, request.metadata.coinSelectOpts); // check execution execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); From 939f92c4034ab42e71f0800936260ce245a71bd8 Mon Sep 17 00:00:00 2001 From: cedric ogire Date: Fri, 17 Mar 2023 11:32:39 +0800 Subject: [PATCH 8/8] Put CoinSelectOption variables private --- src/masternodes/coinselect.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/masternodes/coinselect.h b/src/masternodes/coinselect.h index 79265b4fc1..2d0f2a656b 100644 --- a/src/masternodes/coinselect.h +++ b/src/masternodes/coinselect.h @@ -21,11 +21,12 @@ static const std::string& ARG_STR_WALLET_COIN_OPT_SKIP_SOLVABLE = "-walletcoinop static const std::string& ARG_STR_WALLET_COIN_OPT_EAGER_SELECT = "-walletcoinopteagerselect"; struct CoinSelectionOptions { - public: + private: std::optional fastSelect{}; std::optional skipSolvable{}; std::optional eagerSelect{}; + public: bool IsFastSelectEnabled() const { return fastSelect.value_or(false); } bool IsSkipSolvableEnabled() const { return skipSolvable.value_or(false); } bool IsEagerSelectEnabled() const { return eagerSelect.value_or(false); }