| 212 | } |
| 213 | |
| 214 | static RPCMethod getrawtransaction() |
| 215 | { |
| 216 | const std::vector<RPCResult> verbosity_1_block{ |
| 217 | {RPCResult::Type::BOOL, "in_active_chain", /*optional=*/true, "Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)"}, |
| 218 | {RPCResult::Type::STR_HEX, "blockhash", /*optional=*/true, "the block hash"}, |
| 219 | {RPCResult::Type::NUM, "confirmations", /*optional=*/true, "The confirmations"}, |
| 220 | {RPCResult::Type::NUM_TIME, "blocktime", /*optional=*/true, "The block time expressed in " + UNIX_EPOCH_TIME}, |
| 221 | {RPCResult::Type::NUM, "time", /*optional=*/true, "Same as \"blocktime\""}, |
| 222 | {RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"}, |
| 223 | }; |
| 224 | const auto v2_extras = Cat<std::vector<RPCResult>>( |
| 225 | std::vector<RPCResult>{{ |
| 226 | RPCResult::Type::NUM, "fee", /*optional=*/true, |
| 227 | "transaction fee in " + CURRENCY_UNIT + ", omitted if block undo data is not available" |
| 228 | }}, |
| 229 | TxDoc({.elision_mode = ElisionMode::Silent, |
| 230 | .prevout = true, |
| 231 | .prevout_optional = true, |
| 232 | .vin_inner_elision = "Same vin fields as verbosity = 1"})); |
| 233 | return RPCMethod{ |
| 234 | "getrawtransaction", |
| 235 | |
| 236 | "By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled\n" |
| 237 | "and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.\n" |
| 238 | "If a blockhash argument is passed, it will return the transaction if\n" |
| 239 | "the specified block is available and the transaction is in that block.\n\n" |
| 240 | "Hint: Use gettransaction for wallet transactions.\n\n" |
| 241 | |
| 242 | "If verbosity is 0 or omitted, returns the serialized transaction as a hex-encoded string.\n" |
| 243 | "If verbosity is 1, returns a JSON Object with information about the transaction.\n" |
| 244 | "If verbosity is 2, returns a JSON Object with information about the transaction, including fee and prevout information.", |
| 245 | { |
| 246 | {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"}, |
| 247 | {"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", |
| 248 | RPCArgOptions{.skip_type_check = true}}, |
| 249 | {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "The block in which to look for the transaction"}, |
| 250 | }, |
| 251 | { |
| 252 | RPCResult{"if verbosity is not set or set to 0", |
| 253 | RPCResult::Type::STR, "data", "The serialized transaction as a hex-encoded string for 'txid'" |
| 254 | }, |
| 255 | RPCResult{"if verbosity is set to 1", |
| 256 | RPCResult::Type::OBJ, "", "", |
| 257 | Cat<std::vector<RPCResult>>( |
| 258 | verbosity_1_block, |
| 259 | TxDoc({.txid_field_doc="The transaction id (same as provided)"})), |
| 260 | }, |
| 261 | RPCResult{"for verbosity = 2", RPCResult::Type::OBJ, "", "", |
| 262 | Cat(ElideGroup(verbosity_1_block, "Same output as verbosity = 1"), v2_extras)}, |
| 263 | }, |
| 264 | RPCExamples{ |
| 265 | HelpExampleCli("getrawtransaction", "\"mytxid\"") |
| 266 | + HelpExampleCli("getrawtransaction", "\"mytxid\" 1") |
| 267 | + HelpExampleRpc("getrawtransaction", "\"mytxid\", 1") |
| 268 | + HelpExampleCli("getrawtransaction", "\"mytxid\" 0 \"myblockhash\"") |
| 269 | + HelpExampleCli("getrawtransaction", "\"mytxid\" 1 \"myblockhash\"") |
| 270 | + HelpExampleCli("getrawtransaction", "\"mytxid\" 2 \"myblockhash\"") |
| 271 | }, |
nothing calls this directly
no test coverage detected