Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 598 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
HelpExampleRpc("getmempoolancestors", "\"mytxid\"")); | HelpExampleRpc("getmempoolancestors", "\"mytxid\"")); | ||||
} | } | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | TxId txid(ParseHashV(request.params[0], "parameter 1")); | ||||
LOCK(g_mempool.cs); | LOCK(g_mempool.cs); | ||||
CTxMemPool::txiter it = g_mempool.mapTx.find(hash); | CTxMemPool::txiter it = g_mempool.mapTx.find(txid); | ||||
if (it == g_mempool.mapTx.end()) { | if (it == g_mempool.mapTx.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not in mempool"); | "Transaction not in mempool"); | ||||
} | } | ||||
CTxMemPool::setEntries setAncestors; | CTxMemPool::setEntries setAncestors; | ||||
uint64_t noLimit = std::numeric_limits<uint64_t>::max(); | uint64_t noLimit = std::numeric_limits<uint64_t>::max(); | ||||
std::string dummy; | std::string dummy; | ||||
g_mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, | g_mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, | ||||
noLimit, noLimit, dummy, false); | noLimit, noLimit, dummy, false); | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
UniValue o(UniValue::VARR); | UniValue o(UniValue::VARR); | ||||
for (CTxMemPool::txiter ancestorIt : setAncestors) { | for (CTxMemPool::txiter ancestorIt : setAncestors) { | ||||
o.push_back(ancestorIt->GetTx().GetId().ToString()); | o.push_back(ancestorIt->GetTx().GetId().ToString()); | ||||
} | } | ||||
return o; | return o; | ||||
} else { | } else { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (CTxMemPool::txiter ancestorIt : setAncestors) { | for (CTxMemPool::txiter ancestorIt : setAncestors) { | ||||
const CTxMemPoolEntry &e = *ancestorIt; | const CTxMemPoolEntry &e = *ancestorIt; | ||||
const uint256 &_hash = e.GetTx().GetId(); | const TxId &_txid = e.GetTx().GetId(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(::g_mempool, info, e); | entryToJSON(::g_mempool, info, e); | ||||
o.pushKV(_hash.ToString(), info); | o.pushKV(_txid.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
static UniValue getmempooldescendants(const Config &config, | static UniValue getmempooldescendants(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
Show All 23 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
HelpExampleRpc("getmempooldescendants", "\"mytxid\"")); | HelpExampleRpc("getmempooldescendants", "\"mytxid\"")); | ||||
} | } | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | TxId txid(ParseHashV(request.params[0], "parameter 1")); | ||||
LOCK(g_mempool.cs); | LOCK(g_mempool.cs); | ||||
CTxMemPool::txiter it = g_mempool.mapTx.find(hash); | CTxMemPool::txiter it = g_mempool.mapTx.find(txid); | ||||
if (it == g_mempool.mapTx.end()) { | if (it == g_mempool.mapTx.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not in mempool"); | "Transaction not in mempool"); | ||||
} | } | ||||
CTxMemPool::setEntries setDescendants; | CTxMemPool::setEntries setDescendants; | ||||
g_mempool.CalculateDescendants(it, setDescendants); | g_mempool.CalculateDescendants(it, setDescendants); | ||||
// CTxMemPool::CalculateDescendants will include the given tx | // CTxMemPool::CalculateDescendants will include the given tx | ||||
setDescendants.erase(it); | setDescendants.erase(it); | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
UniValue o(UniValue::VARR); | UniValue o(UniValue::VARR); | ||||
for (CTxMemPool::txiter descendantIt : setDescendants) { | for (CTxMemPool::txiter descendantIt : setDescendants) { | ||||
o.push_back(descendantIt->GetTx().GetId().ToString()); | o.push_back(descendantIt->GetTx().GetId().ToString()); | ||||
} | } | ||||
return o; | return o; | ||||
} else { | } else { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (CTxMemPool::txiter descendantIt : setDescendants) { | for (CTxMemPool::txiter descendantIt : setDescendants) { | ||||
const CTxMemPoolEntry &e = *descendantIt; | const CTxMemPoolEntry &e = *descendantIt; | ||||
const uint256 &_hash = e.GetTx().GetId(); | const TxId &_txid = e.GetTx().GetId(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(::g_mempool, info, e); | entryToJSON(::g_mempool, info, e); | ||||
o.pushKV(_hash.ToString(), info); | o.pushKV(_txid.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
static UniValue getmempoolentry(const Config &config, | static UniValue getmempoolentry(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempoolentry txid\n" | "getmempoolentry txid\n" | ||||
"\nReturns mempool data for given transaction\n" | "\nReturns mempool data for given transaction\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) " | "1. \"txid\" (string, required) " | ||||
"The transaction id (must be in mempool)\n" | "The transaction id (must be in mempool)\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"{ (json object)\n" + | "{ (json object)\n" + | ||||
EntryDescriptionString() + | EntryDescriptionString() + | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getmempoolentry", "\"mytxid\"") + | HelpExampleCli("getmempoolentry", "\"mytxid\"") + | ||||
HelpExampleRpc("getmempoolentry", "\"mytxid\"")); | HelpExampleRpc("getmempoolentry", "\"mytxid\"")); | ||||
} | } | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | TxId txid(ParseHashV(request.params[0], "parameter 1")); | ||||
LOCK(g_mempool.cs); | LOCK(g_mempool.cs); | ||||
CTxMemPool::txiter it = g_mempool.mapTx.find(hash); | CTxMemPool::txiter it = g_mempool.mapTx.find(txid); | ||||
if (it == g_mempool.mapTx.end()) { | if (it == g_mempool.mapTx.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not in mempool"); | "Transaction not in mempool"); | ||||
} | } | ||||
const CTxMemPoolEntry &e = *it; | const CTxMemPoolEntry &e = *it; | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(::g_mempool, info, e); | entryToJSON(::g_mempool, info, e); | ||||
▲ Show 20 Lines • Show All 1,794 Lines • Show Last 20 Lines |