mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-18 12:01:02 +01:00
rpc: add decoded tx details to gettransaction with extra wallet fields
This commit is contained in:
@@ -242,7 +242,7 @@ static RPCHelpMan getrawtransaction()
|
||||
{RPCResult::Type::NUM, "time", /*optional=*/true, "Same as \"blocktime\""},
|
||||
{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"},
|
||||
},
|
||||
DecodeTxDoc(/*txid_field_doc=*/"The transaction id (same as provided)")),
|
||||
DecodeTxDoc(/*txid_field_doc=*/"The transaction id (same as provided)", /*wallet=*/false)),
|
||||
},
|
||||
RPCResult{"for verbosity = 2",
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
@@ -415,7 +415,7 @@ static RPCHelpMan decoderawtransaction()
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
DecodeTxDoc(/*txid_field_doc=*/"The transaction id"),
|
||||
DecodeTxDoc(/*txid_field_doc=*/"The transaction id", /*wallet=*/false),
|
||||
},
|
||||
RPCExamples{
|
||||
HelpExampleCli("decoderawtransaction", "\"hexstring\"")
|
||||
|
||||
@@ -335,7 +335,7 @@ void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
|
||||
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc, bool wallet)
|
||||
{
|
||||
return {
|
||||
{RPCResult::Type::STR_HEX, "txid", txid_field_doc},
|
||||
@@ -366,13 +366,17 @@ std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
|
||||
}},
|
||||
{RPCResult::Type::ARR, "vout", "",
|
||||
{
|
||||
{RPCResult::Type::OBJ, "", "",
|
||||
{
|
||||
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
|
||||
{RPCResult::Type::NUM, "n", "index"},
|
||||
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
|
||||
{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only if wallet transaction and true for selected rpcwallet)"},
|
||||
}},
|
||||
{RPCResult::Type::OBJ, "", "", Cat(
|
||||
{
|
||||
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
|
||||
{RPCResult::Type::NUM, "n", "index"},
|
||||
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
|
||||
},
|
||||
wallet ?
|
||||
std::vector<RPCResult>{{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only present if true)"}} :
|
||||
std::vector<RPCResult>{}
|
||||
)
|
||||
},
|
||||
}},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in);
|
||||
/** Create a transaction from univalue parameters */
|
||||
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf);
|
||||
|
||||
/** Explain the UniValue "decoded" transaction object **/
|
||||
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc);
|
||||
/** Explain the UniValue "decoded" transaction object, may include extra fields if processed by wallet **/
|
||||
std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc, bool wallet);
|
||||
|
||||
#endif // BITCOIN_RPC_RAWTRANSACTION_UTIL_H
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <key_io.h>
|
||||
#include <policy/rbf.h>
|
||||
#include <rpc/util.h>
|
||||
#include <rpc/rawtransaction_util.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <util/vector.h>
|
||||
#include <wallet/receive.h>
|
||||
@@ -738,7 +739,7 @@ RPCHelpMan gettransaction()
|
||||
{RPCResult::Type::STR_HEX, "hex", "Raw data for transaction"},
|
||||
{RPCResult::Type::OBJ, "decoded", /*optional=*/true, "The decoded transaction (only present when `verbose` is passed)",
|
||||
{
|
||||
{RPCResult::Type::ELISION, "", "Equivalent to the RPC decoderawtransaction method, or the RPC getrawtransaction method when `verbose` is passed."},
|
||||
DecodeTxDoc(/*txid_field_doc=*/"The transaction id", /*wallet=*/true),
|
||||
}},
|
||||
RESULT_LAST_PROCESSED_BLOCK,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user