From ebf97d76f0020eb027175818ebbdafd6d578aa77 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 15 Jul 2016 12:11:55 +0100 Subject: wallet: new {ex,im}port_key_images commands and RPC calls They are used to export a signed set of key images from a wallet with a private spend key, so an auditor with the matching view key may see which of those are spent, and which are not. --- src/wallet/wallet_rpc_server.cpp | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'src/wallet/wallet_rpc_server.cpp') diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index dbfb880a1..debd7056a 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -995,5 +995,71 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_export_key_images(const wallet_rpc::COMMAND_RPC_EXPORT_KEY_IMAGES::request& req, wallet_rpc::COMMAND_RPC_EXPORT_KEY_IMAGES::response& res, epee::json_rpc::error& er) + { + try + { + std::vector> ski = m_wallet.export_key_images(); + res.signed_key_images.resize(ski.size()); + for (size_t n = 0; n < ski.size(); ++n) + { + res.signed_key_images[n].key_image = epee::string_tools::pod_to_hex(ski[n].first); + res.signed_key_images[n].signature = epee::string_tools::pod_to_hex(ski[n].second); + } + } + + catch (...) + { + er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; + er.message = "Failed"; + return false; + } + + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_import_key_images(const wallet_rpc::COMMAND_RPC_IMPORT_KEY_IMAGES::request& req, wallet_rpc::COMMAND_RPC_IMPORT_KEY_IMAGES::response& res, epee::json_rpc::error& er) + { + try + { + std::vector> ski; + ski.resize(req.signed_key_images.size()); + for (size_t n = 0; n < ski.size(); ++n) + { + cryptonote::blobdata bd; + + if(!epee::string_tools::parse_hexstr_to_binbuff(req.signed_key_images[n].key_image, bd)) + { + er.code = WALLET_RPC_ERROR_CODE_WRONG_KEY_IMAGE; + er.message = "failed to parse key image"; + return false; + } + ski[n].first = *reinterpret_cast(bd.data()); + + if(!epee::string_tools::parse_hexstr_to_binbuff(req.signed_key_images[n].signature, bd)) + { + er.code = WALLET_RPC_ERROR_CODE_WRONG_SIGNATURE; + er.message = "failed to parse signature"; + return false; + } + ski[n].second = *reinterpret_cast(bd.data()); + } + uint64_t spent = 0, unspent = 0; + uint64_t height = m_wallet.import_key_images(ski, spent, unspent); + res.spent = spent; + res.unspent = unspent; + res.height = height; + } + + catch (...) + { + er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; + er.message = "Failed"; + return false; + } + + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ } -- cgit v1.2.3