Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | if (pnext) { | ||||
result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue getblockcount(const Config &config, | static UniValue getblockcount(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getblockcount", | "getblockcount", | ||||
"\nReturns the number of blocks in the longest blockchain.\n", | "\nReturns the number of blocks in the longest blockchain.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"n (numeric) The current block count\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("getblockcount", "") + | ||||
"n (numeric) The current block count\n" | HelpExampleRpc("getblockcount", "")}, | ||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("getblockcount", "") + | .ToStringWithResultsAndExamples()); | ||||
HelpExampleRpc("getblockcount", "")); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return ::ChainActive().Height(); | return ::ChainActive().Height(); | ||||
} | } | ||||
static UniValue getbestblockhash(const Config &config, | static UniValue getbestblockhash(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getbestblockhash", | "getbestblockhash", | ||||
"\nReturns the hash of the best (tip) block in the " | "\nReturns the hash of the best (tip) block in the " | ||||
"longest blockchain.\n", | "longest blockchain.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"\"hex\" (string) the block hash, hex-encoded\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("getbestblockhash", "") + | ||||
"\"hex\" (string) the block hash hex-encoded\n" | HelpExampleRpc("getbestblockhash", "")}, | ||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("getbestblockhash", "") + | .ToStringWithResultsAndExamples()); | ||||
HelpExampleRpc("getbestblockhash", "")); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return ::ChainActive().Tip()->GetBlockHash().GetHex(); | return ::ChainActive().Tip()->GetBlockHash().GetHex(); | ||||
} | } | ||||
UniValue getfinalizedblockhash(const Config &config, | UniValue getfinalizedblockhash(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getfinalizedblockhash", | "getfinalizedblockhash", | ||||
"\nReturns the hash of the currently finalized block\n", | "\nReturns the hash of the currently finalized block\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"\"hex\" (string) the block hash hex-encoded\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("getfinalizedblockhash", "") + | ||||
"\"hex\" (string) the block hash hex-encoded\n"); | HelpExampleRpc("getfinalizedblockhash", "")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CBlockIndex *blockIndexFinalized = GetFinalizedBlock(); | const CBlockIndex *blockIndexFinalized = GetFinalizedBlock(); | ||||
if (blockIndexFinalized) { | if (blockIndexFinalized) { | ||||
return blockIndexFinalized->GetBlockHash().GetHex(); | return blockIndexFinalized->GetBlockHash().GetHex(); | ||||
} | } | ||||
return UniValue(UniValue::VSTR); | return UniValue(UniValue::VSTR); | ||||
} | } | ||||
void RPCNotifyBlockChange(bool ibd, const CBlockIndex *pindex) { | void RPCNotifyBlockChange(bool ibd, const CBlockIndex *pindex) { | ||||
if (pindex) { | if (pindex) { | ||||
std::lock_guard<std::mutex> lock(cs_blockchange); | std::lock_guard<std::mutex> lock(cs_blockchange); | ||||
latestblock.hash = pindex->GetBlockHash(); | latestblock.hash = pindex->GetBlockHash(); | ||||
latestblock.height = pindex->nHeight; | latestblock.height = pindex->nHeight; | ||||
} | } | ||||
cond_blockchange.notify_all(); | cond_blockchange.notify_all(); | ||||
} | } | ||||
static UniValue waitfornewblock(const Config &config, | static UniValue waitfornewblock(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(RPCHelpMan{ | ||||
RPCHelpMan{"waitfornewblock", | "waitfornewblock", | ||||
"\nWaits for a specific new block and returns useful " | "\nWaits for a specific new block and returns useful " | ||||
"info about it.\n" | "info about it.\n" | ||||
"\nReturns the current block on timeout or exit.\n", | "\nReturns the current block on timeout or exit.\n", | ||||
{ | { | ||||
{"timeout", RPCArg::Type::NUM, /* opt */ true, | {"timeout", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "0", | /* default_val */ "0", | ||||
"Time in milliseconds to wait for a response. 0 " | "Time in milliseconds to wait for a response. 0 " | ||||
"indicates no timeout."}, | "indicates no timeout."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"{ (json object)\n" | ||||
"\nResult:\n" | |||||
"{ (json object)\n" | |||||
" \"hash\" : { (string) The blockhash\n" | " \"hash\" : { (string) The blockhash\n" | ||||
" \"height\" : { (int) Block height\n" | " \"height\" : { (int) Block height\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("waitfornewblock", "1000") + | ||||
HelpExampleCli("waitfornewblock", "1000") + | HelpExampleRpc("waitfornewblock", "1000")}, | ||||
HelpExampleRpc("waitfornewblock", "1000")); | } | ||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
int timeout = 0; | int timeout = 0; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
timeout = request.params[0].get_int(); | timeout = request.params[0].get_int(); | ||||
} | } | ||||
CUpdatedBlock block; | CUpdatedBlock block; | ||||
{ | { | ||||
WAIT_LOCK(cs_blockchange, lock); | WAIT_LOCK(cs_blockchange, lock); | ||||
Show All 17 Lines | static UniValue waitfornewblock(const Config &config, | ||||
ret.pushKV("height", block.height); | ret.pushKV("height", block.height); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue waitforblock(const Config &config, | static UniValue waitforblock(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() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"waitforblock", | "waitforblock", | ||||
"\nWaits for a specific new block and returns useful " | "\nWaits for a specific new block and returns useful " | ||||
"info about it.\n" | "info about it.\n" | ||||
"\nReturns the current block on timeout or exit.\n", | "\nReturns the current block on timeout or exit.\n", | ||||
{ | { | ||||
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, | {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "Block hash to wait for."}, | /* default_val */ "", "Block hash to wait for."}, | ||||
{"timeout", RPCArg::Type::NUM, /* opt */ true, | {"timeout", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "0", | /* default_val */ "0", | ||||
"Time in milliseconds to wait for a response. 0 " | "Time in milliseconds to wait for a response. 0 " | ||||
"indicates no timeout."}, | "indicates no timeout."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"{ (json object)\n" | ||||
"\nResult:\n" | |||||
"{ (json object)\n" | |||||
" \"hash\" : { (string) The blockhash\n" | " \"hash\" : { (string) The blockhash\n" | ||||
" \"height\" : { (int) Block height\n" | " \"height\" : { (int) Block height\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("waitforblock", | ||||
HelpExampleCli("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4" | "\"0000000000079f8ef3d2c688c244eb7a4" | ||||
"570b24c9ed7b4a8c619eb02596f8862\", " | "570b24c9ed7b4a8c619eb02596f8862\", " | ||||
"1000") + | "1000") + | ||||
HelpExampleRpc("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4" | HelpExampleRpc("waitforblock", | ||||
"\"0000000000079f8ef3d2c688c244eb7a4" | |||||
"570b24c9ed7b4a8c619eb02596f8862\", " | "570b24c9ed7b4a8c619eb02596f8862\", " | ||||
"1000")); | "1000")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
int timeout = 0; | int timeout = 0; | ||||
BlockHash hash(ParseHashV(request.params[0], "blockhash")); | BlockHash hash(ParseHashV(request.params[0], "blockhash")); | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
timeout = request.params[1].get_int(); | timeout = request.params[1].get_int(); | ||||
Show All 20 Lines | static UniValue waitforblock(const Config &config, | ||||
ret.pushKV("height", block.height); | ret.pushKV("height", block.height); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue waitforblockheight(const Config &config, | static UniValue waitforblockheight(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() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"waitforblockheight", | "waitforblockheight", | ||||
"\nWaits for (at least) block height and returns the " | "\nWaits for (at least) block height and returns the " | ||||
"height and hash\nof the current tip.\n" | "height and hash\nof the current tip.\n" | ||||
"\nReturns the current block on timeout or exit.\n", | "\nReturns the current block on timeout or exit.\n", | ||||
{ | { | ||||
{"height", RPCArg::Type::NUM, /* opt */ false, | {"height", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", "Block height to wait for."}, | /* default_val */ "", "Block height to wait for."}, | ||||
{"timeout", RPCArg::Type::NUM, /* opt */ true, | {"timeout", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "0", | /* default_val */ "0", | ||||
"Time in milliseconds to wait for a response. 0 " | "Time in milliseconds to wait for a response. 0 " | ||||
"indicates no timeout."}, | "indicates no timeout."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"{ (json object)\n" | ||||
"\nResult:\n" | |||||
"{ (json object)\n" | |||||
" \"hash\" : { (string) The blockhash\n" | " \"hash\" : { (string) The blockhash\n" | ||||
" \"height\" : { (int) Block height\n" | " \"height\" : { (int) Block height\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("waitforblockheight", "\"100\", 1000") + | ||||
HelpExampleCli("waitforblockheight", "\"100\", 1000") + | HelpExampleRpc("waitforblockheight", "\"100\", 1000")}, | ||||
HelpExampleRpc("waitforblockheight", "\"100\", 1000")); | } | ||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
int timeout = 0; | int timeout = 0; | ||||
int height = request.params[0].get_int(); | int height = request.params[0].get_int(); | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
timeout = request.params[1].get_int(); | timeout = request.params[1].get_int(); | ||||
Show All 19 Lines | static UniValue waitforblockheight(const Config &config, | ||||
ret.pushKV("height", block.height); | ret.pushKV("height", block.height); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue | static UniValue | ||||
syncwithvalidationinterfacequeue(const Config &config, | syncwithvalidationinterfacequeue(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"syncwithvalidationinterfacequeue", | "syncwithvalidationinterfacequeue", | ||||
"\nWaits for the validation interface queue to catch up on " | "\nWaits for the validation interface queue to catch up on " | ||||
"everything that was there when we entered this function.\n", | "everything that was there when we entered this function.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("syncwithvalidationinterfacequeue", "") + | ||||
HelpExampleCli("syncwithvalidationinterfacequeue", "") + | HelpExampleRpc("syncwithvalidationinterfacequeue", "")}, | ||||
HelpExampleRpc("syncwithvalidationinterfacequeue", "")); | } | ||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue getdifficulty(const Config &config, | static UniValue getdifficulty(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getdifficulty", | "getdifficulty", | ||||
"\nReturns the proof-of-work difficulty as a " | "\nReturns the proof-of-work difficulty as a multiple of the " | ||||
"multiple of the minimum difficulty.\n", | "minimum difficulty.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"n.nnn (numeric) the proof-of-work difficulty as a " | ||||
"\nResult:\n" | "multiple of the minimum difficulty.\n"}, | ||||
"n.nnn (numeric) the proof-of-work " | RPCExamples{HelpExampleCli("getdifficulty", "") + | ||||
"difficulty as a multiple of the minimum " | HelpExampleRpc("getdifficulty", "")}, | ||||
"difficulty.\n" | } | ||||
"\nExamples:\n" + | .ToStringWithResultsAndExamples()); | ||||
HelpExampleCli("getdifficulty", "") + | |||||
HelpExampleRpc("getdifficulty", "")); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return GetDifficulty(::ChainActive().Tip()); | return GetDifficulty(::ChainActive().Tip()); | ||||
} | } | ||||
static std::string EntryDescriptionString() { | static std::string EntryDescriptionString() { | ||||
return " \"size\" : n, (numeric) transaction size.\n" | return " \"size\" : n, (numeric) transaction size.\n" | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | if (verbose) { | ||||
return a; | return a; | ||||
} | } | ||||
} | } | ||||
static UniValue getrawmempool(const Config &config, | static UniValue getrawmempool(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(RPCHelpMan{ | ||||
RPCHelpMan{"getrawmempool", | "getrawmempool", | ||||
"\nReturns all transaction ids in memory pool as a json " | "\nReturns all transaction ids in memory pool as a json " | ||||
"array of string transaction ids.\n" | "array of string transaction ids.\n" | ||||
"\nHint: use getmempoolentry to fetch a specific " | "\nHint: use getmempoolentry to fetch a specific " | ||||
"transaction from the mempool.\n", | "transaction from the mempool.\n", | ||||
{ | { | ||||
{"verbose", RPCArg::Type::BOOL, /* opt */ true, | {"verbose", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", | /* default_val */ "false", | ||||
"True for a json object, false for array of " | "True for a json object, false for array of " | ||||
"transaction ids"}, | "transaction ids"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"for verbose = false", | ||||
"\nResult: (for verbose = false):\n" | |||||
"[ (json array of string)\n" | "[ (json array of string)\n" | ||||
" \"transactionid\" (string) The transaction id\n" | " \"transactionid\" (string) The transaction id\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nResult: (for verbose = true):\n" | "\nResult: (for verbose = true):\n" | ||||
"{ (json object)\n" | "{ (json object)\n" | ||||
" \"transactionid\" : { (json object)\n" + | " \"transactionid\" : { (json object)\n" + | ||||
EntryDescriptionString() + | EntryDescriptionString() + | ||||
" }, ...\n" | " }, ...\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("getrawmempool", "true") + | ||||
HelpExampleCli("getrawmempool", "true") + | HelpExampleRpc("getrawmempool", "true")}, | ||||
HelpExampleRpc("getrawmempool", "true")); | } | ||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
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(::g_mempool, fVerbose); | return MempoolToJSON(::g_mempool, fVerbose); | ||||
} | } | ||||
static UniValue getmempoolancestors(const Config &config, | static UniValue getmempoolancestors(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() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getmempoolancestors", | "getmempoolancestors", | ||||
"\nIf txid is in the mempool, returns all in-mempool " | "\nIf txid is in the mempool, returns all in-mempool " | ||||
"ancestors.\n", | "ancestors.\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, | {"txid", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The transaction id (must be in mempool)"}, | "The transaction id (must be in mempool)"}, | ||||
{"verbose", RPCArg::Type::BOOL, /* opt */ true, | {"verbose", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", | /* default_val */ "false", | ||||
"True for a json object, false for array of " | "True for a json object, false for array of " | ||||
"transaction ids"}, | "transaction ids"}, | ||||
}} | }, | ||||
.ToString() + | { | ||||
"\nResult (for verbose = false):\n" | RPCResult{ | ||||
"for verbose = false", | |||||
"[ (json array of strings)\n" | "[ (json array of strings)\n" | ||||
" \"transactionid\" (string) The transaction id of an " | " \"transactionid\" (string) The transaction id " | ||||
"in-mempool ancestor transaction\n" | "of an in-mempool ancestor transaction\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n"}, | ||||
"\nResult (for verbose = true):\n" | RPCResult{"for verbose = true", | ||||
"{ (json object)\n" | "{ (json object)\n" | ||||
" \"transactionid\" : { (json object)\n" + | " \"transactionid\" : { (json object)\n" + | ||||
EntryDescriptionString() + | EntryDescriptionString() + | ||||
" }, ...\n" | " }, ...\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | }, | ||||
HelpExampleCli("getmempoolancestors", "\"mytxid\"") + | RPCExamples{HelpExampleCli("getmempoolancestors", "\"mytxid\"") + | ||||
HelpExampleRpc("getmempoolancestors", "\"mytxid\"")); | HelpExampleRpc("getmempoolancestors", "\"mytxid\"")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
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(); | ||||
} | } | ||||
TxId txid(ParseHashV(request.params[0], "parameter 1")); | TxId txid(ParseHashV(request.params[0], "parameter 1")); | ||||
Show All 31 Lines | if (!fVerbose) { | ||||
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 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getmempooldescendants", | "getmempooldescendants", | ||||
"\nIf txid is in the mempool, returns all in-mempool " | "\nIf txid is in the mempool, returns all in-mempool " | ||||
"descendants.\n", | "descendants.\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, | {"txid", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The transaction id (must be in mempool)"}, | "The transaction id (must be in mempool)"}, | ||||
{"verbose", RPCArg::Type::BOOL, /* opt */ true, | {"verbose", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", | /* default_val */ "false", | ||||
"True for a json object, false for array of " | "True for a json object, false for array of " | ||||
"transaction ids"}, | "transaction ids"}, | ||||
}} | }, | ||||
.ToString() + | { | ||||
"\nResult (for verbose = false):\n" | RPCResult{ | ||||
"for verbose = false", | |||||
"[ (json array of strings)\n" | "[ (json array of strings)\n" | ||||
" \"transactionid\" (string) The transaction id of an " | " \"transactionid\" (string) The transaction id " | ||||
"in-mempool descendant transaction\n" | "of an in-mempool descendant transaction\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n"}, | ||||
"\nResult (for verbose = true):\n" | RPCResult{"for verbose = true", | ||||
"{ (json object)\n" | "{ (json object)\n" | ||||
" \"transactionid\" : { (json object)\n" + | " \"transactionid\" : { (json object)\n" + | ||||
EntryDescriptionString() + | EntryDescriptionString() + | ||||
" }, ...\n" | " }, ...\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | }, | ||||
HelpExampleCli("getmempooldescendants", "\"mytxid\"") + | RPCExamples{HelpExampleCli("getmempooldescendants", "\"mytxid\"") + | ||||
HelpExampleRpc("getmempooldescendants", "\"mytxid\"")); | HelpExampleRpc("getmempooldescendants", "\"mytxid\"")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
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(); | ||||
} | } | ||||
TxId txid(ParseHashV(request.params[0], "parameter 1")); | TxId txid(ParseHashV(request.params[0], "parameter 1")); | ||||
Show All 29 Lines | if (!fVerbose) { | ||||
} | } | ||||
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(RPCHelpMan{ | ||||
RPCHelpMan{"getmempoolentry", | "getmempoolentry", | ||||
"\nReturns mempool data for given transaction\n", | "\nReturns mempool data for given transaction\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, | {"txid", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The transaction id (must be in mempool)"}, | "The transaction id (must be in mempool)"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"{ (json object)\n" + | ||||
"\nResult:\n" | EntryDescriptionString() + "}\n"}, | ||||
"{ (json object)\n" + | RPCExamples{HelpExampleCli("getmempoolentry", "\"mytxid\"") + | ||||
EntryDescriptionString() + | HelpExampleRpc("getmempoolentry", "\"mytxid\"")}, | ||||
"}\n" | } | ||||
"\nExamples:\n" + | .ToStringWithResultsAndExamples()); | ||||
HelpExampleCli("getmempoolentry", "\"mytxid\"") + | |||||
HelpExampleRpc("getmempoolentry", "\"mytxid\"")); | |||||
} | } | ||||
TxId txid(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(txid); | 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); | ||||
return info; | return info; | ||||
} | } | ||||
static UniValue getblockhash(const Config &config, | static UniValue getblockhash(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(RPCHelpMan{ | ||||
RPCHelpMan{"getblockhash", | "getblockhash", | ||||
"\nReturns hash of block in best-block-chain at height " | "\nReturns hash of block in best-block-chain at height " | ||||
"provided.\n", | "provided.\n", | ||||
{ | { | ||||
{"height", RPCArg::Type::NUM, /* opt */ false, | {"height", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", "The height index"}, | /* default_val */ "", "The height index"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"\"hash\" (string) The block hash\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("getblockhash", "1000") + | ||||
"\"hash\" (string) The block hash\n" | HelpExampleRpc("getblockhash", "1000")}, | ||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("getblockhash", "1000") + | .ToStringWithResultsAndExamples()); | ||||
HelpExampleRpc("getblockhash", "1000")); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
int nHeight = request.params[0].get_int(); | int nHeight = request.params[0].get_int(); | ||||
if (nHeight < 0 || nHeight > ::ChainActive().Height()) { | if (nHeight < 0 || nHeight > ::ChainActive().Height()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); | ||||
} | } | ||||
CBlockIndex *pblockindex = ::ChainActive()[nHeight]; | CBlockIndex *pblockindex = ::ChainActive()[nHeight]; | ||||
return pblockindex->GetBlockHash().GetHex(); | return pblockindex->GetBlockHash().GetHex(); | ||||
} | } | ||||
static UniValue getblockheader(const Config &config, | static UniValue getblockheader(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() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getblockheader", | "getblockheader", | ||||
"\nIf verbose is false, returns a string that is " | "\nIf verbose is false, returns a string that is " | ||||
"serialized, hex-encoded data for blockheader 'hash'.\n" | "serialized, hex-encoded data for blockheader 'hash'.\n" | ||||
"If verbose is true, returns an Object with information " | "If verbose is true, returns an Object with information " | ||||
"about blockheader <hash>.\n", | "about blockheader <hash>.\n", | ||||
{ | { | ||||
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, | {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "The block hash"}, | /* default_val */ "", "The block hash"}, | ||||
{"verbose", RPCArg::Type::BOOL, /* opt */ true, | {"verbose", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "true", | /* default_val */ "true", | ||||
"true for a json object, false for the hex-encoded data"}, | "true for a json object, false for the hex-encoded data"}, | ||||
}} | }, | ||||
.ToString() + | { | ||||
"\nResult (for verbose = true):\n" | RPCResult{ | ||||
"for verbose = true", | |||||
"{\n" | "{\n" | ||||
" \"hash\" : \"hash\", (string) the block hash (same as " | " \"hash\" : \"hash\", (string) the block hash (same " | ||||
"provided)\n" | "as provided)\n" | ||||
" \"confirmations\" : n, (numeric) The number of confirmations, " | " \"confirmations\" : n, (numeric) The number of " | ||||
"or -1 if the block is not on the main chain\n" | "confirmations, or -1 if the block is not on the main " | ||||
" \"height\" : n, (numeric) The block height or index\n" | "chain\n" | ||||
" \"height\" : n, (numeric) The block height or " | |||||
"index\n" | |||||
" \"version\" : n, (numeric) The block version\n" | " \"version\" : n, (numeric) The block version\n" | ||||
" \"versionHex\" : \"00000000\", (string) The block version " | " \"versionHex\" : \"00000000\", (string) The block " | ||||
"formatted in hexadecimal\n" | "version formatted in hexadecimal\n" | ||||
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n" | " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" | ||||
" \"time\" : ttt, (numeric) The block time in seconds " | " \"time\" : ttt, (numeric) The block time in " | ||||
"since epoch (Jan 1 1970 GMT)\n" | |||||
" \"mediantime\" : ttt, (numeric) The median block time in " | |||||
"seconds since epoch (Jan 1 1970 GMT)\n" | "seconds since epoch (Jan 1 1970 GMT)\n" | ||||
" \"mediantime\" : ttt, (numeric) The median block " | |||||
"time in seconds since epoch (Jan 1 1970 GMT)\n" | |||||
" \"nonce\" : n, (numeric) The nonce\n" | " \"nonce\" : n, (numeric) The nonce\n" | ||||
" \"bits\" : \"1d00ffff\", (string) The bits\n" | " \"bits\" : \"1d00ffff\", (string) The bits\n" | ||||
" \"difficulty\" : x.xxx, (numeric) The difficulty\n" | " \"difficulty\" : x.xxx, (numeric) The difficulty\n" | ||||
" \"chainwork\" : \"0000...1f3\" (string) Expected number of " | " \"chainwork\" : \"0000...1f3\" (string) Expected " | ||||
"hashes required to produce the current chain (in hex)\n" | "number of hashes required to produce the current chain " | ||||
" \"nTx\" : n, (numeric) The number of transactions " | "(in hex)\n" | ||||
"in the block.\n" | " \"nTx\" : n, (numeric) The number of " | ||||
" \"previousblockhash\" : \"hash\", (string) The hash of the " | "transactions in the block.\n" | ||||
"previous block\n" | " \"previousblockhash\" : \"hash\", (string) The hash of " | ||||
" \"nextblockhash\" : \"hash\", (string) The hash of the " | "the previous block\n" | ||||
"next block\n" | " \"nextblockhash\" : \"hash\", (string) The hash of " | ||||
"}\n" | "the next block\n" | ||||
"\nResult (for verbose=false):\n" | "}\n"}, | ||||
"\"data\" (string) A string that is serialized, " | RPCResult{"for verbose=false", | ||||
"hex-encoded data for block 'hash'.\n" | "\"data\" (string) A string that is " | ||||
"\nExamples:\n" + | "serialized, hex-encoded data for block 'hash'.\n"}, | ||||
HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec3" | }, | ||||
RPCExamples{HelpExampleCli("getblockheader", | |||||
"\"00000000c937983704a73af28acdec3" | |||||
"7b049d214adbda81d7e2a3dd146f6ed09" | "7b049d214adbda81d7e2a3dd146f6ed09" | ||||
"\"") + | "\"") + | ||||
HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec3" | HelpExampleRpc("getblockheader", | ||||
"\"00000000c937983704a73af28acdec3" | |||||
"7b049d214adbda81d7e2a3dd146f6ed09" | "7b049d214adbda81d7e2a3dd146f6ed09" | ||||
"\"")); | "\"")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
BlockHash hash(ParseHashV(request.params[0], "hash")); | BlockHash hash(ParseHashV(request.params[0], "hash")); | ||||
bool fVerbose = true; | bool fVerbose = true; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
Show All 37 Lines | static CBlock GetBlockChecked(const Config &config, | ||||
} | } | ||||
return block; | return block; | ||||
} | } | ||||
static UniValue getblock(const Config &config, const JSONRPCRequest &request) { | static UniValue getblock(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getblock", | "getblock", | ||||
"\nIf verbosity is 0 or false, returns a string that is " | "\nIf verbosity is 0 or false, returns a string that is " | ||||
"serialized, hex-encoded data for block 'hash'.\n" | "serialized, hex-encoded data for block 'hash'.\n" | ||||
"If verbosity is 1 or true, returns an Object with information " | "If verbosity is 1 or true, returns an Object with information " | ||||
"about block <hash>.\n" | "about block <hash>.\n" | ||||
"If verbosity is 2, returns an Object with information about " | "If verbosity is 2, returns an Object with information about " | ||||
"block <hash> and information about each transaction.\n", | "block <hash> and information about each transaction.\n", | ||||
{ | { | ||||
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, | {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "The block hash"}, | /* default_val */ "", "The block hash"}, | ||||
{"verbosity", RPCArg::Type::NUM, /* opt */ true, | {"verbosity", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "1", | /* default_val */ "1", | ||||
"0 for hex-encoded data, 1 for a json object, and 2 for " | "0 for hex-encoded data, 1 for a json object, and 2 for " | ||||
"json object with transaction data"}, | "json object with transaction data"}, | ||||
}} | }, | ||||
.ToString() + | { | ||||
"\nResult (for verbosity = 0):\n" | RPCResult{ | ||||
"\"data\" (string) A string that is serialized, " | "for verbosity = 0", | ||||
"hex-encoded data for block 'hash'.\n" | "\"data\" (string) A string that is " | ||||
"\nResult (for verbosity = 1):\n" | "serialized, hex-encoded data for block 'hash'.\n"}, | ||||
RPCResult{ | |||||
"for verbosity = 1", | |||||
"{\n" | "{\n" | ||||
" \"hash\" : \"hash\", (string) The block hash (same as " | " \"hash\" : \"hash\", (string) The block hash " | ||||
"provided)\n" | "(same as provided)\n" | ||||
" \"confirmations\" : n, (numeric) The number of confirmations, " | " \"confirmations\" : n, (numeric) The number of " | ||||
"or -1 if the block is not on the main chain\n" | "confirmations, or -1 if the block is not on the main " | ||||
"chain\n" | |||||
" \"size\" : n, (numeric) The block size\n" | " \"size\" : n, (numeric) The block size\n" | ||||
" \"height\" : n, (numeric) The block height or index\n" | " \"height\" : n, (numeric) The block height or " | ||||
"index\n" | |||||
" \"version\" : n, (numeric) The block version\n" | " \"version\" : n, (numeric) The block version\n" | ||||
" \"versionHex\" : \"00000000\", (string) The block version " | " \"versionHex\" : \"00000000\", (string) The block " | ||||
"formatted in hexadecimal\n" | "version formatted in hexadecimal\n" | ||||
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n" | " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" | ||||
" \"tx\" : [ (array of string) The transaction ids\n" | " \"tx\" : [ (array of string) The " | ||||
"transaction ids\n" | |||||
" \"transactionid\" (string) The transaction id\n" | " \"transactionid\" (string) The transaction id\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"time\" : ttt, (numeric) The block time in seconds " | " \"time\" : ttt, (numeric) The block time in " | ||||
"since epoch (Jan 1 1970 GMT)\n" | |||||
" \"mediantime\" : ttt, (numeric) The median block time in " | |||||
"seconds since epoch (Jan 1 1970 GMT)\n" | "seconds since epoch (Jan 1 1970 GMT)\n" | ||||
" \"mediantime\" : ttt, (numeric) The median block " | |||||
"time in seconds since epoch (Jan 1 1970 GMT)\n" | |||||
" \"nonce\" : n, (numeric) The nonce\n" | " \"nonce\" : n, (numeric) The nonce\n" | ||||
" \"bits\" : \"1d00ffff\", (string) The bits\n" | " \"bits\" : \"1d00ffff\", (string) The bits\n" | ||||
" \"difficulty\" : x.xxx, (numeric) The difficulty\n" | " \"difficulty\" : x.xxx, (numeric) The difficulty\n" | ||||
" \"chainwork\" : \"xxxx\", (string) Expected number of hashes " | " \"chainwork\" : \"xxxx\", (string) Expected number of " | ||||
"required to produce the chain up to this block (in hex)\n" | "hashes required to produce the chain up to this block (in " | ||||
" \"nTx\" : n, (numeric) The number of transactions " | "hex)\n" | ||||
"in the block.\n" | " \"nTx\" : n, (numeric) The number of " | ||||
" \"previousblockhash\" : \"hash\", (string) The hash of the " | "transactions in the block.\n" | ||||
"previous block\n" | " \"previousblockhash\" : \"hash\", (string) The hash of " | ||||
" \"nextblockhash\" : \"hash\" (string) The hash of the " | "the previous block\n" | ||||
"next block\n" | " \"nextblockhash\" : \"hash\" (string) The hash of " | ||||
"}\n" | "the next block\n" | ||||
"\nResult (for verbosity = 2):\n" | "}\n"}, | ||||
RPCResult{ | |||||
"for verbosity = 2", | |||||
"{\n" | "{\n" | ||||
" ..., Same output as verbosity = 1\n" | " ..., Same output as verbosity = 1\n" | ||||
" \"tx\" : [ (array of Objects) The transactions in " | " \"tx\" : [ (array of Objects) The " | ||||
"the format of the getrawtransaction RPC; different from verbosity " | "transactions in the format of the getrawtransaction RPC; " | ||||
"= 1 \"tx\" result\n" | "different from verbosity = 1 \"tx\" result\n" | ||||
" ...\n" | " ...\n" | ||||
" ],\n" | " ],\n" | ||||
" ... Same output as verbosity = 1\n" | " ... Same output as verbosity = 1\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | }, | ||||
HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d" | RPCExamples{HelpExampleCli("getblock", | ||||
"\"00000000c937983704a73af28acdec37b049d" | |||||
"214adbda81d7e2a3dd146f6ed09\"") + | "214adbda81d7e2a3dd146f6ed09\"") + | ||||
HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d" | HelpExampleRpc("getblock", | ||||
"214adbda81d7e2a3dd146f6ed09\"")); | "\"00000000c937983704a73af28acdec37b049d" | ||||
"214adbda81d7e2a3dd146f6ed09\"")}, | |||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
BlockHash hash(ParseHashV(request.params[0], "blockhash")); | BlockHash hash(ParseHashV(request.params[0], "blockhash")); | ||||
int verbosity = 1; | int verbosity = 1; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
▲ Show 20 Lines • Show All 1,785 Lines • Show Last 20 Lines |