diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-07-26 08:55:25 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-07-26 08:55:25 +0200 |
commit | b34506da81ed7d53c0a11cc30f6eb349fe2ca48c (patch) | |
tree | 4cd4132d8c1c57e89f8c4f417c2e078b6d9e5d44 /src/wallet/wallet_rpc_server.cpp | |
parent | Merge pull request #931 (diff) | |
parent | wallet: new {ex,im}port_key_images commands and RPC calls (diff) | |
download | monero-b34506da81ed7d53c0a11cc30f6eb349fe2ca48c.tar.xz |
Merge pull request #928
ebf97d7 wallet: new {ex,im}port_key_images commands and RPC calls (moneromooo-monero)
Diffstat (limited to 'src/wallet/wallet_rpc_server.cpp')
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
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<std::pair<crypto::key_image, crypto::signature>> 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<std::pair<crypto::key_image, crypto::signature>> 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<const crypto::key_image*>(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<const crypto::signature*>(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; + } + //------------------------------------------------------------------------------------------------------------------------------ } |