wallet: Pass comment and comment_to to CommitTransaction
What changed, and why it matters
This is a routine internal code cleanup in Bitcoin Core's wallet. It changes how optional user comments (like a note on a payment) are passed through the code, moving them from a generic key-value map to explicit function parameters. The actual behavior—storing the comments with the transaction—remains the same. There is no security issue visible in this change.
No action required. This is a benign refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors CWallet::CommitTransaction and its callers (sendtoaddress, sendmany RPCs) to accept optional comment and comment_to strings directly instead of embedding them in a mapValue_t map. CommitTransaction still writes the same keys (‘comment’ and ‘to’) into wtx.mapValue internally. This is a pure refactoring step toward eventually removing mapValue; no logic, validation, or storage semantics change.
Changed components
src/wallet/rpc/spend.cppsrc/wallet/wallet.cppsrc/wallet/wallet.hInspect captured patch +20 / −11
diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp
index 45248713..796349a5 100644
--- a/src/wallet/rpc/spend.cpp
+++ b/src/wallet/rpc/spend.cpp
@@ -168,7 +168,7 @@ static void PreventOutdatedOptions(const UniValue& options)
}
}
-UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vector<CRecipient> &recipients, mapValue_t map_value, bool verbose)
+UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vector<CRecipient> &recipients, std::optional<std::string> comment, std::optional<std::string> comment_to, bool verbose)
{
EnsureWalletIsUnlocked(wallet);
@@ -191,7 +191,7 @@ UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vecto
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, util::ErrorString(res).original);
}
const CTransactionRef& tx = res->tx;
- wallet.CommitTransaction(tx, std::move(map_value), /*orderForm=*/{});
+ wallet.CommitTransaction(tx, /*mapValue=*/{}, /*orderForm=*/{}, /*replaces_txid=*/std::nullopt, comment, comment_to);
if (verbose) {
UniValue entry(UniValue::VOBJ);
entry.pushKV("txid", tx->GetHash().GetHex());
@@ -301,11 +301,12 @@ RPCMethod sendtoaddress()
LOCK(pwallet->cs_wallet);
// Wallet comments
- mapValue_t mapValue;
+ std::optional<std::string> comment;
+ std::optional<std::string> comment_to;
if (!request.params[2].isNull() && !request.params[2].get_str().empty())
- mapValue["comment"] = request.params[2].get_str();
+ comment = request.params[2].get_str();
if (!request.params[3].isNull() && !request.params[3].get_str().empty())
- mapValue["to"] = request.params[3].get_str();
+ comment_to = request.params[3].get_str();
CCoinControl coin_control;
if (!request.params[5].isNull()) {
@@ -332,7 +333,7 @@ RPCMethod sendtoaddress()
std::vector<CRecipient> recipients{CreateRecipients(ParseOutputs(address_amounts), sffo_set)};
const bool verbose{request.params[10].isNull() ? false : request.params[10].get_bool()};
- return SendMoney(*pwallet, coin_control, recipients, mapValue, verbose);
+ return SendMoney(*pwallet, coin_control, recipients, comment, comment_to, verbose);
},
};
}
@@ -409,9 +410,9 @@ RPCMethod sendmany()
}
UniValue sendTo = request.params[1].get_obj();
- mapValue_t mapValue;
+ std::optional<std::string> comment;
if (!request.params[3].isNull() && !request.params[3].get_str().empty())
- mapValue["comment"] = request.params[3].get_str();
+ comment = request.params[3].get_str();
CCoinControl coin_control;
if (!request.params[5].isNull()) {
@@ -426,7 +427,7 @@ RPCMethod sendmany()
);
const bool verbose{request.params[9].isNull() ? false : request.params[9].get_bool()};
- return SendMoney(*pwallet, coin_control, recipients, std::move(mapValue), verbose);
+ return SendMoney(*pwallet, coin_control, recipients, comment, /*comment_to=*/std::nullopt, verbose);
},
};
}
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index ef3eb4b2..28c055f4 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2328,7 +2328,9 @@ void CWallet::CommitTransaction(
CTransactionRef tx,
mapValue_t mapValue,
std::vector<std::pair<std::string, std::string>> orderForm,
- std::optional<Txid> replaces_txid
+ std::optional<Txid> replaces_txid,
+ std::optional<std::string> comment,
+ std::optional<std::string> comment_to
)
{
LOCK(cs_wallet);
@@ -2341,6 +2343,8 @@ void CWallet::CommitTransaction(
CHECK_NONFATAL(wtx.vOrderForm.empty());
wtx.mapValue = std::move(mapValue);
if (replaces_txid) wtx.mapValue["replaces_txid"] = replaces_txid->ToString();
+ if (comment) wtx.mapValue["comment"] = *comment;
+ if (comment_to) wtx.mapValue["to"] = *comment_to;
wtx.vOrderForm = std::move(orderForm);
return true;
});
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 9a0fc4b3..f9bfaa79 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -693,12 +693,16 @@ public:
* @param[in] mapValue key-values to be set on the transaction.
* @param[in] orderForm BIP 70 / BIP 21 order form details to be set on the transaction.
* @param[in] replaces_txid The txid of the transaction that this transaction replaces
+ * @param[in] comment The user's comment for this transaction
+ * @param[in] comment_to The comment for this transaction indicating where coins are sent to
*/
void CommitTransaction(
CTransactionRef tx,
mapValue_t mapValue,
std::vector<std::pair<std::string, std::string>> orderForm,
- std::optional<Txid> replaces_txid = std::nullopt
+ std::optional<Txid> replaces_txid = std::nullopt,
+ std::optional<std::string> comment = std::nullopt,
+ std::optional<std::string> comment_to = std::nullopt
);
/** Pass this transaction to node for optional mempool insertion and relay to peers. */
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.