Skip to content

Commit 060bb55

Browse files
committed
rpc: add decoded tx details to gettransaction with extra wallet fields
1 parent ad1c3bd commit 060bb55

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static RPCHelpMan getrawtransaction()
242242
{RPCResult::Type::NUM, "time", /*optional=*/true, "Same as \"blocktime\""},
243243
{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"},
244244
},
245-
DecodeTxDoc(/*txid_field_doc=*/"The transaction id (same as provided)")),
245+
DecodeTxDoc(/*txid_field_doc=*/"The transaction id (same as provided)", /*wallet=*/false)),
246246
},
247247
RPCResult{"for verbosity = 2",
248248
RPCResult::Type::OBJ, "", "",
@@ -415,7 +415,7 @@ static RPCHelpMan decoderawtransaction()
415415
},
416416
RPCResult{
417417
RPCResult::Type::OBJ, "", "",
418-
DecodeTxDoc(/*txid_field_doc=*/"The transaction id"),
418+
DecodeTxDoc(/*txid_field_doc=*/"The transaction id", /*wallet=*/false),
419419
},
420420
RPCExamples{
421421
HelpExampleCli("decoderawtransaction", "\"hexstring\"")

src/rpc/rawtransaction_util.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const
335335
}
336336
}
337337

338-
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
338+
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc, bool wallet)
339339
{
340340
return {
341341
{RPCResult::Type::STR_HEX, "txid", txid_field_doc},
@@ -366,13 +366,17 @@ std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
366366
}},
367367
{RPCResult::Type::ARR, "vout", "",
368368
{
369-
{RPCResult::Type::OBJ, "", "",
370-
{
371-
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
372-
{RPCResult::Type::NUM, "n", "index"},
373-
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
374-
{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only if wallet transaction and true for selected rpcwallet)"},
375-
}},
369+
{RPCResult::Type::OBJ, "", "", Cat(
370+
{
371+
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
372+
{RPCResult::Type::NUM, "n", "index"},
373+
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
374+
},
375+
wallet ?
376+
std::vector<RPCResult>{{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only present if true)"}} :
377+
std::vector<RPCResult>{}
378+
)
379+
},
376380
}},
377381
};
378382
}

src/rpc/rawtransaction_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in);
5656
/** Create a transaction from univalue parameters */
5757
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf);
5858

59-
/** Explain the UniValue "decoded" transaction object **/
60-
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc);
59+
/** Explain the UniValue "decoded" transaction object, may include extra fields if processed by wallet **/
60+
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc, bool wallet);
6161

6262
#endif // BITCOIN_RPC_RAWTRANSACTION_UTIL_H

src/wallet/rpc/transactions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <key_io.h>
77
#include <policy/rbf.h>
88
#include <rpc/util.h>
9+
#include <rpc/rawtransaction_util.h>
910
#include <rpc/blockchain.h>
1011
#include <util/vector.h>
1112
#include <wallet/receive.h>
@@ -738,7 +739,7 @@ RPCHelpMan gettransaction()
738739
{RPCResult::Type::STR_HEX, "hex", "Raw data for transaction"},
739740
{RPCResult::Type::OBJ, "decoded", /*optional=*/true, "The decoded transaction (only present when `verbose` is passed)",
740741
{
741-
{RPCResult::Type::ELISION, "", "Equivalent to the RPC decoderawtransaction method, or the RPC getrawtransaction method when `verbose` is passed."},
742+
DecodeTxDoc(/*txid_field_doc=*/"The transaction id", /*wallet=*/true),
742743
}},
743744
RESULT_LAST_PROCESSED_BLOCK,
744745
})

0 commit comments

Comments
 (0)