Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | if (!hashBlock.IsNull()) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static UniValue getrawtransaction(const Config &config, | static UniValue getrawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getrawtransaction \"txid\" ( verbose )\n" | "getrawtransaction \"txid\" ( verbose ( \"blockid\" ) )\n" | ||||
"\nNOTE: By default this function only works for mempool " | "\nNOTE: By default this function only works for mempool " | ||||
"transactions. If the -txindex option is\n" | "transactions. If the -txindex option is\n" | ||||
"enabled, it also works for blockchain transactions.\n" | "enabled, it also works for blockchain transactions.\n" | ||||
"DEPRECATED: for now, it also works for transactions with unspent " | "DEPRECATED: for now, it also works for transactions with unspent " | ||||
"outputs.\n" | "outputs.\n" | ||||
"\nReturn the raw transaction data.\n" | "\nReturn the raw transaction data.\n" | ||||
"\nIf verbose is 'true', returns an Object with information about " | "\nIf verbose is 'true', returns an Object with information about " | ||||
"'txid'.\n" | "'txid'.\n" | ||||
"If verbose is 'false' or omitted, returns a string that is " | "If verbose is 'false' or omitted, returns a string that is " | ||||
"serialized, hex-encoded data for 'txid'.\n" | "serialized, hex-encoded data for 'txid'.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id\n" | "1. \"txid\" (string, required) The transaction id\n" | ||||
"2. verbose (bool, optional, default=false) If false, return " | "2. verbose (bool, optional, default=false) If false, return " | ||||
"a string, otherwise return a json object\n" | "a string, otherwise return a json object\n" | ||||
"3. \"blockid\" (string, optional) The block id; allows " | |||||
"retrieval when run without -txindex option (e.g. pruning enabled)" | |||||
"\nResult (if verbose is not set or set to false):\n" | "\nResult (if verbose is not set or set to false):\n" | ||||
"\"data\" (string) The serialized, hex-encoded data for " | "\"data\" (string) The serialized, hex-encoded data for " | ||||
"'txid'\n" | "'txid'\n" | ||||
"\nResult (if verbose is set to true):\n" | "\nResult (if verbose is set to true):\n" | ||||
"{\n" | "{\n" | ||||
" \"hex\" : \"data\", (string) The serialized, hex-encoded " | " \"hex\" : \"data\", (string) The serialized, hex-encoded " | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"seconds since epoch (Jan 1 1970 GMT)\n" | "seconds since epoch (Jan 1 1970 GMT)\n" | ||||
" \"blocktime\" : ttt (numeric) The block time in seconds " | " \"blocktime\" : ttt (numeric) The block time in seconds " | ||||
"since epoch (Jan 1 1970 GMT)\n" | "since epoch (Jan 1 1970 GMT)\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getrawtransaction", "\"mytxid\"") + | HelpExampleCli("getrawtransaction", "\"mytxid\"") + | ||||
HelpExampleCli("getrawtransaction", "\"mytxid\" true") + | HelpExampleCli("getrawtransaction", "\"mytxid\" true") + | ||||
HelpExampleCli("getrawtransaction", | |||||
"\"mytxid\" true \"myblockid\"") + | |||||
HelpExampleRpc("getrawtransaction", "\"mytxid\", true")); | HelpExampleRpc("getrawtransaction", "\"mytxid\", true")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
TxId txid = TxId(ParseHashV(request.params[0], "parameter 1")); | TxId txid = TxId(ParseHashV(request.params[0], "parameter 1")); | ||||
// Accept either a bool (true) or a num (>=1) to indicate verbose output. | // Accept either a bool (true) or a num (>=1) to indicate verbose output. | ||||
Show All 9 Lines | if (request.params.size() > 1) { | ||||
} | } | ||||
} else { | } else { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_TYPE_ERROR, | RPC_TYPE_ERROR, | ||||
"Invalid type provided. Verbose parameter must be a boolean."); | "Invalid type provided. Verbose parameter must be a boolean."); | ||||
} | } | ||||
} | } | ||||
CBlockIndex *blockindex = nullptr; | |||||
if (request.params.size() > 2) { | |||||
uint256 blockhash = ParseHashV(request.params[2], "parameter 3"); | |||||
BlockMap::iterator it = mapBlockIndex.find(blockhash); | |||||
if (it == mapBlockIndex.end()) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
"Block hash not found"); | |||||
} | |||||
blockindex = it->second; | |||||
} | |||||
CTransactionRef tx; | CTransactionRef tx; | ||||
uint256 hashBlock; | uint256 hashBlock; | ||||
if (!GetTransaction(config, txid, tx, hashBlock, true)) { | if (!GetTransaction(config, txid, tx, hashBlock, true, blockindex)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_ADDRESS_OR_KEY, | RPC_INVALID_ADDRESS_OR_KEY, | ||||
std::string(fTxIndex ? "No such mempool or blockchain transaction" | std::string(fTxIndex ? "No such mempool or blockchain transaction" | ||||
: "No such mempool transaction. Use -txindex " | : "No such mempool transaction. Use -txindex " | ||||
"to enable blockchain transaction queries") + | "to enable blockchain transaction queries, " | ||||
"or specify the containing blockid") + | |||||
". Use gettransaction for wallet transactions."); | ". Use gettransaction for wallet transactions."); | ||||
} | } | ||||
std::string strHex = EncodeHexTx(*tx, RPCSerializationFlags()); | std::string strHex = EncodeHexTx(*tx, RPCSerializationFlags()); | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
return strHex; | return strHex; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 949 Lines • Show Last 20 Lines |