diff --git a/src/serial_bridge_index.cpp b/src/serial_bridge_index.cpp index 81b0d7d..cbc00ee 100644 --- a/src/serial_bridge_index.cpp +++ b/src/serial_bridge_index.cpp @@ -327,6 +327,28 @@ string serial_bridge::estimated_tx_network_fee(const string &args_string) // return ret_json_from_root(root); } +string serial_bridge::estimate_rct_tx_size(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"); + } + std::size_t size = monero_fee_utils::estimate_rct_tx_size( + stoul(json_root.get("n_inputs")), + stoul(json_root.get("mixin")), + stoul(json_root.get("n_outputs")), + stoul(json_root.get("extra_size")), + json_root.get("bulletproof") + ); + std::ostringstream o; + o << size; + // + boost::property_tree::ptree root; + root.put(ret_json_key__generic_retVal(), o.str()); + // + return ret_json_from_root(root); +} // string serial_bridge::generate_key_image(const string &args_string) { diff --git a/src/serial_bridge_index.hpp b/src/serial_bridge_index.hpp index 70d4908..711f14f 100644 --- a/src/serial_bridge_index.hpp +++ b/src/serial_bridge_index.hpp @@ -62,6 +62,7 @@ namespace serial_bridge string validate_components_for_login(const string &args_string); // string estimated_tx_network_fee(const string &args_string); + string estimate_rct_tx_size(const string &args_string); // string generate_key_image(const string &args_string); // diff --git a/test/test_all.cpp b/test/test_all.cpp index 9f23299..31d3ce3 100644 --- a/test/test_all.cpp +++ b/test/test_all.cpp @@ -865,6 +865,33 @@ BOOST_AUTO_TEST_CASE(bridged__estimated_tx_network_fee) BOOST_REQUIRE(fee == 330047330); cout << "bridged__estimated_tx_network_fee: " << fee << endl; } +BOOST_AUTO_TEST_CASE(bridged__estimate_rct_tx_size) +{ + using namespace serial_bridge; + // + boost::property_tree::ptree root; + root.put("n_inputs", "1"); + root.put("mixin", "10"); + root.put("n_outputs", "2"); + root.put("extra_size", "0"); + root.put("bulletproof", "true"); + // + auto ret_string = serial_bridge::estimate_rct_tx_size(args_string_from_root(root)); + stringstream ret_stream; + ret_stream << ret_string; + boost::property_tree::ptree ret_tree; + boost::property_tree::read_json(ret_stream, ret_tree); + optional err_string = ret_tree.get_optional(ret_json_key__any__err_msg()); + if (err_string != none) { + BOOST_REQUIRE_MESSAGE(false, *err_string); + } + optional size_string = ret_tree.get_optional(ret_json_key__generic_retVal()); + BOOST_REQUIRE(size_string != none); + BOOST_REQUIRE((*size_string).size() > 0); + size_t size = stoul(*size_string); + BOOST_REQUIRE(size == 1848); + cout << "bridged__estimate_rct_tx_size: " << size << endl; +} BOOST_AUTO_TEST_CASE(bridged__generate_key_image) { using namespace serial_bridge;