|
|
@ -64,12 +64,15 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) |
|
|
|
|
|
|
|
|
|
|
|
UniValue getrawtransaction(const JSONRPCRequest& request) |
|
|
|
UniValue getrawtransaction(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) |
|
|
|
throw std::runtime_error( |
|
|
|
throw std::runtime_error( |
|
|
|
"getrawtransaction \"txid\" ( verbose )\n" |
|
|
|
"getrawtransaction \"txid\" ( verbose \"blockhash\" )\n" |
|
|
|
|
|
|
|
|
|
|
|
"\nNOTE: By default this function only works for mempool transactions. If the -txindex option is\n" |
|
|
|
"\nNOTE: By default this function only works for mempool transactions. If the -txindex option is\n" |
|
|
|
"enabled, it also works for blockchain transactions.\n" |
|
|
|
"enabled, it also works for blockchain transactions. If the block which contains the transaction\n" |
|
|
|
|
|
|
|
"is known, its hash can be provided even for nodes without -txindex. Note that if a blockhash is\n" |
|
|
|
|
|
|
|
"provided, only that block will be searched and if the transaction is in the mempool or other\n" |
|
|
|
|
|
|
|
"blocks, or if this node does not have the given block available, the transaction will not be found.\n" |
|
|
|
"DEPRECATED: for now, it also works for transactions with unspent outputs.\n" |
|
|
|
"DEPRECATED: for now, it also works for transactions with unspent outputs.\n" |
|
|
|
|
|
|
|
|
|
|
|
"\nReturn the raw transaction data.\n" |
|
|
|
"\nReturn the raw transaction data.\n" |
|
|
@ -79,12 +82,14 @@ UniValue getrawtransaction(const JSONRPCRequest& request) |
|
|
|
"\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 a string, otherwise return a json object\n" |
|
|
|
"2. verbose (bool, optional, default=false) If false, return a string, otherwise return a json object\n" |
|
|
|
|
|
|
|
"3. \"blockhash\" (string, optional) The block in which to look for the transaction\n" |
|
|
|
|
|
|
|
|
|
|
|
"\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 'txid'\n" |
|
|
|
"\"data\" (string) The serialized, hex-encoded data for 'txid'\n" |
|
|
|
|
|
|
|
|
|
|
|
"\nResult (if verbose is set to true):\n" |
|
|
|
"\nResult (if verbose is set to true):\n" |
|
|
|
"{\n" |
|
|
|
"{\n" |
|
|
|
|
|
|
|
" \"in_active_chain\": b, (bool) Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)\n" |
|
|
|
" \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n" |
|
|
|
" \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n" |
|
|
|
" \"txid\" : \"id\", (string) The transaction id (same as provided)\n" |
|
|
|
" \"txid\" : \"id\", (string) The transaction id (same as provided)\n" |
|
|
|
" \"hash\" : \"id\", (string) The transaction hash (differs from txid for witness transactions)\n" |
|
|
|
" \"hash\" : \"id\", (string) The transaction hash (differs from txid for witness transactions)\n" |
|
|
@ -132,11 +137,15 @@ UniValue getrawtransaction(const JSONRPCRequest& request) |
|
|
|
+ HelpExampleCli("getrawtransaction", "\"mytxid\"") |
|
|
|
+ HelpExampleCli("getrawtransaction", "\"mytxid\"") |
|
|
|
+ HelpExampleCli("getrawtransaction", "\"mytxid\" true") |
|
|
|
+ HelpExampleCli("getrawtransaction", "\"mytxid\" true") |
|
|
|
+ HelpExampleRpc("getrawtransaction", "\"mytxid\", true") |
|
|
|
+ HelpExampleRpc("getrawtransaction", "\"mytxid\", true") |
|
|
|
|
|
|
|
+ HelpExampleCli("getrawtransaction", "\"mytxid\" false \"myblockhash\"") |
|
|
|
|
|
|
|
+ HelpExampleCli("getrawtransaction", "\"mytxid\" true \"myblockhash\"") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
LOCK(cs_main); |
|
|
|
LOCK(cs_main); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool in_active_chain = true; |
|
|
|
uint256 hash = ParseHashV(request.params[0], "parameter 1"); |
|
|
|
uint256 hash = ParseHashV(request.params[0], "parameter 1"); |
|
|
|
|
|
|
|
CBlockIndex* blockindex = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
bool fVerbose = false; |
|
|
|
bool fVerbose = false; |
|
|
@ -144,18 +153,42 @@ UniValue getrawtransaction(const JSONRPCRequest& request) |
|
|
|
fVerbose = request.params[1].isNum() ? (request.params[1].get_int() != 0) : request.params[1].get_bool(); |
|
|
|
fVerbose = request.params[1].isNum() ? (request.params[1].get_int() != 0) : request.params[1].get_bool(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!request.params[2].isNull()) { |
|
|
|
|
|
|
|
uint256 blockhash = ParseHashV(request.params[2], "parameter 3"); |
|
|
|
|
|
|
|
if (!blockhash.IsNull()) { |
|
|
|
|
|
|
|
BlockMap::iterator it = mapBlockIndex.find(blockhash); |
|
|
|
|
|
|
|
if (it == mapBlockIndex.end()) { |
|
|
|
|
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block hash not found"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
blockindex = it->second; |
|
|
|
|
|
|
|
in_active_chain = chainActive.Contains(blockindex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CTransactionRef tx; |
|
|
|
CTransactionRef tx; |
|
|
|
uint256 hashBlock; |
|
|
|
uint256 hash_block; |
|
|
|
if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true)) |
|
|
|
if (!GetTransaction(hash, tx, Params().GetConsensus(), hash_block, true, blockindex)) { |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string(fTxIndex ? "No such mempool or blockchain transaction" |
|
|
|
std::string errmsg; |
|
|
|
: "No such mempool transaction. Use -txindex to enable blockchain transaction queries") + |
|
|
|
if (blockindex) { |
|
|
|
". Use gettransaction for wallet transactions."); |
|
|
|
if (!(blockindex->nStatus & BLOCK_HAVE_DATA)) { |
|
|
|
|
|
|
|
throw JSONRPCError(RPC_MISC_ERROR, "Block not available"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
errmsg = "No such transaction found in the provided block"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
errmsg = fTxIndex |
|
|
|
|
|
|
|
? "No such mempool or blockchain transaction" |
|
|
|
|
|
|
|
: "No such mempool transaction. Use -txindex to enable blockchain transaction queries"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, errmsg + ". Use gettransaction for wallet transactions."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!fVerbose) |
|
|
|
if (!fVerbose) { |
|
|
|
return EncodeHexTx(*tx, RPCSerializationFlags()); |
|
|
|
return EncodeHexTx(*tx, RPCSerializationFlags()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UniValue result(UniValue::VOBJ); |
|
|
|
UniValue result(UniValue::VOBJ); |
|
|
|
TxToJSON(*tx, hashBlock, result); |
|
|
|
if (blockindex) result.push_back(Pair("in_active_chain", in_active_chain)); |
|
|
|
|
|
|
|
TxToJSON(*tx, hash_block, result); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -983,7 +1016,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request) |
|
|
|
static const CRPCCommand commands[] = |
|
|
|
static const CRPCCommand commands[] = |
|
|
|
{ // category name actor (function) argNames
|
|
|
|
{ // category name actor (function) argNames
|
|
|
|
// --------------------- ------------------------ ----------------------- ----------
|
|
|
|
// --------------------- ------------------------ ----------------------- ----------
|
|
|
|
{ "rawtransactions", "getrawtransaction", &getrawtransaction, {"txid","verbose"} }, |
|
|
|
{ "rawtransactions", "getrawtransaction", &getrawtransaction, {"txid","verbose","blockhash"} }, |
|
|
|
{ "rawtransactions", "createrawtransaction", &createrawtransaction, {"inputs","outputs","locktime","replaceable"} }, |
|
|
|
{ "rawtransactions", "createrawtransaction", &createrawtransaction, {"inputs","outputs","locktime","replaceable"} }, |
|
|
|
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, {"hexstring"} }, |
|
|
|
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, {"hexstring"} }, |
|
|
|
{ "rawtransactions", "decodescript", &decodescript, {"hexstring"} }, |
|
|
|
{ "rawtransactions", "decodescript", &decodescript, {"hexstring"} }, |
|
|
|