From 1fd7d422bd0177bc775da16454f5c4830525a82d Mon Sep 17 00:00:00 2001 From: Guten Ye Date: Thu, 22 Nov 2018 10:19:48 +0800 Subject: [PATCH] Added estimate_rct_tx_size --- src/serial_bridge_index.cpp | 22 ++++++++++++++++++++++ src/serial_bridge_index.hpp | 1 + test/test_all.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/src/serial_bridge_index.cpp b/src/serial_bridge_index.cpp index a41cfd8..5a8e567 100644 --- a/src/serial_bridge_index.cpp +++ b/src/serial_bridge_index.cpp @@ -417,6 +417,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 e13c9dd..b9925d4 100644 --- a/src/serial_bridge_index.hpp +++ b/src/serial_bridge_index.hpp @@ -60,6 +60,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 7c73c54..6f9349e 100644 --- a/test/test_all.cpp +++ b/test/test_all.cpp @@ -860,6 +860,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;