diff --git a/src/page.h b/src/page.h index 25f5e71..f206a60 100644 --- a/src/page.h +++ b/src/page.h @@ -1458,9 +1458,9 @@ namespace xmreg } // parse string representing given monero address - cryptonote::account_public_address address; + cryptonote::address_parse_info address_info; - if (!xmreg::parse_str_address(xmr_address_str, address, testnet)) + if (!xmreg::parse_str_address(xmr_address_str, address_info, testnet)) { cerr << "Cant parse string address: " << xmr_address_str << endl; return string("Cant parse xmr address: " + xmr_address_str); @@ -1649,7 +1649,7 @@ namespace xmreg // to create, so called, derived key. key_derivation derivation; - public_key pub_key = tx_prove ? address.m_view_public_key : txd.pk; + public_key pub_key = tx_prove ? address_info.address.m_view_public_key : txd.pk; //cout << "txd.pk: " << pod_to_hex(txd.pk) << endl; @@ -1693,7 +1693,7 @@ namespace xmreg derive_public_key(derivation, output_idx, - address.m_spend_public_key, + address_info.address.m_spend_public_key, tx_pubkey); //cout << pod_to_hex(outp.first.key) << endl; @@ -1948,7 +1948,7 @@ namespace xmreg derive_public_key(derivation, output_idx_in_tx, - address.m_spend_public_key, + address_info.address.m_spend_public_key, tx_pubkey_generated); // check if generated public key matches the current output's key @@ -2239,7 +2239,8 @@ namespace xmreg for (const tx_destination_entry& a_dest: tx_cd.splitted_dsts) { mstch::map dest_info { - {"dest_address" , get_account_address_as_str(testnet, a_dest.addr)}, + {"dest_address" , get_account_address_as_str( + testnet, a_dest.is_subaddress, a_dest.addr)}, {"dest_amount" , xmreg::xmr_amount_to_str(a_dest.amount)} }; @@ -2579,7 +2580,8 @@ namespace xmreg destination_addresses.push_back( mstch::map { - {"dest_address" , get_account_address_as_str(testnet, a_dest.addr)}, + {"dest_address" , get_account_address_as_str( + testnet, a_dest.is_subaddress, a_dest.addr)}, {"dest_amount" , xmreg::xmr_amount_to_str(a_dest.amount)}, {"is_this_change" , false} } @@ -2595,8 +2597,10 @@ namespace xmreg { destination_addresses.push_back( mstch::map { - {"dest_address" , get_account_address_as_str(testnet, ptx.construction_data.change_dts.addr)}, - {"dest_amount" , xmreg::xmr_amount_to_str(ptx.construction_data.change_dts.amount)}, + {"dest_address" , get_account_address_as_str( + testnet, ptx.construction_data.change_dts.is_subaddress, ptx.construction_data.change_dts.addr)}, + {"dest_amount" , + xmreg::xmr_amount_to_str(ptx.construction_data.change_dts.amount)}, {"is_this_change" , true} } ); @@ -3101,8 +3105,13 @@ namespace xmreg reinterpret_cast( decoded_raw_data.data()); - context.insert({"address" , REMOVE_HASH_BRAKETS(xmreg::print_address(*xmr_address, testnet))}); - context.insert({"viewkey" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", prv_view_key))}); + address_parse_info address_info {*xmr_address, false}; + + + context.insert({"address" , REMOVE_HASH_BRAKETS( + xmreg::print_address(address_info, testnet))}); + context.insert({"viewkey" , REMOVE_HASH_BRAKETS( + fmt::format("{:s}", prv_view_key))}); context.insert({"has_total_xmr" , false}); context.insert({"total_xmr" , string{}}); context.insert({"key_imgs" , mstch::array{}}); @@ -3128,7 +3137,8 @@ namespace xmreg {"key_no" , fmt::format("{:03d}", n)}, {"key_image" , pod_to_hex(key_image)}, {"signature" , fmt::format("{:s}", signature)}, - {"address" , xmreg::print_address(*xmr_address, testnet)}, + {"address" , xmreg::print_address( + address_info, testnet)}, {"is_spent" , core_storage->have_tx_keyimg_as_spent(key_image)}, {"tx_hash" , string{}} }; @@ -3229,8 +3239,12 @@ namespace xmreg reinterpret_cast( decoded_raw_data.data()); - context.insert({"address" , REMOVE_HASH_BRAKETS(xmreg::print_address(*xmr_address, testnet))}); - context.insert({"viewkey" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", prv_view_key))}); + address_parse_info address_info {*xmr_address, false}; + + context.insert({"address" , REMOVE_HASH_BRAKETS( + xmreg::print_address(address_info, testnet))}); + context.insert({"viewkey" , REMOVE_HASH_BRAKETS( + fmt::format("{:s}", prv_view_key))}); context.insert({"has_total_xmr" , false}); context.insert({"total_xmr" , string{}}); context.insert({"output_keys" , mstch::array{}}); @@ -3436,47 +3450,48 @@ namespace xmreg if (search_str_length == 95) { // parse string representing given monero address - cryptonote::account_public_address address; + address_parse_info address_info; bool testnet_addr {false}; if (search_text[0] == '9' || search_text[0] == 'A') testnet_addr = true; - if (!xmreg::parse_str_address(search_text, address, testnet_addr)) + if (!xmreg::parse_str_address(search_text, address_info, testnet_addr)) { cerr << "Cant parse string address: " << search_text << endl; return string("Cant parse address (probably incorrect format): ") + search_text; } - return show_address_details(address, testnet_addr); + return show_address_details(address_info, testnet_addr); } - // check if integrated monero address is given based on its length - // if yes, then show its public components search tx based on encrypted id - if (search_str_length == 106) - { - - cryptonote::account_public_address address; - - bool has_payment_id; - - crypto::hash8 encrypted_payment_id; - - if (!get_account_integrated_address_from_str(address, - has_payment_id, - encrypted_payment_id, - testnet, - search_text)) - { - cerr << "Cant parse string integerated address: " << search_text << endl; - return string("Cant parse address (probably incorrect format): ") - + search_text; - } - - return show_integrated_address_details(address, encrypted_payment_id, testnet); - } +// // check if integrated monero address is given based on its length +// // if yes, then show its public components search tx based on encrypted id +// @todo does not work with integrated address for now +// if (search_str_length == 106) +// { +// +// cryptonote::account_public_address address; +// +// bool has_payment_id; +// +// crypto::hash8 encrypted_payment_id; +// +// if (!get_account_integrated_address_from_str(address_info.address, +// has_payment_id, +// encrypted_payment_id, +// testnet, +// search_text)) +// { +// cerr << "Cant parse string integerated address: " << search_text << endl; +// return string("Cant parse address (probably incorrect format): ") +// + search_text; +// } +// +// return show_integrated_address_details(address_info.address, encrypted_payment_id, testnet); +// } // all_possible_tx_hashes was field using custom lmdb database // it was dropped, so all_possible_tx_hashes will be alwasy empty @@ -3489,12 +3504,12 @@ namespace xmreg } string - show_address_details(const account_public_address& address, bool testnet = false) + show_address_details(const address_parse_info& address_info, bool testnet = false) { - string address_str = xmreg::print_address(address, testnet); - string pub_viewkey_str = fmt::format("{:s}", address.m_view_public_key); - string pub_spendkey_str = fmt::format("{:s}", address.m_spend_public_key); + string address_str = xmreg::print_address(address_info, testnet); + string pub_viewkey_str = fmt::format("{:s}", address_info.address.m_view_public_key); + string pub_spendkey_str = fmt::format("{:s}", address_info.address.m_spend_public_key); mstch::map context { {"xmr_address" , REMOVE_HASH_BRAKETS(address_str)}, @@ -3512,14 +3527,14 @@ namespace xmreg // ; string - show_integrated_address_details(const account_public_address& address, + show_integrated_address_details(const address_parse_info& address_info, const crypto::hash8& encrypted_payment_id, bool testnet = false) { - string address_str = xmreg::print_address(address, testnet); - string pub_viewkey_str = fmt::format("{:s}", address.m_view_public_key); - string pub_spendkey_str = fmt::format("{:s}", address.m_spend_public_key); + string address_str = xmreg::print_address(address_info, testnet); + string pub_viewkey_str = fmt::format("{:s}", address_info.address.m_view_public_key); + string pub_spendkey_str = fmt::format("{:s}", address_info.address.m_spend_public_key); string enc_payment_id_str = fmt::format("{:s}", encrypted_payment_id); mstch::map context { @@ -4572,9 +4587,9 @@ namespace xmreg } // parse string representing given monero address - cryptonote::account_public_address address; + address_parse_info address_info; - if (!xmreg::parse_str_address(address_str, address, testnet)) + if (!xmreg::parse_str_address(address_str, address_info, testnet)) { j_response["status"] = "error"; j_response["message"] = "Cant parse monero address: " + address_str; @@ -4618,7 +4633,7 @@ namespace xmreg // to create, so called, derived key. key_derivation derivation; - public_key pub_key = tx_prove ? address.m_view_public_key : txd.pk; + public_key pub_key = tx_prove ? address_info.address.m_view_public_key : txd.pk; //cout << "txd.pk: " << pod_to_hex(txd.pk) << endl; @@ -4646,7 +4661,7 @@ namespace xmreg derive_public_key(derivation, output_idx, - address.m_spend_public_key, + address_info.address.m_spend_public_key, tx_pubkey); // check if generated public key matches the current output's key @@ -4699,7 +4714,7 @@ namespace xmreg // check if submited data in the request // matches to what was used to produce response. j_data["tx_hash"] = pod_to_hex(txd.hash); - j_data["address"] = pod_to_hex(address); + j_data["address"] = pod_to_hex(address_info.address); j_data["viewkey"] = pod_to_hex(prv_view_key); j_data["tx_prove"] = tx_prove; @@ -4758,9 +4773,9 @@ namespace xmreg } // parse string representing given monero address - cryptonote::account_public_address address; + address_parse_info address_info; - if (!xmreg::parse_str_address(address_str, address, testnet)) + if (!xmreg::parse_str_address(address_str, address_info, testnet)) { j_response["status"] = "error"; j_response["message"] = "Cant parse monero address: " + address_str; @@ -4806,7 +4821,7 @@ namespace xmreg } if (!find_our_outputs( - address, prv_view_key, + address_info.address, prv_view_key, 0 /* block_no */, true /*is mempool*/, tmp_vector.cbegin(), tmp_vector.cend(), j_outptus /* found outputs are pushed to this*/, @@ -4863,7 +4878,7 @@ namespace xmreg (void) missed_txs; if (!find_our_outputs( - address, prv_view_key, + address_info.address, prv_view_key, block_no, false /*is mempool*/, blk_txs.cbegin(), blk_txs.cend(), j_outptus /* found outputs are pushed to this*/, @@ -4881,7 +4896,7 @@ namespace xmreg // return parsed values. can be use to double // check if submited data in the request // matches to what was used to produce response. - j_data["address"] = pod_to_hex(address); + j_data["address"] = pod_to_hex(address_info.address); j_data["viewkey"] = pod_to_hex(prv_view_key); j_data["limit"] = _limit; j_data["height"] = height; diff --git a/src/tools.cpp b/src/tools.cpp index 17fbc84..1bb0501 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -77,11 +77,11 @@ namespace xmreg */ bool parse_str_address(const string& address_str, - account_public_address& address, + address_parse_info& address_info, bool testnet) { - if (!get_account_address_from_str(address, testnet, address_str)) + if (!get_account_address_from_str(address_info, testnet, address_str)) { cerr << "Error getting address: " << address_str << endl; return false; @@ -95,9 +95,11 @@ namespace xmreg * Return string representation of monero address */ string - print_address(const account_public_address& address, bool testnet) + print_address(const address_parse_info& address_info, bool testnet) { - return "<" + get_account_address_as_str(testnet, address) + ">"; + return "<" + get_account_address_as_str( + testnet, address_info.is_subaddress, address_info.address) + + ">"; } string @@ -176,9 +178,9 @@ namespace xmreg } ostream& - operator<< (ostream& os, const account_public_address& addr) + operator<< (ostream& os, const address_parse_info& addr_info) { - os << get_account_address_as_str(false, addr); + os << get_account_address_as_str(false, addr_info.is_subaddress, addr_info.address); return os; } diff --git a/src/tools.h b/src/tools.h index a395b75..a22d314 100644 --- a/src/tools.h +++ b/src/tools.h @@ -80,14 +80,14 @@ namespace xmreg bool parse_str_address(const string& address_str, - account_public_address& address, + address_parse_info& address_info, bool testnet = false); inline bool is_separator(char c); string - print_address(const account_public_address& address, + print_address(const address_parse_info& address, bool testnet = false); string @@ -103,7 +103,7 @@ namespace xmreg timestamp_to_str_gm(time_t timestamp, const char* format = "%F %T"); ostream& - operator<< (ostream& os, const account_public_address& addr); + operator<< (ostream& os, const address_parse_info& addr_info); string