Skip to content

Commit cbc653c

Browse files
MarcoFalkeknst
authored andcommitted
Merge bitcoin#24721: doc: Use DecodeTxDoc helper
fa58427 doc: Use DecodeTxDoc helper (MarcoFalke) Pull request description: ACKs for top commit: fanquake: ACK fa58427 shaavan: ACK fa58427 Tree-SHA512: 58652f15f858822e4fceeba6967866a4866d2455f1547f4814dd4113409da16117616c5b62eb58a6bead5433a4d28c598809a0ff79b6f377d138cad3b2edb2d7
1 parent 6bcbc72 commit cbc653c

File tree

1 file changed

+53
-86
lines changed

1 file changed

+53
-86
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 53 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <util/strencodings.h>
4545
#include <util/string.h>
4646
#include <util/translation.h>
47+
#include <util/vector.h>
4748
#include <validation.h>
4849
#include <validationinterface.h>
4950
#include <util/irange.h>
@@ -128,6 +129,50 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool
128129
entry.pushKV("chainlock", chainLock);
129130
}
130131

132+
static std::vector<RPCResult> DecodeTxDoc(const std::string& txid_field_doc)
133+
{
134+
return {
135+
{RPCResult::Type::STR_HEX, "txid", txid_field_doc},
136+
{RPCResult::Type::NUM, "size", "The serialized transaction size"},
137+
{RPCResult::Type::NUM, "version", "The version"},
138+
{RPCResult::Type::NUM, "type", "The type"},
139+
{RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
140+
{RPCResult::Type::ARR, "vin", "",
141+
{
142+
{RPCResult::Type::OBJ, "", "",
143+
{
144+
{RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, "The coinbase value (only if coinbase transaction)"},
145+
{RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id (if not coinbase transaction)"},
146+
{RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"},
147+
{RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)",
148+
{
149+
{RPCResult::Type::STR, "asm", "asm"},
150+
{RPCResult::Type::STR_HEX, "hex", "hex"},
151+
}},
152+
{RPCResult::Type::NUM, "sequence", "The script sequence number"},
153+
}},
154+
}},
155+
{RPCResult::Type::ARR, "vout", "",
156+
{
157+
{RPCResult::Type::OBJ, "", "",
158+
{
159+
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
160+
{RPCResult::Type::NUM, "n", "index"},
161+
{RPCResult::Type::OBJ, "scriptPubKey", "",
162+
{
163+
{RPCResult::Type::STR, "asm", "the asm"},
164+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
165+
{RPCResult::Type::STR_HEX, "hex", "the hex"},
166+
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
167+
{RPCResult::Type::STR, "address", /*optional=*/true, "The Dash address (only if a well-defined address exists)"},
168+
}},
169+
}},
170+
}},
171+
{RPCResult::Type::NUM, "extraPayloadSize", /*optional=*/true, "Size of DIP2 extra payload. Only present if it's a special TX"},
172+
{RPCResult::Type::STR_HEX, "extraPayload", /*optional=*/true, "Hex-encoded DIP2 extra payload data. Only present if it's a special TX"},
173+
};
174+
}
175+
131176
static std::vector<RPCArg> CreateTxDoc()
132177
{
133178
return {
@@ -167,7 +212,7 @@ static RPCHelpMan getrawtransaction()
167212
{
168213
return RPCHelpMan{
169214
"getrawtransaction",
170-
"\nReturn the raw transaction data.\n"
215+
"Return the raw transaction data.\n"
171216

172217
"\nBy default, this call only returns a transaction if it is in the mempool. If -txindex is enabled\n"
173218
"and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.\n"
@@ -176,7 +221,7 @@ static RPCHelpMan getrawtransaction()
176221
"\nHint: Use gettransaction for wallet transactions.\n"
177222

178223
"\nIf verbose is 'true', returns an Object with information about 'txid'.\n"
179-
"If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.\n",
224+
"If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.",
180225
{
181226
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
182227
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "If false, return a string, otherwise return a json object"},
@@ -187,50 +232,10 @@ static RPCHelpMan getrawtransaction()
187232
RPCResult::Type::STR, "data", "The serialized, hex-encoded data for 'txid'"
188233
},
189234
RPCResult{"if verbose is set to true",
190-
// When updating this documentation, update `decoderawtransaction` in the same way.
191235
RPCResult::Type::OBJ, "", "",
236+
Cat<std::vector<RPCResult>>(
192237
{
193238
{RPCResult::Type::BOOL, "in_active_chain", /* optional */ true, "Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)"},
194-
{RPCResult::Type::STR_HEX, "txid", "The transaction id (same as provided)"},
195-
{RPCResult::Type::NUM, "size", "The serialized transaction size"},
196-
{RPCResult::Type::NUM, "version", "The version"},
197-
{RPCResult::Type::NUM, "type", "The type"},
198-
{RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
199-
{RPCResult::Type::ARR, "vin", "",
200-
{
201-
{RPCResult::Type::OBJ, "", "",
202-
{
203-
{RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, "The coinbase value (only if coinbase transaction)"},
204-
{RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id (if not coinbase transaction)"},
205-
{RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"},
206-
{RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)",
207-
{
208-
{
209-
{RPCResult::Type::STR, "asm", "asm"},
210-
{RPCResult::Type::STR_HEX, "hex", "hex"},
211-
}},
212-
{RPCResult::Type::NUM, "sequence", "The script sequence number"},
213-
}},
214-
}},
215-
{RPCResult::Type::ARR, "vout", "",
216-
{
217-
{RPCResult::Type::OBJ, "", "",
218-
{
219-
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
220-
{RPCResult::Type::NUM, "n", "index"},
221-
{RPCResult::Type::OBJ, "scriptPubKey", "",
222-
{
223-
{RPCResult::Type::STR, "asm", "the asm"},
224-
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
225-
{RPCResult::Type::STR_HEX, "hex", "the hex"},
226-
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
227-
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
228-
}},
229-
}},
230-
}},
231-
{RPCResult::Type::NUM, "extraPayloadSize", true /*optional*/, "Size of DIP2 extra payload. Only present if it's a special TX"},
232-
{RPCResult::Type::STR_HEX, "extraPayload", true /*optional*/, "Hex-encoded DIP2 extra payload data. Only present if it's a special TX"},
233-
{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"},
234239
{RPCResult::Type::STR_HEX, "blockhash", /* optional */ true, "the block hash"},
235240
{RPCResult::Type::NUM, "height", "The block height"},
236241
{RPCResult::Type::NUM, "confirmations", /* optional */ true, "The confirmations"},
@@ -239,7 +244,9 @@ static RPCHelpMan getrawtransaction()
239244
{RPCResult::Type::BOOL, "instantlock", "Current transaction lock state"},
240245
{RPCResult::Type::BOOL, "instantlock_internal", "Current internal transaction lock state"},
241246
{RPCResult::Type::BOOL, "chainlock", "The state of the corresponding block ChainLock"},
242-
}
247+
{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"},
248+
},
249+
DecodeTxDoc(/*txid_field_doc=*/"The transaction id (same as provided)")),
243250
},
244251
},
245252
RPCExamples{
@@ -738,53 +745,13 @@ static RPCHelpMan createrawtransaction()
738745
static RPCHelpMan decoderawtransaction()
739746
{
740747
return RPCHelpMan{"decoderawtransaction",
741-
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
748+
"Return a JSON object representing the serialized, hex-encoded transaction.",
742749
{
743750
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"},
744751
},
745752
RPCResult{
746753
RPCResult::Type::OBJ, "", "",
747-
{
748-
// When updating this documentation, update `getrawtransaction` in the same way.
749-
{RPCResult::Type::STR_HEX, "txid", "The transaction id"},
750-
{RPCResult::Type::NUM, "size", "The serialized transaction size"},
751-
{RPCResult::Type::NUM, "version", "The version"},
752-
{RPCResult::Type::NUM, "type", "The type"},
753-
{RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
754-
{RPCResult::Type::ARR, "vin", "",
755-
{
756-
{RPCResult::Type::OBJ, "", "",
757-
{
758-
{RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, "The coinbase value (only if coinbase transaction)"},
759-
{RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id (if not coinbase transaction)"},
760-
{RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"},
761-
{RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)",
762-
{
763-
{RPCResult::Type::STR, "asm", "asm"},
764-
{RPCResult::Type::STR_HEX, "hex", "hex"},
765-
}},
766-
{RPCResult::Type::NUM, "sequence", "The script sequence number"},
767-
}},
768-
}},
769-
{RPCResult::Type::ARR, "vout", "",
770-
{
771-
{RPCResult::Type::OBJ, "", "",
772-
{
773-
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
774-
{RPCResult::Type::NUM, "n", "index"},
775-
{RPCResult::Type::OBJ, "scriptPubKey", "",
776-
{
777-
{RPCResult::Type::STR, "asm", "the asm"},
778-
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
779-
{RPCResult::Type::STR_HEX, "hex", "the hex"},
780-
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
781-
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
782-
}},
783-
}},
784-
}},
785-
{RPCResult::Type::NUM, "extraPayloadSize", true /*optional*/, "Size of DIP2 extra payload. Only present if it's a special TX"},
786-
{RPCResult::Type::STR_HEX, "extraPayload", true /*optional*/, "Hex-encoded DIP2 extra payload data. Only present if it's a special TX"},
787-
}
754+
DecodeTxDoc(/*txid_field_doc=*/"The transaction id"),
788755
},
789756
RPCExamples{
790757
HelpExampleCli("decoderawtransaction", "\"hexstring\"")

0 commit comments

Comments
 (0)