Skip to content

Commit

Permalink
Merge pull request zcash#6926 from daira/createtransaction-init
Browse files Browse the repository at this point in the history
Ensure out-reference parameters of `CWallet::CreateTransaction` are initialized
  • Loading branch information
nuttycom authored Aug 22, 2024
2 parents bd841d8 + 4ca1c79 commit 7ac8c9a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,18 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr

// Create and send the transaction
CReserveKey reservekey(pwalletMain);
CAmount nFeeRequired;
CAmount nFeeRequired = -1;
std::string strError;
vector<CRecipient> vecSend;
int nChangePosRet = -1;
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount};
vecSend.push_back(recipient);
if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError)) {
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) {
bool fCreated;
{
int nChangePosRet = -1; // never used
fCreated = pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError);
}
if (!fCreated) {
if (!fSubtractFeeFromAmount && nFeeRequired >= 0 && nValue + nFeeRequired > curBalance) {
strError = strprintf("Error: Insufficient funds to pay the fee. This transaction needs to spend %s "
"plus a fee of at least %s, but only %s is available",
DisplayMoney(nValue),
Expand Down Expand Up @@ -1348,10 +1352,13 @@ UniValue sendmany(const UniValue& params, bool fHelp)

// Send
CReserveKey keyChange(pwalletMain);
CAmount nFeeRequired = 0;
int nChangePosRet = -1;
string strFailReason;
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason);
bool fCreated;
{
CAmount nFeeRequired = -1; // never used
int nChangePosRet = -1; // never used
fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason);
}
if (!fCreated)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
CValidationState state;
Expand Down Expand Up @@ -2989,7 +2996,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
includeWatching = true;

CMutableTransaction tx(origTx);
CAmount nFee;
CAmount nFee = -1;
string strFailReason;
int nChangePos = -1;
if(!pwalletMain->FundTransaction(tx, nFee, nChangePos, strFailReason, includeWatching))
Expand Down

0 comments on commit 7ac8c9a

Please sign in to comment.