Skip to content

Commit

Permalink
Pass coin select opts all the way through
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl committed Mar 17, 2023
1 parent 00a1c73 commit 62abe58
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 117 deletions.
24 changes: 14 additions & 10 deletions src/masternodes/mn_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ static std::optional<CTxIn> GetAuthInputOnly(CWalletCoinsUnlocker& pwallet, CTxD
return txin;
}

static CTransactionRef CreateAuthTx(CWalletCoinsUnlocker& pwallet, std::set<CScript> const & auths, int32_t txVersion) {
static CTransactionRef CreateAuthTx(CWalletCoinsUnlocker& pwallet,
std::set<CScript> const & auths,
int32_t txVersion,
const CoinSelectionOptions &coinSelectOpts) {

CMutableTransaction mtx(txVersion);
CCoinControl coinControl;

Expand All @@ -337,7 +341,7 @@ static CTransactionRef CreateAuthTx(CWalletCoinsUnlocker& pwallet, std::set<CScr
// Create output to cover 1KB transaction
CTxOut authOut(GetMinimumFee(*pwallet, 1000, coinControl, nullptr), auth);
mtx.vout.push_back(authOut);
fund(mtx, pwallet, {}, &coinControl);
fund(mtx, pwallet, {}, &coinControl, coinSelectOpts);

// AutoAuthPrep, auth output and change
if (mtx.vout.size() == 3) {
Expand All @@ -356,7 +360,7 @@ static CTransactionRef CreateAuthTx(CWalletCoinsUnlocker& pwallet, std::set<CScr
mtx.vout.push_back(authOut);
}

return fund(mtx, pwallet, {}, &coinControl), sign(mtx, pwallet, {});
return fund(mtx, pwallet, {}, &coinControl, coinSelectOpts), sign(mtx, pwallet, {});
}

static std::optional<CTxIn> GetAnyFoundationAuthInput(CWalletCoinsUnlocker& pwallet) {
Expand Down Expand Up @@ -428,7 +432,7 @@ std::vector<CTxIn> 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());
}
Expand Down Expand Up @@ -593,7 +597,7 @@ UniValue setgov(const JSONRPCRequest& request) {
UniValue const & txInputs = request.params[1];
CTransactionRef optAuthTx;
std::set<CScript> 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;

Expand All @@ -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);
Expand Down Expand Up @@ -685,7 +689,7 @@ UniValue unsetgov(const JSONRPCRequest& request) {
UniValue const & txInputs = request.params[1];
CTransactionRef optAuthTx;
std::set<CScript> 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;

Expand All @@ -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);
Expand Down Expand Up @@ -807,7 +811,7 @@ UniValue setgovheight(const JSONRPCRequest& request) {
UniValue const & txInputs = request.params[2];
CTransactionRef optAuthTx;
std::set<CScript> 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;

Expand All @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions src/masternodes/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -806,7 +806,7 @@ UniValue accounttoaccount(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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;

Expand All @@ -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);
Expand Down Expand Up @@ -911,7 +911,7 @@ UniValue accounttoutxos(const JSONRPCRequest& request) {
const UniValue &txInputs = request.params[2];
CTransactionRef optAuthTx;
std::set<CScript> 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;

Expand All @@ -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
{
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2230,14 +2230,14 @@ UniValue HandleSendDFIP2201BTCInput(const JSONRPCRequest& request, CWalletCoinsU

CTransactionRef optAuthTx;
std::set<CScript> 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);
Expand Down Expand Up @@ -2379,14 +2379,14 @@ UniValue futureswap(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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);
Expand Down Expand Up @@ -2470,14 +2470,14 @@ UniValue withdrawfutureswap(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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);
Expand Down
28 changes: 14 additions & 14 deletions src/masternodes/rpc_icxorderbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ UniValue icxcreateorder(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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));

Expand All @@ -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);
Expand Down Expand Up @@ -465,7 +465,7 @@ UniValue icxmakeoffer(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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));

Expand All @@ -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);
Expand Down Expand Up @@ -607,7 +607,7 @@ UniValue icxsubmitdfchtlc(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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));

Expand All @@ -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);
Expand Down Expand Up @@ -753,7 +753,7 @@ UniValue icxsubmitexthtlc(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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));

Expand All @@ -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);
Expand Down Expand Up @@ -857,7 +857,7 @@ UniValue icxclaimdfchtlc(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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));

Expand All @@ -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);
Expand Down Expand Up @@ -953,7 +953,7 @@ UniValue icxcloseorder(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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));

Expand All @@ -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);
Expand Down Expand Up @@ -1050,7 +1050,7 @@ UniValue icxcloseoffer(const JSONRPCRequest& request) {

CTransactionRef optAuthTx;
std::set<CScript> 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));

Expand All @@ -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);
Expand Down
Loading

0 comments on commit 62abe58

Please sign in to comment.