Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
HelpExampleRpc("getrawtransaction", "\"mytxid\", true") + | HelpExampleRpc("getrawtransaction", "\"mytxid\", true") + | ||||
HelpExampleCli("getrawtransaction", | HelpExampleCli("getrawtransaction", | ||||
"\"mytxid\" false \"myblockhash\"") + | "\"mytxid\" false \"myblockhash\"") + | ||||
HelpExampleCli("getrawtransaction", | HelpExampleCli("getrawtransaction", | ||||
"\"mytxid\" true \"myblockhash\"")}, | "\"mytxid\" true \"myblockhash\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
const NodeContext &node = EnsureNodeContext(request.context); | |||||
bool in_active_chain = true; | bool in_active_chain = true; | ||||
TxId txid = TxId(ParseHashV(request.params[0], "parameter 1")); | TxId txid = TxId(ParseHashV(request.params[0], "parameter 1")); | ||||
CBlockIndex *blockindex = nullptr; | CBlockIndex *blockindex = nullptr; | ||||
const CChainParams ¶ms = config.GetChainParams(); | const CChainParams ¶ms = config.GetChainParams(); | ||||
if (txid == params.GenesisBlock().hashMerkleRoot) { | if (txid == params.GenesisBlock().hashMerkleRoot) { | ||||
// Special exception for the genesis block coinbase transaction | // Special exception for the genesis block coinbase transaction | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
Show All 21 Lines | if (!request.params[2].isNull()) { | ||||
in_active_chain = ::ChainActive().Contains(blockindex); | in_active_chain = ::ChainActive().Contains(blockindex); | ||||
} | } | ||||
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; | |||||
BlockHash hash_block; | BlockHash hash_block; | ||||
if (!GetTransaction(txid, tx, params.GetConsensus(), hash_block, | const CTransactionRef tx = GetTransaction( | ||||
blockindex)) { | blockindex, node.mempool, txid, params.GetConsensus(), hash_block); | ||||
if (!tx) { | |||||
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) { | ||||
errmsg = "No such mempool transaction. Use -txindex or provide a " | errmsg = "No such mempool transaction. Use -txindex or provide a " | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | if (g_txindex && !pblockindex) { | ||||
g_txindex->BlockUntilSyncedToCurrentChain(); | g_txindex->BlockUntilSyncedToCurrentChain(); | ||||
} | } | ||||
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; | const CTransactionRef tx = GetTransaction( | ||||
if (!GetTransaction(oneTxId, tx, params, hashBlock) || | /* block_index */ nullptr, | ||||
hashBlock.IsNull()) { | /* mempool */ nullptr, oneTxId, Params().GetConsensus(), hashBlock); | ||||
if (!tx || 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,814 Lines • Show Last 20 Lines |