Compare commits

...

3 Commits

Author SHA1 Message Date
Jonathan "Duke" Leto 7912f5f15d WIP allow some rpc methods in warmup 5 years ago
Jonathan "Duke" Leto 509bc51c68 Docs about ztxrates 5 years ago
Jonathan "Duke" Leto 0989dbdc1d Lots mo docs 5 years ago
  1. 21
      src/rpc/blockchain.cpp
  2. 31
      src/rpc/server.cpp

21
src/rpc/blockchain.cpp

@ -1953,14 +1953,31 @@ UniValue getchaintxstats(const UniValue& params, bool fHelp)
"\nResult:\n"
"{\n"
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
" \"notarizations\": xxxxx, (optional, numeric) The number of notarizations in the chain.\n"
" \"notarizations\": xxxxx, (numeric) The number of notarizations in the chain. Only returned if zindex=1\n"
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
" \"window_final_block_hash\": \"...\", (string) The hash of the final block in the window.\n"
" \"window_final_block_height\": \"...\", (numeric) The height of the final block in the window.\n"
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
" \"window_notarizations\": xxxxx, (optional, numeric) Number of notarization transactions in window.\n"
" \"window_notarizations\": xxxxx, (numeric) Number of notarization transactions in window. Only returned if zindex=1\n"
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
" \"window_payments\": xxxxx, (numeric) The number of payments in the window. Only returned if \"window_block_count\" is > 0 and zindex=1.\n"
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
" \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n"
" \"shielded_txrate\": x.xx, (numeric) The average rate of shielded transactions per second in the window. Only returned if \"window_interval\" is > 0 and zindex=1.\n"
" \"shielding_txrate\": x.xx, (numeric) The average rate of shielding transactions per second in the window. Only returned if \"window_interval\" is > 0 and zindex=1.\n"
" \"deshielding_txrate\": x.xx, (numeric) The average rate of deshielding transactions per second in the window. Only returned if \"window_interval\" is > 0 and zindex=1.\n"
" \"fully_shielded_txrate\": x.xx, (numeric) The average rate of fully shielded transactions per second in the window. Only returned if \"window_interval\" is > 0 and zindex=1.\n"
" \"notarization_txrate\": x.xx, (numeric) The average rate of notarization transactions per second in the window. Only returned if \"window_interval\" is > 0 and zindex=1.\n"
" \"paymentrate\": x.xx, (numeric) The average rate of payments per second in the window. Only returned if \"window_interval\" is > 0 and zindex=1.\n"
" \"shielded_paymentrate\": x.xx, (numeric) The average rate of shielded payments per second in the window. Only returned if \"window_interval\" is > 0 and zindex=1.\n"
" \"shielded_txcount\": xxxxx, (numeric) The total number of shielded transactions in the chain up to that point. Only returned if zindex=1\n"
" \"fully_shielded_txcount\": xxxxx, (numeric) The total number of fully shielded transactions (z2z) in the chain up to that point. Only returned if zindex=1\n"
" \"shielding_txcount\": xxxxx, (numeric) The total number of shielding transactions (t=>z) in the chain up to that point. Only returned if zindex=1\n"
" \"deshielding_txcount\": xxxxx, (numeric) The total number of deshielding transactions (z=>t) in the chain up to that point. Only returned if zindex=1\n"
" \"shielded_payments\": xxxxx, (numeric) The total number of shielded payments in the chain up to that point. Only returned if zindex=1\n"
" \"fully_shielded_payments\": xxxxx, (numeric) The total number of fully shielded payments (z2z) in the chain up to that point. Only returned if zindex=1\n"
" \"shielding_payments\": xxxxx, (numeric) The total number of shielding payments (t=>z) in the chain up to that point. Only returned if zindex=1\n"
" \"deshielding_payments\": xxxxx, (numeric) The total number of deshielding payments (z=>t) in the chain up to that point. Only returned if zindex=1\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getchaintxstats", "")

31
src/rpc/server.cpp

@ -850,21 +850,36 @@ std::string JSONRPCExecBatch(const UniValue& vReq)
return ret.write() + "\n";
}
bool valid_in_warmup(const std::string method)
{
// Which methods are truly incompatible with this?
// Most RPCs allowed in safe mode are probably fine, and some other read-only ops
// TODO: use a proper struct or lookup table
if (method != "getinfo" && method != "stop" && method != "z_listaddresses" && method != "getnewaddress" && method != "z_getnewaddress")
return false;
return true;
}
UniValue CRPCTable::execute(const std::string &strMethod, const UniValue &params) const
{
// Find method
const CRPCCommand *pcmd = tableRPC[strMethod];
if (!pcmd)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
// Return immediately if in warmup
{
LOCK(cs_rpcWarmup);
if (fRPCInWarmup)
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
if (fRPCInWarmup) {
if (valid_in_warmup(pcmd->name)) {
fprintf(stderr,"Method %s allowed in warmup\n", pcmd->name.c_str() );
} else {
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
}
}
}
//printf("RPC call: %s\n", strMethod.c_str());
// Find method
const CRPCCommand *pcmd = tableRPC[strMethod];
if (!pcmd)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
// printf("RPC call: %s\n", strMethod.c_str());
g_rpcSignals.PreCommand(*pcmd);

Loading…
Cancel
Save