From b7816112eecb0fc9cf10d2188ba71c89d94a9ab9 Mon Sep 17 00:00:00 2001 From: Jouzo <15011228+Jouzo@users.noreply.github.com> Date: Fri, 17 Mar 2023 07:36:39 +0100 Subject: [PATCH] Adds coin select flags to defid with option to override from CLI (#1820) * Support optional bool args, support coin select defaults on defid * Switch FromHeader to no overwrite * Use compiler flag to determine if running defi-cli or defid * Fix coinSelectOpts logic for optional bool * Simplify access logic * Add metadata default in JSONRPCRequest initialization list * Pass coin select opts all the way through * Put CoinSelectOption variables private --------- Co-authored-by: Prasanna Loganathar Co-authored-by: cedric ogire --- src/Makefile.am | 1 + src/init.cpp | 1 + src/masternodes/coinselect.h | 31 +++++++++++++++------ 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 ++++++++--------- src/rpc/request.h | 2 +- src/util/system.cpp | 10 +++++-- src/util/system.h | 9 +++++++ src/wallet/wallet.cpp | 11 +++----- 17 files changed, 162 insertions(+), 136 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index aa6a94a580d..62e2dc5fe7d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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/init.cpp b/src/init.cpp index b3c49ec7895..217cb38702f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -644,6 +644,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 5c852124a63..2d0f2a656b6 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; @@ -20,10 +21,15 @@ 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 { + private: + std::optional fastSelect{}; + std::optional skipSolvable{}; + std::optional eagerSelect{}; + public: - bool fastSelect{}; - bool skipSolvable{}; - bool 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); @@ -37,9 +43,10 @@ struct CoinSelectionOptions { return opts; } + static void FromArgs(CoinSelectionOptions& m, ArgsManager& args) { struct V { - bool& target; + std::optional& target; const std::string& arg; const bool& def; }; @@ -48,13 +55,20 @@ 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}, }) { - v = args.GetBoolArg(str, def); + // If it's defid, respond with defaults. + // If it's defi-cli, just skip init unless it's provided, + // so we just directly call GetOptionalBoolArg + #ifdef DEFI_CLI + v = args.GetOptionalBoolArg(str); + #else + v = args.GetBoolArg(str, def); + #endif } } static void FromHTTPHeader(CoinSelectionOptions &m, const HTTPHeaderQueryFunc headerFunc) { struct V { - bool& target; + std::optional& target; const std::string& arg; }; for (auto &[v, str]: { @@ -69,7 +83,7 @@ struct CoinSelectionOptions { 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 +91,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/masternodes/mn_rpc.cpp b/src/masternodes/mn_rpc.cpp index 52ebe59e811..5ccd5e01c24 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 538a14e2e45..068e899821a 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 d48f4bddbdf..a9c677a8dc4 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 f024f3e4141..1f03e1e939c 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 39e22d47caa..40a0635ae59 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 9a3defc9f14..125c7f90dd2 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 5b735f6f88e..43540c1353b 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 be376e650a0..dce091328b7 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 2d7ed94eae5..392085553bf 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 39511bba73d..409861b92c9 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); diff --git a/src/rpc/request.h b/src/rpc/request.h index a02be8512da..afdf23642f9 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); }; diff --git a/src/util/system.cpp b/src/util/system.cpp index 206a0acf2ad..8472bc0b65b 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -518,12 +518,18 @@ double ArgsManager::GetDoubleArg(const std::string& strArg, double fDefault) con return fDefault; } -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 8d52486ccfd..5adabfda302 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(); @@ -253,6 +254,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 * diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f87bab139f7..d3523ad5c8f 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; - if (!skipSolvable) { - 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; - if (!eagerSelect) { - eagerSelect = coinSelectOpts.fastSelect; - } + bool eagerSelect = coinSelectOpts.IsEagerSelectEnabled() || coinSelectOpts.IsFastSelectEnabled(); + const auto sumAmountToSelect = eagerSelect ? nValue + DEFAULT_TRANSACTION_MAXFEE : MAX_MONEY; if (vecSend.empty())