Skip to content

Commit

Permalink
merge bitcoin#15596: Ignore sendmany::minconf as dummy value
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Dec 13, 2021
1 parent 7cf7736 commit 06cc4bb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 59 deletions.
26 changes: 8 additions & 18 deletions src/wallet/rpcwallet.cpp
Expand Up @@ -866,9 +866,7 @@ static UniValue sendmany(const JSONRPCRequest& request)
return NullUniValue;
}

if (request.fHelp || request.params.size() < 2 || request.params.size() > 10)
throw std::runtime_error(
RPCHelpMan{"sendmany",
const RPCHelpMan help{"sendmany",
"\nSend multiple times. Amounts are double-precision floating point numbers." +
HelpRequiringPassphrase(pwallet) + "\n",
{
Expand All @@ -878,8 +876,8 @@ static UniValue sendmany(const JSONRPCRequest& request)
{"address", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The dash address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value"},
},
},
{"minconf", RPCArg::Type::NUM, /* default */ "1", "Only use the balance confirmed at least this many times."},
{"addlocked", RPCArg::Type::BOOL, /* default */ "false", "Whether to include transactions locked via InstantSend."},
{"minconf", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "Ignored dummy value"},
{"addlocked", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED_NAMED_ARG, "Ignored dummy value"},
{"comment", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "A comment"},
{"subtractfeefrom", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array with addresses.\n"
" The fee will be equally deducted from the amount of each selected address.\n"
Expand Down Expand Up @@ -909,7 +907,11 @@ static UniValue sendmany(const JSONRPCRequest& request)
"\nAs a json rpc call\n"
+ HelpExampleRpc("sendmany", "\"\", \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcG\\\":0.02}\", 6, false, \"testing\"")
},
}.ToString());
};

if (request.fHelp || request.params.size() < 2 || request.params.size() > 10) {
throw std::runtime_error(help.ToString());
}

// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
Expand All @@ -926,11 +928,6 @@ static UniValue sendmany(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\"");
}
UniValue sendTo = request.params[1].get_obj();
int nMinDepth = 1;
if (!request.params[2].isNull())
nMinDepth = request.params[2].get_int();
bool fAddLocked = (!request.params[3].isNull() && request.params[3].get_bool());

mapValue_t mapValue;
if (!request.params[4].isNull() && !request.params[4].get_str().empty())
mapValue["comment"] = request.params[4].get_str();
Expand Down Expand Up @@ -964,7 +961,6 @@ static UniValue sendmany(const JSONRPCRequest& request)
std::set<CTxDestination> destinations;
std::vector<CRecipient> vecSend;

CAmount totalAmount = 0;
std::vector<std::string> keys = sendTo.getKeys();
for (const std::string& name_ : keys) {
CTxDestination dest = DecodeDestination(name_);
Expand All @@ -981,7 +977,6 @@ static UniValue sendmany(const JSONRPCRequest& request)
CAmount nAmount = AmountFromValue(sendTo[name_]);
if (nAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
totalAmount += nAmount;

bool fSubtractFeeFromAmount = false;
for (unsigned int idx = 0; idx < subtractFeeFrom.size(); idx++) {
Expand All @@ -996,11 +991,6 @@ static UniValue sendmany(const JSONRPCRequest& request)

EnsureWalletIsUnlocked(pwallet);

// Check funds
if (totalAmount > pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, fAddLocked)) {
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Wallet has insufficient funds");
}

// Send
CReserveKey keyChange(pwallet);
CAmount nFeeRequired = 0;
Expand Down
40 changes: 0 additions & 40 deletions src/wallet/wallet.cpp
Expand Up @@ -2784,46 +2784,6 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const
return nTotal;
}

// Calculate total balance in a different way from GetBalance. The biggest
// difference is that GetBalance sums up all unspent TxOuts paying to the
// wallet, while this sums up both spent and unspent TxOuts paying to the
// wallet, and then subtracts the values of TxIns spending from the wallet. This
// also has fewer restrictions on which unconfirmed transactions are considered
// trusted.
CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, const bool fAddLocked) const
{
auto locked_chain = chain().lock();
LOCK(cs_wallet);

CAmount balance = 0;
for (const auto& entry : mapWallet) {
const CWalletTx& wtx = entry.second;
const int depth = wtx.GetDepthInMainChain(*locked_chain);
if (depth < 0 || !locked_chain->checkFinalTx(*wtx.tx) || wtx.IsImmatureCoinBase(*locked_chain)) {
continue;
}

// Loop through tx outputs and add incoming payments. For outgoing txs,
// treat change outputs specially, as part of the amount debited.
CAmount debit = wtx.GetDebit(filter);
const bool outgoing = debit > 0;
for (const CTxOut& out : wtx.tx->vout) {
if (outgoing && IsChange(out)) {
debit -= out.nValue;
} else if (IsMine(out) & filter && (depth >= minDepth || (fAddLocked && wtx.IsLockedByInstantSend()))) {
balance += out.nValue;
}
}

// For outgoing txs, subtract amount debited.
if (outgoing) {
balance -= debit;
}
}

return balance;
}

CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
{
auto locked_chain = chain().lock();
Expand Down
1 change: 0 additions & 1 deletion src/wallet/wallet.h
Expand Up @@ -999,7 +999,6 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
CAmount m_denominated_trusted{0};
CAmount m_denominated_untrusted_pending{0};
};
CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const bool fAddLocked) const;
Balance GetBalance(int min_depth = 0, const bool fAddLocked = false, const CCoinControl* coinControl = nullptr) const;

CAmount GetAnonymizableBalance(bool fSkipDenominated = false, bool fSkipUnconfirmed = true) const;
Expand Down

0 comments on commit 06cc4bb

Please sign in to comment.