Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 580 Lines • ▼ Show 20 Lines | static void entryToJSON(const CTxMemPool &pool, UniValue &info, | ||||
for (const CTxMemPoolEntry &child : children) { | for (const CTxMemPoolEntry &child : children) { | ||||
spent.push_back(child.GetTx().GetId().ToString()); | spent.push_back(child.GetTx().GetId().ToString()); | ||||
} | } | ||||
info.pushKV("spentby", spent); | info.pushKV("spentby", spent); | ||||
info.pushKV("unbroadcast", pool.IsUnbroadcastTx(tx.GetId())); | info.pushKV("unbroadcast", pool.IsUnbroadcastTx(tx.GetId())); | ||||
} | } | ||||
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose) { | UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, | ||||
bool include_mempool_sequence) { | |||||
if (verbose) { | if (verbose) { | ||||
if (include_mempool_sequence) { | |||||
throw JSONRPCError( | |||||
RPC_INVALID_PARAMETER, | |||||
"Verbose results cannot contain mempool sequence values."); | |||||
} | |||||
LOCK(pool.cs); | LOCK(pool.cs); | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (const CTxMemPoolEntry &e : pool.mapTx) { | for (const CTxMemPoolEntry &e : pool.mapTx) { | ||||
const uint256 &txid = e.GetTx().GetId(); | const uint256 &txid = e.GetTx().GetId(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(pool, info, e); | entryToJSON(pool, info, e); | ||||
// Mempool has unique entries so there is no advantage in using | // Mempool has unique entries so there is no advantage in using | ||||
// UniValue::pushKV, which checks if the key already exists in O(N). | // UniValue::pushKV, which checks if the key already exists in O(N). | ||||
// UniValue::__pushKV is used instead which currently is O(1). | // UniValue::__pushKV is used instead which currently is O(1). | ||||
o.__pushKV(txid.ToString(), info); | o.__pushKV(txid.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} else { | } else { | ||||
uint64_t mempool_sequence; | |||||
std::vector<uint256> vtxids; | std::vector<uint256> vtxids; | ||||
{ | |||||
LOCK(pool.cs); | |||||
pool.queryHashes(vtxids); | pool.queryHashes(vtxids); | ||||
mempool_sequence = pool.GetSequence(); | |||||
} | |||||
UniValue a(UniValue::VARR); | UniValue a(UniValue::VARR); | ||||
for (const uint256 &txid : vtxids) { | for (const uint256 &txid : vtxids) { | ||||
a.push_back(txid.ToString()); | a.push_back(txid.ToString()); | ||||
} | } | ||||
if (!include_mempool_sequence) { | |||||
return a; | return a; | ||||
} else { | |||||
UniValue o(UniValue::VOBJ); | |||||
o.pushKV("txids", a); | |||||
o.pushKV("mempool_sequence", mempool_sequence); | |||||
return o; | |||||
} | |||||
} | } | ||||
} | } | ||||
static RPCHelpMan getrawmempool() { | static RPCHelpMan getrawmempool() { | ||||
return RPCHelpMan{ | return RPCHelpMan{ | ||||
"getrawmempool", | "getrawmempool", | ||||
"Returns all transaction ids in memory pool as a json array of " | "Returns all transaction ids in memory pool as a json array of " | ||||
"string transaction ids.\n" | "string transaction ids.\n" | ||||
"\nHint: use getmempoolentry to fetch a specific transaction from the " | "\nHint: use getmempoolentry to fetch a specific transaction from the " | ||||
"mempool.\n", | "mempool.\n", | ||||
{ | { | ||||
{"verbose", RPCArg::Type::BOOL, /* default */ "false", | {"verbose", RPCArg::Type::BOOL, /* default */ "false", | ||||
"True for a json object, false for array of transaction ids"}, | "True for a json object, false for array of transaction ids"}, | ||||
{"mempool_sequence", RPCArg::Type::BOOL, /* default */ "false", | |||||
"If verbose=false, returns a json object with transaction list " | |||||
"and mempool sequence number attached."}, | |||||
}, | }, | ||||
{ | { | ||||
RPCResult{"for verbose = false", | RPCResult{"for verbose = false", | ||||
RPCResult::Type::ARR, | RPCResult::Type::ARR, | ||||
"", | "", | ||||
"", | "", | ||||
{ | { | ||||
{RPCResult::Type::STR_HEX, "", "The transaction id"}, | {RPCResult::Type::STR_HEX, "", "The transaction id"}, | ||||
}}, | }}, | ||||
RPCResult{"for verbose = true", | RPCResult{"for verbose = true", | ||||
RPCResult::Type::OBJ_DYN, | RPCResult::Type::OBJ_DYN, | ||||
"", | "", | ||||
"", | "", | ||||
{ | { | ||||
{RPCResult::Type::OBJ, "transactionid", "", | {RPCResult::Type::OBJ, "transactionid", "", | ||||
MempoolEntryDescription()}, | MempoolEntryDescription()}, | ||||
}}, | }}, | ||||
RPCResult{ | |||||
"for verbose = false and mempool_sequence = true", | |||||
RPCResult::Type::OBJ, | |||||
"", | |||||
"", | |||||
{ | |||||
{RPCResult::Type::ARR, | |||||
"txids", | |||||
"", | |||||
{ | |||||
{RPCResult::Type::STR_HEX, "", "The transaction id"}, | |||||
}}, | |||||
{RPCResult::Type::NUM, "mempool_sequence", | |||||
"The mempool sequence value."}, | |||||
}}, | |||||
}, | }, | ||||
RPCExamples{HelpExampleCli("getrawmempool", "true") + | RPCExamples{HelpExampleCli("getrawmempool", "true") + | ||||
HelpExampleRpc("getrawmempool", "true")}, | HelpExampleRpc("getrawmempool", "true")}, | ||||
[&](const RPCHelpMan &self, const Config &config, | [&](const RPCHelpMan &self, const Config &config, | ||||
const JSONRPCRequest &request) -> UniValue { | const JSONRPCRequest &request) -> UniValue { | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
fVerbose = request.params[0].get_bool(); | fVerbose = request.params[0].get_bool(); | ||||
} | } | ||||
return MempoolToJSON(EnsureMemPool(request.context), fVerbose); | bool include_mempool_sequence = false; | ||||
if (!request.params[1].isNull()) { | |||||
include_mempool_sequence = request.params[1].get_bool(); | |||||
} | |||||
return MempoolToJSON(EnsureMemPool(request.context), fVerbose, | |||||
include_mempool_sequence); | |||||
}, | }, | ||||
}; | }; | ||||
} | } | ||||
static RPCHelpMan getmempoolancestors() { | static RPCHelpMan getmempoolancestors() { | ||||
return RPCHelpMan{ | return RPCHelpMan{ | ||||
"getmempoolancestors", | "getmempoolancestors", | ||||
"If txid is in the mempool, returns all in-mempool ancestors.\n", | "If txid is in the mempool, returns all in-mempool ancestors.\n", | ||||
▲ Show 20 Lines • Show All 2,368 Lines • ▼ Show 20 Lines | static const CRPCCommand commands[] = { | ||||
{ "blockchain", "getblockstats", getblockstats, {"hash_or_height","stats"} }, | { "blockchain", "getblockstats", getblockstats, {"hash_or_height","stats"} }, | ||||
{ "blockchain", "getchaintips", getchaintips, {} }, | { "blockchain", "getchaintips", getchaintips, {} }, | ||||
{ "blockchain", "getchaintxstats", getchaintxstats, {"nblocks", "blockhash"} }, | { "blockchain", "getchaintxstats", getchaintxstats, {"nblocks", "blockhash"} }, | ||||
{ "blockchain", "getdifficulty", getdifficulty, {} }, | { "blockchain", "getdifficulty", getdifficulty, {} }, | ||||
{ "blockchain", "getmempoolancestors", getmempoolancestors, {"txid","verbose"} }, | { "blockchain", "getmempoolancestors", getmempoolancestors, {"txid","verbose"} }, | ||||
{ "blockchain", "getmempooldescendants", getmempooldescendants, {"txid","verbose"} }, | { "blockchain", "getmempooldescendants", getmempooldescendants, {"txid","verbose"} }, | ||||
{ "blockchain", "getmempoolentry", getmempoolentry, {"txid"} }, | { "blockchain", "getmempoolentry", getmempoolentry, {"txid"} }, | ||||
{ "blockchain", "getmempoolinfo", getmempoolinfo, {} }, | { "blockchain", "getmempoolinfo", getmempoolinfo, {} }, | ||||
{ "blockchain", "getrawmempool", getrawmempool, {"verbose"} }, | { "blockchain", "getrawmempool", getrawmempool, {"verbose", "mempool_sequence"} }, | ||||
{ "blockchain", "gettxout", gettxout, {"txid","n","include_mempool"} }, | { "blockchain", "gettxout", gettxout, {"txid","n","include_mempool"} }, | ||||
{ "blockchain", "gettxoutsetinfo", gettxoutsetinfo, {"hash_type"} }, | { "blockchain", "gettxoutsetinfo", gettxoutsetinfo, {"hash_type"} }, | ||||
{ "blockchain", "pruneblockchain", pruneblockchain, {"height"} }, | { "blockchain", "pruneblockchain", pruneblockchain, {"height"} }, | ||||
{ "blockchain", "savemempool", savemempool, {} }, | { "blockchain", "savemempool", savemempool, {} }, | ||||
{ "blockchain", "verifychain", verifychain, {"checklevel","nblocks"} }, | { "blockchain", "verifychain", verifychain, {"checklevel","nblocks"} }, | ||||
{ "blockchain", "preciousblock", preciousblock, {"blockhash"} }, | { "blockchain", "preciousblock", preciousblock, {"blockhash"} }, | ||||
{ "blockchain", "scantxoutset", scantxoutset, {"action", "scanobjects"} }, | { "blockchain", "scantxoutset", scantxoutset, {"action", "scanobjects"} }, | ||||
{ "blockchain", "getblockfilter", getblockfilter, {"blockhash", "filtertype"} }, | { "blockchain", "getblockfilter", getblockfilter, {"blockhash", "filtertype"} }, | ||||
Show All 19 Lines |