Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
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() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error(RPCHelpMan{ | throw std::runtime_error(RPCHelpMan{ | ||||
"getrawtransaction", | "getrawtransaction", | ||||
"\nNOTE: By default this function only works for " | "\nBy default this function only works for mempool " | ||||
"mempool transactions. If the -txindex option is\n" | "transactions. When called with a blockhash\n" | ||||
"enabled, it also works for blockchain transactions. If " | "argument, getrawtransaction will return the transaction if " | ||||
"the block which contains the transaction\n" | "the specified block is available and\n" | ||||
"is known, its hash can be provided even for nodes " | "the transaction is found in that block. When called without a " | ||||
"without -txindex. Note that if a blockhash is\n" | "blockhash argument, getrawtransaction\n" | ||||
"provided, only that block will be searched and if the " | "will return the transaction if it is in the mempool, or if " | ||||
"transaction is in the mempool or other\n" | "-txindex is enabled and the transaction\n" | ||||
"blocks, or if this node does not have the given block " | "is in a block in the blockchain.\n" | ||||
"available, the transaction will not be found.\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" | ||||
"\nIf verbose is 'true', returns an Object with information " | "\nIf verbose is 'true', returns an Object with information " | ||||
"about 'txid'.\n" | "about '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", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, | {"txid", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | static UniValue getrawtransaction(const Config &config, | ||||
bool f_txindex_ready = false; | bool f_txindex_ready = false; | ||||
if (g_txindex && !blockindex) { | if (g_txindex && !blockindex) { | ||||
f_txindex_ready = g_txindex->BlockUntilSyncedToCurrentChain(); | f_txindex_ready = g_txindex->BlockUntilSyncedToCurrentChain(); | ||||
} | } | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
BlockHash hash_block; | BlockHash hash_block; | ||||
if (!GetTransaction(txid, tx, params.GetConsensus(), hash_block, true, | if (!GetTransaction(txid, tx, params.GetConsensus(), hash_block, | ||||
blockindex)) { | blockindex)) { | ||||
std::string errmsg; | std::string errmsg; | ||||
if (blockindex) { | if (blockindex) { | ||||
if (!blockindex->nStatus.hasData()) { | if (!blockindex->nStatus.hasData()) { | ||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not available"); | throw JSONRPCError(RPC_MISC_ERROR, "Block not available"); | ||||
} | } | ||||
errmsg = "No such transaction found in the provided block"; | errmsg = "No such transaction found in the provided block"; | ||||
} else if (!g_txindex) { | } else if (!g_txindex) { | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | static UniValue gettxoutproof(const Config &config, | ||||
} | } | ||||
const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); | const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (pblockindex == nullptr) { | if (pblockindex == nullptr) { | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
if (!GetTransaction(oneTxId, tx, params, hashBlock, false) || | if (!GetTransaction(oneTxId, tx, params, hashBlock) || | ||||
hashBlock.IsNull()) { | hashBlock.IsNull()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not yet in block"); | "Transaction not yet in block"); | ||||
} | } | ||||
pblockindex = LookupBlockIndex(hashBlock); | pblockindex = LookupBlockIndex(hashBlock); | ||||
if (!pblockindex) { | if (!pblockindex) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Transaction index corrupt"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "Transaction index corrupt"); | ||||
▲ Show 20 Lines • Show All 1,716 Lines • Show Last 20 Lines |