diff --git a/src/monero_key_image_utils.cpp b/src/monero_key_image_utils.cpp index 33385ed..c29d912 100644 --- a/src/monero_key_image_utils.cpp +++ b/src/monero_key_image_utils.cpp @@ -58,7 +58,7 @@ bool monero_key_image_utils::new__key_image( r = crypto::generate_key_derivation(tx_public_key, account_sec_view_key, derivation); if (!r) { retVals.did_error = true; - std::stringstream ss{}; + std::ostringstream ss{}; ss << "failed to generate_key_derivation(" << tx_public_key << ", " << account_sec_view_key << ")"; retVals.err_string = ss.str(); // @@ -68,7 +68,7 @@ bool monero_key_image_utils::new__key_image( r = crypto::derive_public_key(derivation, out_index, account_pub_spend_key, in_ephemeral.pub); if (!r) { retVals.did_error = true; - std::stringstream ss{}; + std::ostringstream ss{}; ss << "failed to derive_public_key (" << derivation << ", " << out_index << ", " << account_pub_spend_key << ")"; retVals.err_string = ss.str(); // @@ -79,7 +79,7 @@ bool monero_key_image_utils::new__key_image( r = crypto::secret_key_to_public_key(in_ephemeral.sec, out_pkey_test); if (!r) { retVals.did_error = true; - std::stringstream ss{}; + std::ostringstream ss{}; ss << "failed to secret_key_to_public_key(" << in_ephemeral.sec << ")"; retVals.err_string = ss.str(); // diff --git a/src/monero_send_routine.cpp b/src/monero_send_routine.cpp index 0bc7982..77a565d 100644 --- a/src/monero_send_routine.cpp +++ b/src/monero_send_routine.cpp @@ -72,14 +72,14 @@ optional _possible_uint64_from_json( } // LightwalletAPI_Req_GetUnspentOuts monero_send_routine::new__req_params__get_unspent_outs( - const string &from_address_string, - const string &sec_viewKey_string + string from_address_string, + string sec_viewKey_string ) { - stringstream dustT_ss; + ostringstream dustT_ss; dustT_ss << dust_threshold(); return { - from_address_string, - sec_viewKey_string, + std::move(from_address_string), + std::move(sec_viewKey_string), "0", // amount - always sent as "0" fixed_mixinsize(), true, // use dust @@ -95,7 +95,7 @@ LightwalletAPI_Req_GetRandomOuts monero_send_routine::new__req_params__get_rando if (using_out.rct != none && (*(using_out.rct)).size() > 0) { decoy_req__amounts.push_back("0"); } else { - stringstream amount_ss; + ostringstream amount_ss; amount_ss << using_out.amount; decoy_req__amounts.push_back(amount_ss.str()); } @@ -107,7 +107,7 @@ LightwalletAPI_Req_GetRandomOuts monero_send_routine::new__req_params__get_rando } // LightwalletAPI_Res_GetUnspentOuts monero_send_routine::new__parsed_res__get_unspent_outs( - property_tree::ptree &res, + const property_tree::ptree &res, const secret_key &sec_viewKey, const secret_key &sec_spendKey, const public_key &pub_spendKey @@ -149,7 +149,7 @@ LightwalletAPI_Res_GetUnspentOuts monero_send_routine::new__parsed_res__get_unsp }; } vector unspent_outs; - BOOST_FOREACH(boost::property_tree::ptree::value_type &output_desc, res.get_child("outputs")) + BOOST_FOREACH(const boost::property_tree::ptree::value_type &output_desc, res.get_child("outputs")) { assert(output_desc.first.empty()); // array elements have no names // @@ -191,7 +191,7 @@ LightwalletAPI_Res_GetUnspentOuts monero_send_routine::new__parsed_res__get_unsp } bool isOutputSpent = false; // let's see… { - BOOST_FOREACH(boost::property_tree::ptree::value_type &spend_key_image_string, output_desc.second.get_child("spend_key_images")) + BOOST_FOREACH(const boost::property_tree::ptree::value_type &spend_key_image_string, output_desc.second.get_child("spend_key_images")) { // cout << "spend_key_image_string: " << spend_key_image_string.second.data() << endl; KeyImageRetVals retVals; @@ -225,7 +225,7 @@ LightwalletAPI_Res_GetUnspentOuts monero_send_routine::new__parsed_res__get_unsp out.index = output__index; out.tx_pub_key = *optl__tx_pub_key; // just b/c we've already accessed it above // - unspent_outs.push_back(out); + unspent_outs.push_back(std::move(out)); } } return LightwalletAPI_Res_GetUnspentOuts{ @@ -234,10 +234,10 @@ LightwalletAPI_Res_GetUnspentOuts monero_send_routine::new__parsed_res__get_unsp }; } LightwalletAPI_Res_GetRandomOuts monero_send_routine::new__parsed_res__get_random_outs( - property_tree::ptree &res + const property_tree::ptree &res ) { vector mix_outs; - BOOST_FOREACH(boost::property_tree::ptree::value_type &mix_out_desc, res.get_child("amount_outs")) + BOOST_FOREACH(const boost::property_tree::ptree::value_type &mix_out_desc, res.get_child("amount_outs")) { assert(mix_out_desc.first.empty()); // array elements have no names auto amountAndOuts = RandomAmountOutputs{}; @@ -251,7 +251,7 @@ LightwalletAPI_Res_GetRandomOuts monero_send_routine::new__parsed_res__get_rando string err_msg = "Random outs: Unrecognized 'amount' format"; return {err_msg, none}; } - BOOST_FOREACH(boost::property_tree::ptree::value_type &mix_out_output_desc, mix_out_desc.second.get_child("outputs")) + BOOST_FOREACH(const boost::property_tree::ptree::value_type &mix_out_output_desc, mix_out_desc.second.get_child("outputs")) { assert(mix_out_output_desc.first.empty()); // array elements have no names auto amountOutput = RandomAmountOutput{}; @@ -268,9 +268,9 @@ LightwalletAPI_Res_GetRandomOuts monero_send_routine::new__parsed_res__get_rando amountOutput.public_key = mix_out_output_desc.second.get("public_key"); amountOutput.rct = mix_out_output_desc.second.get_optional("rct"); // - amountAndOuts.outputs.push_back(amountOutput); + amountAndOuts.outputs.push_back(std::move(amountOutput)); } - mix_outs.push_back(amountAndOuts); + mix_outs.push_back(std::move(amountAndOuts)); } return { none, mix_outs diff --git a/src/monero_send_routine.hpp b/src/monero_send_routine.hpp index 14b9b80..b7f7522 100644 --- a/src/monero_send_routine.hpp +++ b/src/monero_send_routine.hpp @@ -56,7 +56,7 @@ namespace monero_send_routine // Abstracted Send routine // - Accessory types - Callbacks - Data fetch hooks typedef std::function api_fetch_cb_fn; // struct LightwalletAPI_Req_GetUnspentOuts @@ -69,8 +69,8 @@ namespace monero_send_routine const string dust_threshold; // uint64_string; String(MoneroConstants.dustThreshold, radix: 10) }; LightwalletAPI_Req_GetUnspentOuts new__req_params__get_unspent_outs( // used internally and by emscr async send impl - const string &from_address_string, - const string &sec_viewKey_string + string from_address_string, + string sec_viewKey_string ); typedef std::function> mix_outs; }; LightwalletAPI_Res_GetUnspentOuts new__parsed_res__get_unspent_outs( - property_tree::ptree &res, + const property_tree::ptree &res, const secret_key &sec_viewKey, const secret_key &sec_spendKey, const public_key &pub_spendKey ); LightwalletAPI_Res_GetRandomOuts new__parsed_res__get_random_outs( - property_tree::ptree &res + const property_tree::ptree &res ); // // - Routine entrypoint diff --git a/src/monero_transfer_utils.cpp b/src/monero_transfer_utils.cpp index 67dd2df..4a47452 100644 --- a/src/monero_transfer_utils.cpp +++ b/src/monero_transfer_utils.cpp @@ -94,7 +94,7 @@ bool monero_transfer_utils::is_tx_spendtime_unlocked( } // CreateTransactionErrorCode _add_pid_to_tx_extra( - optional payment_id_string, + const optional& payment_id_string, vector &extra ) { // Detect hash8 or hash32 char hex string as pid and configure 'extra' accordingly bool r = false; @@ -185,9 +185,9 @@ namespace CHECK_AND_ASSERT_MES(!vec.empty(), T(), "Vector must be non-empty"); CHECK_AND_ASSERT_MES(idx < vec.size(), T(), "idx out of bounds"); - T res = vec[idx]; + T res = std::move(vec[idx]); if (idx + 1 != vec.size()) { - vec[idx] = vec.back(); + vec[idx] = std::move(vec.back()); } vec.resize(vec.size() - 1); @@ -210,7 +210,7 @@ namespace void monero_transfer_utils::send_step1__prepare_params_for_get_decoys( Send_Step1_RetVals &retVals, // - optional payment_id_string, + const optional& payment_id_string, uint64_t sending_amount, bool is_sweeping, uint32_t simple_priority, @@ -299,9 +299,9 @@ void monero_transfer_utils::send_step1__prepare_params_for_get_decoys( // cout << "Sweeping and found a dusty but mixable (rct) amount... keeping it!" << endl; } } - retVals.using_outs.push_back(out); using_outs_amount += out.amount; // cout << "Using output: " << out.amount << " - " << out.public_key << endl; + retVals.using_outs.push_back(std::move(out)); } retVals.spendable_balance = using_outs_amount; // must store for needMoreMoneyThanFound return // Note: using_outs and using_outs_amount may still get modified below (so retVals.spendable_balance gets updated) @@ -336,10 +336,12 @@ void monero_transfer_utils::send_step1__prepare_params_for_get_decoys( } else { total_incl_fees = sending_amount + needed_fee; // because fee changed because using_outs.size() was updated while (using_outs_amount < total_incl_fees && remaining_unusedOuts.size() > 0) { // add outputs 1 at a time till we either have them all or can meet the fee - auto out = pop_random_value(remaining_unusedOuts); -// cout << "Using output: " << out.amount << " - " << out.public_key << endl; - retVals.using_outs.push_back(out); - using_outs_amount += out.amount; + { + auto out = pop_random_value(remaining_unusedOuts); +// cout << "Using output: " << out.amount << " - " << out.public_key << endl; + using_outs_amount += out.amount; + retVals.using_outs.push_back(std::move(out)); + } retVals.spendable_balance = using_outs_amount; // must store for needMoreMoneyThanFound return // // Recalculate fee, total incl fees @@ -382,7 +384,7 @@ void monero_transfer_utils::send_step2__try_create_transaction( const string &sec_viewKey_string, const string &sec_spendKey_string, const string &to_address_string, - optional payment_id_string, + const optional& payment_id_string, uint64_t final_total_wo_fee, uint64_t change_amount, uint64_t fee_amount, @@ -692,7 +694,7 @@ void monero_transfer_utils::convenience__create_transaction( const string &sec_viewKey_string, const string &sec_spendKey_string, const string &to_address_string, - optional payment_id_string, + const optional& payment_id_string, uint64_t sending_amount, uint64_t change_amount, uint64_t fee_amount, diff --git a/src/monero_transfer_utils.hpp b/src/monero_transfer_utils.hpp index c1574cc..608eb5c 100644 --- a/src/monero_transfer_utils.hpp +++ b/src/monero_transfer_utils.hpp @@ -189,7 +189,7 @@ namespace monero_transfer_utils void send_step1__prepare_params_for_get_decoys( Send_Step1_RetVals &retVals, // - optional payment_id_string, + const optional& payment_id_string, uint64_t sending_amount, bool is_sweeping, uint32_t simple_priority, @@ -222,7 +222,7 @@ namespace monero_transfer_utils const string &sec_viewKey_string, const string &sec_spendKey_string, const string &to_address_string, - optional payment_id_string, + const optional& payment_id_string, uint64_t final_total_wo_fee, // this gets passed to create_transaction's 'sending_amount' uint64_t change_amount, uint64_t fee_amount, @@ -255,7 +255,7 @@ namespace monero_transfer_utils const string &sec_viewKey_string, const string &sec_spendKey_string, const string &to_address_string, - optional payment_id_string, + const optional& payment_id_string, uint64_t sending_amount, uint64_t change_amount, uint64_t fee_amount, diff --git a/src/monero_wallet_utils.cpp b/src/monero_wallet_utils.cpp index d75be99..0871315 100644 --- a/src/monero_wallet_utils.cpp +++ b/src/monero_wallet_utils.cpp @@ -193,7 +193,7 @@ bool monero_wallet_utils::decoded_seed( // FIXME: any other input sanitization to do here? // const epee::wipeable_string &mnemonic_string__ref = mnemonic_string; // re-obtain wipeable_string ref - std::stringstream stream(mnemonic_string); // to count words… + std::istringstream stream(mnemonic_string); // to count words… unsigned long word_count = std::distance(std::istream_iterator(stream), std::istream_iterator()); // unsigned long word_count = boost::range::distance(boost::algorithm::make_split_iterator(mnemonic_string, boost::algorithm::is_space())); // TODO: get this workin // diff --git a/src/serial_bridge_index.cpp b/src/serial_bridge_index.cpp index 50d4a3d..81b0d7d 100644 --- a/src/serial_bridge_index.cpp +++ b/src/serial_bridge_index.cpp @@ -73,10 +73,10 @@ string serial_bridge::decode_address(const string &args_string) } boost::property_tree::ptree root; root.put(ret_json_key__isSubaddress(), retVals.isSubaddress); - root.put(ret_json_key__pub_viewKey_string(), std::move(*(retVals.pub_viewKey_string))); - root.put(ret_json_key__pub_spendKey_string(), std::move(*(retVals.pub_spendKey_string))); + root.put(ret_json_key__pub_viewKey_string(), *(retVals.pub_viewKey_string)); + root.put(ret_json_key__pub_spendKey_string(), *(retVals.pub_spendKey_string)); if (retVals.paymentID_string != none) { - root.put(ret_json_key__paymentID_string(), std::move(*(retVals.paymentID_string))); + root.put(ret_json_key__paymentID_string(), *(retVals.paymentID_string)); } // return ret_json_from_root(root); @@ -117,7 +117,7 @@ string serial_bridge::new_integrated_address(const string &args_string) optional retVal = monero::address_utils::new_integratedAddrFromStdAddr(json_root.get("address"), json_root.get("short_pid"), nettype_from_string(json_root.get("nettype_string"))); boost::property_tree::ptree root; if (retVal != none) { - root.put(ret_json_key__generic_retVal(), std::move(*retVal)); + root.put(ret_json_key__generic_retVal(), *retVal); } // return ret_json_from_root(root); @@ -132,7 +132,7 @@ string serial_bridge::new_payment_id(const string &args_string) optional retVal = monero_paymentID_utils::new_short_plain_paymentID_string(); boost::property_tree::ptree root; if (retVal != none) { - root.put(ret_json_key__generic_retVal(), std::move(*retVal)); + root.put(ret_json_key__generic_retVal(), *retVal); } // return ret_json_from_root(root); @@ -299,8 +299,8 @@ string serial_bridge::validate_components_for_login(const string &args_string) boost::property_tree::ptree root; root.put(ret_json_key__isValid(), retVals.isValid); root.put(ret_json_key__isInViewOnlyMode(), retVals.isInViewOnlyMode); - root.put(ret_json_key__pub_viewKey_string(), std::move(retVals.pub_viewKey_string)); - root.put(ret_json_key__pub_spendKey_string(), std::move(retVals.pub_spendKey_string)); + root.put(ret_json_key__pub_viewKey_string(), retVals.pub_viewKey_string); + root.put(ret_json_key__pub_spendKey_string(), retVals.pub_spendKey_string); // return ret_json_from_root(root); } @@ -385,7 +385,7 @@ string serial_bridge::send_step1__prepare_params_for_get_decoys(const string &ar out.index = stoull(output_desc.second.get("index")); out.tx_pub_key = output_desc.second.get("tx_pub_key"); // - unspent_outs.push_back(out); + unspent_outs.push_back(std::move(out)); } optional optl__passedIn_attemptAt_fee_string = json_root.get_optional("passedIn_attemptAt_fee"); optional optl__passedIn_attemptAt_fee = none; @@ -415,27 +415,28 @@ string serial_bridge::send_step1__prepare_params_for_get_decoys(const string &ar root.put(ret_json_key__any__err_msg(), err_msg_from_err_code__create_transaction(retVals.errCode)); // // The following will be set if errCode==needMoreMoneyThanFound - and i'm depending on them being 0 otherwise - root.put(ret_json_key__send__spendable_balance(), std::move(RetVals_Transforms::str_from(retVals.spendable_balance))); - root.put(ret_json_key__send__required_balance(), std::move(RetVals_Transforms::str_from(retVals.required_balance))); + root.put(ret_json_key__send__spendable_balance(), RetVals_Transforms::str_from(retVals.spendable_balance)); + root.put(ret_json_key__send__required_balance(), RetVals_Transforms::str_from(retVals.required_balance)); } else { - root.put(ret_json_key__send__mixin(), std::move(RetVals_Transforms::str_from(retVals.mixin))); - root.put(ret_json_key__send__using_fee(), std::move(RetVals_Transforms::str_from(retVals.using_fee))); - root.put(ret_json_key__send__final_total_wo_fee(), std::move(RetVals_Transforms::str_from(retVals.final_total_wo_fee))); - root.put(ret_json_key__send__change_amount(), std::move(RetVals_Transforms::str_from(retVals.change_amount))); + root.put(ret_json_key__send__mixin(), RetVals_Transforms::str_from(retVals.mixin)); + root.put(ret_json_key__send__using_fee(), RetVals_Transforms::str_from(retVals.using_fee)); + root.put(ret_json_key__send__final_total_wo_fee(), RetVals_Transforms::str_from(retVals.final_total_wo_fee)); + root.put(ret_json_key__send__change_amount(), RetVals_Transforms::str_from(retVals.change_amount)); { boost::property_tree::ptree using_outs_ptree; BOOST_FOREACH(SpendableOutput &out, retVals.using_outs) { // PROBABLY don't need to shuttle these back (could send only public_key) but consumers might like the feature of being able to send this JSON structure directly back to step2 without reconstructing it for themselves - boost::property_tree::ptree out_ptree; - out_ptree.put("amount", std::move(RetVals_Transforms::str_from(out.amount))); - out_ptree.put("public_key", out.public_key); // FIXME: no std::move correct? + auto out_ptree_pair = std::make_pair("", boost::property_tree::ptree{}); + auto& out_ptree = out_ptree_pair.second; + out_ptree.put("amount", RetVals_Transforms::str_from(out.amount)); + out_ptree.put("public_key", out.public_key); if (out.rct != none) { - out_ptree.put("rct", *out.rct); // copy vs move ? + out_ptree.put("rct", *out.rct); } - out_ptree.put("global_index", std::move(RetVals_Transforms::str_from(out.global_index))); - out_ptree.put("index", std::move(RetVals_Transforms::str_from(out.index))); + out_ptree.put("global_index", RetVals_Transforms::str_from(out.global_index)); + out_ptree.put("index", RetVals_Transforms::str_from(out.index)); out_ptree.put("tx_pub_key", out.tx_pub_key); - using_outs_ptree.push_back(std::make_pair("", out_ptree)); + using_outs_ptree.push_back(out_ptree_pair); } root.add_child(ret_json_key__send__using_outs(), using_outs_ptree); } @@ -462,7 +463,7 @@ string serial_bridge::send_step2__try_create_transaction(const string &args_stri out.index = stoull(output_desc.second.get("index")); out.tx_pub_key = output_desc.second.get("tx_pub_key"); // - using_outs.push_back(out); + using_outs.push_back(std::move(out)); } vector mix_outs; BOOST_FOREACH(boost::property_tree::ptree::value_type &mix_out_desc, json_root.get_child("mix_outs")) @@ -477,9 +478,9 @@ string serial_bridge::send_step2__try_create_transaction(const string &args_stri amountOutput.global_index = stoull(mix_out_output_desc.second.get("global_index")); // this is, I believe, presently supplied as a string by the API, probably to avoid overflow amountOutput.public_key = mix_out_output_desc.second.get("public_key"); amountOutput.rct = mix_out_output_desc.second.get_optional("rct"); - amountAndOuts.outputs.push_back(amountOutput); + amountAndOuts.outputs.push_back(std::move(amountOutput)); } - mix_outs.push_back(amountAndOuts); + mix_outs.push_back(std::move(amountAndOuts)); } Send_Step2_RetVals retVals; monero_transfer_utils::send_step2__try_create_transaction( @@ -511,13 +512,13 @@ string serial_bridge::send_step2__try_create_transaction(const string &args_stri } else { if (retVals.tx_must_be_reconstructed) { root.put(ret_json_key__send__tx_must_be_reconstructed(), true); - root.put(ret_json_key__send__fee_actually_needed(), std::move(RetVals_Transforms::str_from(retVals.fee_actually_needed))); // must be passed back + root.put(ret_json_key__send__fee_actually_needed(), RetVals_Transforms::str_from(retVals.fee_actually_needed)); // must be passed back } else { root.put(ret_json_key__send__tx_must_be_reconstructed(), false); // so consumers have it available - root.put(ret_json_key__send__serialized_signed_tx(), std::move(*(retVals.signed_serialized_tx_string))); - root.put(ret_json_key__send__tx_hash(), std::move(*(retVals.tx_hash_string))); - root.put(ret_json_key__send__tx_key(), std::move(*(retVals.tx_key_string))); - root.put(ret_json_key__send__tx_pub_key(), std::move(*(retVals.tx_pub_key_string))); + root.put(ret_json_key__send__serialized_signed_tx(), *(retVals.signed_serialized_tx_string)); + root.put(ret_json_key__send__tx_hash(), *(retVals.tx_hash_string)); + root.put(ret_json_key__send__tx_key(), *(retVals.tx_key_string)); + root.put(ret_json_key__send__tx_pub_key(), *(retVals.tx_pub_key_string)); } } return ret_json_from_root(root); @@ -561,7 +562,7 @@ string serial_bridge::decodeRct(const string &args_string) if (!epee::string_tools::hex_to_pod(ecdh_info_desc.second.get("amount"), ecdh_info.amount)) { return error_ret_json_from_message("Invalid rv.ecdhInfo[].amount"); } - rv.ecdhInfo.push_back(ecdh_info); + rv.ecdhInfo.push_back(ecdh_info); // rct keys aren't movable } BOOST_FOREACH(boost::property_tree::ptree::value_type &outPk_desc, rv_desc.get_child("outPk")) { @@ -571,7 +572,7 @@ string serial_bridge::decodeRct(const string &args_string) return error_ret_json_from_message("Invalid rv.outPk[].mask"); } // FIXME: does dest need to be placed on the key? - rv.outPk.push_back(outPk); + rv.outPk.push_back(outPk); // rct keys aren't movable } // rct::key mask; @@ -584,7 +585,7 @@ string serial_bridge::decodeRct(const string &args_string) } catch (std::exception const& e) { return error_ret_json_from_message(e.what()); } - stringstream decoded_amount_ss; + ostringstream decoded_amount_ss; decoded_amount_ss << decoded_amount; // boost::property_tree::ptree root; diff --git a/src/serial_bridge_utils.cpp b/src/serial_bridge_utils.cpp index 9a006f6..d720b9b 100644 --- a/src/serial_bridge_utils.cpp +++ b/src/serial_bridge_utils.cpp @@ -85,9 +85,7 @@ string serial_bridge_utils::string_from_nettype(network_type nettype) bool serial_bridge_utils::parsed_json_root(const string &args_string, boost::property_tree::ptree &json_root) { // cout << "args_string: " << args_string << endl; - - std::stringstream ss; - ss << args_string; + std::istringstream ss(args_string); try { boost::property_tree::read_json(ss, json_root); } catch (std::exception const& e) { @@ -100,7 +98,7 @@ bool serial_bridge_utils::parsed_json_root(const string &args_string, boost::pro // Shared - Factories - Return values string serial_bridge_utils::ret_json_from_root(const boost::property_tree::ptree &root) { - stringstream ret_ss; + ostringstream ret_ss; boost::property_tree::write_json(ret_ss, root, false/*pretty*/); // return ret_ss.str();