From eb355a4021a5dd7ef225325bbdde93e6805cbfdf Mon Sep 17 00:00:00 2001 From: Oran Juice Date: Thu, 6 Nov 2014 21:35:53 +0530 Subject: [PATCH] Added getheight --- CMakeLists.txt | 1 + src/rpc/json_rpc_handlers.h | 49 ++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78e4b426f..859f1416b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,7 @@ endif() # set(BSDI TRUE) include_directories(src contrib/epee/include external "${CMAKE_BINARY_DIR}/version") +include_directories(src/common) if(APPLE) include_directories(SYSTEM /usr/include/malloc) diff --git a/src/rpc/json_rpc_handlers.h b/src/rpc/json_rpc_handlers.h index 536220930..e0c4244c1 100644 --- a/src/rpc/json_rpc_handlers.h +++ b/src/rpc/json_rpc_handlers.h @@ -8,6 +8,8 @@ #include +#define CHECK_CORE_BUSY() if (check_core_busy()) { return ns_rpc_create_reply(buf, len, req, "{s:s}", "status", CORE_RPC_STATUS_BUSY); } + namespace RPC { cryptonote::core *core; @@ -57,14 +59,49 @@ namespace RPC port = command_line::get_arg(vm, p2p_bind_arg); } - int foo(char *buf, int len, struct ns_rpc_request *req) { - std::cout << "Method name: "; - std::cout << req->method->ptr << std::endl; - return 0; + bool check_core_busy() + { + if (p2p->get_payload_object().get_core().get_blockchain_storage().is_storing_blockchain()) + { + return true; + } + return false; } - const char *method_names[] = {"foo", NULL}; - ns_rpc_handler_t handlers[] = {foo, NULL}; + void create_map_from_request() + { + + } + + int getheight(char *buf, int len, struct ns_rpc_request *req) + { + CHECK_CORE_BUSY(); + uint64_t height = core->get_current_blockchain_height(); + // TODO: uint64_t -> long not ok ! + return ns_rpc_create_reply(buf, len, req, "{s:i,s:s}", "height", height, "status", CORE_RPC_STATUS_OK); + } + + int getblocks(char *buf, int len, struct ns_rpc_request *req) + { + CHECK_CORE_BUSY(); + if (!core->find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT)) + { + return ns_rpc_create_reply(buf, len, req, "{s:s}", "status", "Failed"); + } + req->params + } + + const char *method_names[] = { + "getheight", + "getblocks", + NULL + }; + + ns_rpc_handler_t handlers[] = { + getheight, + getblocks, + NULL + }; void ev_handler(struct ns_connection *nc, int ev, void *ev_data) {