bridged__generate_key_image

pull/29/head
Paul Shapiro 6 years ago
parent 8f25d553a2
commit ecb9d701c3

@ -41,6 +41,7 @@
#include "monero_address_utils.hpp" // TODO: split this/these out into a different namespaces or file so this file can scale (leave file for shared utils)
#include "monero_paymentID_utils.hpp"
#include "monero_wallet_utils.hpp"
#include "monero_key_image_utils.hpp"
#include "wallet_errors.h"
#include "string_tools.h"
//
@ -424,7 +425,41 @@ string serial_bridge::estimated_tx_network_fee(const string &args_string)
//
string serial_bridge::generate_key_image(const string &args_string)
{
boost::property_tree::ptree json_root;
if (!parsed_json_root(args_string, json_root)) {
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
crypto::secret_key sec_viewKey{};
crypto::secret_key sec_spendKey{};
crypto::public_key pub_spendKey{};
crypto::public_key tx_pub_key{};
{
bool r = false;
r = epee::string_tools::hex_to_pod(std::string(json_root.get<string>("sec_viewKey_string")), sec_viewKey);
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Invalid secret view key");
r = epee::string_tools::hex_to_pod(std::string(json_root.get<string>("sec_spendKey_string")), sec_spendKey);
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Invalid secret spend key");
r = epee::string_tools::hex_to_pod(std::string(json_root.get<string>("pub_spendKey_string")), pub_spendKey);
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Invalid public spend key");
r = epee::string_tools::hex_to_pod(std::string(json_root.get<string>("tx_pub_key")), tx_pub_key);
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Invalid tx pub key");
}
monero_key_image_utils::KeyImageRetVals retVals;
bool r = monero_key_image_utils::new__key_image(
pub_spendKey, sec_spendKey, sec_viewKey, tx_pub_key,
stoull(json_root.get<string>("out_index")),
retVals
);
if (!r) {
return error_ret_json_from_message("Unable to generate key image"); // TODO: return error string? (unwrap optional)
}
boost::property_tree::ptree root;
root.put(ret_json_key__generic_retVal(), epee::string_tools::pod_to_hex(retVals.calculated_key_image));
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
//
return ret_ss.str();
}
//
//

@ -687,6 +687,7 @@ BOOST_AUTO_TEST_CASE(bridged__mnemonic_from_seed)
BOOST_REQUIRE((*mnemonic_string).size() > 0);
cout << "bridged__mnemonic_from_seed: mnemonic: " << *mnemonic_string << endl;
}
//
BOOST_AUTO_TEST_CASE(bridged__seed_and_keys_from_mnemonic)
{
using namespace serial_bridge;
@ -858,5 +859,29 @@ BOOST_AUTO_TEST_CASE(bridged__calculate_fee)
BOOST_AUTO_TEST_CASE(bridged__generate_key_image)
{
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("sec_viewKey_string", "7bea1907940afdd480eff7c4bcadb478a0fbb626df9e3ed74ae801e18f53e104");
root.put("sec_spendKey_string", "4e6d43cd03812b803c6f3206689f5fcc910005fc7e91d50d79b0776dbefcd803");
root.put("pub_spendKey_string", "3eb884d3440d71326e27cc07a861b873e72abd339feb654660c36a008a0028b3");
root.put("tx_pub_key", "fc7f85bf64c6e4f6aa612dbc8ddb1bb77a9283656e9c2b9e777c9519798622b2");
root.put("out_index", "0");
//
stringstream args_ss;
boost::property_tree::write_json(args_ss, root);
auto ret_string = serial_bridge::generate_key_image(args_ss.str());
stringstream ret_stream;
ret_stream << ret_string;
boost::property_tree::ptree ret_tree;
boost::property_tree::read_json(ret_stream, ret_tree);
optional<string> err_string = ret_tree.get_optional<string>(ret_json_key__any__err_msg());
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<string> key_image_string = ret_tree.get_optional<string>(ret_json_key__generic_retVal());
BOOST_REQUIRE(key_image_string != none);
BOOST_REQUIRE((*key_image_string).size() > 0);
BOOST_REQUIRE(*key_image_string == "ae30ee23051dc0bdf10303fbd3b7d8035a958079eb66516b1740f2c9b02c804e");
cout << "bridged__generate_key_image: " << *key_image_string << endl;
}

Loading…
Cancel
Save