1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/rpc/server.h]
pub const DEFAULT_RPC_SERIALIZE_VERSION: u32 = 1;
pub mod rpc_server {
pub fn on_started(slot: fn() -> ()) {
todo!();
/*
*/
}
pub fn on_stopped(slot: fn() -> ()) {
todo!();
/*
*/
}
}
/**
| Opaque base class for timers returned
| by NewTimerFunc.
|
| This provides no methods at the moment,
| but makes sure that delete cleans up
| the whole state.
|
*/
pub trait RPCTimerBase { }
/**
| RPC timer "driver".
|
*/
pub trait RPCTimerInterface: GetName {
}
pub trait NewTimer {
/**
| Factory function for timers.
|
| RPC will call the function to create
| a timer that will call func in *millis*
| milliseconds.
|
| -----------
| @note
|
| As the RPC mechanism is backend-neutral,
| it can use different implementations
| of timers.
|
| This is needed to cope with the case in
| which there is no HTTP server, but only
| GUI RPC console, and to break the dependency
| of pcserver on httprpc.
|
*/
fn new_timer(&mut self,
func: &mut fn() -> (),
millis: i64) -> Rc<RefCell<dyn RPCTimerBase>>;
}
pub type RpcMethodFnType = fn() -> RPCHelpMan;
pub struct RPCCommand {
pub category: String,
pub name: String,
pub actor: rpc_command::Actor,
pub arg_names: Vec<String>,
pub unique_id: libc::intptr_t,
}
pub mod rpc_command {
use super::*;
/**
| RPC method handler reading request and
| assigning result. Should return true if
| request is fully handled, false if it
| should be passed on to subsequent
| handlers.
*/
pub type Actor = fn(
request: &JSONRPCRequest,
result: &mut UniValue,
last_handler: bool
) -> bool;
}
impl RPCCommand {
/**
| Constructor taking Actor callback
| supporting multiple handlers.
|
*/
pub fn new(
category: String,
name: String,
actor: rpc_command::Actor,
args: Vec<String>,
unique_id: libc::intptr_t) -> Self {
todo!();
/*
: category(std::move(category)), name(std::move(name)), actor(std::move(actor)), argNames(std::move(args)),
unique_id(unique_id)
*/
}
/**
| Simplified constructor taking plain
|
| RpcMethodFnType function pointer.
|
*/
pub fn new_from_category_and_callback(
category: &str,
fn_: RpcMethodFnType) -> Self {
todo!();
/*
: CRPCCommand(
category,
fn().m_name,
[fn](const JSONRPCRequest& request, UniValue& result, bool) { result = fn().HandleRequest(request); return true; },
fn().GetArgNames(),
intptr_t(fn))
*/
}
}
/**
| RPC command dispatcher.
|
*/
pub struct RPCTable {
map_commands: HashMap<String,Vec<*const RPCCommand>>,
}
lazy_static!{
/*
extern CRPCTable tableRPC;
*/
}
//-------------------------------------------[.cpp/bitcoin/src/rpc/server.cpp]
lazy_static!{
/*
static Mutex g_rpc_warmup_mutex;
static std::atomic<bool> g_rpc_running{false};
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
static std::string rpcWarmupStatus GUARDED_BY(g_rpc_warmup_mutex) = "RPC server started";
/* Timer-creating functions */
static RPCTimerInterface* timerInterface = nullptr;
/* Map of name to timer. */
static Mutex g_deadline_timers_mutex;
static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers GUARDED_BY(g_deadline_timers_mutex);
*/
}
pub struct RPCCommandExecutionInfo
{
method: String,
start: i64,
}
pub struct RPCServerInfo
{
mutex: std::sync::Mutex<rpc_server_info::Inner>,
}
pub mod rpc_server_info {
use super::*;
pub struct Inner {
active_commands: LinkedList<RPCCommandExecutionInfo>,
}
}
lazy_static!{
/*
static RPCServerInfo g_rpc_server_info;
*/
}
pub struct RPCCommandExecution {
it: Box<dyn Iterator<Item = RPCCommandExecutionInfo>>,
}
impl Drop for RPCCommandExecution {
fn drop(&mut self) {
todo!();
/*
LOCK(g_rpc_server_info.mutex);
g_rpc_server_info.active_commands.erase(it);
*/
}
}
impl RPCCommandExecution {
pub fn new(method: &String) -> Self {
todo!();
/*
LOCK(g_rpc_server_info.mutex);
it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.end(), {method, GetTimeMicros()});
*/
}
}
lazy_static!{
/*
static struct CRPCSignals
{
boost::signals2::signal<c_void ()> Started;
boost::signals2::signal<c_void ()> Stopped;
} g_rpcSignals;
*/
}
//TODO: where is this?
pub struct RPCServer {}
impl RPCServer {
pub fn on_started(&mut self, slot: fn() -> ()) {
todo!();
/*
g_rpcSignals.Started.connect(slot);
*/
}
pub fn on_stopped(&mut self, slot: fn() -> ()) {
todo!();
/*
g_rpcSignals.Stopped.connect(slot);
*/
}
}
impl RPCTable {
pub fn help(&self,
str_command: &String,
helpreq: &JSONRPCRequest) -> String {
todo!();
/*
std::string strRet;
std::string category;
std::set<intptr_t> setDone;
std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
for (const auto& entry : mapCommands)
vCommands.push_back(make_pair(entry.second.front()->category + entry.first, entry.second.front()));
sort(vCommands.begin(), vCommands.end());
JSONRPCRequest jreq = helpreq;
jreq.mode = JSONRPCRequest::GET_HELP;
jreq.params = UniValue();
for (const std::pair<std::string, const CRPCCommand*>& command : vCommands)
{
const CRPCCommand *pcmd = command.second;
std::string strMethod = pcmd->name;
if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
continue;
jreq.strMethod = strMethod;
try
{
UniValue unused_result;
if (setDone.insert(pcmd->unique_id).second)
pcmd->actor(jreq, unused_result, true /* last_handler */);
}
catch (const std::exception& e)
{
// Help text is returned in an exception
std::string strHelp = std::string(e.what());
if (strCommand == "")
{
if (strHelp.find('\n') != std::string::npos)
strHelp = strHelp.substr(0, strHelp.find('\n'));
if (category != pcmd->category)
{
if (!category.empty())
strRet += "\n";
category = pcmd->category;
strRet += "== " + Capitalize(category) + " ==\n";
}
}
strRet += strHelp + "\n";
}
}
if (strRet == "")
strRet = strprintf("help: unknown command: %s\n", strCommand);
strRet = strRet.substr(0,strRet.size()-1);
return strRet;
*/
}
}
pub fn help() -> RPCHelpMan {
todo!();
/*
return RPCHelpMan{"help",
"\nList all commands, or get help for a specified command.\n",
{
{"command", RPCArg::Type::STR, RPCArg::DefaultHint{"all commands"}, "The command to get help on"},
},
{
RPCResult{RPCResult::Type::STR, "", "The help text"},
RPCResult{RPCResult::Type::ANY, "", ""},
},
RPCExamples{""},
[&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue
{
std::string strCommand;
if (jsonRequest.params.size() > 0) {
strCommand = jsonRequest.params[0].get_str();
}
if (strCommand == "dump_all_command_conversions") {
// Used for testing only, undocumented
return tableRPC.dumpArgMap(jsonRequest);
}
return tableRPC.help(strCommand, jsonRequest);
},
};
*/
}
pub fn stop() -> RPCHelpMan {
todo!();
/*
static const std::string RESULT{PACKAGE_NAME " stopping"};
return RPCHelpMan{"stop",
// Also accept the hidden 'wait' integer argument (milliseconds)
// For instance, 'stop 1000' makes the call wait 1 second before returning
// to the client (intended for testing)
"\nRequest a graceful shutdown of " PACKAGE_NAME ".",
{
{"wait", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "how long to wait in ms", "", {}, /* hidden */ true},
},
RPCResult{RPCResult::Type::STR, "", "A string with the content '" + RESULT + "'"},
RPCExamples{""},
[&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue
{
// Event loop will exit after current HTTP requests have been handled, so
// this reply will get back to the client.
StartShutdown();
if (jsonRequest.params[0].isNum()) {
UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].get_int()});
}
return RESULT;
},
};
*/
}
pub fn uptime() -> RPCHelpMan {
todo!();
/*
return RPCHelpMan{"uptime",
"\nReturns the total uptime of the server.\n",
{},
RPCResult{
RPCResult::Type::NUM, "", "The number of seconds that the server has been running"
},
RPCExamples{
HelpExampleCli("uptime", "")
+ HelpExampleRpc("uptime", "")
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
return GetTime() - GetStartupTime();
}
};
*/
}
pub fn getrpcinfo() -> RPCHelpMan {
todo!();
/*
return RPCHelpMan{"getrpcinfo",
"\nReturns details of the RPC server.\n",
{},
RPCResult{
RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::ARR, "active_commands", "All active commands",
{
{RPCResult::Type::OBJ, "", "Information about an active command",
{
{RPCResult::Type::STR, "method", "The name of the RPC command"},
{RPCResult::Type::NUM, "duration", "The running time in microseconds"},
}},
}},
{RPCResult::Type::STR, "logpath", "The complete file path to the debug log"},
}
},
RPCExamples{
HelpExampleCli("getrpcinfo", "")
+ HelpExampleRpc("getrpcinfo", "")},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
LOCK(g_rpc_server_info.mutex);
UniValue active_commands(UniValue::VARR);
for (const RPCCommandExecutionInfo& info : g_rpc_server_info.active_commands) {
UniValue entry(UniValue::VOBJ);
entry.pushKV("method", info.method);
entry.pushKV("duration", GetTimeMicros() - info.start);
active_commands.push_back(entry);
}
UniValue result(UniValue::VOBJ);
result.pushKV("active_commands", active_commands);
const std::string path = LogInstance().m_file_path.u8string();
UniValue log_path(UniValue::VSTR, path);
result.pushKV("logpath", log_path);
return result;
}
};
*/
}
lazy_static!{
/*
static const CRPCCommand vRPCCommands[] =
{ // category actor (function)
// --------------------- -----------------------
/* Overall control/query calls */
{ "control", &getrpcinfo, },
{ "control", &help, },
{ "control", &stop, },
{ "control", &uptime, },
};
*/
}
impl Default for RPCTable {
fn default() -> Self {
todo!();
/*
for (const auto& c : vRPCCommands) {
appendCommand(c.name, &c);
}
*/
}
}
impl RPCTable {
/**
| Appends a CRPCCommand to the dispatch
| table.
|
| Precondition: RPC server is not running
|
| Commands with different method names
| but the same unique_id will be considered
| aliases, and only the first registered
| method name will show up in the help text
| command listing. Aliased commands
| do not have to have the same behavior.
| Server and client code can distinguish
| between calls based on method name,
| and aliased commands can also register
| different names, types, and numbers
| of parameters.
|
*/
pub fn append_command(&mut self,
name: &String,
pcmd: *const RPCCommand) {
todo!();
/*
CHECK_NONFATAL(!IsRPCRunning()); // Only add commands before rpc is running
mapCommands[name].push_back(pcmd);
*/
}
pub fn remove_command(&mut self,
name: &String,
pcmd: *const RPCCommand) -> bool {
todo!();
/*
auto it = mapCommands.find(name);
if (it != mapCommands.end()) {
auto new_end = std::remove(it->second.begin(), it->second.end(), pcmd);
if (it->second.end() != new_end) {
it->second.erase(new_end, it->second.end());
return true;
}
}
return false;
*/
}
}
pub fn startrpc() {
todo!();
/*
LogPrint(BCLog::RPC, "Starting RPC\n");
g_rpc_running = true;
g_rpcSignals.Started();
*/
}
pub fn interruptrpc() {
todo!();
/*
static std::once_flag g_rpc_interrupt_flag;
// This function could be called twice if the GUI has been started with -server=1.
std::call_once(g_rpc_interrupt_flag, []() {
LogPrint(BCLog::RPC, "Interrupting RPC\n");
// Interrupt e.g. running longpolls
g_rpc_running = false;
});
*/
}
pub fn stoprpc() {
todo!();
/*
static std::once_flag g_rpc_stop_flag;
// This function could be called twice if the GUI has been started with -server=1.
assert(!g_rpc_running);
std::call_once(g_rpc_stop_flag, []() {
LogPrint(BCLog::RPC, "Stopping RPC\n");
[&]() { LOCK(g_deadline_timers_mutex); deadlineTimers.clear() }()
;
DeleteAuthCookie();
g_rpcSignals.Stopped();
});
*/
}
/**
| Query whether RPC is running
|
*/
pub fn is_rpc_running() -> bool {
todo!();
/*
return g_rpc_running;
*/
}
/**
| Throw JSONRPCError if RPC is not running
|
*/
pub fn rpc_interruption_point() {
todo!();
/*
if (!IsRPCRunning()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
*/
}
/**
| Set the RPC warmup status. When this
| is done, all RPC calls will error out
| immediately with RPC_IN_WARMUP.
|
*/
pub fn set_rpc_warmup_status(new_status: &String) {
todo!();
/*
LOCK(g_rpc_warmup_mutex);
rpcWarmupStatus = newStatus;
*/
}
/**
| Mark warmup as done. RPC calls will be
| processed from now on.
|
*/
pub fn set_rpc_warmup_finished() {
todo!();
/*
LOCK(g_rpc_warmup_mutex);
assert(fRPCInWarmup);
fRPCInWarmup = false;
*/
}
/**
| returns the current warmup state.
|
*/
pub fn rpc_is_in_warmup(out_status: *mut String) -> bool {
todo!();
/*
LOCK(g_rpc_warmup_mutex);
if (outStatus)
*outStatus = rpcWarmupStatus;
return fRPCInWarmup;
*/
}
pub fn is_deprecated_rpc_enabled(method: &String) -> bool {
todo!();
/*
const std::vector<std::string> enabled_methods = gArgs.GetArgs("-deprecatedrpc");
return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end();
*/
}
pub fn jsonrpc_exec_one(
jreq: JSONRPCRequest,
req: &UniValue) -> UniValue {
todo!();
/*
UniValue rpc_result(UniValue::VOBJ);
try {
jreq.parse(req);
UniValue result = tableRPC.execute(jreq);
rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
}
catch (const UniValue& objError)
{
rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
}
catch (const std::exception& e)
{
rpc_result = JSONRPCReplyObj(NullUniValue,
JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
}
return rpc_result;
*/
}
pub fn jsonrpc_exec_batch(
jreq: &JSONRPCRequest,
req: &UniValue) -> String {
todo!();
/*
UniValue ret(UniValue::VARR);
for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
ret.push_back(JSONRPCExecOne(jreq, vReq[reqIdx]));
return ret.write() + "\n";
*/
}
/**
| Process named arguments into a vector
| of positional arguments, based on the
| passed-in specification for the RPC
| call's arguments.
|
*/
#[inline] pub fn transform_named_arguments(
in_: &JSONRPCRequest,
arg_names: &Vec<String>) -> JSONRPCRequest {
todo!();
/*
JSONRPCRequest out = in;
out.params = UniValue(UniValue::VARR);
// Build a map of parameters, and remove ones that have been processed, so that we can throw a focused error if
// there is an unknown one.
const std::vector<std::string>& keys = in.params.getKeys();
const std::vector<UniValue>& values = in.params.getValues();
std::unordered_map<std::string, const UniValue*> argsIn;
for (size_t i=0; i<keys.size(); ++i) {
argsIn[keys[i]] = &values[i];
}
// Process expected parameters.
int hole = 0;
for (const std::string &argNamePattern: argNames) {
std::vector<std::string> vargNames;
boost::algorithm::split(vargNames, argNamePattern, boost::algorithm::is_any_of("|"));
auto fr = argsIn.end();
for (const std::string & argName : vargNames) {
fr = argsIn.find(argName);
if (fr != argsIn.end()) {
break;
}
}
if (fr != argsIn.end()) {
for (int i = 0; i < hole; ++i) {
// Fill hole between specified parameters with JSON nulls,
// but not at the end (for backwards compatibility with calls
// that act based on number of specified parameters).
out.params.push_back(UniValue());
}
hole = 0;
out.params.push_back(*fr->second);
argsIn.erase(fr);
} else {
hole += 1;
}
}
// If there are still arguments in the argsIn map, this is an error.
if (!argsIn.empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown named parameter " + argsIn.begin()->first);
}
// Return request with named arguments transformed to positional arguments
return out;
*/
}
pub fn execute_commands(
commands: &Vec<*const RPCCommand>,
request: &JSONRPCRequest,
result: &mut UniValue) -> bool {
todo!();
/*
for (const auto& command : commands) {
if (ExecuteCommand(*command, request, result, &command == &commands.back())) {
return true;
}
}
return false;
*/
}
impl RPCTable {
/**
| Execute a method.
|
| -----------
| @param request
|
| The JSONRPCRequest to execute
|
| -----------
| @return
|
| Result of the call. @throws an exception
| (UniValue) when an error happens.
|
*/
pub fn execute(&self, request: &JSONRPCRequest) -> UniValue {
todo!();
/*
// Return immediately if in warmup
{
LOCK(g_rpc_warmup_mutex);
if (fRPCInWarmup)
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
}
// Find method
auto it = mapCommands.find(request.strMethod);
if (it != mapCommands.end()) {
UniValue result;
if (ExecuteCommands(it->second, request, result)) {
return result;
}
}
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
*/
}
/**
| Returns a list of registered commands
|
| -----------
| @return
|
| List of registered commands.
|
*/
pub fn list_commands(&self) -> Vec<String> {
todo!();
/*
std::vector<std::string> commandList;
for (const auto& i : mapCommands) commandList.emplace_back(i.first);
return commandList;
*/
}
/**
| Return all named arguments that need
| to be converted by the client from string
| to another JSON type
|
*/
pub fn dump_arg_map(&self, args_request: &JSONRPCRequest) -> UniValue {
todo!();
/*
JSONRPCRequest request = args_request;
request.mode = JSONRPCRequest::GET_ARGS;
UniValue ret{UniValue::VARR};
for (const auto& cmd : mapCommands) {
UniValue result;
if (ExecuteCommands(cmd.second, request, result)) {
for (const auto& values : result.getValues()) {
ret.push_back(values);
}
}
}
return ret;
*/
}
}
/**
| Set the factory function for timer,
| but only, if unset
|
*/
pub fn rpc_set_timer_interface_if_unset<'a>(iface: &'a mut dyn RPCTimerInterface) {
todo!();
/*
if (!timerInterface)
timerInterface = iface;
*/
}
/**
| Set the factory function for timers
|
*/
pub fn rpc_set_timer_interface<'a>(iface: &'a mut dyn RPCTimerInterface) {
todo!();
/*
timerInterface = iface;
*/
}
/**
| Unset factory function for timers
|
*/
pub fn rpc_unset_timer_interface<'a>(iface: &'a mut dyn RPCTimerInterface) {
todo!();
/*
if (timerInterface == iface)
timerInterface = nullptr;
*/
}
/**
| Run func nSeconds from now.
|
| Overrides previous timer <name> (if
| any).
|
*/
pub fn rpc_run_later(
name: &String,
func: fn() -> (),
n_seconds: i64) {
todo!();
/*
if (!timerInterface)
throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
LOCK(g_deadline_timers_mutex);
deadlineTimers.erase(name);
LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));
*/
}
/**
| Retrieves any serialization flags
| requested in command line argument
|
*/
pub fn rpc_serialization_flags() -> i32 {
todo!();
/*
int flag = 0;
if (gArgs.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0)
flag |= SERIALIZE_TRANSACTION_NO_WITNESS;
return flag;
*/
}
lazy_static!{
/*
CRPCTable tableRPC;
*/
}
pub fn execute_command(
command: &RPCCommand,
request: &JSONRPCRequest,
result: &mut UniValue,
last_handler: bool) -> bool {
todo!();
/*
try
{
RPCCommandExecution execution(request.strMethod);
// Execute, convert arguments to array if necessary
if (request.params.isObject()) {
return command.actor(transformNamedArguments(request, command.argNames), result, last_handler);
} else {
return command.actor(request, result, last_handler);
}
}
catch (const std::exception& e)
{
throw JSONRPCError(RPC_MISC_ERROR, e.what());
}
*/
}