Added estimate_rct_tx_size

pull/12/head
Guten Ye 6 years ago
parent 41fbc55521
commit 1fd7d422bd

@ -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<string>("n_inputs")),
stoul(json_root.get<string>("mixin")),
stoul(json_root.get<string>("n_outputs")),
stoul(json_root.get<string>("extra_size")),
json_root.get<bool>("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)
{

@ -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);
//

@ -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<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> size_string = ret_tree.get_optional<string>(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;

Loading…
Cancel
Save