Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
HelpExampleCli("getrawtransaction", | HelpExampleCli("getrawtransaction", | ||||
"\"mytxid\" true \"myblockhash\"")); | "\"mytxid\" true \"myblockhash\"")); | ||||
} | } | ||||
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; | ||||
if (txid == config.GetChainParams().GenesisBlock().hashMerkleRoot) { | const CChainParams ¶ms = config.GetChainParams(); | ||||
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, | ||||
"The genesis block coinbase is not considered an " | "The genesis block coinbase is not considered an " | ||||
"ordinary transaction and cannot be retrieved"); | "ordinary transaction and cannot be retrieved"); | ||||
} | } | ||||
// 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; | ||||
Show All 17 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; | ||||
uint256 hash_block; | uint256 hash_block; | ||||
if (!GetTransaction(config, txid, tx, hash_block, true, blockindex)) { | if (!GetTransaction(params.GetConsensus(), txid, tx, hash_block, true, | ||||
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) { | ||||
errmsg = "No such mempool transaction. Use -txindex to enable " | errmsg = "No such mempool transaction. Use -txindex to enable " | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | static UniValue gettxoutproof(const Config &config, | ||||
} | } | ||||
// Allow txindex to catch up if we need to query it and before we acquire | // Allow txindex to catch up if we need to query it and before we acquire | ||||
// cs_main. | // cs_main. | ||||
if (g_txindex && !pblockindex) { | if (g_txindex && !pblockindex) { | ||||
g_txindex->BlockUntilSyncedToCurrentChain(); | g_txindex->BlockUntilSyncedToCurrentChain(); | ||||
} | } | ||||
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(config, oneTxId, tx, hashBlock, false) || | if (!GetTransaction(params, oneTxId, tx, hashBlock, false) || | ||||
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"); | ||||
} | } | ||||
} | } | ||||
CBlock block; | CBlock block; | ||||
if (!ReadBlockFromDisk(block, pblockindex, config)) { | if (!ReadBlockFromDisk(block, pblockindex, params)) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); | ||||
} | } | ||||
unsigned int ntxFound = 0; | unsigned int ntxFound = 0; | ||||
for (const auto &tx : block.vtx) { | for (const auto &tx : block.vtx) { | ||||
if (setTxIds.count(tx->GetId())) { | if (setTxIds.count(tx->GetId())) { | ||||
ntxFound++; | ntxFound++; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,010 Lines • Show Last 20 Lines |