From 83bbea4c7f47d05933ec1b5baca2e9724561e49c Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 11 Aug 2015 10:49:15 +0100 Subject: Add a is_key_image_spent daemon command and RPC call --- src/daemon/command_parser_executor.cpp | 20 +++++++++++++++++++ src/daemon/command_parser_executor.h | 2 ++ src/daemon/command_server.cpp | 5 +++++ src/daemon/rpc_command_executor.cpp | 36 ++++++++++++++++++++++++++++++++++ src/daemon/rpc_command_executor.h | 2 ++ 5 files changed, 65 insertions(+) (limited to 'src/daemon') diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 58cb475ab..e6666c443 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -180,6 +180,26 @@ bool t_command_parser_executor::print_transaction(const std::vector return true; } +bool t_command_parser_executor::is_key_image_spent(const std::vector& args) +{ + if (args.empty()) + { + std::cout << "expected: is_key_image_spent " << std::endl; + return true; + } + + const std::string& str = args.front(); + crypto::key_image ki; + crypto::hash hash; + if (parse_hash256(str, hash)) + { + memcpy(&ki, &hash, sizeof(ki)); + m_executor.is_key_image_spent(ki); + } + + return true; +} + bool t_command_parser_executor::print_transaction_pool_long(const std::vector& args) { if (!args.empty()) return false; diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h index d1e299877..ddc207cfe 100644 --- a/src/daemon/command_parser_executor.h +++ b/src/daemon/command_parser_executor.h @@ -75,6 +75,8 @@ public: bool print_transaction(const std::vector& args); + bool is_key_image_spent(const std::vector& args); + bool print_transaction_pool_long(const std::vector& args); bool print_transaction_pool_short(const std::vector& args); diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp index 65bceff75..047b52c3e 100644 --- a/src/daemon/command_server.cpp +++ b/src/daemon/command_server.cpp @@ -84,6 +84,11 @@ t_command_server::t_command_server( , std::bind(&t_command_parser_executor::print_transaction, &m_parser, p::_1) , "Print transaction, print_tx " ); + m_command_lookup.set_handler( + "is_key_image_spent" + , std::bind(&t_command_parser_executor::is_key_image_spent, &m_parser, p::_1) + , "Prints whether a given key image is in the spent key images set, is_key_image_spent " + ); m_command_lookup.set_handler( "start_mining" , std::bind(&t_command_parser_executor::start_mining, &m_parser, p::_1) diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 2f3a6b4d5..62f254c76 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -520,6 +520,42 @@ bool t_rpc_command_executor::print_transaction(crypto::hash transaction_hash) { return true; } +bool t_rpc_command_executor::is_key_image_spent(const crypto::key_image &ki) { + cryptonote::COMMAND_RPC_IS_KEY_IMAGE_SPENT::request req; + cryptonote::COMMAND_RPC_IS_KEY_IMAGE_SPENT::response res; + + std::string fail_message = "Problem checkking key image"; + + req.key_images.push_back(epee::string_tools::pod_to_hex(ki)); + if (m_is_rpc) + { + if (!m_rpc_client->rpc_request(req, res, "/is_key_image_spent", fail_message.c_str())) + { + return true; + } + } + else + { + if (!m_rpc_server->on_is_key_image_spent(req, res)) + { + tools::fail_msg_writer() << fail_message.c_str(); + return true; + } + } + + if (1 == res.spent_status.size()) + { + // first as hex + tools::success_msg_writer() << ki << ": " << (res.spent_status.front() ? "spent" : "unspent"); + } + else + { + tools::fail_msg_writer() << "key image status could not be determined" << std::endl; + } + + return true; +} + bool t_rpc_command_executor::print_transaction_pool_long() { cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::request req; cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::response res; diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index 5e332f3fc..b40a67bf8 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -87,6 +87,8 @@ public: bool print_transaction(crypto::hash transaction_hash); + bool is_key_image_spent(const crypto::key_image &ki); + bool print_transaction_pool_long(); bool print_transaction_pool_short(); -- cgit v1.2.3