Skip to content

Commit 97115de

Browse files
committed
doc: Refactor/Format getrawtransaction RPC docs and add ScriptPubKeyDoc function
1 parent cbcad79 commit 97115de

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue&
8080
}
8181
}
8282

83+
static std::vector<RPCResult> ScriptPubKeyDoc() {
84+
return
85+
{
86+
{RPCResult::Type::STR, "asm", "Disassembly of the public key script"},
87+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
88+
{RPCResult::Type::STR_HEX, "hex", "The raw public key script bytes, hex-encoded"},
89+
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
90+
{RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"},
91+
};
92+
}
93+
8394
static std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
8495
{
8596
return {
@@ -115,14 +126,7 @@ static std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
115126
{
116127
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
117128
{RPCResult::Type::NUM, "n", "index"},
118-
{RPCResult::Type::OBJ, "scriptPubKey", "",
119-
{
120-
{RPCResult::Type::STR, "asm", "Disassembly of the public key script"},
121-
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
122-
{RPCResult::Type::STR_HEX, "hex", "The raw public key script bytes, hex-encoded"},
123-
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
124-
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
125-
}},
129+
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
126130
}},
127131
}},
128132
};
@@ -177,8 +181,8 @@ static RPCHelpMan getrawtransaction()
177181
"Hint: Use gettransaction for wallet transactions.\n\n"
178182

179183
"If verbosity is 0 or omitted, returns the serialized transaction as a hex-encoded string.\n"
180-
"If verbosity is 1, returns a JSON Object with information about transaction.\n"
181-
"If verbosity is 2, returns a JSON Object with information about transaction, including fee and prevout information.",
184+
"If verbosity is 1, returns a JSON Object with information about the transaction.\n"
185+
"If verbosity is 2, returns a JSON Object with information about the transaction, including fee and prevout information.",
182186
{
183187
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
184188
{"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{0}, "0 for hex-encoded data, 1 for a JSON object, and 2 for JSON object with fee and prevout"},
@@ -189,7 +193,6 @@ static RPCHelpMan getrawtransaction()
189193
RPCResult::Type::STR, "data", "The serialized transaction as a hex-encoded string for 'txid'"
190194
},
191195
RPCResult{"if verbosity is set to 1",
192-
// When updating this documentation, update `decoderawtransaction` in the same way.
193196
RPCResult::Type::OBJ, "", "",
194197
Cat<std::vector<RPCResult>>(
195198
{
@@ -206,25 +209,18 @@ static RPCHelpMan getrawtransaction()
206209
RPCResult::Type::OBJ, "", "",
207210
{
208211
{RPCResult::Type::ELISION, "", "Same output as verbosity = 1"},
209-
{RPCResult::Type::NUM, "fee", /* optional */ true, "transaction fee in " + CURRENCY_UNIT + ", omitted if block undo data is not available"},
212+
{RPCResult::Type::NUM, "fee", /*optional=*/true, "transaction fee in " + CURRENCY_UNIT + ", omitted if block undo data is not available"},
210213
{RPCResult::Type::ARR, "vin", "",
211214
{
212-
{RPCResult::Type::OBJ, "", /* optional */ true, "utxo being spent, omitted if block undo data is not available",
215+
{RPCResult::Type::OBJ, "", "utxo being spent, omitted if block undo data is not available",
213216
{
214217
{RPCResult::Type::ELISION, "", "Same output as verbosity = 1"},
215-
{RPCResult::Type::OBJ, "prevout", "Only if undo information is available)",
218+
{RPCResult::Type::OBJ, "prevout", /*optional=*/true, "Only if undo information is available)",
216219
{
217220
{RPCResult::Type::BOOL, "generated", "Coinbase or not"},
218221
{RPCResult::Type::NUM, "height", "The height of the prevout"},
219222
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
220-
{RPCResult::Type::OBJ, "scriptPubKey", "",
221-
{
222-
{RPCResult::Type::STR, "asm", "Disassembly of the public key script"},
223-
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
224-
{RPCResult::Type::STR_HEX, "hex", "The raw public key script bytes, hex-encoded"},
225-
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
226-
{RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"},
227-
}},
223+
{RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
228224
}},
229225
}},
230226
}},

0 commit comments

Comments
 (0)