<details><summary>Some suggestions for the rpc</summary><p>
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -4647,13 +4647,16 @@ static RPCHelpMan upgradewallet()
RPCHelpMan analyzerawtransaction()
{
return RPCHelpMan{"analyzerawtransaction",
- "\nCalculate the balance change resulting in the signing and broadcasting of the given transaction.\n" +
+ "\nCalculate the balance change that would result from the signing and broadcasting of the given transaction.\n" +
HELP_REQUIRING_PASSPHRASE,
{
{"hexstring", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction hex string"},
},
RPCResult{
- RPCResult::Type::NUM, "", "The wallet balance change (negative means decrease)."
+ RPCResult::Type::OBJ, "", "",
+ {
+ {RPCResult::Type::STR_AMOUNT, "balance_change", "The wallet balance change (negative means decrease)."},
+ }
},
RPCExamples{
HelpExampleCli("analyzerawtransaction", "\"myhex\"")
@@ -4673,26 +4676,31 @@ RPCHelpMan analyzerawtransaction()
// Decode the transaction
CMutableTransaction mtx;
if (!DecodeHexTx(mtx, request.params[0].get_str(), true, true)) {
- throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
+ throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Transaction hex string decoding failed. Make sure the transaction has at least one input.");
}
// Calculate changes
- CAmount changes = 0;
+ CAmount changes{0};
- // Fetch debit; we are *spending* these; if the transaction is signed and broadcast, we will lose everything in these
+ // Fetch debit; we are *spending* these; if the transaction is signed and
+ // broadcast, we will lose everything in these.
for (size_t i = 0; i < mtx.vin.size(); ++i) {
changes -= pwallet->GetDebit(mtx.vin.at(i), ISMINE_SPENDABLE);
}
- // Iterate over outputs; we are *receiving* these, if the wallet considers them "mine"; if the transaciton is signed
- // and broadcast, we will receive everything in these
+ // Iterate over outputs; we are *receiving* these, if the wallet considers
+ // them "mine"; if the transaction is signed and broadcast, we will receive
+ // everything in these.
for (size_t i = 0; i < mtx.vout.size(); ++i) {
const CTxOut& txout = mtx.vout.at(i);
if (!pwallet->IsMine(txout)) continue;
changes += txout.nValue;
}
- return ValueFromAmount(changes);
+ UniValue result(UniValue::VOBJ);
+ result.pushKV("balance_change", ValueFromAmount(changes));
+
+ return result;
}
};
}
@@ -4762,6 +4770,7 @@ static const CRPCCommand commands[] =
{ "wallet", &abandontransaction, },
{ "wallet", &abortrescan, },
{ "wallet", &addmultisigaddress, },
+ { "wallet", &analyzerawtransaction, },
{ "wallet", &backupwallet, },
{ "wallet", &bumpfee, },
{ "wallet", &psbtbumpfee, },
@@ -4816,7 +4825,6 @@ static const CRPCCommand commands[] =
{ "wallet", &unloadwallet, },
{ "wallet", &upgradewallet, },
{ "wallet", &walletcreatefundedpsbt, },
- { "wallet", &analyzerawtransaction, },
</p></details>
- return an amount? (edit: seems to give the same result)
- ISTM returning the result as a JSON object is preferred
s/transaciton/transaction/ line 4610
- sort here