bridged a few integrated and sub address accessors

pull/29/head
Paul Shapiro 6 years ago
parent 53a12f1d28
commit 6c19abf379

@ -75,13 +75,17 @@ DecodedAddress_RetVals address_utils::decodedAddress(const string &addressString
bool address_utils::isSubAddress(const string &addressString, cryptonote::network_type nettype)
{
DecodedAddress_RetVals retVals = decodedAddress(addressString, nettype);
//
if (retVals.did_error) {
return false; // just treat it as a no
}
return retVals.isSubaddress;
}
bool address_utils::isIntegratedAddress(const string &addressString, cryptonote::network_type nettype)
{
DecodedAddress_RetVals retVals = decodedAddress(addressString, nettype);
//
if (retVals.did_error) {
return false; // just treat it as a no
}
return retVals.paymentID_string != boost::none;
}
//

@ -145,11 +145,35 @@ string serial_bridge::decode_address(const string &args_string)
}
string serial_bridge::is_subaddress(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");
}
network_type nettype = nettype_from_string(json_root.get<string>("nettype_string"));
bool retVal = monero::address_utils::isSubAddress(json_root.get<string>("address"), nettype);
boost::property_tree::ptree root;
root.put(ret_json_key__generic_retVal(), retVal);
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
//
return ret_ss.str();
}
string serial_bridge::is_integrated_address(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");
}
network_type nettype = nettype_from_string(json_root.get<string>("nettype_string"));
bool retVal = monero::address_utils::isIntegratedAddress(json_root.get<string>("address"), nettype);
boost::property_tree::ptree root;
root.put(ret_json_key__generic_retVal(), retVal);
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
//
return ret_ss.str();
}
string serial_bridge::new_integrated_address(const string &args_string)
{

@ -68,8 +68,11 @@ namespace serial_bridge
string string_from_nettype(network_type nettype);
//
// JSON keys - Ret vals
// - - Error
static inline string ret_json_key__any__err_msg() { return "err_msg"; } // optional
static inline string ret_json_key__any__err_code() { return "err_code"; } // optional
// - - Shared
static inline string ret_json_key__generic_retVal() { return "retVal"; }
// - - create_transaction
static inline string ret_json_key__create_transaction__serialized_signed_tx() { return "serialized_signed_tx"; }
static inline string ret_json_key__create_transaction__tx_hash() { return "tx_hash"; }
@ -78,6 +81,7 @@ namespace serial_bridge
static inline string ret_json_key__decode_address__pub_spendKey_string() { return "pub_spendKey_string"; }
static inline string ret_json_key__decode_address__paymentID_string() { return "paymentID_string"; } // optional
static inline string ret_json_key__decode_address__isSubaddress() { return "isSubaddress"; }
// JSON keys - Args
// TODO:
// static inline string args_json_key__

@ -488,3 +488,53 @@ BOOST_AUTO_TEST_CASE(bridged__decode_address)
BOOST_REQUIRE(*isSubaddress == false);
cout << "bridged: isSubaddress: " << *isSubaddress << endl;
}
//
BOOST_AUTO_TEST_CASE(bridged__is_subaddress)
{
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET)); // TODO: specify this by constant and transform fn
root.put("address", "4L6Gcy9TAHqPVPMnqa5cPtJK25tr7maE7LrJe67vzumiCtWwjDBvYnHZr18wFexJpih71Mxsjv8b7EpQftpB9NjPaL41VrjstLM5WevLZx");
//
stringstream args_ss;
boost::property_tree::write_json(args_ss, root);
auto ret_string = serial_bridge::is_subaddress(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<bool> isSubaddress = ret_tree.get_optional<bool>(ret_json_key__generic_retVal());
BOOST_REQUIRE(isSubaddress != none);
BOOST_REQUIRE(*isSubaddress == false);
cout << "bridged: isSubaddress: " << *isSubaddress << endl;
}
//
BOOST_AUTO_TEST_CASE(bridged__is_integrated_address)
{
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET)); // TODO: specify this by constant and transform fn
root.put("address", "4L6Gcy9TAHqPVPMnqa5cPtJK25tr7maE7LrJe67vzumiCtWwjDBvYnHZr18wFexJpih71Mxsjv8b7EpQftpB9NjPaL41VrjstLM5WevLZx");
//
stringstream args_ss;
boost::property_tree::write_json(args_ss, root);
auto ret_string = serial_bridge::is_integrated_address(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<bool> isIntegratedAddress = ret_tree.get_optional<bool>(ret_json_key__generic_retVal());
BOOST_REQUIRE(isIntegratedAddress != none);
BOOST_REQUIRE(*isIntegratedAddress == true);
cout << "bridged: isIntegratedAddress: " << *isIntegratedAddress << endl;
}

Loading…
Cancel
Save