diff --git a/src/daemon/monero_daemon.h b/src/daemon/monero_daemon.h index ec44c9f..e7034e8 100644 --- a/src/daemon/monero_daemon.h +++ b/src/daemon/monero_daemon.h @@ -54,8 +54,6 @@ #include "monero_daemon_model.h" -using namespace std; - /** * Public library interface. */ diff --git a/src/daemon/monero_daemon_model.cpp b/src/daemon/monero_daemon_model.cpp index 475a46a..131622b 100644 --- a/src/daemon/monero_daemon_model.cpp +++ b/src/daemon/monero_daemon_model.cpp @@ -64,8 +64,8 @@ namespace monero { // ----------------------- UNDECLARED PRIVATE HELPERS ----------------------- - void merge_tx(vector>& txs, const shared_ptr& tx) { - for (const shared_ptr& aTx : txs) { + void merge_tx(std::vector>& txs, const std::shared_ptr& tx) { + for (const std::shared_ptr& aTx : txs) { if (aTx->m_hash.get() == tx->m_hash.get()) { aTx->merge(aTx, tx); return; @@ -76,11 +76,11 @@ namespace monero { // ------------------------- INITIALIZE CONSTANTS --------------------------- - const string monero_tx::DEFAULT_PAYMENT_ID = string("0000000000000000"); + const std::string monero_tx::DEFAULT_PAYMENT_ID = std::string("0000000000000000"); // ------------------------- SERIALIZABLE STRUCT ---------------------------- - string serializable_struct::serialize() const { + std::string serializable_struct::serialize() const { rapidjson::Document doc; doc.SetObject(); rapidjson::Value val = to_rapidjson_val(doc.GetAllocator()); @@ -113,7 +113,7 @@ namespace monero { // create root rapidjson::Value root(rapidjson::kObjectType); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_uri != boost::none) monero_utils::addJsonMember("uri", m_uri.get(), allocator, root, value_str); if (m_username != boost::none) monero_utils::addJsonMember("username", m_username.get(), allocator, root, value_str); @@ -147,7 +147,7 @@ namespace monero { if (m_num_txs != boost::none) monero_utils::addJsonMember("numTxs", m_num_txs.get(), allocator, root, value_num); if (m_reward != boost::none) monero_utils::addJsonMember("reward", m_reward.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_hash != boost::none) monero_utils::addJsonMember("hash", m_hash.get(), allocator, root, value_str); if (m_prev_hash != boost::none) monero_utils::addJsonMember("prevHash", m_prev_hash.get(), allocator, root, value_str); @@ -160,8 +160,8 @@ namespace monero { return root; } - void monero_block_header::merge(const shared_ptr& self, const shared_ptr& other) { - if (this != self.get()) throw runtime_error("this != self"); + void monero_block_header::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + if (this != self.get()) throw std::runtime_error("this != self"); if (self == other) return; m_hash = gen_utils::reconcile(m_hash, other->m_hash); m_height = gen_utils::reconcile(m_height, other->m_height, boost::none, boost::none, true, "block height"); // height can increase @@ -190,7 +190,7 @@ namespace monero { // serialize root from superclass rapidjson::Value root = monero_block_header::to_rapidjson_val(allocator); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_hex != boost::none) monero_utils::addJsonMember("hex", m_hex.get(), allocator, root, value_str); @@ -205,12 +205,12 @@ namespace monero { return root; } - void monero_block::merge(const shared_ptr& self, const shared_ptr& other) { - merge(static_pointer_cast(self), static_pointer_cast(other)); + void monero_block::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + merge(std::static_pointer_cast(self), std::static_pointer_cast(other)); } - void monero_block::merge(const shared_ptr& self, const shared_ptr& other) { - if (this != self.get()) throw runtime_error("this != self"); + void monero_block::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + if (this != self.get()) throw std::runtime_error("this != self"); if (self == other) return; // merge header fields @@ -229,7 +229,7 @@ namespace monero { // merge non-miner txs if (!other->m_txs.empty()) { - for (const shared_ptr otherTx : other->m_txs) { // NOTE: not using reference so shared_ptr is not deleted when block is dereferenced + for (const std::shared_ptr otherTx : other->m_txs) { // NOTE: not using reference so std::shared_ptr is not deleted when block is dereferenced otherTx->m_block = self; merge_tx(self->m_txs, otherTx); } @@ -257,7 +257,7 @@ namespace monero { if (m_last_failed_height != boost::none) monero_utils::addJsonMember("lastFailedHeight", m_last_failed_height.get(), allocator, root, value_num); if (m_max_used_block_height != boost::none) monero_utils::addJsonMember("maxUsedBlockHeight", m_max_used_block_height.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_hash != boost::none) monero_utils::addJsonMember("hash", m_hash.get(), allocator, root, value_str); if (m_payment_id != boost::none) monero_utils::addJsonMember("paymentId", m_payment_id.get(), allocator, root, value_str); @@ -294,53 +294,53 @@ namespace monero { return root; } - void monero_tx::from_property_tree(const boost::property_tree::ptree& node, shared_ptr tx) { + void monero_tx::from_property_tree(const boost::property_tree::ptree& node, std::shared_ptr tx) { // initialize tx from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("hash")) tx->m_hash = it->second.data(); - else if (key == string("version")) throw runtime_error("version deserializationn not implemented"); - else if (key == string("isMinerTx")) tx->m_is_miner_tx = it->second.get_value(); - else if (key == string("paymentId")) tx->m_payment_id = it->second.data(); - else if (key == string("fee")) tx->m_fee = it->second.get_value(); - else if (key == string("mixin")) throw runtime_error("mixin deserialization not implemented"); - else if (key == string("relay")) tx->m_relay = it->second.get_value(); - else if (key == string("isRelayed")) tx->m_is_relayed = it->second.get_value(); - else if (key == string("isConfirmed")) tx->m_is_confirmed = it->second.get_value(); - else if (key == string("inTxPool")) tx->m_in_tx_pool = it->second.get_value(); - else if (key == string("numConfirmations")) tx->m_num_confirmations = it->second.get_value(); - else if (key == string("unlockTime")) tx->m_unlock_time = it->second.get_value(); - else if (key == string("lastRelayedTimestamp")) tx->m_last_relayed_timestamp = it->second.get_value(); - else if (key == string("receivedTimestamp")) tx->m_received_timestamp = it->second.get_value(); - else if (key == string("isDoubleSpendSeen")) tx->m_is_double_spend_seen = it->second.get_value(); - else if (key == string("key")) tx->m_key = it->second.data(); - else if (key == string("fullHex")) tx->m_full_hex = it->second.data(); - else if (key == string("prunedHex")) tx->m_pruned_hex = it->second.data(); - else if (key == string("prunableHex")) tx->m_prunable_hex = it->second.data(); - else if (key == string("prunableHash")) tx->m_prunable_hash = it->second.data(); - else if (key == string("size")) throw runtime_error("size deserialization not implemented"); - else if (key == string("weight")) throw runtime_error("weight deserialization not implemented"); - else if (key == string("inputs")) throw runtime_error("inputs deserializationn not implemented"); - else if (key == string("outputs")) throw runtime_error("outputs deserializationn not implemented"); - else if (key == string("outputIndices")) throw runtime_error("m_output_indices deserialization not implemented"); - else if (key == string("metadata")) tx->m_metadata = it->second.data(); - else if (key == string("commonTxSets")) throw runtime_error("commonTxSets deserialization not implemented"); - else if (key == string("extra")) throw runtime_error("extra deserialization not implemented"); - else if (key == string("rctSignatures")) throw runtime_error("rctSignatures deserialization not implemented"); - else if (key == string("rctSigPrunable")) throw runtime_error("rctSigPrunable deserialization not implemented"); - else if (key == string("isKeptByBlock")) tx->m_is_kept_by_block = it->second.get_value(); - else if (key == string("isFailed")) tx->m_is_failed = it->second.get_value(); - else if (key == string("lastFailedHeight")) throw runtime_error("lastFailedHeight deserialization not implemented"); - else if (key == string("lastFailedHash")) tx->m_last_failed_hash = it->second.data(); - else if (key == string("maxUsedBlockHeight")) throw runtime_error("maxUsedBlockHeight deserialization not implemented"); - else if (key == string("maxUsedBlockHash")) tx->m_max_used_block_hash = it->second.data(); - else if (key == string("signatures")) throw runtime_error("signatures deserialization not implemented"); + std::string key = it->first; + if (key == std::string("hash")) tx->m_hash = it->second.data(); + else if (key == std::string("version")) throw std::runtime_error("version deserializationn not implemented"); + else if (key == std::string("isMinerTx")) tx->m_is_miner_tx = it->second.get_value(); + else if (key == std::string("paymentId")) tx->m_payment_id = it->second.data(); + else if (key == std::string("fee")) tx->m_fee = it->second.get_value(); + else if (key == std::string("mixin")) throw std::runtime_error("mixin deserialization not implemented"); + else if (key == std::string("relay")) tx->m_relay = it->second.get_value(); + else if (key == std::string("isRelayed")) tx->m_is_relayed = it->second.get_value(); + else if (key == std::string("isConfirmed")) tx->m_is_confirmed = it->second.get_value(); + else if (key == std::string("inTxPool")) tx->m_in_tx_pool = it->second.get_value(); + else if (key == std::string("numConfirmations")) tx->m_num_confirmations = it->second.get_value(); + else if (key == std::string("unlockTime")) tx->m_unlock_time = it->second.get_value(); + else if (key == std::string("lastRelayedTimestamp")) tx->m_last_relayed_timestamp = it->second.get_value(); + else if (key == std::string("receivedTimestamp")) tx->m_received_timestamp = it->second.get_value(); + else if (key == std::string("isDoubleSpendSeen")) tx->m_is_double_spend_seen = it->second.get_value(); + else if (key == std::string("key")) tx->m_key = it->second.data(); + else if (key == std::string("fullHex")) tx->m_full_hex = it->second.data(); + else if (key == std::string("prunedHex")) tx->m_pruned_hex = it->second.data(); + else if (key == std::string("prunableHex")) tx->m_prunable_hex = it->second.data(); + else if (key == std::string("prunableHash")) tx->m_prunable_hash = it->second.data(); + else if (key == std::string("size")) throw std::runtime_error("size deserialization not implemented"); + else if (key == std::string("weight")) throw std::runtime_error("weight deserialization not implemented"); + else if (key == std::string("inputs")) throw std::runtime_error("inputs deserializationn not implemented"); + else if (key == std::string("outputs")) throw std::runtime_error("outputs deserializationn not implemented"); + else if (key == std::string("outputIndices")) throw std::runtime_error("m_output_indices deserialization not implemented"); + else if (key == std::string("metadata")) tx->m_metadata = it->second.data(); + else if (key == std::string("commonTxSets")) throw std::runtime_error("commonTxSets deserialization not implemented"); + else if (key == std::string("extra")) throw std::runtime_error("extra deserialization not implemented"); + else if (key == std::string("rctSignatures")) throw std::runtime_error("rctSignatures deserialization not implemented"); + else if (key == std::string("rctSigPrunable")) throw std::runtime_error("rctSigPrunable deserialization not implemented"); + else if (key == std::string("isKeptByBlock")) tx->m_is_kept_by_block = it->second.get_value(); + else if (key == std::string("isFailed")) tx->m_is_failed = it->second.get_value(); + else if (key == std::string("lastFailedHeight")) throw std::runtime_error("lastFailedHeight deserialization not implemented"); + else if (key == std::string("lastFailedHash")) tx->m_last_failed_hash = it->second.data(); + else if (key == std::string("maxUsedBlockHeight")) throw std::runtime_error("maxUsedBlockHeight deserialization not implemented"); + else if (key == std::string("maxUsedBlockHash")) tx->m_max_used_block_hash = it->second.data(); + else if (key == std::string("signatures")) throw std::runtime_error("signatures deserialization not implemented"); } } - shared_ptr monero_tx::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_tx::copy(const shared_ptr& src, const shared_ptr& tgt)"); + std::shared_ptr monero_tx::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + MTRACE("monero_tx::copy(const std::shared_ptr& src, const std::shared_ptr& tgt)"); tgt->m_hash = src->m_hash; tgt->m_version = src->m_version; tgt->m_is_miner_tx = src->m_is_miner_tx; @@ -364,25 +364,25 @@ namespace monero { tgt->m_size = src->m_size; tgt->m_weight = src->m_weight; if (!src->m_inputs.empty()) { - tgt->m_inputs = vector>(); - for (const shared_ptr& input : src->m_inputs) { - shared_ptr input_copy = input->copy(input, make_shared()); + tgt->m_inputs = std::vector>(); + for (const std::shared_ptr& input : src->m_inputs) { + std::shared_ptr input_copy = input->copy(input, std::make_shared()); input_copy->m_tx = tgt; tgt->m_inputs.push_back(input_copy); } } if (!src->m_outputs.empty()) { - tgt->m_outputs = vector>(); - for (const shared_ptr& output : src->m_outputs) { - shared_ptr output_copy = output->copy(output, make_shared()); + tgt->m_outputs = std::vector>(); + for (const std::shared_ptr& output : src->m_outputs) { + std::shared_ptr output_copy = output->copy(output, std::make_shared()); output_copy->m_tx = tgt; tgt->m_outputs.push_back(output_copy); } } - if (!src->m_output_indices.empty()) tgt->m_output_indices = vector(src->m_output_indices); + if (!src->m_output_indices.empty()) tgt->m_output_indices = std::vector(src->m_output_indices); tgt->m_metadata = src->m_metadata; tgt->m_common_tx_sets = src->m_common_tx_sets; - if (!src->m_extra.empty()) throw runtime_error("extra deep copy not implemented"); // TODO: implement extra + if (!src->m_extra.empty()) throw std::runtime_error("extra deep copy not implemented"); // TODO: implement extra tgt->m_rct_signatures = src->m_rct_signatures; tgt->m_rct_sig_prunable = src->m_rct_sig_prunable; tgt->m_is_kept_by_block = src->m_is_kept_by_block; @@ -391,7 +391,7 @@ namespace monero { tgt->m_last_failed_hash = src->m_last_failed_hash; tgt->m_max_used_block_height = src->m_max_used_block_height; tgt->m_max_used_block_hash = src->m_max_used_block_hash; - if (!src->m_signatures.empty()) tgt->m_signatures = vector(src->m_signatures); + if (!src->m_signatures.empty()) tgt->m_signatures = std::vector(src->m_signatures); return tgt; } @@ -400,19 +400,19 @@ namespace monero { return *((*m_block)->m_height); } - void monero_tx::merge(const shared_ptr& self, const shared_ptr& other) { - if (this != self.get()) throw runtime_error("this != self"); + void monero_tx::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + if (this != self.get()) throw std::runtime_error("this != self"); if (self == other) return; // merge blocks if they're different which comes back to merging txs if (m_block != other->m_block) { if (m_block == boost::none) { - m_block = make_shared(); + m_block = std::make_shared(); m_block.get()->m_txs.push_back(self); m_block.get()->m_height = other->get_height(); } if (other->m_block == boost::none) { - other->m_block = make_shared(); + other->m_block = std::make_shared(); other->m_block.get()->m_txs.push_back(other); other->m_block.get()->m_height = self->get_height(); } @@ -455,10 +455,10 @@ namespace monero { // merge inputs if (!other->m_inputs.empty()) { - for (const shared_ptr& merger : other->m_inputs) { + for (const std::shared_ptr& merger : other->m_inputs) { bool merged = false; merger->m_tx = self; - for (const shared_ptr& mergee : m_inputs) { + for (const std::shared_ptr& mergee : m_inputs) { if ((*mergee->m_key_image)->m_hex == (*merger->m_key_image)->m_hex) { mergee->merge(mergee, merger); merged = true; @@ -471,24 +471,24 @@ namespace monero { // merge outputs if (!other->m_outputs.empty()) { - for (const shared_ptr& output : other->m_outputs) output->m_tx = self; + for (const std::shared_ptr& output : other->m_outputs) output->m_tx = self; if (m_outputs.empty()) m_outputs = other->m_outputs; else { // validate output indices if present int num_indices = 0; - for (const shared_ptr& output : this->m_outputs) if (output->m_index != boost::none) num_indices++; - for (const shared_ptr& output : other->m_outputs) if (output->m_index != boost::none) num_indices++; + for (const std::shared_ptr& output : this->m_outputs) if (output->m_index != boost::none) num_indices++; + for (const std::shared_ptr& output : other->m_outputs) if (output->m_index != boost::none) num_indices++; if (num_indices != 0 && this->m_outputs.size() + other->m_outputs.size() != num_indices) { - throw runtime_error("Some outputs have an output index and some do not"); + throw std::runtime_error("Some outputs have an output index and some do not"); } // merge by output indices if present if (num_indices > 0) { - for (const shared_ptr& merger : other->m_outputs) { + for (const std::shared_ptr& merger : other->m_outputs) { bool merged = false; merger->m_tx = self; - for (const shared_ptr& mergee : this->m_outputs) { + for (const std::shared_ptr& mergee : this->m_outputs) { if (mergee->m_index.get() == merger->m_index.get()) { mergee->merge(mergee, merger); merged = true; @@ -501,26 +501,26 @@ namespace monero { // determine if key images present int numKeyImages = 0; - for (const shared_ptr output : m_outputs) { + for (const std::shared_ptr output : m_outputs) { if (output->m_key_image != boost::none) { - if ((*output->m_key_image)->m_hex == boost::none) throw runtime_error("Key image hex cannot be null"); + if ((*output->m_key_image)->m_hex == boost::none) throw std::runtime_error("Key image hex cannot be null"); numKeyImages++; } } - for (const shared_ptr& output : other->m_outputs) { + for (const std::shared_ptr& output : other->m_outputs) { if (output->m_key_image != boost::none) { - if ((*output->m_key_image)->m_hex == boost::none) throw runtime_error("Key image hex cannot be null"); + if ((*output->m_key_image)->m_hex == boost::none) throw std::runtime_error("Key image hex cannot be null"); numKeyImages++; } } - if (numKeyImages != 0 && m_outputs.size() + other->m_outputs.size() != numKeyImages) throw runtime_error("Some outputs have a key image and some do not"); + if (numKeyImages != 0 && m_outputs.size() + other->m_outputs.size() != numKeyImages) throw std::runtime_error("Some outputs have a key image and some do not"); // merge by key images if (numKeyImages > 0) { - for (const shared_ptr& merger : other->m_outputs) { + for (const std::shared_ptr& merger : other->m_outputs) { bool merged = false; merger->m_tx = self; - for (const shared_ptr& mergee : m_outputs) { + for (const std::shared_ptr& mergee : m_outputs) { if ((*mergee->m_key_image)->m_hex == (*merger->m_key_image)->m_hex) { mergee->merge(mergee, merger); merged = true; @@ -533,7 +533,7 @@ namespace monero { // merge by position else { - if (m_outputs.size() != other->m_outputs.size()) throw runtime_error("Vout sizes are different"); + if (m_outputs.size() != other->m_outputs.size()) throw std::runtime_error("Vout sizes are different"); for (int i = 0; i < other->m_outputs.size(); i++) { m_outputs.at(i)->merge(m_outputs.at(i), other->m_outputs.at(i)); } @@ -561,7 +561,7 @@ namespace monero { // create root rapidjson::Value root(rapidjson::kObjectType); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_hex != boost::none) monero_utils::addJsonMember("hex", m_hex.get(), allocator, root, value_str); if (m_signature != boost::none) monero_utils::addJsonMember("signature", m_signature.get(), allocator, root, value_str); @@ -570,17 +570,17 @@ namespace monero { return root; } - void monero_key_image::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& key_image) { + void monero_key_image::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& key_image) { // initialize key image from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("hex")) key_image->m_hex = it->second.data(); - else if (key == string("signature")) key_image->m_signature = it->second.data(); + std::string key = it->first; + if (key == std::string("hex")) key_image->m_hex = it->second.data(); + else if (key == std::string("signature")) key_image->m_signature = it->second.data(); } } - vector> monero_key_image::deserialize_key_images(const string& key_images_json) { + std::vector> monero_key_image::deserialize_key_images(const std::string& key_images_json) { // deserialize json to property node std::istringstream iss = key_images_json.empty() ? std::istringstream() : std::istringstream(key_images_json); @@ -588,12 +588,12 @@ namespace monero { boost::property_tree::read_json(iss, node); // convert property tree to key images - vector> key_images; + std::vector> key_images; for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("keyImages")) { + std::string key = it->first; + if (key == std::string("keyImages")) { for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) { - shared_ptr key_image = make_shared(); + std::shared_ptr key_image = std::make_shared(); monero_key_image::from_property_tree(it2->second, key_image); key_images.push_back(key_image); } @@ -603,15 +603,15 @@ namespace monero { return key_images; } - shared_ptr monero_key_image::copy(const shared_ptr& src, const shared_ptr& tgt) const { - if (this != src.get()) throw runtime_error("this != src"); + std::shared_ptr monero_key_image::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + if (this != src.get()) throw std::runtime_error("this != src"); tgt->m_hex = src->m_hex; tgt->m_signature = src->m_signature; return tgt; } - void monero_key_image::merge(const shared_ptr& self, const shared_ptr& other) { - throw runtime_error("Not implemented"); + void monero_key_image::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + throw std::runtime_error("Not implemented"); } // ------------------------------ MONERO OUTPUT ----------------------------- @@ -637,35 +637,35 @@ namespace monero { return root; } - void monero_output::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& output) { + void monero_output::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& output) { // initialize output from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("keyImage")) { - output->m_key_image = make_shared(); + std::string key = it->first; + if (key == std::string("keyImage")) { + output->m_key_image = std::make_shared(); monero_key_image::from_property_tree(it->second, output->m_key_image.get()); } - else if (key == string("amount")) output->m_amount = it->second.get_value(); - else if (key == string("index")) output->m_index = it->second.get_value(); - else if (key == string("ringOutputIndices")) throw runtime_error("node_to_tx() deserialize ringOutputIndices not implemented"); - else if (key == string("stealthPublicKey")) throw runtime_error("node_to_tx() deserialize stealthPublicKey not implemented"); + else if (key == std::string("amount")) output->m_amount = it->second.get_value(); + else if (key == std::string("index")) output->m_index = it->second.get_value(); + else if (key == std::string("ringOutputIndices")) throw std::runtime_error("node_to_tx() deserialize ringOutputIndices not implemented"); + else if (key == std::string("stealthPublicKey")) throw std::runtime_error("node_to_tx() deserialize stealthPublicKey not implemented"); } } - shared_ptr monero_output::copy(const shared_ptr& src, const shared_ptr& tgt) const { - if (this != src.get()) throw runtime_error("this != src"); + std::shared_ptr monero_output::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + if (this != src.get()) throw std::runtime_error("this != src"); tgt->m_tx = src->m_tx; // reference same parent tx by default - if (src->m_key_image != boost::none) tgt->m_key_image = src->m_key_image.get()->copy(src->m_key_image.get(), make_shared()); + if (src->m_key_image != boost::none) tgt->m_key_image = src->m_key_image.get()->copy(src->m_key_image.get(), std::make_shared()); tgt->m_amount = src->m_amount; tgt->m_index = src->m_index; - if (!src->m_ring_output_indices.empty()) tgt->m_ring_output_indices = vector(src->m_ring_output_indices); + if (!src->m_ring_output_indices.empty()) tgt->m_ring_output_indices = std::vector(src->m_ring_output_indices); tgt->m_stealth_public_key = src->m_stealth_public_key; return tgt; } - void monero_output::merge(const shared_ptr& self, const shared_ptr& other) { - if (this != self.get()) throw runtime_error("this != self"); + void monero_output::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + if (this != self.get()) throw std::runtime_error("this != self"); if (self == other) return; // merge txs if they're different which comes back to merging outputs diff --git a/src/daemon/monero_daemon_model.h b/src/daemon/monero_daemon_model.h index 565bc8d..f1b9f96 100644 --- a/src/daemon/monero_daemon_model.h +++ b/src/daemon/monero_daemon_model.h @@ -58,8 +58,6 @@ #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" -using namespace std; - /** * Public interface for libmonero-cpp library. */ @@ -71,11 +69,11 @@ namespace monero { struct serializable_struct { /** - * Serializes the struct to a json string. + * Serializes the struct to a json std::string. * - * @return the struct serialized to a json string + * @return the struct serialized to a json std::string */ - string serialize() const; + std::string serialize() const; /** * Converts the struct to a rapidjson Value. @@ -109,11 +107,11 @@ namespace monero { * Models a connection to a daemon. */ struct monero_rpc_connection : public serializable_struct { - boost::optional m_uri; - boost::optional m_username; - boost::optional m_password; + boost::optional m_uri; + boost::optional m_username; + boost::optional m_password; - monero_rpc_connection(const boost::optional& uri = boost::none, const boost::optional& username = boost::none, const boost::optional& password = boost::none) : m_uri(uri), m_username(username), m_password(password) {} + monero_rpc_connection(const boost::optional& uri = boost::none, const boost::optional& username = boost::none, const boost::optional& password = boost::none) : m_uri(uri), m_username(username), m_password(password) {} rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; }; @@ -127,7 +125,7 @@ namespace monero { * TODO: a header that is transmitted may have fewer fields like cryptonote::block_header; separate? */ struct monero_block_header : public serializable_struct { - boost::optional m_hash; + boost::optional m_hash; boost::optional m_height; boost::optional m_timestamp; boost::optional m_size; @@ -139,41 +137,41 @@ namespace monero { boost::optional m_major_version; boost::optional m_minor_version; boost::optional m_nonce; - boost::optional m_miner_tx_hash; + boost::optional m_miner_tx_hash; boost::optional m_num_txs; boost::optional m_orphan_status; - boost::optional m_prev_hash; + boost::optional m_prev_hash; boost::optional m_reward; - boost::optional m_pow_hash; + boost::optional m_pow_hash; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - virtual void merge(const shared_ptr& self, const shared_ptr& other); + virtual void merge(const std::shared_ptr& self, const std::shared_ptr& other); }; /** * Models a Monero block in the blockchain. */ struct monero_block : public monero_block_header { - boost::optional m_hex; - boost::optional> m_miner_tx; - vector> m_txs; - vector m_tx_hashes; + boost::optional m_hex; + boost::optional> m_miner_tx; + std::vector> m_txs; + std::vector m_tx_hashes; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - void merge(const shared_ptr& self, const shared_ptr& other); - void merge(const shared_ptr& self, const shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); }; /** * Models a Monero transaction on the blockchain. */ struct monero_tx : public serializable_struct { - static const string DEFAULT_PAYMENT_ID; // default payment id "0000000000000000" - boost::optional> m_block; - boost::optional m_hash; + static const std::string DEFAULT_PAYMENT_ID; // default payment id "0000000000000000" + boost::optional> m_block; + boost::optional m_hash; boost::optional m_version; boost::optional m_is_miner_tx; - boost::optional m_payment_id; + boost::optional m_payment_id; boost::optional m_fee; boost::optional m_ring_size; boost::optional m_relay; @@ -185,33 +183,33 @@ namespace monero { boost::optional m_last_relayed_timestamp; boost::optional m_received_timestamp; boost::optional m_is_double_spend_seen; - boost::optional m_key; - boost::optional m_full_hex; - boost::optional m_pruned_hex; - boost::optional m_prunable_hex; - boost::optional m_prunable_hash; + boost::optional m_key; + boost::optional m_full_hex; + boost::optional m_pruned_hex; + boost::optional m_prunable_hex; + boost::optional m_prunable_hash; boost::optional m_size; boost::optional m_weight; - vector> m_inputs; - vector> m_outputs; - vector m_output_indices; - boost::optional m_metadata; - boost::optional m_common_tx_sets; - vector m_extra; - boost::optional m_rct_signatures; // TODO: implement - boost::optional m_rct_sig_prunable; // TODO: implement + std::vector> m_inputs; + std::vector> m_outputs; + std::vector m_output_indices; + boost::optional m_metadata; + boost::optional m_common_tx_sets; + std::vector m_extra; + boost::optional m_rct_signatures; // TODO: implement + boost::optional m_rct_sig_prunable; // TODO: implement boost::optional m_is_kept_by_block; boost::optional m_is_failed; boost::optional m_last_failed_height; - boost::optional m_last_failed_hash; + boost::optional m_last_failed_hash; boost::optional m_max_used_block_height; - boost::optional m_max_used_block_hash; - vector m_signatures; + boost::optional m_max_used_block_hash; + std::vector m_signatures; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, shared_ptr tx); - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - virtual void merge(const shared_ptr& self, const shared_ptr& other); + static void from_property_tree(const boost::property_tree::ptree& node, std::shared_ptr tx); + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + virtual void merge(const std::shared_ptr& self, const std::shared_ptr& other); boost::optional get_height() const; }; @@ -219,30 +217,30 @@ namespace monero { * Models a Monero key image. */ struct monero_key_image : public serializable_struct { - boost::optional m_hex; - boost::optional m_signature; + boost::optional m_hex; + boost::optional m_signature; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& key_image); - static vector> deserialize_key_images(const string& key_images_json); // TODO: remove this specialty util used once - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - void merge(const shared_ptr& self, const shared_ptr& other); + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& key_image); + static std::vector> deserialize_key_images(const std::string& key_images_json); // TODO: remove this specialty util used once + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + void merge(const std::shared_ptr& self, const std::shared_ptr& other); }; /** * Models a Monero transaction output. */ struct monero_output : public serializable_struct { - shared_ptr m_tx; - boost::optional> m_key_image; + std::shared_ptr m_tx; + boost::optional> m_key_image; boost::optional m_amount; boost::optional m_index; - vector m_ring_output_indices; - boost::optional m_stealth_public_key; + std::vector m_ring_output_indices; + boost::optional m_stealth_public_key; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& output); - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - virtual void merge(const shared_ptr& self, const shared_ptr& other); + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& output); + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + virtual void merge(const std::shared_ptr& self, const std::shared_ptr& other); }; } diff --git a/src/utils/gen_utils.cpp b/src/utils/gen_utils.cpp index 437a897..6e5aba1 100644 --- a/src/utils/gen_utils.cpp +++ b/src/utils/gen_utils.cpp @@ -51,5 +51,3 @@ */ #include "gen_utils.h" - -using namespace std; diff --git a/src/utils/gen_utils.h b/src/utils/gen_utils.h index c1755c0..d91305f 100644 --- a/src/utils/gen_utils.h +++ b/src/utils/gen_utils.h @@ -62,13 +62,11 @@ */ namespace gen_utils { - using namespace std; - // ------------------------- VALUE RECONCILATION- --------------------------- // TODO: refactor common template code - template ::value, T>::type* = nullptr> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const string& err_msg = "") { + template ::value, T>::type* = nullptr> + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const std::string& err_msg = "") { // check for equality if (val1 == val2) return val1; @@ -79,15 +77,15 @@ namespace gen_utils else return val1 == boost::none ? val2 : val1; } - throw runtime_error(string("Cannot reconcile strings: ") + to_string(val1) + string(" vs ") + to_string(val2) + (!err_msg.empty() ? string(". ") + err_msg : string(""))); + throw std::runtime_error(std::string("Cannot reconcile strings: ") + to_string(val1) + std::string(" vs ") + to_string(val2) + (!err_msg.empty() ? std::string(". ") + err_msg : std::string(""))); } - template ::value, T>::type* = nullptr> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& err_msg = "") { + template ::value, T>::type* = nullptr> + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const std::string& err_msg = "") { return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg); } template ::value, T>::type* = nullptr> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const string& err_msg = "") { + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const std::string& err_msg = "") { // check for equality if (val1 == val2) return val1; @@ -100,19 +98,19 @@ namespace gen_utils // resolve different numbers if (resolve_max != boost::none) { - return *resolve_max ? max(*val1, *val2) : min(*val1, *val2); + return *resolve_max ? std::max(*val1, *val2) : std::min(*val1, *val2); } - // throw runtime_error("Cannot reconcile values " + val1 + " and " + val2 + " with config: [" + resolve_defined + ", " + resolve_true + ", " + resolve_max + "]", val1, val2); - throw runtime_error(string("Cannot reconcile integrals: ") + to_string(val1) + string(" vs ") + to_string(val2) + (!err_msg.empty() ? string(". ") + err_msg : string(""))); + // throw std::runtime_error("Cannot reconcile values " + val1 + " and " + val2 + " with config: [" + resolve_defined + ", " + resolve_true + ", " + resolve_max + "]", val1, val2); + throw std::runtime_error(std::string("Cannot reconcile integrals: ") + to_string(val1) + std::string(" vs ") + to_string(val2) + (!err_msg.empty() ? std::string(". ") + err_msg : std::string(""))); } template ::value, T>::type* = nullptr> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& err_msg = "") { + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const std::string& err_msg = "") { return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg); } template ::value, T>::type> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const string& err_msg = "") { + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const std::string& err_msg = "") { // check for equality if (val1 == val2) return val1; @@ -127,16 +125,16 @@ namespace gen_utils if (resolve_true != boost::none) { return val1 == resolve_true ? val1 : val2; // if resolve true, return true, else return false } else { - throw runtime_error(string("Cannot reconcile booleans: ") + to_string(val1) + string(" vs ") + to_string(val2) + (!err_msg.empty() ? string(". ") + err_msg : string(""))); + throw std::runtime_error(std::string("Cannot reconcile booleans: ") + to_string(val1) + std::string(" vs ") + to_string(val2) + (!err_msg.empty() ? std::string(". ") + err_msg : std::string(""))); } } template ::value, T>::type> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& err_msg = "") { + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const std::string& err_msg = "") { return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg); } template - vector reconcile(const vector& v1, const vector& v2, const string& err_msg = "") { + std::vector reconcile(const std::vector& v1, const std::vector& v2, const std::string& err_msg = "") { // check for equality if (v1 == v2) return v1; @@ -146,7 +144,7 @@ namespace gen_utils if (v2.empty()) return v1; // otherwise cannot reconcile - throw runtime_error("Cannot reconcile vectors" + (!err_msg.empty() ? string(". ") + err_msg : string(""))); + throw std::runtime_error("Cannot reconcile vectors" + (!err_msg.empty() ? std::string(". ") + err_msg : std::string(""))); } } #endif /* gen_utils_h */ diff --git a/src/utils/monero_utils.cpp b/src/utils/monero_utils.cpp index 306658f..d98eba7 100644 --- a/src/utils/monero_utils.cpp +++ b/src/utils/monero_utils.cpp @@ -56,7 +56,6 @@ #include "cryptonote_basic/cryptonote_format_utils.h" #include "string_tools.h" -using namespace std; using namespace cryptonote; using namespace monero_utils; @@ -120,7 +119,7 @@ void monero_utils::binary_blocks_to_json(const std::string &bin, std::string &js root.put("status", resp_struct.status); root.put("untrusted", resp_struct.untrusted); // TODO: loss of ints and bools - // convert root to string // TODO: common utility with serial_bridge + // convert root to std::string // TODO: common utility with serial_bridge std::stringstream ss; boost::property_tree::write_json(ss, root, false/*pretty*/); json = ss.str(); @@ -128,38 +127,38 @@ void monero_utils::binary_blocks_to_json(const std::string &bin, std::string &js // ------------------------------- RAPIDJSON ---------------------------------- -string monero_utils::serialize(const rapidjson::Document& doc) { +std::string monero_utils::serialize(const rapidjson::Document& doc) { rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); doc.Accept(writer); return buffer.GetString(); } -void monero_utils::addJsonMember(string key, uint8_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { +void monero_utils::addJsonMember(std::string key, uint8_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { rapidjson::Value field_key(key.c_str(), key.size(), allocator); field.SetInt(val); root.AddMember(field_key, field, allocator); } -void monero_utils::addJsonMember(string key, uint32_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { +void monero_utils::addJsonMember(std::string key, uint32_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { rapidjson::Value field_key(key.c_str(), key.size(), allocator); field.SetUint64(val); root.AddMember(field_key, field, allocator); } -void monero_utils::addJsonMember(string key, uint64_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { +void monero_utils::addJsonMember(std::string key, uint64_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { rapidjson::Value field_key(key.c_str(), key.size(), allocator); field.SetUint64(val); root.AddMember(field_key, field, allocator); } -void monero_utils::addJsonMember(string key, string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { +void monero_utils::addJsonMember(std::string key, std::string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { rapidjson::Value field_key(key.c_str(), key.size(), allocator); field.SetString(val.c_str(), val.size(), allocator); root.AddMember(field_key, field, allocator); } -void monero_utils::addJsonMember(string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root) { +void monero_utils::addJsonMember(std::string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root) { rapidjson::Value field_key(key.c_str(), key.size(), allocator); if (val) { rapidjson::Value field_val(rapidjson::kTrueType); @@ -170,17 +169,17 @@ void monero_utils::addJsonMember(string key, bool val, rapidjson::Document::Allo } } -rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& strs) { +rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& strs) { rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_str(rapidjson::kStringType); - for (const string& str : strs) { + for (const std::string& str : strs) { value_str.SetString(str.c_str(), str.size(), allocator); value_arr.PushBack(value_str, allocator); } return value_arr; } -rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& nums) { +rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& nums) { rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_num(rapidjson::kNumberType); for (const auto& num : nums) { @@ -191,7 +190,7 @@ rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorTy } // TODO: remove these redundant implementations for different sizes? -rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& nums) { +rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& nums) { rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_num(rapidjson::kNumberType); for (const auto& num : nums) { @@ -201,7 +200,7 @@ rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorTy return value_arr; } -rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& nums) { +rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& nums) { rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_num(rapidjson::kNumberType); for (const auto& num : nums) { @@ -213,19 +212,19 @@ rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorTy // ------------------------ PROPERTY TREES --------------------------- -string monero_utils::serialize(const boost::property_tree::ptree& node) { +std::string monero_utils::serialize(const boost::property_tree::ptree& node) { std::stringstream ss; boost::property_tree::write_json(ss, node, false); - string str = ss.str(); + std::string str = ss.str(); return str.substr(0, str.size() - 1); // strip newline } -void monero_utils::deserialize(const string& json, boost::property_tree::ptree& root) { +void monero_utils::deserialize(const std::string& json, boost::property_tree::ptree& root) { std::istringstream iss = json.empty() ? std::istringstream() : std::istringstream(json); try { boost::property_tree::read_json(iss, root); } catch (std::exception const& e) { - throw runtime_error("Invalid JSON"); + throw std::runtime_error("Invalid JSON"); } } @@ -233,10 +232,10 @@ void monero_utils::deserialize(const string& json, boost::property_tree::ptree& // TODO: this is unused -shared_ptr monero_utils::cn_block_to_block(const cryptonote::block& cn_block) { +std::shared_ptr monero_utils::cn_block_to_block(const cryptonote::block& cn_block) { cryptonote::block temp = cn_block; - cout << cryptonote::obj_to_json_str(temp) << endl; - shared_ptr block = make_shared(); + std::cout << cryptonote::obj_to_json_str(temp) << std::endl; + std::shared_ptr block = std::make_shared(); block->m_major_version = cn_block.major_version; block->m_minor_version = cn_block.minor_version; block->m_timestamp = cn_block.timestamp; @@ -249,8 +248,8 @@ shared_ptr monero_utils::cn_block_to_block(const cryptonote::block return block; } -shared_ptr monero_utils::cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet) { - shared_ptr tx = init_as_tx_wallet ? make_shared() : make_shared(); +std::shared_ptr monero_utils::cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet) { + std::shared_ptr tx = init_as_tx_wallet ? std::make_shared() : std::make_shared(); tx->m_version = cn_tx.version; tx->m_unlock_time = cn_tx.unlock_time; tx->m_hash = epee::string_tools::pod_to_hex(cn_tx.hash); @@ -258,23 +257,23 @@ shared_ptr monero_utils::cn_tx_to_tx(const cryptonote::transaction& c // init inputs for (const txin_v& cnVin : cn_tx.vin) { - if (cnVin.which() != 0 && cnVin.which() != 3) throw runtime_error("Unsupported variant type"); + if (cnVin.which() != 0 && cnVin.which() != 3) throw std::runtime_error("Unsupported variant type"); if (tx->m_is_miner_tx == boost::none) tx->m_is_miner_tx = cnVin.which() == 0; if (cnVin.which() != 3) continue; // only process txin_to_key of variant TODO: support other types, like 0 "gen" which is miner tx? - shared_ptr input = init_as_tx_wallet ? make_shared() : make_shared(); + std::shared_ptr input = init_as_tx_wallet ? std::make_shared() : std::make_shared(); input->m_tx = tx; tx->m_inputs.push_back(input); const txin_to_key& txin = boost::get(cnVin); input->m_amount = txin.amount; input->m_ring_output_indices = txin.key_offsets; crypto::key_image cnKeyImage = txin.k_image; - input->m_key_image = make_shared(); + input->m_key_image = std::make_shared(); input->m_key_image.get()->m_hex = epee::string_tools::pod_to_hex(cnKeyImage); } // init outputs for (const tx_out& cnVout : cn_tx.vout) { - shared_ptr output = init_as_tx_wallet ? make_shared() : make_shared(); + std::shared_ptr output = init_as_tx_wallet ? std::make_shared() : std::make_shared(); output->m_tx = tx; tx->m_outputs.push_back(output); output->m_amount = cnVout.amount; diff --git a/src/utils/monero_utils.h b/src/utils/monero_utils.h index 9402c92..5658a5a 100644 --- a/src/utils/monero_utils.h +++ b/src/utils/monero_utils.h @@ -65,7 +65,6 @@ */ namespace monero_utils { - using namespace std; using namespace cryptonote; // ------------------------ CONSTANTS --------------------------- @@ -80,16 +79,16 @@ namespace monero_utils // ------------------------------ RAPIDJSON --------------------------------- - string serialize(const rapidjson::Document& doc); + std::string serialize(const rapidjson::Document& doc); - void addJsonMember(string key, uint8_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); - void addJsonMember(string key, uint32_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); - void addJsonMember(string key, uint64_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); - void addJsonMember(string key, string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); - void addJsonMember(string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root); + void addJsonMember(std::string key, uint8_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); + void addJsonMember(std::string key, uint32_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); + void addJsonMember(std::string key, uint64_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); + void addJsonMember(std::string key, std::string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); + void addJsonMember(std::string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root); // TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation - template rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector>& vals) { + template rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector>& vals) { rapidjson::Value value_arr(rapidjson::kArrayType); for (const auto& val : vals) { value_arr.PushBack(val->to_rapidjson_val(allocator), allocator); @@ -98,7 +97,7 @@ namespace monero_utils } // TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation - template rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& vals) { + template rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& vals) { rapidjson::Value value_arr(rapidjson::kArrayType); for (const auto& val : vals) { value_arr.PushBack(val.to_rapidjson_val(allocator), allocator); @@ -106,21 +105,21 @@ namespace monero_utils return value_arr; } - rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& strs); - rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& nums); - rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& nums); - rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector& nums); + rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& strs); + rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& nums); + rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& nums); + rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector& nums); // ------------------------ PROPERTY TREES --------------------------- // TODO: fully switch from property trees to rapidjson - string serialize(const boost::property_tree::ptree& node); - void deserialize(const string& json, boost::property_tree::ptree& root); + std::string serialize(const boost::property_tree::ptree& node); + void deserialize(const std::string& json, boost::property_tree::ptree& root); // -------------------------------------------------------------------------- - void deserialize(const string& json, boost::property_tree::ptree& root); + void deserialize(const std::string& json, boost::property_tree::ptree& root); /** * Convert a Monero Core cryptonote::block to a block in this library's native model. @@ -128,7 +127,7 @@ namespace monero_utils * @param cn_block is the Core block to convert * @return a block in this library's native model */ - shared_ptr cn_block_to_block(const cryptonote::block& cn_block); + std::shared_ptr cn_block_to_block(const cryptonote::block& cn_block); /** * Convert a Monero Core crpytonote::transaction to a transaction in this library's @@ -137,10 +136,10 @@ namespace monero_utils * @param cn_tx is the Core transaction to convert * @param init_as_tx_wallet specifies if a monero_tx xor monero_tx_wallet should be initialized */ - shared_ptr cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet = false); + std::shared_ptr cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet = false); /** - * Modified from core_rpc_server.cpp to return a string. + * Modified from core_rpc_server.cpp to return a std::string. * * TODO: remove this duplicate, use core_rpc_server instead */ @@ -158,15 +157,15 @@ namespace monero_utils * * @param block is the block to free */ - static void free(shared_ptr block) { - for (shared_ptr& tx : block->m_txs) { + static void free(std::shared_ptr block) { + for (std::shared_ptr& tx : block->m_txs) { tx->m_block.reset(); monero_tx_wallet* tx_wallet = dynamic_cast(tx.get()); if (tx_wallet != nullptr) { if (tx_wallet->m_outgoing_transfer != boost::none) tx_wallet->m_outgoing_transfer.get()->m_tx.reset(); - for (shared_ptr transfer : tx_wallet->m_incoming_transfers) transfer->m_tx.reset(); - for (shared_ptr output : tx_wallet->m_outputs) output->m_tx.reset(); - for (shared_ptr input : tx_wallet->m_inputs) { + for (std::shared_ptr transfer : tx_wallet->m_incoming_transfers) transfer->m_tx.reset(); + for (std::shared_ptr output : tx_wallet->m_outputs) output->m_tx.reset(); + for (std::shared_ptr input : tx_wallet->m_inputs) { input->m_key_image.reset(); input->m_tx.reset(); } @@ -180,8 +179,8 @@ namespace monero_utils * * @param blocks are blocks to free */ - static void free(vector> blocks) { - for (shared_ptr& block : blocks) monero_utils::free(block); + static void free(std::vector> blocks) { + for (std::shared_ptr& block : blocks) monero_utils::free(block); } } #endif /* monero_utils_h */ diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 4af9ac7..5ba60d5 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -54,7 +54,6 @@ #include "monero_wallet_model.h" -using namespace std; using namespace monero; /** @@ -79,7 +78,7 @@ namespace monero { * @param percent_done - sync progress as a percentage * @param message - human-readable description of the current progress */ - virtual void on_sync_progress(uint64_t height, uint64_t start_height, uint64_t end_height, double percent_done, const string& message) {} + virtual void on_sync_progress(uint64_t height, uint64_t start_height, uint64_t end_height, double percent_done, const std::string& message) {} /** * Invoked when a new block is processed. @@ -127,7 +126,7 @@ namespace monero { * @return true if the wallet is view-only, false otherwise */ virtual bool is_view_only() const { - throw runtime_error("is_view_only() not supported"); + throw std::runtime_error("is_view_only() not supported"); } /** @@ -137,8 +136,8 @@ namespace monero { * @param username is the username to authenticate with the daemon (optional) * @param password is the password to authenticate with the daemon (optional) */ - virtual void set_daemon_connection(const string& uri, const string& username = "", const string& password = "") { - throw runtime_error("set_daemon_connection() not supported"); + virtual void set_daemon_connection(const std::string& uri, const std::string& username = "", const std::string& password = "") { + throw std::runtime_error("set_daemon_connection() not supported"); } /** @@ -147,7 +146,7 @@ namespace monero { * @param connection is the connection to set */ virtual void set_daemon_connection(const boost::optional& connection) { - throw runtime_error("set_daemon_connection() not supported"); + throw std::runtime_error("set_daemon_connection() not supported"); } /** @@ -156,7 +155,7 @@ namespace monero { * @return the wallet's daemon connection */ virtual boost::optional get_daemon_connection() const { - throw runtime_error("get_daemon_connection() not supported"); + throw std::runtime_error("get_daemon_connection() not supported"); } /** @@ -165,7 +164,7 @@ namespace monero { * @return true if the wallet is connected to a daemon, false otherwise */ virtual bool is_connected() const { - throw runtime_error("is_connected() not supported"); + throw std::runtime_error("is_connected() not supported"); } /** @@ -174,7 +173,7 @@ namespace monero { * @return true if the daemon is synced with the network, false otherwise */ virtual bool is_daemon_synced() const { - throw runtime_error("is_daemon_synced() not supported"); + throw std::runtime_error("is_daemon_synced() not supported"); } /** @@ -183,7 +182,7 @@ namespace monero { * @return true if the daemon is trusted, false otherwise */ virtual bool is_daemon_trusted() const { - throw runtime_error("is_daemon_trusted() not supported"); + throw std::runtime_error("is_daemon_trusted() not supported"); } /** @@ -192,7 +191,7 @@ namespace monero { * @return true if the wallet is synced with the daemon, false otherwise */ virtual bool is_synced() const { - throw runtime_error("is_synced() not supported"); + throw std::runtime_error("is_synced() not supported"); } /** @@ -201,7 +200,7 @@ namespace monero { * @return the wallet's version */ virtual monero_version get_version() const { - throw runtime_error("get_version() not supported"); + throw std::runtime_error("get_version() not supported"); } /** @@ -209,8 +208,8 @@ namespace monero { * * @return the path of this wallet's file on disk */ - virtual string get_path() const { - throw runtime_error("get_path() not supported"); + virtual std::string get_path() const { + throw std::runtime_error("get_path() not supported"); } /** @@ -219,7 +218,7 @@ namespace monero { * @return the wallet's network type */ virtual monero_network_type get_network_type() const { - throw runtime_error("get_network_type() not supported"); + throw std::runtime_error("get_network_type() not supported"); } /** @@ -227,8 +226,8 @@ namespace monero { * * @param mnemonic is assigned the wallet's mnemonic phrase */ - virtual string get_mnemonic() const { - throw runtime_error("get_mnemonic() not supported"); + virtual std::string get_mnemonic() const { + throw std::runtime_error("get_mnemonic() not supported"); } /** @@ -236,8 +235,8 @@ namespace monero { * * @return the language of the wallet's mnemonic phrase */ - virtual string get_mnemonic_language() const { - throw runtime_error("get_mnemonic_language() not supported"); + virtual std::string get_mnemonic_language() const { + throw std::runtime_error("get_mnemonic_language() not supported"); } /** @@ -245,8 +244,8 @@ namespace monero { * * @return the wallet's public view key */ - virtual string get_public_view_key() const { - throw runtime_error("get_public_view_key() not supported"); + virtual std::string get_public_view_key() const { + throw std::runtime_error("get_public_view_key() not supported"); } /** @@ -254,8 +253,8 @@ namespace monero { * * @return the wallet's private view key */ - virtual string get_private_view_key() const { - throw runtime_error("get_private_view_key() not supported"); + virtual std::string get_private_view_key() const { + throw std::runtime_error("get_private_view_key() not supported"); } /** @@ -263,8 +262,8 @@ namespace monero { * * @return the wallet's public spend key */ - virtual string get_public_spend_key() const { - throw runtime_error("get_public_spend_key() not supported"); + virtual std::string get_public_spend_key() const { + throw std::runtime_error("get_public_spend_key() not supported"); } /** @@ -272,8 +271,8 @@ namespace monero { * * @return the wallet's private spend key */ - virtual string get_private_spend_key() const { - throw runtime_error("get_private_spend_key() not supported"); + virtual std::string get_private_spend_key() const { + throw std::runtime_error("get_private_spend_key() not supported"); } /** @@ -281,7 +280,7 @@ namespace monero { * * @return the wallet's primary address */ - virtual string get_primary_address() const { + virtual std::string get_primary_address() const { return get_address(0, 0); } @@ -292,8 +291,8 @@ namespace monero { * @param subaddress_idx specifies the subaddress index within the account * @return the receive address of the specified subaddress */ - virtual string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const { - throw runtime_error("get_address() not supported"); + virtual std::string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const { + throw std::runtime_error("get_address() not supported"); } /** @@ -303,8 +302,8 @@ namespace monero { * @return the account and subaddress indices * @throws exception if address is not a wallet address */ - virtual monero_subaddress get_address_index(const string& address) const { - throw runtime_error("get_address_index() not supported"); + virtual monero_subaddress get_address_index(const std::string& address) const { + throw std::runtime_error("get_address_index() not supported"); } /** @@ -314,8 +313,8 @@ namespace monero { * @param payment_id is the integrated addresse's payment id (defaults to randomly generating new payment id) * @return the integrated address */ - virtual monero_integrated_address get_integrated_address(const string& standard_address = "", const string& payment_id = "") const { - throw runtime_error("get_integrated_address() not supported"); + virtual monero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const { + throw std::runtime_error("get_integrated_address() not supported"); } /** @@ -324,8 +323,8 @@ namespace monero { * @param integrated_address is an integrated address to decode * @return the decoded integrated address including standard address and payment id */ - virtual monero_integrated_address decode_integrated_address(const string& integrated_address) const { - throw runtime_error("decode_integrated_address() not supported"); + virtual monero_integrated_address decode_integrated_address(const std::string& integrated_address) const { + throw std::runtime_error("decode_integrated_address() not supported"); } /** @@ -334,7 +333,7 @@ namespace monero { * @return the height of the last block processed by the wallet */ virtual uint64_t get_height() const { - throw runtime_error("get_height() not supported"); + throw std::runtime_error("get_height() not supported"); } /** @@ -343,7 +342,7 @@ namespace monero { * @return the height of the first block that the wallet scans */ virtual uint64_t get_sync_height() const { - throw runtime_error("get_sync_height() not supported"); + throw std::runtime_error("get_sync_height() not supported"); } /** @@ -352,7 +351,7 @@ namespace monero { * @param sync_height is the height of the first block that the wallet scans */ virtual void set_sync_height(uint64_t sync_height) { - throw runtime_error("set_sync_height() not supported"); + throw std::runtime_error("set_sync_height() not supported"); } /** @@ -361,7 +360,7 @@ namespace monero { * @return the height that the wallet's daemon is synced to */ virtual uint64_t get_daemon_height() const { - throw runtime_error("get_daemon_height() not supported"); + throw std::runtime_error("get_daemon_height() not supported"); } /** @@ -370,7 +369,7 @@ namespace monero { * @return the maximum height of the peers the wallet's daemon is connected to */ virtual uint64_t get_daemon_max_peer_height() const { - throw runtime_error("get_daemon_max_peer_height() not supported"); + throw std::runtime_error("get_daemon_max_peer_height() not supported"); } /** @@ -379,7 +378,7 @@ namespace monero { * @param listener is the listener to receive wallet notifications */ virtual void add_listener(monero_wallet_listener& listener) { - throw runtime_error("add_listener() not supported"); + throw std::runtime_error("add_listener() not supported"); } /** @@ -388,14 +387,14 @@ namespace monero { * @param listener is the listener to unregister */ virtual void remove_listener(monero_wallet_listener& listener) { - throw runtime_error("remove_listener() not supported"); + throw std::runtime_error("remove_listener() not supported"); } /** * Get the listeners registered with the wallet. */ - virtual set get_listeners() { - throw runtime_error("get_listeners() not supported"); + virtual std::set get_listeners() { + throw std::runtime_error("get_listeners() not supported"); } /** @@ -404,7 +403,7 @@ namespace monero { * @return the sync result */ virtual monero_sync_result sync() { - throw runtime_error("sync() not supported"); + throw std::runtime_error("sync() not supported"); } /** @@ -414,7 +413,7 @@ namespace monero { * @return the sync result */ virtual monero_sync_result sync(monero_wallet_listener& listener) { - throw runtime_error("sync() not supported"); + throw std::runtime_error("sync() not supported"); } /** @@ -424,7 +423,7 @@ namespace monero { * @return the sync result */ virtual monero_sync_result sync(uint64_t start_height) { - throw runtime_error("sync() not supported"); + throw std::runtime_error("sync() not supported"); } /** @@ -435,21 +434,21 @@ namespace monero { * @return the sync result */ virtual monero_sync_result sync(uint64_t start_height, monero_wallet_listener& listener) { - throw runtime_error("sync() not supported"); + throw std::runtime_error("sync() not supported"); } /** * Start an asynchronous thread to continuously synchronize the wallet with the daemon. */ virtual void start_syncing() { - throw runtime_error("start_syncing() not supported"); + throw std::runtime_error("start_syncing() not supported"); } /** * Stop the asynchronous thread to continuously synchronize the wallet with the daemon. */ virtual void stop_syncing() { - throw runtime_error("stop_syncing() not supported"); + throw std::runtime_error("stop_syncing() not supported"); } /** @@ -462,7 +461,7 @@ namespace monero { * daemon. This method should be manually invoked to rescan outputs. */ virtual void rescan_spent() { - throw runtime_error("rescan_spent() not supported"); + throw std::runtime_error("rescan_spent() not supported"); } /** @@ -473,7 +472,7 @@ namespace monero { * tx notes, etc. */ virtual void rescan_blockchain() { - throw runtime_error("rescan_blockchain() not supported"); + throw std::runtime_error("rescan_blockchain() not supported"); } /** @@ -482,7 +481,7 @@ namespace monero { * @return the wallet's balance */ virtual uint64_t get_balance() const { - throw runtime_error("get_balance() not supported"); + throw std::runtime_error("get_balance() not supported"); } /** @@ -492,7 +491,7 @@ namespace monero { * @return the account's balance */ virtual uint64_t get_balance(uint32_t account_idx) const { - throw runtime_error("get_balance() not supported"); + throw std::runtime_error("get_balance() not supported"); } /** @@ -503,7 +502,7 @@ namespace monero { * @return the subaddress's balance */ virtual uint64_t get_balance(uint32_t account_idx, uint32_t subaddress_idx) const { - throw runtime_error("get_balance() not supported"); + throw std::runtime_error("get_balance() not supported"); } /** @@ -512,7 +511,7 @@ namespace monero { * @return the wallet's unlocked balance */ virtual uint64_t get_unlocked_balance() const { - throw runtime_error("get_unlocked_balance() not supported"); + throw std::runtime_error("get_unlocked_balance() not supported"); } /** @@ -522,7 +521,7 @@ namespace monero { * @return the account's unlocked balance */ virtual uint64_t get_unlocked_balance(uint32_t account_idx) const { - throw runtime_error("get_unlocked_balance() not supported"); + throw std::runtime_error("get_unlocked_balance() not supported"); } /** @@ -533,7 +532,7 @@ namespace monero { * @return the subaddress's balance */ virtual uint64_t get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const { - throw runtime_error("get_unlocked_balance() not supported"); + throw std::runtime_error("get_unlocked_balance() not supported"); } /** @@ -541,8 +540,8 @@ namespace monero { * * @return List are all accounts within the wallet */ - virtual vector get_accounts() const { - return get_accounts(false, string("")); + virtual std::vector get_accounts() const { + return get_accounts(false, std::string("")); } /** @@ -551,7 +550,7 @@ namespace monero { * @param include_subaddresses specifies if subaddresses should be included * @return List are all accounts */ - virtual vector get_accounts(bool include_subaddresses) const { + virtual std::vector get_accounts(bool include_subaddresses) const { return get_accounts(include_subaddresses, ""); } @@ -561,7 +560,7 @@ namespace monero { * @param tag is the tag for filtering accounts, all accounts if null * @return List are all accounts for the wallet with the given tag */ - virtual vector get_accounts(const string& tag) const { + virtual std::vector get_accounts(const std::string& tag) const { return get_accounts(false, tag); } @@ -572,8 +571,8 @@ namespace monero { * @param tag is the tag for filtering accounts, all accounts if null * @return List are all accounts for the wallet with the given tag */ - virtual vector get_accounts(bool include_subaddresses, const string& tag) const { - throw runtime_error("get_accounts() not supported"); + virtual std::vector get_accounts(bool include_subaddresses, const std::string& tag) const { + throw std::runtime_error("get_accounts() not supported"); } /** @@ -594,7 +593,7 @@ namespace monero { * @return the retrieved account */ virtual monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const { - throw runtime_error("get_account() not supported"); + throw std::runtime_error("get_account() not supported"); } /** @@ -603,8 +602,8 @@ namespace monero { * @param label specifies the label for the account's first subaddress (optional) * @return the created account */ - virtual monero_account create_account(const string& label = "") { - throw runtime_error("create_account() not supported"); + virtual monero_account create_account(const std::string& label = "") { + throw std::runtime_error("create_account() not supported"); } /** @@ -613,8 +612,8 @@ namespace monero { * @param account_idx specifies the account to get subaddresses within * @return List are the retrieved subaddresses */ - virtual vector get_subaddresses(const uint32_t account_idx) const { - return get_subaddresses(account_idx, vector()); + virtual std::vector get_subaddresses(const uint32_t account_idx) const { + return get_subaddresses(account_idx, std::vector()); } /** @@ -624,8 +623,8 @@ namespace monero { * @param subaddress_indices are specific subaddresses to get (optional) * @return the retrieved subaddresses */ - virtual vector get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const { - throw runtime_error("get_subaddresses() not supported"); + virtual std::vector get_subaddresses(const uint32_t account_idx, const std::vector& subaddress_indices) const { + throw std::runtime_error("get_subaddresses() not supported"); } /** @@ -636,18 +635,18 @@ namespace monero { * @return the retrieved subaddress */ virtual monero_subaddress get_subaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const { - throw runtime_error("get_subaddress() not supported"); + throw std::runtime_error("get_subaddress() not supported"); } /** * Create a subaddress within an account. * * @param account_idx specifies the index of the account to create the subaddress within - * @param label specifies the the label for the subaddress (defaults to empty string) + * @param label specifies the the label for the subaddress (defaults to empty std::string) * @return the created subaddress */ - virtual monero_subaddress create_subaddress(uint32_t account_idx, const string& label = "") { - throw runtime_error("create_subaddress() not supported"); + virtual monero_subaddress create_subaddress(uint32_t account_idx, const std::string& label = "") { + throw std::runtime_error("create_subaddress() not supported"); } /** @@ -656,8 +655,8 @@ namespace monero { * * @return all wallet transactions */ - virtual vector> get_txs() const { - throw runtime_error("get_txs() not supported"); + virtual std::vector> get_txs() const { + throw std::runtime_error("get_txs() not supported"); } /** @@ -672,8 +671,8 @@ namespace monero { * @param query filters query results (optional) * @return wallet transactions per the query */ - virtual vector> get_txs(const monero_tx_query& query) const { - throw runtime_error("get_txs(query) not supported"); + virtual std::vector> get_txs(const monero_tx_query& query) const { + throw std::runtime_error("get_txs(query) not supported"); } /** @@ -684,8 +683,8 @@ namespace monero { * @param missing_tx_hashes are populated with requested tx hashes that are not part of the wallet * @return wallet transactions per the request */ - virtual vector> get_txs(const monero_tx_query& query, vector& missing_tx_hashes) const { - throw runtime_error("get_txs(query, missing_tx_hashes) not supported"); + virtual std::vector> get_txs(const monero_tx_query& query, std::vector& missing_tx_hashes) const { + throw std::runtime_error("get_txs(query, missing_tx_hashes) not supported"); } /** @@ -704,8 +703,8 @@ namespace monero { * @param query filters query results (optional) * @return wallet transfers per the query */ - virtual vector> get_transfers(const monero_transfer_query& query) const { - throw runtime_error("get_transfers() not supported"); + virtual std::vector> get_transfers(const monero_transfer_query& query) const { + throw std::runtime_error("get_transfers() not supported"); } /** @@ -720,17 +719,17 @@ namespace monero { * @param query specifies query options (optional) * @return wallet outputs per the query */ - virtual vector> get_outputs(const monero_output_query& query) const { - throw runtime_error("get_outputs() not supported"); + virtual std::vector> get_outputs(const monero_output_query& query) const { + throw std::runtime_error("get_outputs() not supported"); } /** * Export all outputs in hex format. * - * @return all outputs in hex format, empty string if no outputs + * @return all outputs in hex format, empty std::string if no outputs */ - virtual string get_outputs_hex() const { - throw runtime_error("get_outputs_hex() not supported"); + virtual std::string get_outputs_hex() const { + throw std::runtime_error("get_outputs_hex() not supported"); } /** @@ -739,8 +738,8 @@ namespace monero { * @param outputs_hex are outputs in hex format * @return the number of outputs imported */ - virtual int import_outputs_hex(const string& outputs_hex) { - throw runtime_error("import_outputs_hex() not supported"); + virtual int import_outputs_hex(const std::string& outputs_hex) { + throw std::runtime_error("import_outputs_hex() not supported"); } /** @@ -748,8 +747,8 @@ namespace monero { * * @return the wallet's signed key images */ - virtual vector> get_key_images() const { - throw runtime_error("get_key_images() not supported"); + virtual std::vector> get_key_images() const { + throw std::runtime_error("get_key_images() not supported"); } /** @@ -758,8 +757,8 @@ namespace monero { * @param key_images are key images to import and verify (requires hex and signature) * @return results of the import */ - virtual shared_ptr import_key_images(const vector>& key_images) { - throw runtime_error("import_key_images() not supported"); + virtual std::shared_ptr import_key_images(const std::vector>& key_images) { + throw std::runtime_error("import_key_images() not supported"); } /** @@ -768,8 +767,8 @@ namespace monero { * @param config configures the transaction to create * @return the created transaction */ - virtual shared_ptr create_tx(const monero_tx_config& config) { - if (config.m_can_split != boost::none && config.m_can_split.get()) throw runtime_error("Cannot split transactions with create_tx(); use create_txs() instead"); + virtual std::shared_ptr create_tx(const monero_tx_config& config) { + if (config.m_can_split != boost::none && config.m_can_split.get()) throw std::runtime_error("Cannot split transactions with create_tx(); use create_txs() instead"); monero_tx_config config_copy = monero_tx_config(config); config_copy.m_can_split = false; return create_txs(config_copy)[0]; @@ -781,8 +780,8 @@ namespace monero { * @param config configures the transactions to create * @return the created transactions */ - virtual vector> create_txs(const monero_tx_config& config) { - throw runtime_error("create_txs() not supported"); + virtual std::vector> create_txs(const monero_tx_config& config) { + throw std::runtime_error("create_txs() not supported"); } /** @@ -791,8 +790,8 @@ namespace monero { * @param config is the sweep configuration * @return the created transactions */ - virtual vector> sweep_unlocked(const monero_tx_config& config) { - throw runtime_error("sweep_unlocked() not supported"); + virtual std::vector> sweep_unlocked(const monero_tx_config& config) { + throw std::runtime_error("sweep_unlocked() not supported"); } /** @@ -801,8 +800,8 @@ namespace monero { * @param config configures the sweep transaction * @return the created transaction */ - virtual shared_ptr sweep_output(const monero_tx_config& config) { - throw runtime_error("sweep_output() not supported"); + virtual std::shared_ptr sweep_output(const monero_tx_config& config) { + throw std::runtime_error("sweep_output() not supported"); } /** @@ -811,18 +810,18 @@ namespace monero { * @param relay specifies if the resulting transaction should be relayed (default false) * @return the created transactions */ - virtual vector> sweep_dust(bool relay = false) { - throw runtime_error("sweep_dust() not supported"); + virtual std::vector> sweep_dust(bool relay = false) { + throw std::runtime_error("sweep_dust() not supported"); } /** * Relay a transaction previously created without relaying. * * @param txMetadata is transaction metadata previously created without relaying - * @return string is the hash of the relayed tx + * @return std::string is the hash of the relayed tx */ - virtual string relay_tx(const string& tx_metadata) { - vector tx_metadatas; + virtual std::string relay_tx(const std::string& tx_metadata) { + std::vector tx_metadatas; tx_metadatas.push_back(tx_metadata); return relay_txs(tx_metadatas)[0]; } @@ -833,7 +832,7 @@ namespace monero { * @param tx is the transaction to relay * @return the hash of the relayed tx */ - virtual string relay_tx(const monero_tx_wallet& tx) { + virtual std::string relay_tx(const monero_tx_wallet& tx) { return relay_tx(tx.m_metadata.get()); } @@ -843,9 +842,9 @@ namespace monero { * @param txs are the transactions to relay * @return the hashes of the relayed txs */ - virtual vector relay_txs(const vector>& txs) { - vector tx_hexes; - for (const shared_ptr& tx : txs) tx_hexes.push_back(tx->m_metadata.get()); + virtual std::vector relay_txs(const std::vector>& txs) { + std::vector tx_hexes; + for (const std::shared_ptr& tx : txs) tx_hexes.push_back(tx->m_metadata.get()); return relay_txs(tx_hexes); } @@ -855,8 +854,8 @@ namespace monero { * @param tx_metadatas are transaction metadata previously created without relaying * @return the hashes of the relayed txs */ - virtual vector relay_txs(const vector& tx_metadatas) { - throw runtime_error("relay_txs() not supported"); + virtual std::vector relay_txs(const std::vector& tx_metadatas) { + throw std::runtime_error("relay_txs() not supported"); } /** @@ -866,7 +865,7 @@ namespace monero { * @return the parsed tx set containing structured transactions */ virtual monero_tx_set parse_tx_set(const monero_tx_set& tx_set) { - throw runtime_error("parse_tx_set() not supported"); + throw std::runtime_error("parse_tx_set() not supported"); } /** @@ -875,8 +874,8 @@ namespace monero { * @param unsigned_tx_hex is unsigned transaction hex from when the transactions were created * @return the signed transaction hex */ - virtual string sign_txs(const string& unsigned_tx_hex) { - throw runtime_error("sign_txs() not supported"); + virtual std::string sign_txs(const std::string& unsigned_tx_hex) { + throw std::runtime_error("sign_txs() not supported"); } /** @@ -885,8 +884,8 @@ namespace monero { * @param signed_tx_hex is signed transaction hex from signTxs() * @return the resulting transaction hashes */ - virtual vector submit_txs(const string& signed_tx_hex) { - throw runtime_error("submit_txs() not supported"); + virtual std::vector submit_txs(const std::string& signed_tx_hex) { + throw std::runtime_error("submit_txs() not supported"); } /** @@ -895,8 +894,8 @@ namespace monero { * @param msg is the message to sign * @return the signature */ - virtual string sign_message(const string& msg) const { - throw runtime_error("sign_message() not supported"); + virtual std::string sign_message(const std::string& msg) const { + throw std::runtime_error("sign_message() not supported"); } /** @@ -907,8 +906,8 @@ namespace monero { * @param signature is the signature * @return true if the signature is good, false otherwise */ - virtual bool verify_message(const string& msg, const string& address, const string& signature) const { - throw runtime_error("verify_message() not supported"); + virtual bool verify_message(const std::string& msg, const std::string& address, const std::string& signature) const { + throw std::runtime_error("verify_message() not supported"); } /** @@ -917,8 +916,8 @@ namespace monero { * @param tx_hash is the transaction's hash * @return is the transaction's secret key */ - virtual string get_tx_key(const string& tx_hash) const { - throw runtime_error("get_tx_key() not supported"); + virtual std::string get_tx_key(const std::string& tx_hash) const { + throw std::runtime_error("get_tx_key() not supported"); } /** @@ -929,8 +928,8 @@ namespace monero { * @param address is the destination public address of the transaction * @return the result of the check */ - virtual shared_ptr check_tx_key(const string& tx_hash, const string& tx_key, const string& address) const { - throw runtime_error("check_tx_key() not supported"); + virtual std::shared_ptr check_tx_key(const std::string& tx_hash, const std::string& tx_key, const std::string& address) const { + throw std::runtime_error("check_tx_key() not supported"); } /** @@ -941,8 +940,8 @@ namespace monero { * @param message is a message to include with the signature to further authenticate the proof (optional) * @return the transaction signature */ - virtual string get_tx_proof(const string& tx_hash, const string& address, const string& message) const { - throw runtime_error("get_tx_proof() not supported"); + virtual std::string get_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message) const { + throw std::runtime_error("get_tx_proof() not supported"); } /** @@ -954,8 +953,8 @@ namespace monero { * @param signature is the transaction signature to confirm * @return the result of the check */ - virtual shared_ptr check_tx_proof(const string& tx_hash, const string& address, const string& message, const string& signature) const { - throw runtime_error("check_tx_proof() not supported"); + virtual std::shared_ptr check_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message, const std::string& signature) const { + throw std::runtime_error("check_tx_proof() not supported"); } /** @@ -965,8 +964,8 @@ namespace monero { * @param message is a message to include with the signature to further authenticate the proof (optional) * @return the transaction signature */ - virtual string get_spend_proof(const string& tx_hash, const string& message) const { - throw runtime_error("get_spend_proof() not supported"); + virtual std::string get_spend_proof(const std::string& tx_hash, const std::string& message) const { + throw std::runtime_error("get_spend_proof() not supported"); } /** @@ -977,8 +976,8 @@ namespace monero { * @param signature is the transaction signature to confirm * @return true if the signature is good, false otherwise */ - virtual bool check_spend_proof(const string& tx_hash, const string& message, const string& signature) const { - throw runtime_error("check_spend_proof() not supported"); + virtual bool check_spend_proof(const std::string& tx_hash, const std::string& message, const std::string& signature) const { + throw std::runtime_error("check_spend_proof() not supported"); } /** @@ -987,8 +986,8 @@ namespace monero { * @param message is a message included with the signature to further authenticate the proof (optional) * @return the reserve proof signature */ - virtual string get_reserve_proof_wallet(const string& message) const { - throw runtime_error("get_reserve_proof_wallet() not supported"); + virtual std::string get_reserve_proof_wallet(const std::string& message) const { + throw std::runtime_error("get_reserve_proof_wallet() not supported"); } /** @@ -999,8 +998,8 @@ namespace monero { * @param message is a message to include with the signature to further authenticate the proof (optional) * @return the reserve proof signature */ - virtual string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const { - throw runtime_error("get_reserve_proof_account() not supported"); + virtual std::string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const std::string& message) const { + throw std::runtime_error("get_reserve_proof_account() not supported"); } /** @@ -1011,8 +1010,8 @@ namespace monero { * @param signature is the reserve proof signature to check * @return the result of checking the signature proof */ - virtual shared_ptr check_reserve_proof(const string& address, const string& message, const string& signature) const { - throw runtime_error("check_reserve_proof() not supported"); + virtual std::shared_ptr check_reserve_proof(const std::string& address, const std::string& message, const std::string& signature) const { + throw std::runtime_error("check_reserve_proof() not supported"); } /** @@ -1021,8 +1020,8 @@ namespace monero { * @param tx_hash specifies the transaction to get the note of * @return the tx note */ - virtual string get_tx_note(const string& tx_hash) const { - throw runtime_error("get_tx_note() not supported"); + virtual std::string get_tx_note(const std::string& tx_hash) const { + throw std::runtime_error("get_tx_note() not supported"); } /** @@ -1031,8 +1030,8 @@ namespace monero { * @param tx_hashes identify the transactions to get notes for * @preturns notes for the transactions */ - virtual vector get_tx_notes(const vector& tx_hashes) const { - throw runtime_error("get_tx_notes() not supported"); + virtual std::vector get_tx_notes(const std::vector& tx_hashes) const { + throw std::runtime_error("get_tx_notes() not supported"); } /** @@ -1041,8 +1040,8 @@ namespace monero { * @param tx_hash specifies the transaction * @param note specifies the note */ - virtual void set_tx_note(const string& tx_hash, const string& note) { - throw runtime_error("set_tx_note() not supported"); + virtual void set_tx_note(const std::string& tx_hash, const std::string& note) { + throw std::runtime_error("set_tx_note() not supported"); } /** @@ -1051,8 +1050,8 @@ namespace monero { * @param tx_hashes specify the transactions to set notes for * @param notes are the notes to set for the transactions */ - virtual void set_tx_notes(const vector& tx_hashes, const vector& notes) { - throw runtime_error("set_tx_notes() not supported"); + virtual void set_tx_notes(const std::vector& tx_hashes, const std::vector& notes) { + throw std::runtime_error("set_tx_notes() not supported"); } /** @@ -1061,8 +1060,8 @@ namespace monero { * @param indices are indices of the entries to get * @return the address book entries */ - virtual vector get_address_book_entries(const vector& indices) const { - throw runtime_error("get_address_book_entries() not supported"); + virtual std::vector get_address_book_entries(const std::vector& indices) const { + throw std::runtime_error("get_address_book_entries() not supported"); } /** @@ -1072,8 +1071,8 @@ namespace monero { * @param description is the entry description (optional) * @return the index of the added entry */ - virtual uint64_t add_address_book_entry(const string& address, const string& description) { - throw runtime_error("add_address_book_entry() not supported"); + virtual uint64_t add_address_book_entry(const std::string& address, const std::string& description) { + throw std::runtime_error("add_address_book_entry() not supported"); } /** @@ -1085,8 +1084,8 @@ namespace monero { * @param set_description specifies if the description should be updated * @param description is the updated description */ - virtual void edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description) { - throw runtime_error("edit_address_book_entry() not supported"); + virtual void edit_address_book_entry(uint64_t index, bool set_address, const std::string& address, bool set_description, const std::string& description) { + throw std::runtime_error("edit_address_book_entry() not supported"); } /** @@ -1095,7 +1094,7 @@ namespace monero { * @param index is the index of the entry to delete */ virtual void delete_address_book_entry(uint64_t index) { - throw runtime_error("delete_address_book_entry() not supported"); + throw std::runtime_error("delete_address_book_entry() not supported"); } /** @@ -1104,8 +1103,8 @@ namespace monero { * @param config specifies configuration for a potential tx * @return is the payment uri */ - virtual string create_payment_uri(const monero_tx_config& config) const { - throw runtime_error("create_payment_uri() not supported"); + virtual std::string create_payment_uri(const monero_tx_config& config) const { + throw std::runtime_error("create_payment_uri() not supported"); } /** @@ -1114,8 +1113,8 @@ namespace monero { * @param uri is the payment uri to parse * @return the tx configuration parsed from the uri */ - virtual shared_ptr parse_payment_uri(const string& uri) const { - throw runtime_error("parse_payment_uri() not supported"); + virtual std::shared_ptr parse_payment_uri(const std::string& uri) const { + throw std::runtime_error("parse_payment_uri() not supported"); } /** @@ -1125,8 +1124,8 @@ namespace monero { * @param value is set to the key's value if set * @return true if the key's value has been set, false otherwise */ - virtual bool get_attribute(const string& key, string& value) const { - throw runtime_error("get_attribute() not supported"); + virtual bool get_attribute(const std::string& key, std::string& value) const { + throw std::runtime_error("get_attribute() not supported"); } /** @@ -1135,8 +1134,8 @@ namespace monero { * @param key is the attribute key * @param val is the attribute value */ - virtual void set_attribute(const string& key, const string& val) { - throw runtime_error("set_attribute() not supported"); + virtual void set_attribute(const std::string& key, const std::string& val) { + throw std::runtime_error("set_attribute() not supported"); } /** @@ -1147,14 +1146,14 @@ namespace monero { * @param ignore_battery specifies if the battery should be ignored for mining (optional) */ virtual void start_mining(boost::optional num_threads, boost::optional background_mining, boost::optional ignore_battery) { - throw runtime_error("start_mining() not supported"); + throw std::runtime_error("start_mining() not supported"); } /** * Stop mining. */ virtual void stop_mining() { - throw runtime_error("stop_mining() not supported"); + throw std::runtime_error("stop_mining() not supported"); } /** @@ -1163,7 +1162,7 @@ namespace monero { * @return the height of the next block when it is added to the chain */ virtual uint64_t wait_for_next_block() { - throw runtime_error("wait_for_next_block() not supported"); + throw std::runtime_error("wait_for_next_block() not supported"); } /** @@ -1172,7 +1171,7 @@ namespace monero { * @return true if importing multisig data is needed for returning a correct balance, false otherwise */ virtual bool is_multisig_import_needed() const { - throw runtime_error("is_multisig_import_needed() not supported"); + throw std::runtime_error("is_multisig_import_needed() not supported"); } // TODO: bool is_multisig() @@ -1183,7 +1182,7 @@ namespace monero { * @return multisig info about this wallet */ virtual monero_multisig_info get_multisig_info() { - throw runtime_error("get_multisig_info() not supported"); + throw std::runtime_error("get_multisig_info() not supported"); } /** @@ -1192,8 +1191,8 @@ namespace monero { * * @return this wallet's multisig hex to share with participants */ - virtual string prepare_multisig() { - throw runtime_error("prepare_multisig() not supported"); + virtual std::string prepare_multisig() { + throw std::runtime_error("prepare_multisig() not supported"); } /** @@ -1204,8 +1203,8 @@ namespace monero { * @password is the wallet password * @return the result which has the multisig's address xor this wallet's multisig hex to share with participants iff not N/N */ - virtual monero_multisig_init_result make_multisig(const vector& multisig_hexes, int threshold, const string& password) { - throw runtime_error("make_multisig() not supported"); + virtual monero_multisig_init_result make_multisig(const std::vector& multisig_hexes, int threshold, const std::string& password) { + throw std::runtime_error("make_multisig() not supported"); } /** @@ -1217,8 +1216,8 @@ namespace monero { * @param password is the wallet's password // TODO monero core: redundant? wallet is created with password * @return the result which has the multisig's address xor this wallet's multisig hex to share with participants iff not done */ - virtual monero_multisig_init_result exchange_multisig_keys(const vector& mutisig_hexes, const string& password) { - throw runtime_error("exchange_multisig_keys() not supported"); + virtual monero_multisig_init_result exchange_multisig_keys(const std::vector& mutisig_hexes, const std::string& password) { + throw std::runtime_error("exchange_multisig_keys() not supported"); } /** @@ -1226,8 +1225,8 @@ namespace monero { * * @return this wallet's multisig info as hex for other participants */ - virtual string get_multisig_hex() { - throw runtime_error("get_multisig_hex() not supported"); + virtual std::string get_multisig_hex() { + throw std::runtime_error("get_multisig_hex() not supported"); } /** @@ -1240,8 +1239,8 @@ namespace monero { * @param multisig_hexes are multisig hex from each participant * @return the number of outputs signed with the given multisig hex */ - virtual int import_multisig_hex(const vector& multisig_hexes) { - throw runtime_error("import_multisig_hex() not supported"); + virtual int import_multisig_hex(const std::vector& multisig_hexes) { + throw std::runtime_error("import_multisig_hex() not supported"); } /** @@ -1250,25 +1249,25 @@ namespace monero { * @param multisig_tx_hex is the hex shared among the multisig transactions when they were created * @return the result of signing the multisig transactions */ - virtual monero_multisig_sign_result sign_multisig_tx_hex(const string& multisig_tx_hex) { - throw runtime_error("monero_multisig_sign_result() not supported"); + virtual monero_multisig_sign_result sign_multisig_tx_hex(const std::string& multisig_tx_hex) { + throw std::runtime_error("monero_multisig_sign_result() not supported"); } /** - * Submit signed multisig transactions as represented by a hex string. + * Submit signed multisig transactions as represented by a hex std::string. * * @param signed_multisig_tx_hex is the signed multisig hex returned from signMultisigTxs() * @return the resulting transaction hashes */ - virtual vector submit_multisig_tx_hex(const string& signed_multisig_tx_hex) { - throw runtime_error("submit_multisig_tx_hex() not supported"); + virtual std::vector submit_multisig_tx_hex(const std::string& signed_multisig_tx_hex) { + throw std::runtime_error("submit_multisig_tx_hex() not supported"); } /** * Save the wallet at its current path. */ virtual void save() { - throw runtime_error("save() not supported"); + throw std::runtime_error("save() not supported"); } /** @@ -1277,8 +1276,8 @@ namespace monero { * @param path is the new wallet's path * @param password is the new wallet's password */ - virtual void move_to(string path, string password) { - throw runtime_error("move_to() not supported"); + virtual void move_to(std::string path, std::string password) { + throw std::runtime_error("move_to() not supported"); } /** @@ -1287,7 +1286,7 @@ namespace monero { * @param save specifies if the wallet should be saved before being closed (default false) */ virtual void close(bool save = false) { - throw runtime_error("close() not supported"); + throw std::runtime_error("close() not supported"); } }; } diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index 1835c98..d79846b 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -26,10 +26,10 @@ * * All rights reserved. * - * 1. Redistributions of source code must retain the above copyright notice, this list of + * 1. Redistributions of source code must retain the above copyright notice, this std::list of * conditions and the following disclaimer. * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * 2. Redistributions in binary form must reproduce the above copyright notice, this std::list * of conditions and the following disclaimer in the documentation and/or other * materials provided with the distribution. * @@ -66,7 +66,6 @@ #include #endif -using namespace std; using namespace tools; /** @@ -89,7 +88,7 @@ namespace monero { * @param query the query to decontextualize * @return a reference to the query for convenience */ - shared_ptr decontextualize(shared_ptr query) { + std::shared_ptr decontextualize(std::shared_ptr query) { query->m_is_incoming = boost::none; query->m_is_outgoing = boost::none; query->m_transfer_query = boost::none; @@ -117,15 +116,15 @@ namespace monero { return opt_val == boost::none ? false : val == *opt_val; } - shared_ptr build_tx_with_incoming_transfer(const tools::wallet2& m_w2, uint64_t height, const crypto::hash &payment_id, const tools::wallet2::payment_details &pd) { + std::shared_ptr build_tx_with_incoming_transfer(const tools::wallet2& m_w2, uint64_t height, const crypto::hash &payment_id, const tools::wallet2::payment_details &pd) { // construct block - shared_ptr block = make_shared(); + std::shared_ptr block = std::make_shared(); block->m_height = pd.m_block_height; block->m_timestamp = pd.m_timestamp; // construct tx - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); tx->m_block = block; block->m_txs.push_back(tx); tx->m_hash = epee::string_tools::pod_to_hex(pd.m_tx_hash); @@ -152,7 +151,7 @@ namespace monero { else tx->m_num_confirmations = height - *block->m_height; // construct transfer - shared_ptr incoming_transfer = make_shared(); + std::shared_ptr incoming_transfer = std::make_shared(); incoming_transfer->m_tx = tx; tx->m_incoming_transfers.push_back(incoming_transfer); incoming_transfer->m_amount = pd.m_amount; @@ -170,15 +169,15 @@ namespace monero { return tx; } - shared_ptr build_tx_with_outgoing_transfer(const tools::wallet2& m_w2, uint64_t height, const crypto::hash &txid, const tools::wallet2::confirmed_transfer_details &pd) { + std::shared_ptr build_tx_with_outgoing_transfer(const tools::wallet2& m_w2, uint64_t height, const crypto::hash &txid, const tools::wallet2::confirmed_transfer_details &pd) { // construct block - shared_ptr block = make_shared(); + std::shared_ptr block = std::make_shared(); block->m_height = pd.m_block_height; block->m_timestamp = pd.m_timestamp; // construct tx - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); tx->m_block = block; block->m_txs.push_back(tx); tx->m_hash = epee::string_tools::pod_to_hex(txid); @@ -204,14 +203,14 @@ namespace monero { else tx->m_num_confirmations = height - *block->m_height; // construct transfer - shared_ptr outgoing_transfer = make_shared(); + std::shared_ptr outgoing_transfer = std::make_shared(); outgoing_transfer->m_tx = tx; tx->m_outgoing_transfer = outgoing_transfer; uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known outgoing_transfer->m_amount = pd.m_amount_in - change - *tx->m_fee; outgoing_transfer->m_account_index = pd.m_subaddr_account; - vector subaddress_indices; - vector addresses; + std::vector subaddress_indices; + std::vector addresses; for (uint32_t i: pd.m_subaddr_indices) { subaddress_indices.push_back(i); addresses.push_back(m_w2.get_subaddress_as_str({pd.m_subaddr_account, i})); @@ -221,7 +220,7 @@ namespace monero { // initialize destinations for (const auto &d: pd.m_dests) { - shared_ptr destination = make_shared(); + std::shared_ptr destination = std::make_shared(); destination->m_amount = d.amount; destination->m_address = d.address(m_w2.nettype(), pd.m_payment_id); outgoing_transfer->m_destinations.push_back(destination); @@ -231,7 +230,7 @@ namespace monero { // TODO monero core: confirmed tx from/to same account has amount 0 but cached transfer destinations if (*outgoing_transfer->m_amount == 0 && !outgoing_transfer->m_destinations.empty()) { uint64_t amount = 0; - for (const shared_ptr& destination : outgoing_transfer->m_destinations) amount += *destination->m_amount; + for (const std::shared_ptr& destination : outgoing_transfer->m_destinations) amount += *destination->m_amount; outgoing_transfer->m_amount = amount; } @@ -244,11 +243,11 @@ namespace monero { return tx; } - shared_ptr build_tx_with_incoming_transfer_unconfirmed(const tools::wallet2& m_w2, const crypto::hash &payment_id, const tools::wallet2::pool_payment_details &ppd) { + std::shared_ptr build_tx_with_incoming_transfer_unconfirmed(const tools::wallet2& m_w2, const crypto::hash &payment_id, const tools::wallet2::pool_payment_details &ppd) { // construct tx const tools::wallet2::payment_details &pd = ppd.m_pd; - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); tx->m_hash = epee::string_tools::pod_to_hex(pd.m_tx_hash); tx->m_is_incoming = true; tx->m_payment_id = epee::string_tools::pod_to_hex(payment_id); @@ -269,7 +268,7 @@ namespace monero { tx->m_num_confirmations = 0; // construct transfer - shared_ptr incoming_transfer = make_shared(); + std::shared_ptr incoming_transfer = std::make_shared(); incoming_transfer->m_tx = tx; tx->m_incoming_transfers.push_back(incoming_transfer); incoming_transfer->m_amount = pd.m_amount; @@ -286,10 +285,10 @@ namespace monero { return tx; } - shared_ptr build_tx_with_outgoing_transfer_unconfirmed(const tools::wallet2& m_w2, const crypto::hash &txid, const tools::wallet2::unconfirmed_transfer_details &pd) { + std::shared_ptr build_tx_with_outgoing_transfer_unconfirmed(const tools::wallet2& m_w2, const crypto::hash &txid, const tools::wallet2::unconfirmed_transfer_details &pd) { // construct tx - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); tx->m_is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed; tx->m_hash = epee::string_tools::pod_to_hex(txid); tx->m_is_outgoing = true; @@ -310,13 +309,13 @@ namespace monero { tx->m_num_confirmations = 0; // construct transfer - shared_ptr outgoing_transfer = make_shared(); + std::shared_ptr outgoing_transfer = std::make_shared(); outgoing_transfer->m_tx = tx; tx->m_outgoing_transfer = outgoing_transfer; outgoing_transfer->m_amount = pd.m_amount_in - pd.m_change - tx->m_fee.get(); outgoing_transfer->m_account_index = pd.m_subaddr_account; - vector subaddress_indices; - vector addresses; + std::vector subaddress_indices; + std::vector addresses; for (uint32_t i: pd.m_subaddr_indices) { subaddress_indices.push_back(i); addresses.push_back(m_w2.get_subaddress_as_str({pd.m_subaddr_account, i})); @@ -326,7 +325,7 @@ namespace monero { // initialize destinations for (const auto &d: pd.m_dests) { - shared_ptr destination = make_shared(); + std::shared_ptr destination = std::make_shared(); destination->m_amount = d.amount; destination->m_address = d.address(m_w2.nettype(), pd.m_payment_id); outgoing_transfer->m_destinations.push_back(destination); @@ -336,7 +335,7 @@ namespace monero { // TODO monero core: confirmed tx from/to same account has amount 0 but cached transfer destinations if (*outgoing_transfer->m_amount == 0 && !outgoing_transfer->m_destinations.empty()) { uint64_t amount = 0; - for (const shared_ptr& destination : outgoing_transfer->m_destinations) amount += *destination->m_amount; + for (const std::shared_ptr& destination : outgoing_transfer->m_destinations) amount += *destination->m_amount; outgoing_transfer->m_amount = amount; } @@ -349,14 +348,14 @@ namespace monero { return tx; } - shared_ptr build_tx_with_vout(const tools::wallet2& m_w2, const tools::wallet2::transfer_details& td) { + std::shared_ptr build_tx_with_vout(const tools::wallet2& m_w2, const tools::wallet2::transfer_details& td) { // construct block - shared_ptr block = make_shared(); + std::shared_ptr block = std::make_shared(); block->m_height = td.m_block_height; // construct tx - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); tx->m_block = block; block->m_txs.push_back(tx); tx->m_hash = epee::string_tools::pod_to_hex(td.m_txid); @@ -369,7 +368,7 @@ namespace monero { tx->m_is_locked = !m_w2.is_transfer_unlocked(td); // construct output - shared_ptr output = make_shared(); + std::shared_ptr output = std::make_shared(); output->m_tx = tx; tx->m_outputs.push_back(output); output->m_amount = td.amount(); @@ -379,7 +378,7 @@ namespace monero { output->m_is_spent = td.m_spent; output->m_is_frozen = td.m_frozen; if (td.m_key_image_known) { - output->m_key_image = make_shared(); + output->m_key_image = std::make_shared(); output->m_key_image.get()->m_hex = epee::string_tools::pod_to_hex(td.m_key_image); } @@ -388,7 +387,7 @@ namespace monero { } /** - * Merges a transaction into a unique set of transactions. + * Merges a transaction into a unique std::set of transactions. * * TODO monero-core: skip_if_absent only necessary because incoming payments not returned * when sent from/to same account #4500 @@ -398,11 +397,11 @@ namespace monero { * @param block_map maps block heights to blocks * @param skip_if_absent specifies if the tx should not be added if it doesn't already exist */ - void merge_tx(const shared_ptr& tx, map>& tx_map, map>& block_map, bool skip_if_absent) { - if (tx->m_hash == boost::none) throw runtime_error("Tx hash is not initialized"); + void merge_tx(const std::shared_ptr& tx, std::map>& tx_map, std::map>& block_map, bool skip_if_absent) { + if (tx->m_hash == boost::none) throw std::runtime_error("Tx hash is not initialized"); // if tx doesn't exist, add it (unless skipped) - map>::const_iterator tx_iter = tx_map.find(*tx->m_hash); + std::map>::const_iterator tx_iter = tx_map.find(*tx->m_hash); if (tx_iter == tx_map.end()) { if (!skip_if_absent) { tx_map[*tx->m_hash] = tx; @@ -413,17 +412,17 @@ namespace monero { // otherwise merge with existing tx else { - shared_ptr& a_tx = tx_map[*tx->m_hash]; + std::shared_ptr& a_tx = tx_map[*tx->m_hash]; a_tx->merge(a_tx, tx); } // if confirmed, merge tx's block if (tx->get_height() != boost::none) { - map>::const_iterator block_iter = block_map.find(tx->get_height().get()); + std::map>::const_iterator block_iter = block_map.find(tx->get_height().get()); if (block_iter == block_map.end()) { block_map[tx->get_height().get()] = tx->m_block.get(); } else { - shared_ptr& a_block = block_map[tx->get_height().get()]; + std::shared_ptr& a_block = block_map[tx->get_height().get()]; a_block->merge(a_block, tx->m_block.get()); } } @@ -432,7 +431,7 @@ namespace monero { /** * Returns true iff tx1's height is known to be less than tx2's height for sorting. */ - bool tx_height_less_than(const shared_ptr& tx1, const shared_ptr& tx2) { + bool tx_height_less_than(const std::shared_ptr& tx1, const std::shared_ptr& tx2) { if (tx1->m_block != boost::none && tx2->m_block != boost::none) return tx1->get_height() < tx2->get_height(); else if (tx1->m_block == boost::none) return false; else return true; @@ -441,7 +440,7 @@ namespace monero { /** * Returns true iff transfer1 is ordered before transfer2 by ascending account and subaddress indices. */ - bool incoming_transfer_before(const shared_ptr& transfer1, const shared_ptr& transfer2) { + bool incoming_transfer_before(const std::shared_ptr& transfer1, const std::shared_ptr& transfer2) { // compare by height if (tx_height_less_than(transfer1->m_tx, transfer2->m_tx)) return true; @@ -455,9 +454,9 @@ namespace monero { /** * Returns true iff wallet vout1 is ordered before vout2 by ascending account and subaddress indices then index. */ - bool vout_before(const shared_ptr& o1, const shared_ptr& o2) { - shared_ptr ow1 = static_pointer_cast(o1); - shared_ptr ow2 = static_pointer_cast(o2); + bool vout_before(const std::shared_ptr& o1, const std::shared_ptr& o2) { + std::shared_ptr ow1 = std::static_pointer_cast(o1); + std::shared_ptr ow2 = std::static_pointer_cast(o2); // compare by height if (tx_height_less_than(ow1->m_tx, ow2->m_tx)) return true; @@ -646,7 +645,7 @@ namespace monero { if (multisig_txset.empty()) { er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = "Failed to save multisig tx set after creation"; + er.message = "Failed to save multisig tx std::set after creation"; return false; } } @@ -657,7 +656,7 @@ namespace monero { if (unsigned_txset.empty()) { er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = "Failed to save unsigned tx set after creation"; + er.message = "Failed to save unsigned tx std::set after creation"; return false; } } @@ -711,7 +710,7 @@ namespace monero { } void on_sync_start(uint64_t start_height) { - if (m_sync_start_height != boost::none || m_sync_end_height != boost::none) throw runtime_error("Sync start or end height should not already be allocated, is previous sync in progress?"); + if (m_sync_start_height != boost::none || m_sync_end_height != boost::none) throw std::runtime_error("Sync start or end height should not already be allocated, is previous sync in progress?"); m_sync_start_height = start_height; m_sync_end_height = m_wallet.get_daemon_height(); } @@ -735,7 +734,7 @@ namespace monero { // notify listeners of sync progress if (height >= *m_sync_end_height) m_sync_end_height = height + 1; // increase end height if necessary double percent_done = (double) (height - *m_sync_start_height + 1) / (double) (*m_sync_end_height - *m_sync_start_height); - string message = string("Synchronizing"); + std::string message = std::string("Synchronizing"); for (monero_wallet_listener* listener : m_wallet.get_listeners()) { listener->on_sync_progress(height, *m_sync_start_height, *m_sync_end_height, percent_done, message); } @@ -745,9 +744,9 @@ namespace monero { if (m_wallet.get_listeners().empty()) return; // create library tx - shared_ptr tx = static_pointer_cast(monero_utils::cn_tx_to_tx(cn_tx, true)); + std::shared_ptr tx = std::static_pointer_cast(monero_utils::cn_tx_to_tx(cn_tx, true)); tx->m_hash = epee::string_tools::pod_to_hex(txid); - shared_ptr output = make_shared(); + std::shared_ptr output = std::make_shared(); tx->m_outputs.push_back(output); output->m_tx = tx; output->m_amount = amount; @@ -768,14 +767,14 @@ namespace monero { if (m_wallet.get_listeners().empty()) return; // create native library tx - shared_ptr block = make_shared(); + std::shared_ptr block = std::make_shared(); block->m_height = height; - shared_ptr tx = static_pointer_cast(monero_utils::cn_tx_to_tx(cn_tx, true)); + std::shared_ptr tx = std::static_pointer_cast(monero_utils::cn_tx_to_tx(cn_tx, true)); block->m_txs.push_back(tx); tx->m_block = block; tx->m_hash = epee::string_tools::pod_to_hex(txid); tx->m_unlock_time = unlock_time; - shared_ptr output = make_shared(); + std::shared_ptr output = std::make_shared(); tx->m_outputs.push_back(output); output->m_tx = tx; output->m_amount = amount; @@ -795,16 +794,16 @@ namespace monero { void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cn_tx_in, uint64_t amount, const cryptonote::transaction& cn_tx_out, const cryptonote::subaddress_index& subaddr_index) { if (m_wallet.get_listeners().empty()) return; - if (&cn_tx_in != &cn_tx_out) throw runtime_error("on_money_spent() in tx is different than out tx"); + if (&cn_tx_in != &cn_tx_out) throw std::runtime_error("on_money_spent() in tx is different than out tx"); // create native library tx - shared_ptr block = make_shared(); + std::shared_ptr block = std::make_shared(); block->m_height = height; - shared_ptr tx = static_pointer_cast(monero_utils::cn_tx_to_tx(cn_tx_in, true)); + std::shared_ptr tx = std::static_pointer_cast(monero_utils::cn_tx_to_tx(cn_tx_in, true)); block->m_txs.push_back(tx); tx->m_block = block; tx->m_hash = epee::string_tools::pod_to_hex(txid); - shared_ptr output = make_shared(); + std::shared_ptr output = std::make_shared(); tx->m_inputs.push_back(output); output->m_tx = tx; output->m_amount = amount; @@ -843,7 +842,7 @@ namespace monero { // --------------------------- STATIC WALLET UTILS -------------------------- - bool monero_wallet_core::wallet_exists(const string& path) { + bool monero_wallet_core::wallet_exists(const std::string& path) { MTRACE("wallet_exists(" << path << ")"); bool key_file_exists; bool wallet_file_exists; @@ -851,21 +850,21 @@ namespace monero { return wallet_file_exists; } - monero_wallet_core* monero_wallet_core::open_wallet(const string& path, const string& password, const monero_network_type network_type) { + monero_wallet_core* monero_wallet_core::open_wallet(const std::string& path, const std::string& password, const monero_network_type network_type) { MTRACE("open_wallet(" << path << ", ***, " << network_type << ")"); monero_wallet_core* wallet = new monero_wallet_core(); - wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); + wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); wallet->m_w2->load(path, password); wallet->m_w2->init(""); wallet->init_common(); return wallet; } - monero_wallet_core* monero_wallet_core::open_wallet_data(const string& password, const monero_network_type network_type, const string& keys_data, const string& cache_data, const monero_rpc_connection& daemon_connection, unique_ptr http_client_factory) { + monero_wallet_core* monero_wallet_core::open_wallet_data(const std::string& password, const monero_network_type network_type, const std::string& keys_data, const std::string& cache_data, const monero_rpc_connection& daemon_connection, std::unique_ptr http_client_factory) { MTRACE("open_wallet_data(...)"); monero_wallet_core* wallet = new monero_wallet_core(); - if (http_client_factory == nullptr) wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); - else wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); + if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); + else wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); wallet->m_w2->load("", password, keys_data, cache_data); wallet->m_w2->init(""); wallet->set_daemon_connection(daemon_connection); @@ -873,11 +872,11 @@ namespace monero { return wallet; } - monero_wallet_core* monero_wallet_core::create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const string& language, unique_ptr http_client_factory) { + monero_wallet_core* monero_wallet_core::create_wallet_random(const std::string& path, const std::string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const std::string& language, std::unique_ptr http_client_factory) { MTRACE("create_wallet_random(...)"); monero_wallet_core* wallet = new monero_wallet_core(); - if (http_client_factory == nullptr) wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); - else wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); + if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); + else wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); wallet->set_daemon_connection(daemon_connection); wallet->m_w2->set_seed_language(language); crypto::secret_key secret_key; @@ -887,23 +886,23 @@ namespace monero { return wallet; } - monero_wallet_core* monero_wallet_core::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& seed_offset, unique_ptr http_client_factory) { + monero_wallet_core* monero_wallet_core::create_wallet_from_mnemonic(const std::string& path, const std::string& password, const monero_network_type network_type, const std::string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const std::string& seed_offset, std::unique_ptr http_client_factory) { MTRACE("create_wallet_from_mnemonic(path, password, mnemonic, network_type, daemon_connection, restore_height)"); monero_wallet_core* wallet = new monero_wallet_core(); // validate mnemonic and get recovery key and language crypto::secret_key recovery_key; - string language; + std::string language; bool is_valid = crypto::ElectrumWords::words_to_bytes(mnemonic, recovery_key, language); - if (!is_valid) throw runtime_error("Invalid mnemonic"); + if (!is_valid) throw std::runtime_error("Invalid mnemonic"); if (language == crypto::ElectrumWords::old_language_name) language = Language::English().get_language_name(); // apply offset if given if (!seed_offset.empty()) recovery_key = cryptonote::decrypt_key(recovery_key, seed_offset); // initialize wallet - if (http_client_factory == nullptr) wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); - else wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); + if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); + else wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); wallet->set_daemon_connection(daemon_connection); wallet->m_w2->set_seed_language(language); wallet->m_w2->generate(path, password, recovery_key, true, false); @@ -912,13 +911,13 @@ namespace monero { return wallet; } - monero_wallet_core* monero_wallet_core::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language, unique_ptr http_client_factory) { + monero_wallet_core* monero_wallet_core::create_wallet_from_keys(const std::string& path, const std::string& password, const monero_network_type network_type, const std::string& address, const std::string& view_key, const std::string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const std::string& language, std::unique_ptr http_client_factory) { MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height, language)"); monero_wallet_core* wallet = new monero_wallet_core(); // validate and parse address cryptonote::address_parse_info info; - if (!get_account_address_from_str(info, static_cast(network_type), address)) throw runtime_error("failed to parse address"); + if (!get_account_address_from_str(info, static_cast(network_type), address)) throw std::runtime_error("failed to parse address"); // validate and parse optional private spend key crypto::secret_key spend_key_sk; @@ -926,7 +925,7 @@ namespace monero { if (!spend_key.empty()) { cryptonote::blobdata spend_key_data; if (!epee::string_tools::parse_hexstr_to_binbuff(spend_key, spend_key_data) || spend_key_data.size() != sizeof(crypto::secret_key)) { - throw runtime_error("failed to parse secret spend key"); + throw std::runtime_error("failed to parse secret spend key"); } has_spend_key = true; spend_key_sk = *reinterpret_cast(spend_key_data.data()); @@ -937,12 +936,12 @@ namespace monero { crypto::secret_key view_key_sk; if (view_key.empty()) { if (has_spend_key) has_view_key = false; - else throw runtime_error("Neither view key nor spend key supplied, cancelled"); + else throw std::runtime_error("Neither view key nor spend key supplied, cancelled"); } if (has_view_key) { cryptonote::blobdata view_key_data; if (!epee::string_tools::parse_hexstr_to_binbuff(view_key, view_key_data) || view_key_data.size() != sizeof(crypto::secret_key)) { - throw runtime_error("failed to parse secret view key"); + throw std::runtime_error("failed to parse secret view key"); } view_key_sk = *reinterpret_cast(view_key_data.data()); } @@ -950,17 +949,17 @@ namespace monero { // check the spend and view keys match the given address crypto::public_key pkey; if (has_spend_key) { - if (!crypto::secret_key_to_public_key(spend_key_sk, pkey)) throw runtime_error("failed to verify secret spend key"); - if (info.address.m_spend_public_key != pkey) throw runtime_error("spend key does not match address"); + if (!crypto::secret_key_to_public_key(spend_key_sk, pkey)) throw std::runtime_error("failed to verify secret spend key"); + if (info.address.m_spend_public_key != pkey) throw std::runtime_error("spend key does not match address"); } if (has_view_key) { - if (!crypto::secret_key_to_public_key(view_key_sk, pkey)) throw runtime_error("failed to verify secret view key"); - if (info.address.m_view_public_key != pkey) throw runtime_error("view key does not match address"); + if (!crypto::secret_key_to_public_key(view_key_sk, pkey)) throw std::runtime_error("failed to verify secret view key"); + if (info.address.m_view_public_key != pkey) throw std::runtime_error("view key does not match address"); } // initialize wallet - if (http_client_factory == nullptr) wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); - else wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); + if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); + else wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); if (has_spend_key && has_view_key) wallet->m_w2->generate(path, password, info.address, spend_key_sk, view_key_sk); else if (has_spend_key) wallet->m_w2->generate(path, password, spend_key_sk, true, false); else wallet->m_w2->generate(path, password, info.address, view_key_sk); @@ -971,8 +970,8 @@ namespace monero { return wallet; } - vector monero_wallet_core::get_mnemonic_languages() { - vector languages; + std::vector monero_wallet_core::get_mnemonic_languages() { + std::vector languages; crypto::ElectrumWords::get_language_list(languages, true); return languages; } @@ -984,7 +983,7 @@ namespace monero { close(false); } - void monero_wallet_core::set_daemon_connection(const string& uri, const string& username, const string& password) { + void monero_wallet_core::set_daemon_connection(const std::string& uri, const std::string& username, const std::string& password) { MTRACE("set_daemon_connection(" << uri << ", " << username << ", " << "***" << ")"); // prepare uri, login, and is_trusted for wallet2 @@ -1000,8 +999,8 @@ namespace monero { // detect ssl TODO: wallet2 does not detect ssl from uri epee::net_utils::ssl_support_t ssl = uri.rfind("https", 0) == 0 ? epee::net_utils::ssl_support_t::e_ssl_support_enabled : epee::net_utils::ssl_support_t::e_ssl_support_disabled; - // init wallet2 and set daemon connection - if (!m_w2->init(uri, login, {}, 0, is_trusted, ssl)) throw runtime_error("Failed to initialize wallet with daemon connection"); + // init wallet2 and std::set daemon connection + if (!m_w2->init(uri, login, {}, 0, is_trusted, ssl)) throw std::runtime_error("Failed to initialize wallet with daemon connection"); is_connected(); // update m_is_connected cache // TODO: better naming? } @@ -1018,7 +1017,7 @@ namespace monero { if (m_w2->get_daemon_login()) { if (!m_w2->get_daemon_login()->username.empty()) connection->m_username = m_w2->get_daemon_login()->username; epee::wipeable_string wipeablePassword = m_w2->get_daemon_login()->password; - string password = string(wipeablePassword.data(), wipeablePassword.size()); + std::string password = std::string(wipeablePassword.data(), wipeablePassword.size()); if (!password.empty()) connection->m_password = password; } return connection; @@ -1034,13 +1033,13 @@ namespace monero { } bool monero_wallet_core::is_daemon_synced() const { - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); uint64_t daemonHeight = get_daemon_height(); return daemonHeight >= get_daemon_max_peer_height() && daemonHeight > 1; } bool monero_wallet_core::is_daemon_trusted() const { - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); return m_w2->is_trusted_daemon(); } @@ -1055,7 +1054,7 @@ namespace monero { return version; } - string monero_wallet_core::get_path() const { + std::string monero_wallet_core::get_path() const { return m_w2->path(); } @@ -1063,56 +1062,56 @@ namespace monero { return static_cast(m_w2->nettype()); } - string monero_wallet_core::get_mnemonic() const { + std::string monero_wallet_core::get_mnemonic() const { if (m_w2->watch_only()) return ""; epee::wipeable_string wipeable_mnemonic; m_w2->get_seed(wipeable_mnemonic); - return string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); + return std::string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); } - string monero_wallet_core::get_mnemonic_language() const { + std::string monero_wallet_core::get_mnemonic_language() const { if (m_w2->watch_only()) return ""; return m_w2->get_seed_language(); } - string monero_wallet_core::get_public_view_key() const { + std::string monero_wallet_core::get_public_view_key() const { MTRACE("get_private_view_key()"); return epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_account_address.m_view_public_key); } - string monero_wallet_core::get_private_view_key() const { + std::string monero_wallet_core::get_private_view_key() const { MTRACE("get_private_view_key()"); return epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_view_secret_key); } - string monero_wallet_core::get_public_spend_key() const { + std::string monero_wallet_core::get_public_spend_key() const { MTRACE("get_public_spend_key()"); return epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_account_address.m_spend_public_key); } - string monero_wallet_core::get_private_spend_key() const { + std::string monero_wallet_core::get_private_spend_key() const { MTRACE("get_private_spend_key()"); - string spend_key = epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_spend_secret_key); + std::string spend_key = epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_spend_secret_key); if (spend_key == "0000000000000000000000000000000000000000000000000000000000000000") spend_key = ""; return spend_key; } - string monero_wallet_core::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { + std::string monero_wallet_core::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { return m_w2->get_subaddress_as_str({account_idx, subaddress_idx}); } - monero_subaddress monero_wallet_core::get_address_index(const string& address) const { + monero_subaddress monero_wallet_core::get_address_index(const std::string& address) const { MTRACE("get_address_index(" << address << ")"); // validate address cryptonote::address_parse_info info; if (!get_account_address_from_str(info, m_w2->nettype(), address)) { - throw runtime_error("Invalid address"); + throw std::runtime_error("Invalid address"); } // get index of address in wallet auto index = m_w2->get_subaddress_index(info.address); - if (!index) throw runtime_error("Address doesn't belong to the wallet"); + if (!index) throw std::runtime_error("Address doesn't belong to the wallet"); // return indices in subaddress monero_subaddress subaddress; @@ -1122,7 +1121,7 @@ namespace monero { return subaddress; } - monero_integrated_address monero_wallet_core::get_integrated_address(const string& standard_address, const string& payment_id) const { + monero_integrated_address monero_wallet_core::get_integrated_address(const std::string& standard_address, const std::string& payment_id) const { MTRACE("get_integrated_address(" << standard_address << ", " << payment_id << ")"); // TODO monero-core: this logic is based on wallet_rpc_server::on_make_integrated_address() and should be moved to wallet so this is unecessary for api users @@ -1132,7 +1131,7 @@ namespace monero { if (payment_id.empty()) { paymen_id_h8 = crypto::rand(); } else { - if (!tools::wallet2::parse_short_payment_id(payment_id, paymen_id_h8)) throw runtime_error("Invalid payment ID: " + payment_id); + if (!tools::wallet2::parse_short_payment_id(payment_id, paymen_id_h8)) throw std::runtime_error("Invalid payment ID: " + payment_id); } // use primary address if standard address not given, else validate @@ -1142,23 +1141,23 @@ namespace monero { // validate standard address cryptonote::address_parse_info info; - if (!cryptonote::get_account_address_from_str(info, m_w2->nettype(), standard_address)) throw runtime_error("Invalid address: " + standard_address); - if (info.is_subaddress) throw runtime_error("Subaddress shouldn't be used"); - if (info.has_payment_id) throw runtime_error("Already integrated address"); - if (payment_id.empty()) throw runtime_error("Payment ID shouldn't be left unspecified"); + if (!cryptonote::get_account_address_from_str(info, m_w2->nettype(), standard_address)) throw std::runtime_error("Invalid address: " + standard_address); + if (info.is_subaddress) throw std::runtime_error("Subaddress shouldn't be used"); + if (info.has_payment_id) throw std::runtime_error("Already integrated address"); + if (payment_id.empty()) throw std::runtime_error("Payment ID shouldn't be left unspecified"); // create integrated address from given standard address return decode_integrated_address(cryptonote::get_account_integrated_address_as_str(m_w2->nettype(), info.address, paymen_id_h8)); } } - monero_integrated_address monero_wallet_core::decode_integrated_address(const string& integrated_address) const { + monero_integrated_address monero_wallet_core::decode_integrated_address(const std::string& integrated_address) const { MTRACE("decode_integrated_address(" << integrated_address << ")"); // validate integrated address cryptonote::address_parse_info info; - if (!cryptonote::get_account_address_from_str(info, m_w2->nettype(), integrated_address)) throw runtime_error("Invalid integrated address: " + integrated_address); - if (!info.has_payment_id) throw runtime_error("Address is not an integrated address"); + if (!cryptonote::get_account_address_from_str(info, m_w2->nettype(), integrated_address)) throw std::runtime_error("Invalid integrated address: " + integrated_address); + if (!info.has_payment_id) throw std::runtime_error("Address is not an integrated address"); // initialize and return result monero_integrated_address result; @@ -1181,18 +1180,18 @@ namespace monero { } uint64_t monero_wallet_core::get_daemon_height() const { - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); std::string err; uint64_t result = m_w2->get_daemon_blockchain_height(err); - if (!err.empty()) throw runtime_error(err); + if (!err.empty()) throw std::runtime_error(err); return result; } uint64_t monero_wallet_core::get_daemon_max_peer_height() const { - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); std::string err; uint64_t result = m_w2->get_daemon_blockchain_target_height(err); - if (!err.empty()) throw runtime_error(err); + if (!err.empty()) throw std::runtime_error(err); if (result == 0) result = get_daemon_height(); // TODO monero core: target height can be 0 when daemon is synced. Use blockchain height instead return result; } @@ -1209,20 +1208,20 @@ namespace monero { if (!m_sync_loop_running) m_w2_listener->update_listening(); // listener is unregistered after sync to avoid segfault } - set monero_wallet_core::get_listeners() { + std::set monero_wallet_core::get_listeners() { MTRACE("get_listeners()"); return m_listeners; } monero_sync_result monero_wallet_core::sync() { MTRACE("sync()"); - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); return lock_and_sync(); } monero_sync_result monero_wallet_core::sync(monero_wallet_listener& listener) { MTRACE("sync(listener)"); - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); // register listener add_listener(listener); @@ -1239,13 +1238,13 @@ namespace monero { monero_sync_result monero_wallet_core::sync(uint64_t start_height) { MTRACE("sync(" << start_height << ")"); - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); return lock_and_sync(start_height); } monero_sync_result monero_wallet_core::sync(uint64_t start_height, monero_wallet_listener& listener) { MTRACE("sync(" << start_height << ", listener)"); - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); // wrap and register sync listener as wallet listener add_listener(listener); @@ -1264,7 +1263,7 @@ namespace monero { * Start automatic syncing as its own thread. */ void monero_wallet_core::start_syncing() { - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); if (!m_syncing_enabled) { m_syncing_enabled = true; run_sync_loop(); // sync wallet on loop in background @@ -1280,15 +1279,15 @@ namespace monero { void monero_wallet_core::rescan_spent() { MTRACE("rescan_spent()"); - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); - if (!is_daemon_trusted()) throw runtime_error("Rescan spent can only be used with a trusted daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); + if (!is_daemon_trusted()) throw std::runtime_error("Rescan spent can only be used with a trusted daemon"); m_w2->rescan_spent(); } // TODO: support arguments bool hard, bool refresh = true, bool keep_key_images = false void monero_wallet_core::rescan_blockchain() { MTRACE("rescan_blockchain()"); - if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); + if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); m_rescan_on_sync = true; lock_and_sync(); } @@ -1304,7 +1303,7 @@ namespace monero { } uint64_t monero_wallet_core::get_balance(uint32_t account_idx, uint32_t subaddress_idx) const { - map balance_per_subaddress = m_w2->balance_per_subaddress(account_idx, STRICT); + std::map balance_per_subaddress = m_w2->balance_per_subaddress(account_idx, STRICT); auto iter = balance_per_subaddress.find(subaddress_idx); return iter == balance_per_subaddress.end() ? 0 : iter->second; } @@ -1323,22 +1322,22 @@ namespace monero { return iter == unlocked_balance_per_subaddress.end() ? 0 : iter->second.first; } - vector monero_wallet_core::get_accounts(bool include_subaddresses, const string& tag) const { + std::vector monero_wallet_core::get_accounts(bool include_subaddresses, const std::string& tag) const { MTRACE("get_accounts(" << include_subaddresses << ", " << tag << ")"); // need transfers to inform if subaddresses used - vector transfers; + std::vector transfers; if (include_subaddresses) m_w2->get_transfers(transfers); // build accounts - vector accounts; + std::vector accounts; for (uint32_t account_idx = 0; account_idx < m_w2->get_num_subaddress_accounts(); account_idx++) { monero_account account; account.m_index = account_idx; account.m_primary_address = get_address(account_idx, 0); account.m_balance = m_w2->balance(account_idx, STRICT); account.m_unlocked_balance = m_w2->unlocked_balance(account_idx, STRICT); - if (include_subaddresses) account.m_subaddresses = get_subaddresses_aux(account_idx, vector(), transfers); + if (include_subaddresses) account.m_subaddresses = get_subaddresses_aux(account_idx, std::vector(), transfers); accounts.push_back(account); } @@ -1349,7 +1348,7 @@ namespace monero { MTRACE("get_account(" << account_idx << ", " << include_subaddresses << ")"); // need transfers to inform if subaddresses used - vector transfers; + std::vector transfers; if (include_subaddresses) m_w2->get_transfers(transfers); // build and return account @@ -1358,11 +1357,11 @@ namespace monero { account.m_primary_address = get_address(account_idx, 0); account.m_balance = m_w2->balance(account_idx, STRICT); account.m_unlocked_balance = m_w2->unlocked_balance(account_idx, STRICT); - if (include_subaddresses) account.m_subaddresses = get_subaddresses_aux(account_idx, vector(), transfers); + if (include_subaddresses) account.m_subaddresses = get_subaddresses_aux(account_idx, std::vector(), transfers); return account; } - monero_account monero_wallet_core::create_account(const string& label) { + monero_account monero_wallet_core::create_account(const std::string& label) { MTRACE("create_account(" << label << ")"); // create account @@ -1377,16 +1376,16 @@ namespace monero { return account; } - vector monero_wallet_core::get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const { + std::vector monero_wallet_core::get_subaddresses(const uint32_t account_idx, const std::vector& subaddress_indices) const { MTRACE("get_subaddresses(" << account_idx << ", ...)"); MTRACE("Subaddress indices size: " << subaddress_indices.size()); - vector transfers; + std::vector transfers; m_w2->get_transfers(transfers); return get_subaddresses_aux(account_idx, subaddress_indices, transfers); } - monero_subaddress monero_wallet_core::create_subaddress(const uint32_t account_idx, const string& label) { + monero_subaddress monero_wallet_core::create_subaddress(const uint32_t account_idx, const std::string& label) { MTRACE("create_subaddress(" << account_idx << ", " << label << ")"); // create subaddress @@ -1406,44 +1405,44 @@ namespace monero { return subaddress; } - vector> monero_wallet_core::get_txs() const { + std::vector> monero_wallet_core::get_txs() const { return get_txs(monero_tx_query()); } - vector> monero_wallet_core::get_txs(const monero_tx_query& query) const { - vector missing_tx_hashes; - vector> txs = monero_wallet_core::get_txs(query, missing_tx_hashes); - if (!missing_tx_hashes.empty()) throw runtime_error("Tx not found in wallet: " + missing_tx_hashes[0]); + std::vector> monero_wallet_core::get_txs(const monero_tx_query& query) const { + std::vector missing_tx_hashes; + std::vector> txs = monero_wallet_core::get_txs(query, missing_tx_hashes); + if (!missing_tx_hashes.empty()) throw std::runtime_error("Tx not found in wallet: " + missing_tx_hashes[0]); return txs; } - vector> monero_wallet_core::get_txs(const monero_tx_query& query, vector& missing_tx_hashes) const { + std::vector> monero_wallet_core::get_txs(const monero_tx_query& query, std::vector& missing_tx_hashes) const { MTRACE("get_txs(query)"); // copy query - shared_ptr query_sp = make_shared(query); // convert to shared pointer - shared_ptr _query = query_sp->copy(query_sp, make_shared()); // deep copy + std::shared_ptr query_sp = std::make_shared(query); // convert to shared pointer + std::shared_ptr _query = query_sp->copy(query_sp, std::make_shared()); // deep copy // // log query -// if (_query->m_block != boost::none) cout << "Tx query's rooted at [block]: " << _query->m_block.get()->serialize() << endl; -// else cout << "Tx _query: " << _query->serialize() << endl; +// if (_query->m_block != boost::none) std::cout << "Tx query's rooted at [block]: " << _query->m_block.get()->serialize() << std::endl; +// else std::cout << "Tx _query: " << _query->serialize() << std::endl; // temporarily disable transfer and output queries in order to collect all tx context - boost::optional> transfer_query = _query->m_transfer_query; - boost::optional> output_query = _query->m_output_query; + boost::optional> transfer_query = _query->m_transfer_query; + boost::optional> output_query = _query->m_output_query; _query->m_transfer_query = boost::none; _query->m_output_query = boost::none; // fetch all transfers that meet tx query - shared_ptr temp_transfer_query = make_shared(); - temp_transfer_query->m_tx_query = decontextualize(_query->copy(_query, make_shared())); + std::shared_ptr temp_transfer_query = std::make_shared(); + temp_transfer_query->m_tx_query = decontextualize(_query->copy(_query, std::make_shared())); temp_transfer_query->m_tx_query.get()->m_transfer_query = temp_transfer_query; - vector> transfers = get_transfers_aux(*temp_transfer_query); + std::vector> transfers = get_transfers_aux(*temp_transfer_query); // collect unique txs from transfers while retaining order - vector> txs = vector>(); - unordered_set> txsSet; - for (const shared_ptr& transfer : transfers) { + std::vector> txs = std::vector>(); + std::unordered_set> txsSet; + for (const std::shared_ptr& transfer : transfers) { if (txsSet.find(transfer->m_tx) == txsSet.end()) { txs.push_back(transfer->m_tx); txsSet.insert(transfer->m_tx); @@ -1451,23 +1450,23 @@ namespace monero { } // cache types into maps for merging and lookup - map> tx_map; - map> block_map; - for (const shared_ptr& tx : txs) { + std::map> tx_map; + std::map> block_map; + for (const std::shared_ptr& tx : txs) { merge_tx(tx, tx_map, block_map, false); } // fetch and merge outputs if requested if ((_query->m_include_outputs != boost::none && *_query->m_include_outputs) || output_query != boost::none) { - shared_ptr temp_output_query = make_shared(); - temp_output_query->m_tx_query = decontextualize(_query->copy(_query, make_shared())); + std::shared_ptr temp_output_query = std::make_shared(); + temp_output_query->m_tx_query = decontextualize(_query->copy(_query, std::make_shared())); temp_output_query->m_tx_query.get()->m_output_query = temp_output_query; - vector> outputs = get_outputs_aux(*temp_output_query); + std::vector> outputs = get_outputs_aux(*temp_output_query); // merge output txs one time while retaining order - unordered_set> output_txs; - for (const shared_ptr& output : outputs) { - shared_ptr tx = static_pointer_cast(output->m_tx); + std::unordered_set> output_txs; + for (const std::shared_ptr& output : outputs) { + std::shared_ptr tx = std::static_pointer_cast(output->m_tx); if (output_txs.find(tx) == output_txs.end()) { merge_tx(tx, tx_map, block_map, true); output_txs.insert(tx); @@ -1480,10 +1479,10 @@ namespace monero { _query->m_output_query = output_query; // filter txs that don't meet transfer query - vector> queried_txs; - vector>::iterator tx_iter = txs.begin(); + std::vector> queried_txs; + std::vector>::iterator tx_iter = txs.begin(); while (tx_iter != txs.end()) { - shared_ptr tx = *tx_iter; + std::shared_ptr tx = *tx_iter; if (_query->meets_criteria(tx.get())) { queried_txs.push_back(tx); tx_iter++; @@ -1496,15 +1495,15 @@ namespace monero { txs = queried_txs; // special case: re-fetch txs if inconsistency caused by needing to make multiple wallet calls // TODO monero core: offer wallet.get_txs(...) - for (const shared_ptr& tx : txs) { + for (const std::shared_ptr& tx : txs) { if (*tx->m_is_confirmed && tx->m_block == boost::none) return get_txs(*_query, missing_tx_hashes); } // if tx hashes requested, order txs and collect missing hashes if (!_query->m_hashes.empty()) { txs.clear(); - for (const string& tx_hash : _query->m_hashes) { - map>::const_iterator tx_iter = tx_map.find(tx_hash); + for (const std::string& tx_hash : _query->m_hashes) { + std::map>::const_iterator tx_iter = tx_map.find(tx_hash); if (tx_iter != tx_map.end()) txs.push_back(tx_iter->second); else missing_tx_hashes.push_back(tx_hash); } @@ -1513,72 +1512,72 @@ namespace monero { return txs; } - vector> monero_wallet_core::get_transfers(const monero_transfer_query& query) const { + std::vector> monero_wallet_core::get_transfers(const monero_transfer_query& query) const { // // log query // if (query.m_tx_query != boost::none) { -// if ((*query.m_tx_query)->m_block == boost::none) cout << "Transfer query's tx query rooted at [tx]:" << (*query.m_tx_query)->serialize() << endl; -// else cout << "Transfer query's tx query rooted at [block]: " << (*(*query.m_tx_query)->m_block)->serialize() << endl; -// } else cout << "Transfer query: " << query.serialize() << endl; +// if ((*query.m_tx_query)->m_block == boost::none) std::cout << "Transfer query's tx query rooted at [tx]:" << (*query.m_tx_query)->serialize() << std::endl; +// else std::cout << "Transfer query's tx query rooted at [block]: " << (*(*query.m_tx_query)->m_block)->serialize() << std::endl; +// } else std::cout << "Transfer query: " << query.serialize() << std::endl; // get transfers directly if query does not require tx context (e.g. other transfers, outputs) if (!is_contextual(query)) return get_transfers_aux(query); // otherwise get txs with full models to fulfill query - vector> transfers; - for (const shared_ptr& tx : get_txs(*(query.m_tx_query.get()))) { - for (const shared_ptr& transfer : tx->filter_transfers(query)) { // collect queried transfers, erase if excluded + std::vector> transfers; + for (const std::shared_ptr& tx : get_txs(*(query.m_tx_query.get()))) { + for (const std::shared_ptr& transfer : tx->filter_transfers(query)) { // collect queried transfers, erase if excluded transfers.push_back(transfer); } } return transfers; } - vector> monero_wallet_core::get_outputs(const monero_output_query& query) const { + std::vector> monero_wallet_core::get_outputs(const monero_output_query& query) const { // // log query // if (query.m_tx_query != boost::none) { -// if ((*query.m_tx_query)->m_block == boost::none) cout << "Output query's tx query rooted at [tx]:" << (*query.m_tx_query)->serialize() << endl; -// else cout << "Output query's tx query rooted at [block]: " << (*(*query.m_tx_query)->m_block)->serialize() << endl; -// } else cout << "Output query: " << query.serialize() << endl; +// if ((*query.m_tx_query)->m_block == boost::none) std::cout << "Output query's tx query rooted at [tx]:" << (*query.m_tx_query)->serialize() << std::endl; +// else std::cout << "Output query's tx query rooted at [block]: " << (*(*query.m_tx_query)->m_block)->serialize() << std::endl; +// } else std::cout << "Output query: " << query.serialize() << std::endl; // get outputs directly if query does not require tx context (e.g. other outputs, transfers) if (!is_contextual(query)) return get_outputs_aux(query); // otherwise get txs with full models to fulfill query - vector> outputs; - for (const shared_ptr& tx : get_txs(*(query.m_tx_query.get()))) { - for (const shared_ptr& output : tx->filter_outputs_wallet(query)) { // collect queried outputs, erase if excluded + std::vector> outputs; + for (const std::shared_ptr& tx : get_txs(*(query.m_tx_query.get()))) { + for (const std::shared_ptr& output : tx->filter_outputs_wallet(query)) { // collect queried outputs, erase if excluded outputs.push_back(output); } } return outputs; } - string monero_wallet_core::get_outputs_hex() const { + std::string monero_wallet_core::get_outputs_hex() const { return epee::string_tools::buff_to_hex_nodelimer(m_w2->export_outputs_to_str(true)); } - int monero_wallet_core::import_outputs_hex(const string& outputs_hex) { + int monero_wallet_core::import_outputs_hex(const std::string& outputs_hex) { // validate and parse hex data cryptonote::blobdata blob; if (!epee::string_tools::parse_hexstr_to_binbuff(outputs_hex, blob)) { - throw runtime_error("Failed to parse hex"); + throw std::runtime_error("Failed to parse hex"); } // import hex and return result return m_w2->import_outputs_from_str(blob); } - vector> monero_wallet_core::get_key_images() const { + std::vector> monero_wallet_core::get_key_images() const { MTRACE("monero_wallet_core::get_key_images()"); // build key images from wallet2 types - vector> key_images; + std::vector> key_images; std::pair>> ski = m_w2->export_key_images(true); for (size_t n = 0; n < ski.second.size(); ++n) { - shared_ptr key_image = make_shared(); + std::shared_ptr key_image = std::make_shared(); key_images.push_back(key_image); key_image->m_hex = epee::string_tools::pod_to_hex(ski.second[n].first); key_image->m_signature = epee::string_tools::pod_to_hex(ski.second[n].second); @@ -1586,7 +1585,7 @@ namespace monero { return key_images; } - shared_ptr monero_wallet_core::import_key_images(const vector>& key_images) { + std::shared_ptr monero_wallet_core::import_key_images(const std::vector>& key_images) { MTRACE("monero_wallet_core::import_key_images()"); // validate and prepare key images for wallet2 @@ -1594,10 +1593,10 @@ namespace monero { ski.resize(key_images.size()); for (size_t n = 0; n < ski.size(); ++n) { if (!epee::string_tools::hex_to_pod(key_images[n]->m_hex.get(), ski[n].first)) { - throw runtime_error("failed to parse key image"); + throw std::runtime_error("failed to parse key image"); } if (!epee::string_tools::hex_to_pod(key_images[n]->m_signature.get(), ski[n].second)) { - throw runtime_error("failed to parse signature"); + throw std::runtime_error("failed to parse signature"); } } @@ -1606,24 +1605,24 @@ namespace monero { uint64_t height = m_w2->import_key_images(ski, 0, spent, unspent, is_connected()); // TODO: use offset? refer to wallet_rpc_server::on_import_key_images() req.offset // translate results - shared_ptr result = make_shared(); + std::shared_ptr result = std::make_shared(); result->m_height = height; result->m_spent_amount = spent; result->m_unspent_amount = unspent; return result; } - vector> monero_wallet_core::create_txs(const monero_tx_config& config) { + std::vector> monero_wallet_core::create_txs(const monero_tx_config& config) { MTRACE("monero_wallet_core::create_txs"); - //cout << "monero_tx_config: " << config.serialize() << endl; + //std::cout << "monero_tx_config: " << config.serialize() << std::endl; // validate config - if (config.m_account_index == boost::none) throw runtime_error("Must specify account index to send from"); + if (config.m_account_index == boost::none) throw std::runtime_error("Must specify account index to send from"); // prepare parameters for wallet rpc's validate_transfer() - string payment_id = config.m_payment_id == boost::none ? string("") : config.m_payment_id.get(); - list tr_destinations; - for (const shared_ptr& destination : config.get_normalized_destinations()) { + std::string payment_id = config.m_payment_id == boost::none ? std::string("") : config.m_payment_id.get(); + std::list tr_destinations; + for (const std::shared_ptr& destination : config.get_normalized_destinations()) { tools::wallet_rpc::transfer_destination tr_destination; tr_destination.amount = destination->m_amount.get(); tr_destination.address = destination->m_address.get(); @@ -1635,7 +1634,7 @@ namespace monero { std::vector extra; epee::json_rpc::error err; if (!validate_transfer(m_w2.get(), tr_destinations, payment_id, dsts, extra, true, err)) { - throw runtime_error(err.message); + throw std::runtime_error(err.message); } // prepare parameters for wallet2's create_transactions_2() @@ -1647,12 +1646,12 @@ namespace monero { for (const uint32_t& subaddress_idx : config.m_subaddress_indices) subaddress_indices.insert(subaddress_idx); // prepare transactions - vector ptx_vector = m_w2->create_transactions_2(dsts, mixin, unlock_time, priority, extra, account_index, subaddress_indices); - if (ptx_vector.empty()) throw runtime_error("No transaction created"); + std::vector ptx_vector = m_w2->create_transactions_2(dsts, mixin, unlock_time, priority, extra, account_index, subaddress_indices); + if (ptx_vector.empty()) throw std::runtime_error("No transaction created"); // check if request cannot be fulfilled due to splitting if (config.m_can_split != boost::none && config.m_can_split.get() == false && ptx_vector.size() != 1) { - throw runtime_error("Transaction would be too large. Try send_txs()"); + throw std::runtime_error("Transaction would be too large. Try send_txs()"); } // config for fill_response() @@ -1662,20 +1661,20 @@ namespace monero { bool relay = config.m_relay != boost::none && config.m_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() - list tx_keys; - list tx_amounts; - list tx_fees; - string multisig_tx_hex; - string unsigned_tx_hex; - list tx_hashes; - list tx_blobs; - list tx_metadatas; + std::list tx_keys; + std::list tx_amounts; + std::list tx_fees; + std::string multisig_tx_hex; + std::string unsigned_tx_hex; + std::list tx_hashes; + std::list tx_blobs; + std::list tx_metadatas; if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) { - throw runtime_error("need to handle error filling response!"); // TODO + throw std::runtime_error("need to handle error filling response!"); // TODO } // build sent txs from results // TODO: break this into separate utility function - vector> txs; + std::vector> txs; auto tx_hashes_iter = tx_hashes.begin(); auto tx_keys_iter = tx_keys.begin(); auto tx_amounts_iter = tx_amounts.begin(); @@ -1685,14 +1684,14 @@ namespace monero { while (tx_fees_iter != tx_fees.end()) { // init tx with outgoing transfer from filled values - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); txs.push_back(tx); tx->m_hash = *tx_hashes_iter; tx->m_key = *tx_keys_iter; tx->m_fee = *tx_fees_iter; tx->m_full_hex = *tx_blobs_iter; tx->m_metadata = *tx_metadatas_iter; - shared_ptr out_transfer = make_shared(); + std::shared_ptr out_transfer = std::make_shared(); tx->m_outgoing_transfer = out_transfer; out_transfer->m_amount = *tx_amounts_iter; @@ -1710,7 +1709,7 @@ namespace monero { tx->m_ring_size = monero_utils::RING_SIZE; tx->m_unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); tx->m_is_locked = true; - if (tx->m_is_relayed.get()) tx->m_last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 + if (tx->m_is_relayed.get()) tx->m_last_relayed_timestamp = static_cast(time(NULL)); // std::set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 out_transfer->m_account_index = config.m_account_index; if (config.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(config.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here out_transfer->m_destinations = config.get_normalized_destinations(); @@ -1724,8 +1723,8 @@ namespace monero { tx_metadatas_iter++; } - // build tx set and return txs - shared_ptr tx_set = make_shared(); + // build tx std::set and return txs + std::shared_ptr tx_set = std::make_shared(); tx_set->m_txs = txs; for (int i = 0; i < txs.size(); i++) txs[i]->m_tx_set = tx_set; if (!multisig_tx_hex.empty()) tx_set->m_multisig_tx_hex = multisig_tx_hex; @@ -1733,32 +1732,32 @@ namespace monero { return txs; } - vector> monero_wallet_core::sweep_unlocked(const monero_tx_config& config) { + std::vector> monero_wallet_core::sweep_unlocked(const monero_tx_config& config) { // validate config - vector> destinations = config.get_normalized_destinations(); - if (destinations.size() != 1) throw runtime_error("Must specify exactly one destination to sweep to"); - if (destinations[0]->m_address == boost::none) throw runtime_error("Must specify destination address to sweep to"); - if (destinations[0]->m_amount != boost::none) throw runtime_error("Cannot specify amount to sweep"); - if (config.m_account_index == boost::none && config.m_subaddress_indices.size() != 0) throw runtime_error("Must specify account index if subaddress indices are specified"); + std::vector> destinations = config.get_normalized_destinations(); + if (destinations.size() != 1) throw std::runtime_error("Must specify exactly one destination to sweep to"); + if (destinations[0]->m_address == boost::none) throw std::runtime_error("Must specify destination address to sweep to"); + if (destinations[0]->m_amount != boost::none) throw std::runtime_error("Cannot specify amount to sweep"); + if (config.m_account_index == boost::none && config.m_subaddress_indices.size() != 0) throw std::runtime_error("Must specify account index if subaddress indices are specified"); // determine account and subaddress indices to sweep; default to all with unlocked balance if not specified - std::map> indices; + std::map> indices; if (config.m_account_index != boost::none) { if (config.m_subaddress_indices.size() != 0) { indices[config.m_account_index.get()] = config.m_subaddress_indices; } else { - vector subaddress_indices; + std::vector subaddress_indices; for (const monero_subaddress& subaddress : monero_wallet::get_subaddresses(config.m_account_index.get())) { if (subaddress.m_unlocked_balance.get() > 0) subaddress_indices.push_back(subaddress.m_index.get()); } indices[config.m_account_index.get()] = subaddress_indices; } } else { - vector accounts = monero_wallet::get_accounts(true); + std::vector accounts = monero_wallet::get_accounts(true); for (const monero_account& account : accounts) { if (account.m_unlocked_balance.get() > 0) { - vector subaddress_indices; + std::vector subaddress_indices; for (const monero_subaddress& subaddress : account.m_subaddresses) { if (subaddress.m_unlocked_balance.get() > 0) subaddress_indices.push_back(subaddress.m_index.get()); } @@ -1768,8 +1767,8 @@ namespace monero { } // sweep from each account and collect resulting txs - vector> txs; - for (pair> subaddress_indices_pair : indices) { + std::vector> txs; + for (std::pair> subaddress_indices_pair : indices) { // copy and modify the original config monero_tx_config copy = config.copy(); @@ -1779,17 +1778,17 @@ namespace monero { // sweep all subaddresses together // TODO monero core: can this reveal outputs belong to the same wallet? if (copy.m_sweep_each_subaddress == boost::none || copy.m_sweep_each_subaddress.get() != true) { copy.m_subaddress_indices = subaddress_indices_pair.second; - vector> account_txs = sweep_account(copy); + std::vector> account_txs = sweep_account(copy); txs.insert(std::end(txs), std::begin(account_txs), std::end(account_txs)); } // otherwise sweep each subaddress individually else { for (uint32_t subaddress_index : subaddress_indices_pair.second) { - vector subaddress_indices; + std::vector subaddress_indices; subaddress_indices.push_back(subaddress_index); copy.m_subaddress_indices = subaddress_indices; - vector> account_txs = sweep_account(copy); + std::vector> account_txs = sweep_account(copy); txs.insert(std::end(txs), std::begin(account_txs), std::end(account_txs)); } } @@ -1799,27 +1798,27 @@ namespace monero { return txs; } - vector> monero_wallet_core::sweep_account(const monero_tx_config& config) { + std::vector> monero_wallet_core::sweep_account(const monero_tx_config& config) { // validate config - vector> destinations = config.get_normalized_destinations(); - if (config.m_account_index == boost::none) throw runtime_error("Must specify account index to sweep from"); - if (destinations.size() != 1 || destinations[0]->m_address == boost::none || destinations[0]->m_address.get().empty()) throw runtime_error("Must provide exactly one destination address to sweep output to"); - if (destinations[0]->m_amount != boost::none) throw runtime_error("Cannot specify destination amount to sweep"); - if (config.m_key_image != boost::none) throw runtime_error("Cannot define key image in sweep_account(); use sweep_output() to sweep an output by its key image"); - if (config.m_sweep_each_subaddress != boost::none && config.m_sweep_each_subaddress.get() == true) throw runtime_error("Cannot sweep each subaddress individually with sweep_account"); + std::vector> destinations = config.get_normalized_destinations(); + if (config.m_account_index == boost::none) throw std::runtime_error("Must specify account index to sweep from"); + if (destinations.size() != 1 || destinations[0]->m_address == boost::none || destinations[0]->m_address.get().empty()) throw std::runtime_error("Must provide exactly one destination address to sweep output to"); + if (destinations[0]->m_amount != boost::none) throw std::runtime_error("Cannot specify destination amount to sweep"); + if (config.m_key_image != boost::none) throw std::runtime_error("Cannot define key image in sweep_account(); use sweep_output() to sweep an output by its key image"); + if (config.m_sweep_each_subaddress != boost::none && config.m_sweep_each_subaddress.get() == true) throw std::runtime_error("Cannot sweep each subaddress individually with sweep_account"); // validate the transfer requested and populate dsts & extra std::list destination; destination.push_back(wallet_rpc::transfer_destination()); destination.back().amount = 0; destination.back().address = destinations[0]->m_address.get(); - string payment_id = config.m_payment_id == boost::none ? string("") : config.m_payment_id.get(); + std::string payment_id = config.m_payment_id == boost::none ? std::string("") : config.m_payment_id.get(); std::vector dsts; std::vector extra; epee::json_rpc::error err; if (!validate_transfer(m_w2.get(), destination, payment_id, dsts, extra, true, err)) { - throw runtime_error("Failed to validate sweep_account transfer request"); + throw std::runtime_error("Failed to validate sweep_account transfer request"); } // TODO monero-core: this is default `outputs` in COMMAND_RPC_SWEEP_ALL which is not documented @@ -1844,20 +1843,20 @@ namespace monero { bool relay = config.m_relay != boost::none && config.m_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() - list tx_keys; - list tx_amounts; - list tx_fees; - string multisig_tx_hex; - string unsigned_tx_hex; - list tx_hashes; - list tx_blobs; - list tx_metadatas; + std::list tx_keys; + std::list tx_amounts; + std::list tx_fees; + std::string multisig_tx_hex; + std::string unsigned_tx_hex; + std::list tx_hashes; + std::list tx_blobs; + std::list tx_metadatas; if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) { - throw runtime_error("need to handle error filling response!"); // TODO + throw std::runtime_error("need to handle error filling response!"); // TODO } // build sent txs from results // TODO: break this into separate utility function - vector> txs; + std::vector> txs; auto tx_hashes_iter = tx_hashes.begin(); auto tx_keys_iter = tx_keys.begin(); auto tx_amounts_iter = tx_amounts.begin(); @@ -1867,7 +1866,7 @@ namespace monero { while (tx_fees_iter != tx_fees.end()) { // init tx with outgoing transfer from filled values - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); txs.push_back(tx); tx->m_hash = *tx_hashes_iter; tx->m_is_locked = true; @@ -1876,10 +1875,10 @@ namespace monero { tx->m_fee = *tx_fees_iter; tx->m_full_hex = *tx_blobs_iter; tx->m_metadata = *tx_metadatas_iter; - shared_ptr out_transfer = make_shared(); + std::shared_ptr out_transfer = std::make_shared(); tx->m_outgoing_transfer = out_transfer; out_transfer->m_amount = *tx_amounts_iter; - shared_ptr destination = make_shared(destinations[0]->m_address.get(), out_transfer->m_amount.get()); + std::shared_ptr destination = std::make_shared(destinations[0]->m_address.get(), out_transfer->m_amount.get()); out_transfer->m_destinations.push_back(destination); // init other known fields @@ -1894,7 +1893,7 @@ namespace monero { tx->m_num_confirmations = 0; tx->m_ring_size = monero_utils::RING_SIZE; tx->m_unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); - if (tx->m_is_relayed.get()) tx->m_last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 + if (tx->m_is_relayed.get()) tx->m_last_relayed_timestamp = static_cast(time(NULL)); // std::set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 out_transfer->m_account_index = config.m_account_index; if (config.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(config.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here @@ -1907,8 +1906,8 @@ namespace monero { tx_metadatas_iter++; } - // link tx set and return - shared_ptr tx_set = make_shared(); + // link tx std::set and return + std::shared_ptr tx_set = std::make_shared(); tx_set->m_txs = txs; for (int i = 0; i < txs.size(); i++) txs[i]->m_tx_set = tx_set; if (!multisig_tx_hex.empty()) tx_set->m_multisig_tx_hex = multisig_tx_hex; @@ -1916,17 +1915,17 @@ namespace monero { return txs; } - shared_ptr monero_wallet_core::sweep_output(const monero_tx_config& config) { + std::shared_ptr monero_wallet_core::sweep_output(const monero_tx_config& config) { MTRACE("sweep_output()"); //MTRACE("monero_tx_config: " << config.serialize()); // validate input config - vector> destinations = config.get_normalized_destinations(); - if (config.m_key_image == boost::none || config.m_key_image.get().empty()) throw runtime_error("Must provide key image of output to sweep"); - if (destinations.size() != 1 || destinations[0]->m_address == boost::none || destinations[0]->m_address.get().empty()) throw runtime_error("Must provide exactly one destination address to sweep output to"); + std::vector> destinations = config.get_normalized_destinations(); + if (config.m_key_image == boost::none || config.m_key_image.get().empty()) throw std::runtime_error("Must provide key image of output to sweep"); + if (destinations.size() != 1 || destinations[0]->m_address == boost::none || destinations[0]->m_address.get().empty()) throw std::runtime_error("Must provide exactly one destination address to sweep output to"); // validate the transfer queried and populate dsts & extra - string m_payment_id = config.m_payment_id == boost::none ? string("") : config.m_payment_id.get(); + std::string m_payment_id = config.m_payment_id == boost::none ? std::string("") : config.m_payment_id.get(); std::vector dsts; std::vector extra; std::list destination; @@ -1935,14 +1934,14 @@ namespace monero { destination.back().address = destinations[0]->m_address.get(); epee::json_rpc::error err; if (!validate_transfer(m_w2.get(), destination, m_payment_id, dsts, extra, true, err)) { - //throw runtime_error(er); // TODO - throw runtime_error("Handle validate_transfer error!"); + //throw std::runtime_error(er); // TODO + throw std::runtime_error("Handle validate_transfer error!"); } // validate key image crypto::key_image ki; if (!epee::string_tools::hex_to_pod(config.m_key_image.get(), ki)) { - throw runtime_error("failed to parse key image"); + throw std::runtime_error("failed to parse key image"); } // create transaction @@ -1952,10 +1951,10 @@ namespace monero { std::vector ptx_vector = m_w2->create_transactions_single(ki, dsts[0].addr, dsts[0].is_subaddress, 1, mixin, unlock_time, priority, extra); // validate created transaction - if (ptx_vector.empty()) throw runtime_error("No outputs found"); - if (ptx_vector.size() > 1) throw runtime_error("Multiple transactions are created, which is not supposed to happen"); + if (ptx_vector.empty()) throw std::runtime_error("No outputs found"); + if (ptx_vector.size() > 1) throw std::runtime_error("Multiple transactions are created, which is not supposed to happen"); const wallet2::pending_tx &ptx = ptx_vector[0]; - if (ptx.selected_transfers.size() > 1) throw runtime_error("The transaction uses multiple inputs, which is not supposed to happen"); + if (ptx.selected_transfers.size() > 1) throw std::runtime_error("The transaction uses multiple inputs, which is not supposed to happen"); // config for fill_response() bool get_tx_keys = true; @@ -1964,20 +1963,20 @@ namespace monero { bool relay = config.m_relay != boost::none && config.m_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() - list tx_keys; - list tx_amounts; - list tx_fees; - string multisig_tx_hex; - string unsigned_tx_hex; - list tx_hashes; - list tx_blobs; - list tx_metadatas; + std::list tx_keys; + std::list tx_amounts; + std::list tx_fees; + std::string multisig_tx_hex; + std::string unsigned_tx_hex; + std::list tx_hashes; + std::list tx_blobs; + std::list tx_metadatas; if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) { - throw runtime_error("need to handle error filling response!"); // TODO: return err message + throw std::runtime_error("need to handle error filling response!"); // TODO: return err message } // build sent txs from results // TODO: use common utility with send_txs() to avoid code duplication - vector> txs; + std::vector> txs; auto tx_hashes_iter = tx_hashes.begin(); auto tx_keys_iter = tx_keys.begin(); auto tx_amounts_iter = tx_amounts.begin(); @@ -1987,7 +1986,7 @@ namespace monero { while (tx_fees_iter != tx_fees.end()) { // init tx with outgoing transfer from filled values - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); txs.push_back(tx); tx->m_hash = *tx_hashes_iter; tx->m_is_outgoing = true; @@ -1995,7 +1994,7 @@ namespace monero { tx->m_fee = *tx_fees_iter; tx->m_full_hex = *tx_blobs_iter; tx->m_metadata = *tx_metadatas_iter; - shared_ptr out_transfer = make_shared(); + std::shared_ptr out_transfer = std::make_shared(); tx->m_outgoing_transfer = out_transfer; out_transfer->m_amount = *tx_amounts_iter; @@ -2012,7 +2011,7 @@ namespace monero { tx->m_ring_size = monero_utils::RING_SIZE; tx->m_unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); tx->m_is_locked = true; - if (tx->m_is_relayed.get()) tx->m_last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 + if (tx->m_is_relayed.get()) tx->m_last_relayed_timestamp = static_cast(time(NULL)); // std::set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 out_transfer->m_account_index = config.m_account_index; if (config.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(config.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here out_transfer->m_destinations = destinations; @@ -2028,10 +2027,10 @@ namespace monero { } // validate one transaction - if (txs.size() != 1) throw runtime_error("Expected 1 transaction but was " + boost::lexical_cast(txs.size())); + if (txs.size() != 1) throw std::runtime_error("Expected 1 transaction but was " + boost::lexical_cast(txs.size())); - // link tx set and return - shared_ptr tx_set = make_shared(); + // link tx std::set and return + std::shared_ptr tx_set = std::make_shared(); tx_set->m_txs = txs; txs[0]->m_tx_set = tx_set; if (!multisig_tx_hex.empty()) tx_set->m_multisig_tx_hex = multisig_tx_hex; @@ -2039,7 +2038,7 @@ namespace monero { return txs[0]; } - vector> monero_wallet_core::sweep_dust(bool relay) { + std::vector> monero_wallet_core::sweep_dust(bool relay) { MTRACE("monero_wallet_core::sweep_dust()"); // create transaction to fill @@ -2051,21 +2050,21 @@ namespace monero { bool get_tx_metadata = true; // commit txs (if relaying) and get response using wallet rpc's fill_response() - list tx_keys; - list tx_amounts; - list tx_fees; - string multisig_tx_hex; - string unsigned_tx_hex; - list tx_hashes; - list tx_blobs; - list tx_metadatas; + std::list tx_keys; + std::list tx_amounts; + std::list tx_fees; + std::string multisig_tx_hex; + std::string unsigned_tx_hex; + std::list tx_hashes; + std::list tx_blobs; + std::list tx_metadatas; epee::json_rpc::error er; if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, er)) { - throw runtime_error("need to handle error filling response!"); // TODO: return err message + throw std::runtime_error("need to handle error filling response!"); // TODO: return err message } // build sent txs from results // TODO: use common utility with send_txs() to avoid code duplication - vector> txs; + std::vector> txs; auto tx_hashes_iter = tx_hashes.begin(); auto tx_keys_iter = tx_keys.begin(); auto tx_amounts_iter = tx_amounts.begin(); @@ -2075,7 +2074,7 @@ namespace monero { while (tx_fees_iter != tx_fees.end()) { // init tx with outgoing transfer from filled values - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); txs.push_back(tx); tx->m_hash = *tx_hashes_iter; tx->m_is_outgoing = true; @@ -2083,7 +2082,7 @@ namespace monero { tx->m_fee = *tx_fees_iter; tx->m_full_hex = *tx_blobs_iter; tx->m_metadata = *tx_metadatas_iter; - shared_ptr out_transfer = make_shared(); + std::shared_ptr out_transfer = std::make_shared(); tx->m_outgoing_transfer = out_transfer; out_transfer->m_amount = *tx_amounts_iter; @@ -2098,7 +2097,7 @@ namespace monero { tx->m_num_confirmations = 0; tx->m_ring_size = monero_utils::RING_SIZE; tx->m_unlock_time = 0; - if (tx->m_is_relayed.get()) tx->m_last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 + if (tx->m_is_relayed.get()) tx->m_last_relayed_timestamp = static_cast(time(NULL)); // std::set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 out_transfer->m_destinations[0]->m_amount = *tx_amounts_iter; // iterate to next element @@ -2111,10 +2110,10 @@ namespace monero { } // throw exception if no dust to sweep (dust only exists pre-rct) - if (txs.empty() && multisig_tx_hex.empty() && unsigned_tx_hex.empty()) throw runtime_error("No dust to sweep"); + if (txs.empty() && multisig_tx_hex.empty() && unsigned_tx_hex.empty()) throw std::runtime_error("No dust to sweep"); - // link tx set and return - shared_ptr tx_set; + // link tx std::set and return + std::shared_ptr tx_set; tx_set->m_txs = txs; for (int i = 0; i < txs.size(); i++) txs[i]->m_tx_set = tx_set; if (!multisig_tx_hex.empty()) tx_set->m_multisig_tx_hex = multisig_tx_hex; @@ -2122,17 +2121,17 @@ namespace monero { return txs; } - vector monero_wallet_core::relay_txs(const vector& tx_metadatas) { + std::vector monero_wallet_core::relay_txs(const std::vector& tx_metadatas) { MTRACE("relay_txs()"); // relay each metadata as a tx - vector tx_hashes; + std::vector tx_hashes; for (const auto& txMetadata : tx_metadatas) { // parse tx metadata hex cryptonote::blobdata blob; if (!epee::string_tools::parse_hexstr_to_binbuff(txMetadata, blob)) { - throw runtime_error("Failed to parse hex"); + throw std::runtime_error("Failed to parse hex"); } // deserialize tx @@ -2142,14 +2141,14 @@ namespace monero { boost::archive::portable_binary_iarchive ar(iss); ar >> ptx; } catch (...) { - throw runtime_error("Failed to parse tx metadata"); + throw std::runtime_error("Failed to parse tx metadata"); } // commit tx try { m_w2->commit_tx(ptx); } catch (const std::exception& e) { - throw runtime_error("Failed to commit tx"); + throw std::runtime_error("Failed to commit tx"); } // collect resulting hash @@ -2163,38 +2162,38 @@ namespace monero { monero_tx_set monero_wallet_core::parse_tx_set(const monero_tx_set& tx_set) { // get unsigned and multisig tx sets - string unsigned_tx_hex = tx_set.m_unsigned_tx_hex == boost::none ? "" : tx_set.m_unsigned_tx_hex.get(); - string multisig_tx_hex = tx_set.m_multisig_tx_hex == boost::none ? "" : tx_set.m_multisig_tx_hex.get(); + std::string unsigned_tx_hex = tx_set.m_unsigned_tx_hex == boost::none ? "" : tx_set.m_unsigned_tx_hex.get(); + std::string multisig_tx_hex = tx_set.m_multisig_tx_hex == boost::none ? "" : tx_set.m_multisig_tx_hex.get(); // validate request - if (m_w2->key_on_device()) throw runtime_error("command not supported by HW wallet"); - if (m_w2->watch_only()) throw runtime_error("command not supported by view-only wallet"); - if (unsigned_tx_hex.empty() && multisig_tx_hex.empty()) throw runtime_error("no txset provided"); + if (m_w2->key_on_device()) throw std::runtime_error("command not supported by HW wallet"); + if (m_w2->watch_only()) throw std::runtime_error("command not supported by view-only wallet"); + if (unsigned_tx_hex.empty() && multisig_tx_hex.empty()) throw std::runtime_error("no txset provided"); std::vector tx_constructions; if (!unsigned_tx_hex.empty()) { try { tools::wallet2::unsigned_tx_set exported_txs; cryptonote::blobdata blob; - if (!epee::string_tools::parse_hexstr_to_binbuff(unsigned_tx_hex, blob)) throw runtime_error("Failed to parse hex."); - if (!m_w2->parse_unsigned_tx_from_str(blob, exported_txs)) throw runtime_error("cannot load unsigned_txset"); + if (!epee::string_tools::parse_hexstr_to_binbuff(unsigned_tx_hex, blob)) throw std::runtime_error("Failed to parse hex."); + if (!m_w2->parse_unsigned_tx_from_str(blob, exported_txs)) throw std::runtime_error("cannot load unsigned_txset"); tx_constructions = exported_txs.txes; } catch (const std::exception &e) { - throw runtime_error("failed to parse unsigned transfers: " + std::string(e.what())); + throw std::runtime_error("failed to parse unsigned transfers: " + std::string(e.what())); } } else if (!multisig_tx_hex.empty()) { try { tools::wallet2::multisig_tx_set exported_txs; cryptonote::blobdata blob; - if (!epee::string_tools::parse_hexstr_to_binbuff(multisig_tx_hex, blob)) throw runtime_error("Failed to parse hex."); - if (!m_w2->parse_multisig_tx_from_str(blob, exported_txs)) throw runtime_error("cannot load multisig_txset"); + if (!epee::string_tools::parse_hexstr_to_binbuff(multisig_tx_hex, blob)) throw std::runtime_error("Failed to parse hex."); + if (!m_w2->parse_multisig_tx_from_str(blob, exported_txs)) throw std::runtime_error("cannot load multisig_txset"); for (size_t n = 0; n < exported_txs.m_ptx.size(); ++n) { tx_constructions.push_back(exported_txs.m_ptx[n].construction_data); } } catch (const std::exception &e) { - throw runtime_error("failed to parse multisig transfers: " + std::string(e.what())); + throw std::runtime_error("failed to parse multisig transfers: " + std::string(e.what())); } } @@ -2202,13 +2201,13 @@ namespace monero { try { // gather info for each tx - vector> txs; + std::vector> txs; std::unordered_map> dests; int first_known_non_zero_change_index = -1; for (size_t n = 0; n < tx_constructions.size(); ++n) { // pre-initialize tx - shared_ptr tx = make_shared(); + std::shared_ptr tx = std::make_shared(); tx->m_is_outgoing = true; tx->m_input_sum = 0; tx->m_output_sum = 0; @@ -2264,14 +2263,14 @@ namespace monero { if (cd.change_dts.amount > 0) { auto it = dests.find(cd.change_dts.addr); - if (it == dests.end()) throw runtime_error("Claimed change does not go to a paid address"); - if (it->second.second < cd.change_dts.amount) throw runtime_error("Claimed change is larger than payment to the change address"); + if (it == dests.end()) throw std::runtime_error("Claimed change does not go to a paid address"); + if (it->second.second < cd.change_dts.amount) throw std::runtime_error("Claimed change is larger than payment to the change address"); if (cd.change_dts.amount > 0) { if (first_known_non_zero_change_index == -1) first_known_non_zero_change_index = n; const tools::wallet2::tx_construction_data &cdn = tx_constructions[first_known_non_zero_change_index]; - if (memcmp(&cd.change_dts.addr, &cdn.change_dts.addr, sizeof(cd.change_dts.addr))) throw runtime_error("Change goes to more than one address"); + if (memcmp(&cd.change_dts.addr, &cdn.change_dts.addr, sizeof(cd.change_dts.addr))) throw std::runtime_error("Change goes to more than one address"); } tx->m_change_amount = tx->m_change_amount.get() + cd.change_dts.amount; it->second.second -= cd.change_dts.amount; @@ -2279,13 +2278,13 @@ namespace monero { dests.erase(cd.change_dts.addr); } - tx->m_outgoing_transfer = make_shared(); + tx->m_outgoing_transfer = std::make_shared(); size_t n_dummy_outputs = 0; for (auto i = dests.begin(); i != dests.end(); ) { if (i->second.second > 0) { - shared_ptr destination = make_shared(); + std::shared_ptr destination = std::make_shared(); destination->m_address = i->second.first; destination->m_amount = i->second.second; tx->m_outgoing_transfer.get()->m_destinations.push_back(destination); @@ -2307,74 +2306,74 @@ namespace monero { txs.push_back(tx); } - // build and return tx set + // build and return tx std::set monero_tx_set tx_set; tx_set.m_txs = txs; return tx_set; } catch (const std::exception &e) { - throw runtime_error("failed to parse unsigned transfers"); + throw std::runtime_error("failed to parse unsigned transfers"); } } // implementation based on monero-project wallet_rpc_server.cpp::on_sign_transfer() - string monero_wallet_core::sign_txs(const string& unsigned_tx_hex) { - if (m_w2->key_on_device()) throw runtime_error("command not supported by HW wallet"); - if (m_w2->watch_only()) throw runtime_error("command not supported by view-only wallet"); + std::string monero_wallet_core::sign_txs(const std::string& unsigned_tx_hex) { + if (m_w2->key_on_device()) throw std::runtime_error("command not supported by HW wallet"); + if (m_w2->watch_only()) throw std::runtime_error("command not supported by view-only wallet"); cryptonote::blobdata blob; - if (!epee::string_tools::parse_hexstr_to_binbuff(unsigned_tx_hex, blob)) throw runtime_error("Failed to parse hex."); + if (!epee::string_tools::parse_hexstr_to_binbuff(unsigned_tx_hex, blob)) throw std::runtime_error("Failed to parse hex."); tools::wallet2::unsigned_tx_set exported_txs; - if(!m_w2->parse_unsigned_tx_from_str(blob, exported_txs)) throw runtime_error("cannot load unsigned_txset"); + if(!m_w2->parse_unsigned_tx_from_str(blob, exported_txs)) throw std::runtime_error("cannot load unsigned_txset"); std::vector ptxs; try { tools::wallet2::signed_tx_set signed_txs; std::string ciphertext = m_w2->sign_tx_dump_to_str(exported_txs, ptxs, signed_txs); - if (ciphertext.empty()) throw runtime_error("Failed to sign unsigned tx"); + if (ciphertext.empty()) throw std::runtime_error("Failed to sign unsigned tx"); return epee::string_tools::buff_to_hex_nodelimer(ciphertext); } catch (const std::exception &e) { - throw runtime_error(std::string("Failed to sign unsigned tx: ") + e.what()); + throw std::runtime_error(std::string("Failed to sign unsigned tx: ") + e.what()); } } // implementation based on monero-project wallet_rpc_server.cpp::on_submit_transfer() - vector monero_wallet_core::submit_txs(const string& signed_tx_hex) { - if (m_w2->key_on_device()) throw runtime_error("command not supported by HW wallet"); + std::vector monero_wallet_core::submit_txs(const std::string& signed_tx_hex) { + if (m_w2->key_on_device()) throw std::runtime_error("command not supported by HW wallet"); cryptonote::blobdata blob; - if (!epee::string_tools::parse_hexstr_to_binbuff(signed_tx_hex, blob)) throw runtime_error("Failed to parse hex."); + if (!epee::string_tools::parse_hexstr_to_binbuff(signed_tx_hex, blob)) throw std::runtime_error("Failed to parse hex."); std::vector ptx_vector; try { - if (!m_w2->parse_tx_from_str(blob, ptx_vector, NULL)) throw runtime_error("Failed to parse signed tx data."); + if (!m_w2->parse_tx_from_str(blob, ptx_vector, NULL)) throw std::runtime_error("Failed to parse signed tx data."); } catch (const std::exception &e) { - throw runtime_error(std::string("Failed to parse signed tx: ") + e.what()); + throw std::runtime_error(std::string("Failed to parse signed tx: ") + e.what()); } try { - vector tx_hashes; + std::vector tx_hashes; for (auto &ptx: ptx_vector) { m_w2->commit_tx(ptx); tx_hashes.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx))); } return tx_hashes; } catch (const std::exception &e) { - throw runtime_error(std::string("Failed to submit signed tx: ") + e.what()); + throw std::runtime_error(std::string("Failed to submit signed tx: ") + e.what()); } } - string monero_wallet_core::sign_message(const string& msg) const { + std::string monero_wallet_core::sign_message(const std::string& msg) const { return m_w2->sign(msg); } - bool monero_wallet_core::verify_message(const string& msg, const string& address, const string& signature) const { + bool monero_wallet_core::verify_message(const std::string& msg, const std::string& address, const std::string& signature) const { // validate and parse address or url cryptonote::address_parse_info info; - string err; + std::string err; if (!get_account_address_from_str_or_url(info, m_w2->nettype(), address, [&err](const std::string &url, const std::vector &addresses, bool dnssec_valid)->std::string { if (!dnssec_valid) { @@ -2388,27 +2387,27 @@ namespace monero { return addresses[0]; })) { - throw runtime_error(err); + throw std::runtime_error(err); } // verify and return result return m_w2->verify(msg, info.address, signature); } - string monero_wallet_core::get_tx_key(const string& tx_hash) const { + std::string monero_wallet_core::get_tx_key(const std::string& tx_hash) const { MTRACE("monero_wallet_core::get_tx_key()"); // validate and parse tx hash crypto::hash _tx_hash; if (!epee::string_tools::hex_to_pod(tx_hash, _tx_hash)) { - throw runtime_error("TX hash has invalid format"); + throw std::runtime_error("TX hash has invalid format"); } // get tx key and additional keys crypto::secret_key _tx_key; std::vector additional_tx_keys; if (!m_w2->get_tx_key(_tx_hash, _tx_key, additional_tx_keys)) { - throw runtime_error("No tx secret key is stored for this tx"); + throw std::runtime_error("No tx secret key is stored for this tx"); } // build and return tx key with additional keys @@ -2420,24 +2419,24 @@ namespace monero { return std::string(s.data(), s.size()); } - shared_ptr monero_wallet_core::check_tx_key(const string& tx_hash, const string& tx_key, const string& address) const { + std::shared_ptr monero_wallet_core::check_tx_key(const std::string& tx_hash, const std::string& tx_key, const std::string& address) const { MTRACE("monero_wallet_core::check_tx_key()"); // validate and parse tx hash crypto::hash _tx_hash; if (!epee::string_tools::hex_to_pod(tx_hash, _tx_hash)) { - throw runtime_error("TX hash has invalid format"); + throw std::runtime_error("TX hash has invalid format"); } // validate and parse tx key epee::wipeable_string tx_key_str = tx_key; if (tx_key_str.size() < 64 || tx_key_str.size() % 64) { - throw runtime_error("Tx key has invalid format"); + throw std::runtime_error("Tx key has invalid format"); } const char *data = tx_key_str.data(); crypto::secret_key _tx_key; if (!epee::wipeable_string(data, 64).hex_to_pod(unwrap(unwrap(_tx_key)))) { - throw runtime_error("Tx key has invalid format"); + throw std::runtime_error("Tx key has invalid format"); } // get additional keys @@ -2446,7 +2445,7 @@ namespace monero { while (offset < tx_key_str.size()) { additional_tx_keys.resize(additional_tx_keys.size() + 1); if (!epee::wipeable_string(data + offset, 64).hex_to_pod(unwrap(unwrap(additional_tx_keys.back())))) { - throw runtime_error("Tx key has invalid format"); + throw std::runtime_error("Tx key has invalid format"); } offset += 64; } @@ -2454,7 +2453,7 @@ namespace monero { // validate and parse address cryptonote::address_parse_info info; if (!get_account_address_from_str(info, m_w2->nettype(), address)) { - throw runtime_error("Invalid address"); + throw std::runtime_error("Invalid address"); } // initialize and return tx check using wallet2 @@ -2462,7 +2461,7 @@ namespace monero { bool in_tx_pool; uint64_t num_confirmations; m_w2->check_tx_key(_tx_hash, _tx_key, additional_tx_keys, info.address, received_amount, in_tx_pool, num_confirmations); - shared_ptr check_tx = make_shared(); + std::shared_ptr check_tx = std::make_shared(); check_tx->m_is_good = true; // check is good if we get this far check_tx->m_received_amount = received_amount; check_tx->m_in_tx_pool = in_tx_pool; @@ -2470,41 +2469,41 @@ namespace monero { return check_tx; } - string monero_wallet_core::get_tx_proof(const string& tx_hash, const string& address, const string& message) const { + std::string monero_wallet_core::get_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message) const { // validate and parse tx hash crypto::hash _tx_hash; if (!epee::string_tools::hex_to_pod(tx_hash, _tx_hash)) { - throw runtime_error("TX hash has invalid format"); + throw std::runtime_error("TX hash has invalid format"); } // validate and parse address cryptonote::address_parse_info info; if (!get_account_address_from_str(info, m_w2->nettype(), address)) { - throw runtime_error("Invalid address"); + throw std::runtime_error("Invalid address"); } // get tx proof return m_w2->get_tx_proof(_tx_hash, info.address, info.is_subaddress, message); } - shared_ptr monero_wallet_core::check_tx_proof(const string& tx_hash, const string& address, const string& message, const string& signature) const { + std::shared_ptr monero_wallet_core::check_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message, const std::string& signature) const { MTRACE("monero_wallet_core::check_tx_proof()"); // validate and parse tx hash crypto::hash _tx_hash; if (!epee::string_tools::hex_to_pod(tx_hash, _tx_hash)) { - throw runtime_error("TX hash has invalid format"); + throw std::runtime_error("TX hash has invalid format"); } // validate and parse address cryptonote::address_parse_info info; if (!get_account_address_from_str(info, m_w2->nettype(), address)) { - throw runtime_error("Invalid address"); + throw std::runtime_error("Invalid address"); } // initialize and return tx check using wallet2 - shared_ptr check_tx = make_shared(); + std::shared_ptr check_tx = std::make_shared(); uint64_t received_amount; bool in_tx_pool; uint64_t num_confirmations; @@ -2517,56 +2516,56 @@ namespace monero { return check_tx; } - string monero_wallet_core::get_spend_proof(const string& tx_hash, const string& message) const { + std::string monero_wallet_core::get_spend_proof(const std::string& tx_hash, const std::string& message) const { MTRACE("monero_wallet_core::get_spend_proof()"); // validate and parse tx hash crypto::hash _tx_hash; if (!epee::string_tools::hex_to_pod(tx_hash, _tx_hash)) { - throw runtime_error("TX hash has invalid format"); + throw std::runtime_error("TX hash has invalid format"); } // return spend proof signature return m_w2->get_spend_proof(_tx_hash, message); } - bool monero_wallet_core::check_spend_proof(const string& tx_hash, const string& message, const string& signature) const { + bool monero_wallet_core::check_spend_proof(const std::string& tx_hash, const std::string& message, const std::string& signature) const { MTRACE("monero_wallet_core::check_spend_proof()"); // validate and parse tx hash crypto::hash _tx_hash; if (!epee::string_tools::hex_to_pod(tx_hash, _tx_hash)) { - throw runtime_error("TX hash has invalid format"); + throw std::runtime_error("TX hash has invalid format"); } // check spend proof return m_w2->check_spend_proof(_tx_hash, message, signature); } - string monero_wallet_core::get_reserve_proof_wallet(const string& message) const { + std::string monero_wallet_core::get_reserve_proof_wallet(const std::string& message) const { MTRACE("monero_wallet_core::get_reserve_proof_wallet()"); boost::optional> account_minreserve; return m_w2->get_reserve_proof(account_minreserve, message); } - string monero_wallet_core::get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const { + std::string monero_wallet_core::get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const std::string& message) const { MTRACE("monero_wallet_core::get_reserve_proof_account()"); boost::optional> account_minreserve; - if (account_idx >= m_w2->get_num_subaddress_accounts()) throw runtime_error("Account index is out of bound"); + if (account_idx >= m_w2->get_num_subaddress_accounts()) throw std::runtime_error("Account index is out of bound"); account_minreserve = std::make_pair(account_idx, amount); return m_w2->get_reserve_proof(account_minreserve, message); } - shared_ptr monero_wallet_core::check_reserve_proof(const string& address, const string& message, const string& signature) const { + std::shared_ptr monero_wallet_core::check_reserve_proof(const std::string& address, const std::string& message, const std::string& signature) const { MTRACE("monero_wallet_core::check_reserve_proof()"); // validate and parse input cryptonote::address_parse_info info; - if (!get_account_address_from_str(info, m_w2->nettype(), address)) throw runtime_error("Invalid address"); - if (info.is_subaddress) throw runtime_error("Address must not be a subaddress"); + if (!get_account_address_from_str(info, m_w2->nettype(), address)) throw std::runtime_error("Invalid address"); + if (info.is_subaddress) throw std::runtime_error("Address must not be a subaddress"); // initialize check reserve using wallet2 - shared_ptr checkReserve = make_shared(); + std::shared_ptr checkReserve = std::make_shared(); uint64_t total_amount; uint64_t unconfirmed_spent_amount; checkReserve->m_is_good = m_w2->check_reserve_proof(info.address, message, signature, total_amount, unconfirmed_spent_amount); @@ -2577,49 +2576,49 @@ namespace monero { return checkReserve; } - string monero_wallet_core::get_tx_note(const string& tx_hash) const { + std::string monero_wallet_core::get_tx_note(const std::string& tx_hash) const { MTRACE("monero_wallet_core::get_tx_note()"); cryptonote::blobdata tx_blob; if (!epee::string_tools::parse_hexstr_to_binbuff(tx_hash, tx_blob) || tx_blob.size() != sizeof(crypto::hash)) { - throw runtime_error("TX hash has invalid format"); + throw std::runtime_error("TX hash has invalid format"); } crypto::hash _tx_hash = *reinterpret_cast(tx_blob.data()); return m_w2->get_tx_note(_tx_hash); } - vector monero_wallet_core::get_tx_notes(const vector& tx_hashes) const { + std::vector monero_wallet_core::get_tx_notes(const std::vector& tx_hashes) const { MTRACE("monero_wallet_core::get_tx_notes()"); - vector notes; + std::vector notes; for (const auto& tx_hash : tx_hashes) notes.push_back(get_tx_note(tx_hash)); return notes; } - void monero_wallet_core::set_tx_note(const string& tx_hash, const string& note) { + void monero_wallet_core::set_tx_note(const std::string& tx_hash, const std::string& note) { MTRACE("monero_wallet_core::set_tx_note()"); cryptonote::blobdata tx_blob; if (!epee::string_tools::parse_hexstr_to_binbuff(tx_hash, tx_blob) || tx_blob.size() != sizeof(crypto::hash)) { - throw runtime_error("TX hash has invalid format"); + throw std::runtime_error("TX hash has invalid format"); } crypto::hash _tx_hash = *reinterpret_cast(tx_blob.data()); m_w2->set_tx_note(_tx_hash, note); } - void monero_wallet_core::set_tx_notes(const vector& tx_hashes, const vector& notes) { + void monero_wallet_core::set_tx_notes(const std::vector& tx_hashes, const std::vector& notes) { MTRACE("monero_wallet_core::set_tx_notes()"); - if (tx_hashes.size() != notes.size()) throw runtime_error("Different amount of txids and notes"); + if (tx_hashes.size() != notes.size()) throw std::runtime_error("Different amount of txids and notes"); for (int i = 0; i < tx_hashes.size(); i++) { set_tx_note(tx_hashes[i], notes[i]); } } - vector monero_wallet_core::get_address_book_entries(const vector& indices) const { + std::vector monero_wallet_core::get_address_book_entries(const std::vector& indices) const { MTRACE("monero_wallet_core::get_address_book_entries()"); // get wallet2 address book entries const auto w2_entries = m_w2->get_address_book(); // build entries from wallet2 types - vector entries; + std::vector entries; if (indices.empty()) { uint64_t idx = 0; for (const auto &w2_entry: w2_entries) { @@ -2628,7 +2627,7 @@ namespace monero { } } else { for (uint64_t idx : indices) { - if (idx >= w2_entries.size()) throw runtime_error("Index out of range: " + std::to_string(idx)); + if (idx >= w2_entries.size()) throw std::runtime_error("Index out of range: " + std::to_string(idx)); const auto &w2_entry = w2_entries[idx]; monero_address_book_entry entry(idx++, cryptonote::get_account_address_as_str(m_w2->nettype(), w2_entry.m_is_subaddress, w2_entry.m_address), w2_entry.m_description, epee::string_tools::pod_to_hex(w2_entry.m_payment_id)); entries.push_back(entry); @@ -2638,28 +2637,28 @@ namespace monero { return entries; } - uint64_t monero_wallet_core::add_address_book_entry(const string& address, const string& description) { + uint64_t monero_wallet_core::add_address_book_entry(const std::string& address, const std::string& description) { MTRACE("add_address_book_entry()"); cryptonote::address_parse_info info; epee::json_rpc::error er; if(!get_account_address_from_str_or_url(info, m_w2->nettype(), address, [&er](const std::string &url, const std::vector &addresses, bool dnssec_valid)->std::string { - if (!dnssec_valid) throw runtime_error(std::string("Invalid DNSSEC for ") + url); - if (addresses.empty()) throw runtime_error(std::string("No Monero address found at ") + url); + if (!dnssec_valid) throw std::runtime_error(std::string("Invalid DNSSEC for ") + url); + if (addresses.empty()) throw std::runtime_error(std::string("No Monero address found at ") + url); return addresses[0]; })) { - throw runtime_error(std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + address); + throw std::runtime_error(std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + address); } - if (!m_w2->add_address_book_row(info.address, info.has_payment_id ? &info.payment_id : NULL, description, info.is_subaddress)) throw runtime_error("Failed to add address book entry"); + if (!m_w2->add_address_book_row(info.address, info.has_payment_id ? &info.payment_id : NULL, description, info.is_subaddress)) throw std::runtime_error("Failed to add address book entry"); return m_w2->get_address_book().size() - 1; } - void monero_wallet_core::edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description) { + void monero_wallet_core::edit_address_book_entry(uint64_t index, bool set_address, const std::string& address, bool set_description, const std::string& description) { MTRACE("edit_address_book_entry()"); const auto ab = m_w2->get_address_book(); - if (index >= ab.size()) throw runtime_error("Index out of range: " + std::to_string(index)); + if (index >= ab.size()) throw std::runtime_error("Index out of range: " + std::to_string(index)); tools::wallet2::address_book_row entry = ab[index]; @@ -2669,12 +2668,12 @@ namespace monero { er.message = ""; if(!get_account_address_from_str_or_url(info, m_w2->nettype(), address, [&er](const std::string &url, const std::vector &addresses, bool dnssec_valid)->std::string { - if (!dnssec_valid) throw runtime_error(std::string("Invalid DNSSEC for ") + url); - if (addresses.empty()) throw runtime_error(std::string("No Monero address found at ") + url); + if (!dnssec_valid) throw std::runtime_error(std::string("Invalid DNSSEC for ") + url); + if (addresses.empty()) throw std::runtime_error(std::string("No Monero address found at ") + url); return addresses[0]; })) { - throw runtime_error("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: " + address); + throw std::runtime_error("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: " + address); } entry.m_address = info.address; entry.m_is_subaddress = info.is_subaddress; @@ -2684,57 +2683,57 @@ namespace monero { if (set_description) entry.m_description = description; if (!m_w2->set_address_book_row(index, entry.m_address, set_address && entry.m_has_payment_id ? &entry.m_payment_id : NULL, entry.m_description, entry.m_is_subaddress)) { - throw runtime_error("Failed to edit address book entry"); + throw std::runtime_error("Failed to edit address book entry"); } } void monero_wallet_core::delete_address_book_entry(uint64_t index) { const auto w2_entries = m_w2->get_address_book(); - if (index >= w2_entries.size()) throw runtime_error("Index out of range: " + std::to_string(index)); - if (!m_w2->delete_address_book_row(index)) throw runtime_error("Failed to delete address book entry"); + if (index >= w2_entries.size()) throw std::runtime_error("Index out of range: " + std::to_string(index)); + if (!m_w2->delete_address_book_row(index)) throw std::runtime_error("Failed to delete address book entry"); } - string monero_wallet_core::create_payment_uri(const monero_tx_config& config) const { + std::string monero_wallet_core::create_payment_uri(const monero_tx_config& config) const { MTRACE("create_payment_uri()"); // validate config - vector> destinations = config.get_normalized_destinations(); - if (destinations.size() != 1) throw runtime_error("Cannot make URI from supplied parameters: must provide exactly one destination to send funds"); - if (destinations.at(0)->m_address == boost::none) throw runtime_error("Cannot make URI from supplied parameters: must provide destination address"); - if (destinations.at(0)->m_amount == boost::none) throw runtime_error("Cannot make URI from supplied parameters: must provide destination amount"); + std::vector> destinations = config.get_normalized_destinations(); + if (destinations.size() != 1) throw std::runtime_error("Cannot make URI from supplied parameters: must provide exactly one destination to send funds"); + if (destinations.at(0)->m_address == boost::none) throw std::runtime_error("Cannot make URI from supplied parameters: must provide destination address"); + if (destinations.at(0)->m_amount == boost::none) throw std::runtime_error("Cannot make URI from supplied parameters: must provide destination amount"); // prepare wallet2 params - string address = destinations.at(0)->m_address.get(); - string payment_id = config.m_payment_id == boost::none ? "" : config.m_payment_id.get(); + std::string address = destinations.at(0)->m_address.get(); + std::string payment_id = config.m_payment_id == boost::none ? "" : config.m_payment_id.get(); uint64_t amount = destinations.at(0)->m_amount.get(); - string note = config.m_note == boost::none ? "" : config.m_note.get(); - string m_recipient_name = config.m_recipient_name == boost::none ? "" : config.m_recipient_name.get(); + std::string note = config.m_note == boost::none ? "" : config.m_note.get(); + std::string m_recipient_name = config.m_recipient_name == boost::none ? "" : config.m_recipient_name.get(); // make uri using wallet2 std::string error; - string uri = m_w2->make_uri(address, payment_id, amount, note, m_recipient_name, error); - if (uri.empty()) throw runtime_error("Cannot make URI from supplied parameters: " + error); + std::string uri = m_w2->make_uri(address, payment_id, amount, note, m_recipient_name, error); + if (uri.empty()) throw std::runtime_error("Cannot make URI from supplied parameters: " + error); return uri; } - shared_ptr monero_wallet_core::parse_payment_uri(const string& uri) const { + std::shared_ptr monero_wallet_core::parse_payment_uri(const std::string& uri) const { MTRACE("parse_payment_uri(" << uri << ")"); // decode uri to parameters - string address; - string payment_id; + std::string address; + std::string payment_id; uint64_t amount = 0; - string note; - string m_recipient_name; - vector unknown_parameters; - string error; + std::string note; + std::string m_recipient_name; + std::vector unknown_parameters; + std::string error; if (!m_w2->parse_uri(uri, address, payment_id, amount, note, m_recipient_name, unknown_parameters, error)) { - throw runtime_error("Error parsing URI: " + error); + throw std::runtime_error("Error parsing URI: " + error); } // initialize config - shared_ptr config = make_shared(); - shared_ptr destination = make_shared(); + std::shared_ptr config = std::make_shared(); + std::shared_ptr destination = std::make_shared(); config->m_destinations.push_back(destination); if (!address.empty()) destination->m_address = address; destination->m_amount = amount; @@ -2745,11 +2744,11 @@ namespace monero { return config; } - bool monero_wallet_core::get_attribute(const string& key, string& value) const { + bool monero_wallet_core::get_attribute(const std::string& key, std::string& value) const { return m_w2->get_attribute(key, value); } - void monero_wallet_core::set_attribute(const string& key, const string& val) { + void monero_wallet_core::set_attribute(const std::string& key, const std::string& val) { m_w2->set_attribute(key, val); } @@ -2757,9 +2756,9 @@ namespace monero { MTRACE("start_mining()"); // only mine on trusted daemon - if (!m_w2->is_trusted_daemon()) throw runtime_error("This command requires a trusted daemon."); + if (!m_w2->is_trusted_daemon()) throw std::runtime_error("This command requires a trusted daemon."); - // set defaults + // std::set defaults if (num_threads == boost::none || num_threads.get() == 0) num_threads = 1; // TODO: how to autodetect optimal number of threads which daemon supports? if (background_mining == boost::none) background_mining = false; if (ignore_battery == boost::none) ignore_battery = false; @@ -2767,7 +2766,7 @@ namespace monero { // validate num threads size_t max_mining_threads_count = (std::max)(tools::get_max_concurrency(), static_cast(2)); if (num_threads.get() < 1 || max_mining_threads_count < num_threads.get()) { - throw runtime_error("The specified number of threads is inappropriate."); + throw std::runtime_error("The specified number of threads is inappropriate."); } // start mining on daemon @@ -2779,7 +2778,7 @@ namespace monero { cryptonote::COMMAND_RPC_START_MINING::response daemon_res; bool r = m_w2->invoke_http_json("/start_mining", daemon_req, daemon_res); if (!r || daemon_res.status != CORE_RPC_STATUS_OK) { - throw runtime_error("Couldn't start mining due to unknown error."); + throw std::runtime_error("Couldn't start mining due to unknown error."); } } @@ -2789,7 +2788,7 @@ namespace monero { cryptonote::COMMAND_RPC_STOP_MINING::response daemon_res; bool r = m_w2->invoke_http_json("/stop_mining", daemon_req, daemon_res); if (!r || daemon_res.status != CORE_RPC_STATUS_OK) { - throw runtime_error("Couldn't stop mining due to unknown error."); + throw std::runtime_error("Couldn't stop mining due to unknown error."); } } @@ -2835,15 +2834,15 @@ namespace monero { return info; } - string monero_wallet_core::prepare_multisig() { - if (m_w2->multisig()) throw runtime_error("This wallet is already multisig"); - if (m_w2->watch_only()) throw runtime_error("This wallet is view-only and cannot be made multisig"); + std::string monero_wallet_core::prepare_multisig() { + if (m_w2->multisig()) throw std::runtime_error("This wallet is already multisig"); + if (m_w2->watch_only()) throw std::runtime_error("This wallet is view-only and cannot be made multisig"); return m_w2->get_multisig_info(); } - monero_multisig_init_result monero_wallet_core::make_multisig(const vector& multisig_hexes, int threshold, const string& password) { - if (m_w2->multisig()) throw runtime_error("This wallet is already multisig"); - if (m_w2->watch_only()) throw runtime_error("This wallet is view-only and cannot be made multisig"); + monero_multisig_init_result monero_wallet_core::make_multisig(const std::vector& multisig_hexes, int threshold, const std::string& password) { + if (m_w2->multisig()) throw std::runtime_error("This wallet is already multisig"); + if (m_w2->watch_only()) throw std::runtime_error("This wallet is view-only and cannot be made multisig"); boost::lock_guard guarg(m_sync_mutex); // do not refresh while making multisig monero_multisig_init_result result; result.m_multisig_hex = m_w2->make_multisig(epee::wipeable_string(password), multisig_hexes, threshold); @@ -2851,20 +2850,20 @@ namespace monero { return result; } - monero_multisig_init_result monero_wallet_core::exchange_multisig_keys(const vector& multisig_hexes, const string& password) { + monero_multisig_init_result monero_wallet_core::exchange_multisig_keys(const std::vector& multisig_hexes, const std::string& password) { // validate state and args bool ready; uint32_t threshold, total; - if (!m_w2->multisig(&ready, &threshold, &total)) throw runtime_error("This wallet is not multisig"); - if (ready) throw runtime_error("This wallet is multisig, and already finalized"); - if (multisig_hexes.size() < 1 || multisig_hexes.size() > total) throw runtime_error("Needs multisig info from more participants"); + if (!m_w2->multisig(&ready, &threshold, &total)) throw std::runtime_error("This wallet is not multisig"); + if (ready) throw std::runtime_error("This wallet is multisig, and already finalized"); + if (multisig_hexes.size() < 1 || multisig_hexes.size() > total) throw std::runtime_error("Needs multisig info from more participants"); // do not refresh while exchanging multisig keys boost::lock_guard guarg(m_sync_mutex); // import peer multisig keys and get multisig hex to be shared next round - string multisig_hex = m_w2->exchange_multisig_keys(epee::wipeable_string(password), multisig_hexes); + std::string multisig_hex = m_w2->exchange_multisig_keys(epee::wipeable_string(password), multisig_hexes); // build and return the exchange result monero_multisig_init_result result; @@ -2873,28 +2872,28 @@ namespace monero { return result; } - string monero_wallet_core::get_multisig_hex() { + std::string monero_wallet_core::get_multisig_hex() { bool ready; - if (!m_w2->multisig(&ready)) throw runtime_error("This wallet is not multisig"); - if (!ready) throw runtime_error("This wallet is multisig, but not yet finalized"); + if (!m_w2->multisig(&ready)) throw std::runtime_error("This wallet is not multisig"); + if (!ready) throw std::runtime_error("This wallet is multisig, but not yet finalized"); return epee::string_tools::buff_to_hex_nodelimer(m_w2->export_multisig()); } - int monero_wallet_core::import_multisig_hex(const vector& multisig_hexes) { + int monero_wallet_core::import_multisig_hex(const std::vector& multisig_hexes) { // validate state and args bool ready; uint32_t threshold, total; - if (!m_w2->multisig(&ready, &threshold, &total)) throw runtime_error("This wallet is not multisig"); - if (!ready) throw runtime_error("This wallet is multisig, but not yet finalized"); - if (multisig_hexes.size() < threshold - 1) throw runtime_error("Needs multisig export info from more participants"); + if (!m_w2->multisig(&ready, &threshold, &total)) throw std::runtime_error("This wallet is not multisig"); + if (!ready) throw std::runtime_error("This wallet is multisig, but not yet finalized"); + if (multisig_hexes.size() < threshold - 1) throw std::runtime_error("Needs multisig export info from more participants"); // validate and parse each peer multisig hex std::vector multisig_blobs; multisig_blobs.resize(multisig_hexes.size()); for (size_t n = 0; n < multisig_hexes.size(); ++n) { if (!epee::string_tools::parse_hexstr_to_binbuff(multisig_hexes[n], multisig_blobs[n])) { - throw runtime_error("Failed to parse hex"); + throw std::runtime_error("Failed to parse hex"); } } @@ -2908,39 +2907,39 @@ namespace monero { return num_outputs; } - monero_multisig_sign_result monero_wallet_core::sign_multisig_tx_hex(const string& multisig_tx_hex) { + monero_multisig_sign_result monero_wallet_core::sign_multisig_tx_hex(const std::string& multisig_tx_hex) { // validate state and args bool ready; uint32_t threshold, total; - if (!m_w2->multisig(&ready, &threshold, &total)) throw runtime_error("This wallet is not multisig"); - if (!ready) throw runtime_error("This wallet is multisig, but not yet finalized"); + if (!m_w2->multisig(&ready, &threshold, &total)) throw std::runtime_error("This wallet is not multisig"); + if (!ready) throw std::runtime_error("This wallet is multisig, but not yet finalized"); // validate and parse multisig tx hex as blob cryptonote::blobdata multisig_tx_blob; if (!epee::string_tools::parse_hexstr_to_binbuff(multisig_tx_hex, multisig_tx_blob)) { - throw runtime_error("Failed to parse hex"); + throw std::runtime_error("Failed to parse hex"); } // validate and parse blob as multisig_tx_set tools::wallet2::multisig_tx_set ms_tx_set; if (!m_w2->load_multisig_tx(multisig_tx_blob, ms_tx_set, NULL)) { - throw runtime_error("Failed to parse multisig tx data"); + throw std::runtime_error("Failed to parse multisig tx data"); } // sign multisig txs bool success = false; - vector tx_hashes; + std::vector tx_hashes; try { success = m_w2->sign_multisig_tx(ms_tx_set, tx_hashes); } catch (const std::exception& e) { - string msg = string("Failed to sign multisig tx: ") + e.what(); - throw runtime_error(msg); + std::string msg = std::string("Failed to sign multisig tx: ") + e.what(); + throw std::runtime_error(msg); } - if (!success) throw runtime_error("Failed to sign multisig tx"); + if (!success) throw std::runtime_error("Failed to sign multisig tx"); // save multisig txs - string signed_multisig_tx_hex = epee::string_tools::buff_to_hex_nodelimer(m_w2->save_multisig_tx(ms_tx_set)); + std::string signed_multisig_tx_hex = epee::string_tools::buff_to_hex_nodelimer(m_w2->save_multisig_tx(ms_tx_set)); // build sign result monero_multisig_sign_result result; @@ -2951,41 +2950,41 @@ namespace monero { return result; } - vector monero_wallet_core::submit_multisig_tx_hex(const string& signed_multisig_tx_hex) { + std::vector monero_wallet_core::submit_multisig_tx_hex(const std::string& signed_multisig_tx_hex) { // validate state and args bool ready; uint32_t threshold, total; - if (!m_w2->multisig(&ready, &threshold, &total)) throw runtime_error("This wallet is not multisig"); - if (!ready) throw runtime_error("This wallet is multisig, but not yet finalized"); + if (!m_w2->multisig(&ready, &threshold, &total)) throw std::runtime_error("This wallet is not multisig"); + if (!ready) throw std::runtime_error("This wallet is multisig, but not yet finalized"); // validate signed multisig tx hex as blob cryptonote::blobdata signed_multisig_tx_blob; if (!epee::string_tools::parse_hexstr_to_binbuff(signed_multisig_tx_hex, signed_multisig_tx_blob)) { - throw runtime_error("Failed to parse hex"); + throw std::runtime_error("Failed to parse hex"); } // validate and parse blob as multisig_tx_set tools::wallet2::multisig_tx_set signed_multisig_tx_set; if (!m_w2->load_multisig_tx(signed_multisig_tx_blob, signed_multisig_tx_set, NULL)) { - throw runtime_error("Failed to parse multisig tx data"); + throw std::runtime_error("Failed to parse multisig tx data"); } // ensure sufficient number of participants have signed if (signed_multisig_tx_set.m_signers.size() < threshold) { - throw runtime_error("Not enough signers signed this transaction"); + throw std::runtime_error("Not enough signers signed this transaction"); } // commit the transactions - vector tx_hashes; + std::vector tx_hashes; try { for (auto& pending_tx : signed_multisig_tx_set.m_ptx) { m_w2->commit_tx(pending_tx); tx_hashes.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(pending_tx.tx))); } } catch (const std::exception& e) { - string msg = string("Failed to submit multisig tx: ") + e.what(); - throw runtime_error(msg); + std::string msg = std::string("Failed to submit multisig tx: ") + e.what(); + throw std::runtime_error(msg); } // return the resulting tx hashes @@ -2997,7 +2996,7 @@ namespace monero { m_w2->store(); } - void monero_wallet_core::move_to(string path, string password) { + void monero_wallet_core::move_to(std::string path, std::string password) { MTRACE("move_to(" << path << ", ***)"); m_w2->store_to(path, password); } @@ -3034,7 +3033,7 @@ namespace monero { void monero_wallet_core::init_common() { MTRACE("monero_wallet_core.cpp init_common()"); - m_w2_listener = unique_ptr(new wallet2_listener(*this, *m_w2)); + m_w2_listener = std::unique_ptr(new wallet2_listener(*this, *m_w2)); if (get_daemon_connection() == boost::none) m_is_connected = false; m_is_synced = false; m_rescan_on_sync = false; @@ -3048,31 +3047,31 @@ namespace monero { #endif } - vector> monero_wallet_core::get_transfers_aux(const monero_transfer_query& query) const { + std::vector> monero_wallet_core::get_transfers_aux(const monero_transfer_query& query) const { MTRACE("monero_wallet_core::get_transfers(query)"); // // log query // if (query.m_tx_query != boost::none) { -// if ((*query.m_tx_query)->m_block == boost::none) cout << "Transfer query's tx query rooted at [tx]:" << (*query.m_tx_query)->serialize() << endl; -// else cout << "Transfer query's tx query rooted at [block]: " << (*(*query.m_tx_query)->m_block)->serialize() << endl; -// } else cout << "Transfer query: " << query.serialize() << endl; +// if ((*query.m_tx_query)->m_block == boost::none) std::cout << "Transfer query's tx query rooted at [tx]:" << (*query.m_tx_query)->serialize() << std::endl; +// else std::cout << "Transfer query's tx query rooted at [block]: " << (*(*query.m_tx_query)->m_block)->serialize() << std::endl; +// } else std::cout << "Transfer query: " << query.serialize() << std::endl; // copy and normalize query - shared_ptr _query; + std::shared_ptr _query; if (query.m_tx_query == boost::none) { - shared_ptr query_ptr = make_shared(query); // convert to shared pointer for copy // TODO: does this copy unecessarily? copy constructor is not defined - _query = query_ptr->copy(query_ptr, make_shared()); - _query->m_tx_query = make_shared(); + std::shared_ptr query_ptr = std::make_shared(query); // convert to shared pointer for copy // TODO: does this copy unecessarily? copy constructor is not defined + _query = query_ptr->copy(query_ptr, std::make_shared()); + _query->m_tx_query = std::make_shared(); _query->m_tx_query.get()->m_transfer_query = _query; } else { - shared_ptr tx_query = query.m_tx_query.get()->copy(query.m_tx_query.get(), make_shared()); + std::shared_ptr tx_query = query.m_tx_query.get()->copy(query.m_tx_query.get(), std::make_shared()); _query = tx_query->m_transfer_query.get(); } - shared_ptr tx_query = _query->m_tx_query.get(); + std::shared_ptr tx_query = _query->m_tx_query.get(); // build parameters for m_w2->get_payments() uint64_t min_height = tx_query->m_min_height == boost::none ? 0 : *tx_query->m_min_height; - uint64_t max_height = tx_query->m_max_height == boost::none ? CRYPTONOTE_MAX_BLOCK_NUMBER : min((uint64_t) CRYPTONOTE_MAX_BLOCK_NUMBER, *tx_query->m_max_height); + uint64_t max_height = tx_query->m_max_height == boost::none ? CRYPTONOTE_MAX_BLOCK_NUMBER : std::min((uint64_t) CRYPTONOTE_MAX_BLOCK_NUMBER, *tx_query->m_max_height); if (min_height > 0) min_height--; // TODO monero core: wallet2::get_payments() m_min_height is exclusive, so manually offset to match intended range (issues 5751, #5598) boost::optional account_index = boost::none; if (_query->m_account_index != boost::none) account_index = *_query->m_account_index; @@ -3083,7 +3082,7 @@ namespace monero { // check if pool txs explicitly requested without daemon connection if (tx_query->m_in_tx_pool != boost::none && tx_query->m_in_tx_pool.get() && !is_connected()) { - throw runtime_error("Cannot fetch pool transactions because wallet has no daemon connection"); + throw std::runtime_error("Cannot fetch pool transactions because wallet has no daemon connection"); } // translate from monero_tx_query to in, out, pending, pool, failed terminology used by monero-wallet-rpc @@ -3099,15 +3098,15 @@ namespace monero { // cache unique txs and blocks uint64_t height = get_height(); - map> tx_map; - map> block_map; + std::map> tx_map; + std::map> block_map; // get confirmed incoming transfers if (is_in) { std::list> payments; m_w2->get_payments(payments, min_height, max_height, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { - shared_ptr tx = build_tx_with_incoming_transfer(*m_w2, height, i->first, i->second); + std::shared_ptr tx = build_tx_with_incoming_transfer(*m_w2, height, i->first, i->second); merge_tx(tx, tx_map, block_map, false); } } @@ -3117,7 +3116,7 @@ namespace monero { std::list> payments; m_w2->get_payments_out(payments, min_height, max_height, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { - shared_ptr tx = build_tx_with_outgoing_transfer(*m_w2, height, i->first, i->second); + std::shared_ptr tx = build_tx_with_outgoing_transfer(*m_w2, height, i->first, i->second); merge_tx(tx, tx_map, block_map, false); } } @@ -3127,7 +3126,7 @@ namespace monero { std::list> upayments; m_w2->get_unconfirmed_payments_out(upayments, account_index, subaddress_indices); for (std::list>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) { - shared_ptr tx = build_tx_with_outgoing_transfer_unconfirmed(*m_w2, i->first, i->second); + std::shared_ptr tx = build_tx_with_outgoing_transfer_unconfirmed(*m_w2, i->first, i->second); if (tx_query->m_is_failed != boost::none && tx_query->m_is_failed.get() != tx->m_is_failed.get()) continue; // skip merging if tx excluded merge_tx(tx, tx_map, block_map, false); } @@ -3144,23 +3143,23 @@ namespace monero { std::list> payments; m_w2->get_unconfirmed_payments(payments, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { - shared_ptr tx = build_tx_with_incoming_transfer_unconfirmed(*m_w2, i->first, i->second); + std::shared_ptr tx = build_tx_with_incoming_transfer_unconfirmed(*m_w2, i->first, i->second); merge_tx(tx, tx_map, block_map, false); } } // sort txs by block height - vector> txs ; - for (map>::const_iterator tx_iter = tx_map.begin(); tx_iter != tx_map.end(); tx_iter++) { + std::vector> txs ; + for (std::map>::const_iterator tx_iter = tx_map.begin(); tx_iter != tx_map.end(); tx_iter++) { txs.push_back(tx_iter->second); } sort(txs.begin(), txs.end(), tx_height_less_than); // filter and return transfers - vector> transfers; - for (const shared_ptr& tx : txs) { + std::vector> transfers; + for (const std::shared_ptr& tx : txs) { - // tx is not incoming/outgoing unless already set + // tx is not incoming/outgoing unless already std::set if (tx->m_is_incoming == boost::none) tx->m_is_incoming = false; if (tx->m_is_outgoing == boost::none) tx->m_is_outgoing = false; @@ -3168,7 +3167,7 @@ namespace monero { sort(tx->m_incoming_transfers.begin(), tx->m_incoming_transfers.end(), incoming_transfer_before); // collect queried transfers, erase if excluded - for (const shared_ptr& transfer : tx->filter_transfers(*_query)) transfers.push_back(transfer); + for (const std::shared_ptr& transfer : tx->filter_transfers(*_query)) transfers.push_back(transfer); // remove excluded txs from block if (tx->m_block != boost::none && tx->m_outgoing_transfer == boost::none && tx->m_incoming_transfers.empty()) { @@ -3180,62 +3179,62 @@ namespace monero { return transfers; } - vector> monero_wallet_core::get_outputs_aux(const monero_output_query& query) const { + std::vector> monero_wallet_core::get_outputs_aux(const monero_output_query& query) const { MTRACE("monero_wallet_core::get_outputs_aux(query)"); // // log query // if (query.m_tx_query != boost::none) { -// if ((*query.m_tx_query)->m_block == boost::none) cout << "Output query's tx query rooted at [tx]:" << (*query.m_tx_query)->serialize() << endl; -// else cout << "Output query's tx query rooted at [block]: " << (*(*query.m_tx_query)->m_block)->serialize() << endl; -// } else cout << "Output query: " << query.serialize() << endl; +// if ((*query.m_tx_query)->m_block == boost::none) std::cout << "Output query's tx query rooted at [tx]:" << (*query.m_tx_query)->serialize() << std::endl; +// else std::cout << "Output query's tx query rooted at [block]: " << (*(*query.m_tx_query)->m_block)->serialize() << std::endl; +// } else std::cout << "Output query: " << query.serialize() << std::endl; // copy and normalize query - shared_ptr _query; + std::shared_ptr _query; if (query.m_tx_query == boost::none) { - shared_ptr query_ptr = make_shared(query); // convert to shared pointer for copy - _query = query_ptr->copy(query_ptr, make_shared()); + std::shared_ptr query_ptr = std::make_shared(query); // convert to shared pointer for copy + _query = query_ptr->copy(query_ptr, std::make_shared()); } else { - shared_ptr tx_query = query.m_tx_query.get()->copy(query.m_tx_query.get(), make_shared()); + std::shared_ptr tx_query = query.m_tx_query.get()->copy(query.m_tx_query.get(), std::make_shared()); if (query.m_tx_query.get()->m_output_query != boost::none && query.m_tx_query.get()->m_output_query.get().get() == &query) { _query = tx_query->m_output_query.get(); } else { - if (query.m_tx_query.get()->m_output_query != boost::none) throw runtime_error("Output query's tx query must be a circular reference or null"); - shared_ptr query_ptr = make_shared(query); // convert query to shared pointer for copy - _query = query_ptr->copy(query_ptr, make_shared()); + if (query.m_tx_query.get()->m_output_query != boost::none) throw std::runtime_error("Output query's tx query must be a circular reference or null"); + std::shared_ptr query_ptr = std::make_shared(query); // convert query to shared pointer for copy + _query = query_ptr->copy(query_ptr, std::make_shared()); _query->m_tx_query = tx_query; } } - if (_query->m_tx_query == boost::none) _query->m_tx_query = make_shared(); + if (_query->m_tx_query == boost::none) _query->m_tx_query = std::make_shared(); // get output data from wallet2 tools::wallet2::transfer_container outputs_w2; m_w2->get_transfers(outputs_w2); // cache unique txs and blocks - map> tx_map; - map> block_map; + std::map> tx_map; + std::map> block_map; for (const auto& output_w2 : outputs_w2) { // TODO: skip tx building if m_w2 output excluded by indices, etc - shared_ptr tx = build_tx_with_vout(*m_w2, output_w2); + std::shared_ptr tx = build_tx_with_vout(*m_w2, output_w2); merge_tx(tx, tx_map, block_map, false); } // sort txs by block height - vector> txs ; - for (map>::const_iterator tx_iter = tx_map.begin(); tx_iter != tx_map.end(); tx_iter++) { + std::vector> txs ; + for (std::map>::const_iterator tx_iter = tx_map.begin(); tx_iter != tx_map.end(); tx_iter++) { txs.push_back(tx_iter->second); } sort(txs.begin(), txs.end(), tx_height_less_than); // filter and return outputs - vector> outputs; - for (const shared_ptr& tx : txs) { + std::vector> outputs; + for (const std::shared_ptr& tx : txs) { // sort outputs sort(tx->m_outputs.begin(), tx->m_outputs.end(), vout_before); // collect queried outputs, erase if excluded - for (const shared_ptr& output : tx->filter_outputs_wallet(*_query)) outputs.push_back(output); + for (const std::shared_ptr& output : tx->filter_outputs_wallet(*_query)) outputs.push_back(output); // remove txs without outputs if (tx->m_outputs.empty() && tx->m_block != boost::none) tx->m_block.get()->m_txs.erase(std::remove(tx->m_block.get()->m_txs.begin(), tx->m_block.get()->m_txs.end(), tx), tx->m_block.get()->m_txs.end()); // TODO, no way to use const_iterator? @@ -3244,15 +3243,15 @@ namespace monero { } // private helper to initialize subaddresses using transfer details - vector monero_wallet_core::get_subaddresses_aux(const uint32_t account_idx, const vector& subaddress_indices, const vector& transfers) const { - vector subaddresses; + std::vector monero_wallet_core::get_subaddresses_aux(const uint32_t account_idx, const std::vector& subaddress_indices, const std::vector& transfers) const { + std::vector subaddresses; // get balances per subaddress as maps - map balance_per_subaddress = m_w2->balance_per_subaddress(account_idx, STRICT); + std::map balance_per_subaddress = m_w2->balance_per_subaddress(account_idx, STRICT); std::map>> unlocked_balance_per_subaddress = m_w2->unlocked_balance_per_subaddress(account_idx, STRICT); // get all indices if no indices given - vector subaddress_indices_req; + std::vector subaddress_indices_req; if (subaddress_indices.empty()) { for (uint32_t subaddress_idx = 0; subaddress_idx < m_w2->get_num_subaddresses(account_idx); subaddress_idx++) { subaddress_indices_req.push_back(subaddress_idx); @@ -3295,7 +3294,7 @@ namespace monero { try { lock_and_sync(); } catch (...) { - cout << "monero_wallet_core failed to background synchronize" << endl; + std::cout << "monero_wallet_core failed to background synchronize" << std::endl; } // only wait if syncing still enabled @@ -3334,8 +3333,8 @@ namespace monero { MTRACE("sync_aux()"); // determine sync start height - uint64_t sync_start_height = start_height == boost::none ? max(get_height(), get_sync_height()) : *start_height; - if (sync_start_height < get_sync_height()) set_sync_height(sync_start_height); // TODO monero core: start height processed > requested start height unless sync height manually set + uint64_t sync_start_height = start_height == boost::none ? std::max(get_height(), get_sync_height()) : *start_height; + if (sync_start_height < get_sync_height()) set_sync_height(sync_start_height); // TODO monero core: start height processed > requested start height unless sync height manually std::set // signal start of sync to registered listeners m_w2_listener->on_sync_start(sync_start_height); @@ -3346,7 +3345,7 @@ namespace monero { m_w2->refresh(m_w2->is_trusted_daemon(), sync_start_height, result.m_num_blocks_fetched, result.m_received_money, true); if (!m_is_synced) m_is_synced = true; m_w2_listener->update_listening(); // cannot unregister during sync which would segfault - } catch (exception& e) { + } catch (std::exception& e) { m_w2_listener->on_sync_end(); // signal end of sync to reset listener's start and end heights throw; } diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index b43f242..ce9f6a1 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -59,8 +59,6 @@ #include #include -using namespace std; - /** * Implements a monero_wallet.h by wrapping wallet2.h. */ @@ -86,7 +84,7 @@ namespace monero { * @param path is the path to check for a wallet * @return true if a wallet exists at the given path, false otherwise */ - static bool wallet_exists(const string& path); + static bool wallet_exists(const std::string& path); /** * Open an existing wallet from disk. @@ -96,7 +94,7 @@ namespace monero { * @param network_type is the wallet's network type * @return a pointer to the wallet instance */ - static monero_wallet_core* open_wallet(const string& path, const string& password, const monero_network_type network_type); + static monero_wallet_core* open_wallet(const std::string& path, const std::string& password, const monero_network_type network_type); /** * Open an in-memory wallet from existing data buffers. @@ -109,7 +107,7 @@ namespace monero { * @param http_client_factory allows use of custom http clients * @return a pointer to the wallet instance */ - static monero_wallet_core* open_wallet_data(const string& password, const monero_network_type, const string& keys_data, const string& cache_data, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), unique_ptr http_client_factory = nullptr); + static monero_wallet_core* open_wallet_data(const std::string& password, const monero_network_type, const std::string& keys_data, const std::string& cache_data, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), std::unique_ptr http_client_factory = nullptr); /** * Create a new wallet with a randomly generated seed. @@ -122,7 +120,7 @@ namespace monero { * @param http_client_factory allows use of custom http clients * @return a pointer to the wallet instance */ - static monero_wallet_core* create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), const string& language = "English", unique_ptr http_client_factory = nullptr); + static monero_wallet_core* create_wallet_random(const std::string& path, const std::string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), const std::string& language = "English", std::unique_ptr http_client_factory = nullptr); /** * Create a wallet from an existing mnemonic phrase. @@ -136,7 +134,7 @@ namespace monero { * @param http_client_factory allows use of custom http clients * @return a pointer to the wallet instance */ - static monero_wallet_core* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), uint64_t restore_height = 0, const string& seed_offset = "", unique_ptr http_client_factory = nullptr); + static monero_wallet_core* create_wallet_from_mnemonic(const std::string& path, const std::string& password, const monero_network_type network_type, const std::string& mnemonic, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), uint64_t restore_height = 0, const std::string& seed_offset = "", std::unique_ptr http_client_factory = nullptr); /** * Create a wallet from an address, view key, and spend key. @@ -153,14 +151,14 @@ namespace monero { * @param http_client_factory allows use of custom http clients * @return a pointer to the wallet instance */ - static monero_wallet_core* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), uint64_t restore_height = 0, const string& language = "English", unique_ptr http_client_factory = nullptr); + static monero_wallet_core* create_wallet_from_keys(const std::string& path, const std::string& password, const monero_network_type network_type, const std::string& address, const std::string& view_key, const std::string& spend_key, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), uint64_t restore_height = 0, const std::string& language = "English", std::unique_ptr http_client_factory = nullptr); /** * Get a list of available languages for the wallet's mnemonic phrase. * * @return the available languages for the wallet's mnemonic phrase */ - static vector get_mnemonic_languages(); + static std::vector get_mnemonic_languages(); // ----------------------------- WALLET METHODS ----------------------------- @@ -173,7 +171,7 @@ namespace monero { * Supported wallet methods. */ bool is_view_only() const override { return m_w2->watch_only(); } - void set_daemon_connection(const string& uri, const string& username = "", const string& password = "") override; + void set_daemon_connection(const std::string& uri, const std::string& username = "", const std::string& password = "") override; void set_daemon_connection(const boost::optional& connection) override; boost::optional get_daemon_connection() const override; bool is_connected() const override; @@ -181,18 +179,18 @@ namespace monero { bool is_daemon_trusted() const override; bool is_synced() const override; monero_version get_version() const override; - string get_path() const override; + std::string get_path() const override; monero_network_type get_network_type() const override; - string get_mnemonic() const override; - string get_mnemonic_language() const override; - string get_public_view_key() const override; - string get_private_view_key() const override; - string get_public_spend_key() const override; - string get_private_spend_key() const override; - string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override; - monero_subaddress get_address_index(const string& address) const override; - monero_integrated_address get_integrated_address(const string& standard_address = "", const string& payment_id = "") const override; - monero_integrated_address decode_integrated_address(const string& integrated_address) const override; + std::string get_mnemonic() const override; + std::string get_mnemonic_language() const override; + std::string get_public_view_key() const override; + std::string get_private_view_key() const override; + std::string get_public_spend_key() const override; + std::string get_private_spend_key() const override; + std::string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override; + monero_subaddress get_address_index(const std::string& address) const override; + monero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const override; + monero_integrated_address decode_integrated_address(const std::string& integrated_address) const override; uint64_t get_height() const override; uint64_t get_sync_height() const override; void set_sync_height(uint64_t sync_height) override; @@ -200,7 +198,7 @@ namespace monero { uint64_t get_daemon_max_peer_height() const override; void add_listener(monero_wallet_listener& listener) override; void remove_listener(monero_wallet_listener& listener) override; - set get_listeners() override; + std::set get_listeners() override; monero_sync_result sync() override; monero_sync_result sync(monero_wallet_listener& listener) override; monero_sync_result sync(uint64_t start_height) override; @@ -215,65 +213,65 @@ namespace monero { uint64_t get_unlocked_balance() const override; uint64_t get_unlocked_balance(uint32_t account_idx) const override; uint64_t get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const override; - vector get_accounts(bool include_subaddresses, const string& tag) const override; + std::vector get_accounts(bool include_subaddresses, const std::string& tag) const override; monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const override; - monero_account create_account(const string& label = "") override; - vector get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const override; - monero_subaddress create_subaddress(uint32_t account_idx, const string& label = "") override; - vector> get_txs() const override; - vector> get_txs(const monero_tx_query& query) const override; - vector> get_txs(const monero_tx_query& query, vector& missing_tx_hashes) const override; - vector> get_transfers(const monero_transfer_query& query) const override; - vector> get_outputs(const monero_output_query& query) const override; - string get_outputs_hex() const override; - int import_outputs_hex(const string& outputs_hex) override; - vector> get_key_images() const override; - shared_ptr import_key_images(const vector>& key_images) override; - vector> create_txs(const monero_tx_config& config) override; - vector> sweep_unlocked(const monero_tx_config& config) override; - shared_ptr sweep_output(const monero_tx_config& config) override; - vector> sweep_dust(bool relay = false) override; - vector relay_txs(const vector& tx_metadatas) override; + monero_account create_account(const std::string& label = "") override; + std::vector get_subaddresses(const uint32_t account_idx, const std::vector& subaddress_indices) const override; + monero_subaddress create_subaddress(uint32_t account_idx, const std::string& label = "") override; + std::vector> get_txs() const override; + std::vector> get_txs(const monero_tx_query& query) const override; + std::vector> get_txs(const monero_tx_query& query, std::vector& missing_tx_hashes) const override; + std::vector> get_transfers(const monero_transfer_query& query) const override; + std::vector> get_outputs(const monero_output_query& query) const override; + std::string get_outputs_hex() const override; + int import_outputs_hex(const std::string& outputs_hex) override; + std::vector> get_key_images() const override; + std::shared_ptr import_key_images(const std::vector>& key_images) override; + std::vector> create_txs(const monero_tx_config& config) override; + std::vector> sweep_unlocked(const monero_tx_config& config) override; + std::shared_ptr sweep_output(const monero_tx_config& config) override; + std::vector> sweep_dust(bool relay = false) override; + std::vector relay_txs(const std::vector& tx_metadatas) override; monero_tx_set parse_tx_set(const monero_tx_set& tx_set) override; - string sign_txs(const string& unsigned_tx_hex) override; - vector submit_txs(const string& signed_tx_hex) override; - string sign_message(const string& msg) const override; - bool verify_message(const string& msg, const string& address, const string& signature) const override; - string get_tx_key(const string& tx_hash) const override; - shared_ptr check_tx_key(const string& tx_hash, const string& txKey, const string& address) const override; - string get_tx_proof(const string& tx_hash, const string& address, const string& message) const override; - shared_ptr check_tx_proof(const string& tx_hash, const string& address, const string& message, const string& signature) const override; - string get_spend_proof(const string& tx_hash, const string& message) const override; - bool check_spend_proof(const string& tx_hash, const string& message, const string& signature) const override; - string get_reserve_proof_wallet(const string& message) const override; - string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const override; - shared_ptr check_reserve_proof(const string& address, const string& message, const string& signature) const override; - string get_tx_note(const string& tx_hash) const override; - vector get_tx_notes(const vector& tx_hashes) const override; - void set_tx_note(const string& tx_hash, const string& note) override; - void set_tx_notes(const vector& tx_hashes, const vector& notes) override; - vector get_address_book_entries(const vector& indices) const override; - uint64_t add_address_book_entry(const string& address, const string& description) override; - void edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description) override; + std::string sign_txs(const std::string& unsigned_tx_hex) override; + std::vector submit_txs(const std::string& signed_tx_hex) override; + std::string sign_message(const std::string& msg) const override; + bool verify_message(const std::string& msg, const std::string& address, const std::string& signature) const override; + std::string get_tx_key(const std::string& tx_hash) const override; + std::shared_ptr check_tx_key(const std::string& tx_hash, const std::string& txKey, const std::string& address) const override; + std::string get_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message) const override; + std::shared_ptr check_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message, const std::string& signature) const override; + std::string get_spend_proof(const std::string& tx_hash, const std::string& message) const override; + bool check_spend_proof(const std::string& tx_hash, const std::string& message, const std::string& signature) const override; + std::string get_reserve_proof_wallet(const std::string& message) const override; + std::string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const std::string& message) const override; + std::shared_ptr check_reserve_proof(const std::string& address, const std::string& message, const std::string& signature) const override; + std::string get_tx_note(const std::string& tx_hash) const override; + std::vector get_tx_notes(const std::vector& tx_hashes) const override; + void set_tx_note(const std::string& tx_hash, const std::string& note) override; + void set_tx_notes(const std::vector& tx_hashes, const std::vector& notes) override; + std::vector get_address_book_entries(const std::vector& indices) const override; + uint64_t add_address_book_entry(const std::string& address, const std::string& description) override; + void edit_address_book_entry(uint64_t index, bool set_address, const std::string& address, bool set_description, const std::string& description) override; void delete_address_book_entry(uint64_t index) override; - string create_payment_uri(const monero_tx_config& config) const override; - shared_ptr parse_payment_uri(const string& uri) const override; - bool get_attribute(const string& key, string& value) const override; - void set_attribute(const string& key, const string& val) override; + std::string create_payment_uri(const monero_tx_config& config) const override; + std::shared_ptr parse_payment_uri(const std::string& uri) const override; + bool get_attribute(const std::string& key, std::string& value) const override; + void set_attribute(const std::string& key, const std::string& val) override; void start_mining(boost::optional num_threads, boost::optional background_mining, boost::optional ignore_battery) override; void stop_mining() override; uint64_t wait_for_next_block() override; bool is_multisig_import_needed() const override; monero_multisig_info get_multisig_info() override; - string prepare_multisig() override; - monero_multisig_init_result make_multisig(const vector& multisig_hexes, int threshold, const string& password) override; - monero_multisig_init_result exchange_multisig_keys(const vector& mutisig_hexes, const string& password) override; - string get_multisig_hex() override; - int import_multisig_hex(const vector& multisig_hexes) override; - monero_multisig_sign_result sign_multisig_tx_hex(const string& multisig_tx_hex) override; - vector submit_multisig_tx_hex(const string& signed_multisig_tx_hex) override; + std::string prepare_multisig() override; + monero_multisig_init_result make_multisig(const std::vector& multisig_hexes, int threshold, const std::string& password) override; + monero_multisig_init_result exchange_multisig_keys(const std::vector& mutisig_hexes, const std::string& password) override; + std::string get_multisig_hex() override; + int import_multisig_hex(const std::vector& multisig_hexes) override; + monero_multisig_sign_result sign_multisig_tx_hex(const std::string& multisig_tx_hex) override; + std::vector submit_multisig_tx_hex(const std::string& signed_multisig_tx_hex) override; void save() override; - void move_to(string path, string password) override; + void move_to(std::string path, std::string password) override; void close(bool save = false) override; /** @@ -286,15 +284,15 @@ namespace monero { private: friend struct wallet2_listener; - unique_ptr m_w2; // internal wallet implementation - unique_ptr m_w2_listener; // internal wallet implementation listener - set m_listeners; // external wallet listeners + std::unique_ptr m_w2; // internal wallet implementation + std::unique_ptr m_w2_listener; // internal wallet implementation listener + std::set m_listeners; // external wallet listeners void init_common(); - vector get_subaddresses_aux(uint32_t account_idx, const vector& subaddress_indices, const vector& transfers) const; - vector> get_transfers_aux(const monero_transfer_query& query) const; - vector> get_outputs_aux(const monero_output_query& query) const; - vector> sweep_account(const monero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked() + std::vector get_subaddresses_aux(uint32_t account_idx, const std::vector& subaddress_indices, const std::vector& transfers) const; + std::vector> get_transfers_aux(const monero_transfer_query& query) const; + std::vector> get_outputs_aux(const monero_output_query& query) const; + std::vector> sweep_account(const monero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked() // blockchain sync management mutable std::atomic m_is_synced; // whether or not wallet is synced diff --git a/src/wallet/monero_wallet_keys.cpp b/src/wallet/monero_wallet_keys.cpp index 24d48e5..3708175 100644 --- a/src/wallet/monero_wallet_keys.cpp +++ b/src/wallet/monero_wallet_keys.cpp @@ -62,7 +62,6 @@ #include "string_tools.h" #include "device/device.hpp" -using namespace std; using namespace epee; using namespace tools; using namespace crypto; @@ -74,7 +73,7 @@ namespace monero { // ---------------------------- WALLET MANAGEMENT --------------------------- - monero_wallet_keys* monero_wallet_keys::create_wallet_random(const monero_network_type network_type, const string& language) { + monero_wallet_keys* monero_wallet_keys::create_wallet_random(const monero_network_type network_type, const std::string& language) { // initialize random wallet account monero_wallet_keys* wallet = new monero_wallet_keys(); @@ -85,21 +84,21 @@ namespace monero { wallet->m_language = language; epee::wipeable_string wipeable_mnemonic; if (!crypto::ElectrumWords::bytes_to_words(spend_key_sk, wipeable_mnemonic, wallet->m_language)) { - throw runtime_error("Failed to create mnemonic from private spend key for language: " + string(wallet->m_language)); + throw std::runtime_error("Failed to create mnemonic from private spend key for language: " + std::string(wallet->m_language)); } - wallet->m_mnemonic = string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); + wallet->m_mnemonic = std::string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); wallet->init_common(); return wallet; } - monero_wallet_keys* monero_wallet_keys::create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic, const string& seed_offset) { + monero_wallet_keys* monero_wallet_keys::create_wallet_from_mnemonic(const monero_network_type network_type, const std::string& mnemonic, const std::string& seed_offset) { // validate mnemonic and get recovery key and language crypto::secret_key spend_key_sk; - string language; + std::string language; bool is_valid = crypto::ElectrumWords::words_to_bytes(mnemonic, spend_key_sk, language); - if (!is_valid) throw runtime_error("Invalid mnemonic"); + if (!is_valid) throw std::runtime_error("Invalid mnemonic"); if (language == crypto::ElectrumWords::old_language_name) language = Language::English().get_language_name(); // apply offset if given @@ -115,19 +114,19 @@ namespace monero { wallet->m_language = language; epee::wipeable_string wipeable_mnemonic; if (!crypto::ElectrumWords::bytes_to_words(spend_key_sk, wipeable_mnemonic, wallet->m_language)) { - throw runtime_error("Failed to create mnemonic from private spend key for language: " + string(wallet->m_language)); + throw std::runtime_error("Failed to create mnemonic from private spend key for language: " + std::string(wallet->m_language)); } - wallet->m_mnemonic = string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); + wallet->m_mnemonic = std::string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); wallet->init_common(); return wallet; } - monero_wallet_keys* monero_wallet_keys::create_wallet_from_keys(const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const string& language) { + monero_wallet_keys* monero_wallet_keys::create_wallet_from_keys(const monero_network_type network_type, const std::string& address, const std::string& view_key, const std::string& spend_key, const std::string& language) { // validate and parse address cryptonote::address_parse_info info; - if (!cryptonote::get_account_address_from_str(info, static_cast(network_type), address)) throw runtime_error("failed to parse address"); + if (!cryptonote::get_account_address_from_str(info, static_cast(network_type), address)) throw std::runtime_error("failed to parse address"); // validate and parse optional private spend key crypto::secret_key spend_key_sk; @@ -135,7 +134,7 @@ namespace monero { if (!spend_key.empty()) { cryptonote::blobdata spend_key_data; if (!epee::string_tools::parse_hexstr_to_binbuff(spend_key, spend_key_data) || spend_key_data.size() != sizeof(crypto::secret_key)) { - throw runtime_error("failed to parse secret spend key"); + throw std::runtime_error("failed to parse secret spend key"); } has_spend_key = true; spend_key_sk = *reinterpret_cast(spend_key_data.data()); @@ -146,12 +145,12 @@ namespace monero { crypto::secret_key view_key_sk; if (view_key.empty()) { if (has_spend_key) has_view_key = false; - else throw runtime_error("Neither view key nor spend key supplied, cancelled"); + else throw std::runtime_error("Neither view key nor spend key supplied, cancelled"); } if (has_view_key) { cryptonote::blobdata view_key_data; if (!epee::string_tools::parse_hexstr_to_binbuff(view_key, view_key_data) || view_key_data.size() != sizeof(crypto::secret_key)) { - throw runtime_error("failed to parse secret view key"); + throw std::runtime_error("failed to parse secret view key"); } view_key_sk = *reinterpret_cast(view_key_data.data()); } @@ -159,12 +158,12 @@ namespace monero { // check the spend and view keys match the given address crypto::public_key pkey; if (has_spend_key) { - if (!crypto::secret_key_to_public_key(spend_key_sk, pkey)) throw runtime_error("failed to verify secret spend key"); - if (info.address.m_spend_public_key != pkey) throw runtime_error("spend key does not match address"); + if (!crypto::secret_key_to_public_key(spend_key_sk, pkey)) throw std::runtime_error("failed to verify secret spend key"); + if (info.address.m_spend_public_key != pkey) throw std::runtime_error("spend key does not match address"); } if (has_view_key) { - if (!crypto::secret_key_to_public_key(view_key_sk, pkey)) throw runtime_error("failed to verify secret view key"); - if (info.address.m_view_public_key != pkey) throw runtime_error("view key does not match address"); + if (!crypto::secret_key_to_public_key(view_key_sk, pkey)) throw std::runtime_error("failed to verify secret view key"); + if (info.address.m_view_public_key != pkey) throw std::runtime_error("view key does not match address"); } // initialize wallet account @@ -184,17 +183,17 @@ namespace monero { wallet->m_language = language; epee::wipeable_string wipeable_mnemonic; if (!crypto::ElectrumWords::bytes_to_words(spend_key_sk, wipeable_mnemonic, wallet->m_language)) { - throw runtime_error("Failed to create mnemonic from private spend key for language: " + string(wallet->m_language)); + throw std::runtime_error("Failed to create mnemonic from private spend key for language: " + std::string(wallet->m_language)); } - wallet->m_mnemonic = string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); + wallet->m_mnemonic = std::string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); } wallet->init_common(); return wallet; } - vector monero_wallet_keys::get_mnemonic_languages() { - vector languages; + std::vector monero_wallet_keys::get_mnemonic_languages() { + std::vector languages; crypto::ElectrumWords::get_language_list(languages, true); return languages; } @@ -213,30 +212,30 @@ namespace monero { return version; } - string monero_wallet_keys::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { + std::string monero_wallet_keys::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { hw::device &hwdev = m_account.get_device(); cryptonote::subaddress_index index{account_idx, subaddress_idx}; cryptonote::account_public_address address = hwdev.get_subaddress(m_account.get_keys(), index); return cryptonote::get_account_address_as_str(static_cast(m_network_type), !index.is_zero(), address); } - monero_integrated_address monero_wallet_keys::get_integrated_address(const string& standard_address, const string& payment_id) const { - cout << "monero_wallet_keys::get_integrated_address()" << endl; - throw runtime_error("monero_wallet_keys::get_integrated_address() not implemented"); + monero_integrated_address monero_wallet_keys::get_integrated_address(const std::string& standard_address, const std::string& payment_id) const { + std::cout << "monero_wallet_keys::get_integrated_address()" << std::endl; + throw std::runtime_error("monero_wallet_keys::get_integrated_address() not implemented"); } - monero_integrated_address monero_wallet_keys::decode_integrated_address(const string& integrated_address) const { - cout << "monero_wallet_keys::decode_integrated_address()" << endl; - throw runtime_error("monero_wallet_keys::decode_integrated_address() not implemented"); + monero_integrated_address monero_wallet_keys::decode_integrated_address(const std::string& integrated_address) const { + std::cout << "monero_wallet_keys::decode_integrated_address()" << std::endl; + throw std::runtime_error("monero_wallet_keys::decode_integrated_address() not implemented"); } monero_account monero_wallet_keys::get_account(uint32_t account_idx, bool include_subaddresses) const { - cout << "monero_wallet_keys::get_account()" << endl; + std::cout << "monero_wallet_keys::get_account()" << std::endl; if (include_subaddresses) { - string err = "monero_wallet_keys::get_account(account_idx, include_subaddresses) include_subaddresses must be false"; - cout << err << endl; - throw runtime_error(err); + std::string err = "monero_wallet_keys::get_account(account_idx, include_subaddresses) include_subaddresses must be false"; + std::cout << err << std::endl; + throw std::runtime_error(err); } // build and return account @@ -246,17 +245,17 @@ namespace monero { return account; } - vector monero_wallet_keys::get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const { + std::vector monero_wallet_keys::get_subaddresses(const uint32_t account_idx, const std::vector& subaddress_indices) const { // must provide subaddress indices if (subaddress_indices.empty()) { - string err = "Keys-only wallet does not have enumerable set of subaddresses; specific specific subaddresses"; - cout << err << endl; - throw runtime_error(err); + std::string err = "Keys-only wallet does not have enumerable set of subaddresses; specific specific subaddresses"; + std::cout << err << std::endl; + throw std::runtime_error(err); } // initialize subaddresses at indices - vector subaddresses; + std::vector subaddresses; for (uint32_t subaddressIndicesIdx = 0; subaddressIndicesIdx < subaddress_indices.size(); subaddressIndicesIdx++) { monero_subaddress subaddress; subaddress.m_account_index = account_idx; @@ -269,18 +268,18 @@ namespace monero { return subaddresses; } - string monero_wallet_keys::sign_message(const string& msg) const { - cout << "monero_wallet_keys::sign_message()" << endl; - throw runtime_error("monero_wallet_keys::sign_message() not implemented"); + std::string monero_wallet_keys::sign_message(const std::string& msg) const { + std::cout << "monero_wallet_keys::sign_message()" << std::endl; + throw std::runtime_error("monero_wallet_keys::sign_message() not implemented"); } - bool monero_wallet_keys::verify_message(const string& msg, const string& address, const string& signature) const { - cout << "monero_wallet_keys::verify_message()" << endl; - throw runtime_error("monero_wallet_keys::verify_message() not implemented"); + bool monero_wallet_keys::verify_message(const std::string& msg, const std::string& address, const std::string& signature) const { + std::cout << "monero_wallet_keys::verify_message()" << std::endl; + throw std::runtime_error("monero_wallet_keys::verify_message() not implemented"); } void monero_wallet_keys::close(bool save) { - if (save) throw runtime_error("MoneroWalletKeys does not support saving"); + if (save) throw std::runtime_error("MoneroWalletKeys does not support saving"); // no pointers to destroy } diff --git a/src/wallet/monero_wallet_keys.h b/src/wallet/monero_wallet_keys.h index 1f4d2b3..8094d8d 100644 --- a/src/wallet/monero_wallet_keys.h +++ b/src/wallet/monero_wallet_keys.h @@ -55,7 +55,6 @@ #include "monero_wallet.h" #include "cryptonote_basic/account.h" -using namespace std; using namespace monero; /** @@ -78,7 +77,7 @@ namespace monero { * @param network_type is the wallet's network type (default = monero_network_type.MAINNET) * @param language is the wallet and mnemonic's language (default = "English") */ - static monero_wallet_keys* create_wallet_random(const monero_network_type network_type, const string& language); + static monero_wallet_keys* create_wallet_random(const monero_network_type network_type, const std::string& language); /** * Create a wallet from an existing mnemonic phrase. @@ -86,7 +85,7 @@ namespace monero { * @param network_type is the wallet's network type * @param mnemonic is the mnemonic of the wallet to construct */ - static monero_wallet_keys* create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic, const string& seed_offset); + static monero_wallet_keys* create_wallet_from_mnemonic(const monero_network_type network_type, const std::string& mnemonic, const std::string& seed_offset); /** * Create a wallet from an address, view key, and spend key. @@ -97,14 +96,14 @@ namespace monero { * @param spend_key is the private spend key of the wallet to construct * @param language is the wallet and mnemonic's language (default = "English") */ - static monero_wallet_keys* create_wallet_from_keys(const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const string& language = "English"); + static monero_wallet_keys* create_wallet_from_keys(const monero_network_type network_type, const std::string& address, const std::string& view_key, const std::string& spend_key, const std::string& language = "English"); /** * Get a list of available languages for the wallet's mnemonic phrase. * * @return the available languages for the wallet's mnemonic phrase */ - static vector get_mnemonic_languages(); + static std::vector get_mnemonic_languages(); // ----------------------------- WALLET METHODS ----------------------------- @@ -119,20 +118,20 @@ namespace monero { bool is_view_only() const override { return m_is_view_only; } monero_version get_version() const override; monero_network_type get_network_type() const override { return m_network_type; } - string get_mnemonic() const override { return m_mnemonic; } - string get_mnemonic_language() const override { return m_language; } - string get_private_view_key() const override { return m_prv_view_key; } - string get_private_spend_key() const override { return m_prv_spend_key; } - string get_public_view_key() const override { return m_pub_view_key; } - string get_public_spend_key() const override { return m_pub_spend_key; } - string get_primary_address() const override { return m_primary_address; } - string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override; - monero_integrated_address get_integrated_address(const string& standard_address = "", const string& payment_id = "") const override; - monero_integrated_address decode_integrated_address(const string& integrated_address) const override; + std::string get_mnemonic() const override { return m_mnemonic; } + std::string get_mnemonic_language() const override { return m_language; } + std::string get_private_view_key() const override { return m_prv_view_key; } + std::string get_private_spend_key() const override { return m_prv_spend_key; } + std::string get_public_view_key() const override { return m_pub_view_key; } + std::string get_public_spend_key() const override { return m_pub_spend_key; } + std::string get_primary_address() const override { return m_primary_address; } + std::string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override; + monero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const override; + monero_integrated_address decode_integrated_address(const std::string& integrated_address) const override; monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const override; - vector get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const override; - string sign_message(const string& msg) const override; - bool verify_message(const string& msg, const string& address, const string& signature) const override; + std::vector get_subaddresses(const uint32_t account_idx, const std::vector& subaddress_indices) const override; + std::string sign_message(const std::string& msg) const override; + bool verify_message(const std::string& msg, const std::string& address, const std::string& signature) const override; void close(bool save = false) override; // --------------------------------- PRIVATE -------------------------------- @@ -141,13 +140,13 @@ namespace monero { bool m_is_view_only; monero_network_type m_network_type; cryptonote::account_base m_account; - string m_mnemonic; - string m_language; - string m_pub_view_key; - string m_prv_view_key; - string m_pub_spend_key; - string m_prv_spend_key; - string m_primary_address; + std::string m_mnemonic; + std::string m_language; + std::string m_pub_view_key; + std::string m_prv_view_key; + std::string m_pub_spend_key; + std::string m_prv_spend_key; + std::string m_primary_address; void init_common(); }; diff --git a/src/wallet/monero_wallet_model.cpp b/src/wallet/monero_wallet_model.cpp index 8ba0edd..6d8d179 100644 --- a/src/wallet/monero_wallet_model.cpp +++ b/src/wallet/monero_wallet_model.cpp @@ -56,8 +56,6 @@ #include "utils/monero_utils.h" #include -using namespace std; - /** * Public library interface. */ @@ -65,8 +63,8 @@ namespace monero { // ----------------------- UNDECLARED PRIVATE HELPERS ----------------------- - void merge_incoming_transfer(vector>& transfers, const shared_ptr& transfer) { - for (const shared_ptr& aTransfer : transfers) { + void merge_incoming_transfer(std::vector>& transfers, const std::shared_ptr& transfer) { + for (const std::shared_ptr& aTransfer : transfers) { if (aTransfer->m_account_index.get() == transfer->m_account_index.get() && aTransfer->m_subaddress_index.get() == transfer->m_subaddress_index.get()) { aTransfer->merge(aTransfer, transfer); return; @@ -75,14 +73,14 @@ namespace monero { transfers.push_back(transfer); } - shared_ptr node_to_block_query(const boost::property_tree::ptree& node) { - shared_ptr block = make_shared(); + std::shared_ptr node_to_block_query(const boost::property_tree::ptree& node) { + std::shared_ptr block = std::make_shared(); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("txs")) { + std::string key = it->first; + if (key == std::string("txs")) { boost::property_tree::ptree txs_node = it->second; for (boost::property_tree::ptree::const_iterator it2 = txs_node.begin(); it2 != txs_node.end(); ++it2) { - shared_ptr tx_query = make_shared(); + std::shared_ptr tx_query = std::make_shared(); monero_tx_query::from_property_tree(it2->second, tx_query); block->m_txs.push_back(tx_query); tx_query->m_block = block; @@ -123,7 +121,7 @@ namespace monero { if (m_balance != boost::none) monero_utils::addJsonMember("balance", m_balance.get(), allocator, root, value_num); if (m_unlocked_balance != boost::none) monero_utils::addJsonMember("unlockedBalance", m_unlocked_balance.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_primary_address != boost::none) monero_utils::addJsonMember("primaryAddress", m_primary_address.get(), allocator, root, value_str); if (m_tag != boost::none) monero_utils::addJsonMember("tag", m_tag.get(), allocator, root, value_str); @@ -151,7 +149,7 @@ namespace monero { if (m_num_unspent_outputs != boost::none) monero_utils::addJsonMember("numUnspentOutputs", m_num_unspent_outputs.get(), allocator, root, value_num); if (m_num_blocks_to_unlock) monero_utils::addJsonMember("numBlocksToUnlock", m_num_blocks_to_unlock.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_address != boost::none) monero_utils::addJsonMember("address", m_address.get(), allocator, root, value_str); if (m_label != boost::none) monero_utils::addJsonMember("label", m_label.get(), allocator, root, value_str); @@ -177,7 +175,7 @@ namespace monero { if (m_change_amount != boost::none) monero_utils::addJsonMember("changeAmount", m_change_amount.get(), allocator, root, value_num); if (m_num_dummy_outputs != boost::none) monero_utils::addJsonMember("numDummyOutputs", m_num_dummy_outputs.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_note != boost::none) monero_utils::addJsonMember("note", m_note.get(), allocator, root, value_str); if (m_change_address != boost::none) monero_utils::addJsonMember("changeAddress", m_change_address.get(), allocator, root, value_str); @@ -198,43 +196,43 @@ namespace monero { return root; } - void monero_tx_wallet::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& tx_wallet) { + void monero_tx_wallet::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& tx_wallet) { monero_tx::from_property_tree(node, tx_wallet); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - //if (key == string("hash")) tx->m_hash = it->second.data(); - if (key == string("isLocked")) tx_wallet->m_is_locked = it->second.get_value(); + std::string key = it->first; + //if (key == std::string("hash")) tx->m_hash = it->second.data(); + if (key == std::string("isLocked")) tx_wallet->m_is_locked = it->second.get_value(); // TODO: deserialize other fields } } - shared_ptr monero_tx_wallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_tx_wallet::copy(const shared_ptr& src, const shared_ptr& tgt)"); - return monero_tx_wallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + std::shared_ptr monero_tx_wallet::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + MTRACE("monero_tx_wallet::copy(const std::shared_ptr& src, const std::shared_ptr& tgt)"); + return monero_tx_wallet::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); }; - shared_ptr monero_tx_wallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_tx_wallet::copy(const shared_ptr& src, const shared_ptr& tgt)"); - if (this != src.get()) throw runtime_error("this != src"); + std::shared_ptr monero_tx_wallet::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + MTRACE("monero_tx_wallet::copy(const std::shared_ptr& src, const std::shared_ptr& tgt)"); + if (this != src.get()) throw std::runtime_error("this != src"); // copy base class - monero_tx::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + monero_tx::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); // copy wallet extensions tgt->m_tx_set = src->m_tx_set; tgt->m_is_incoming = src->m_is_incoming; tgt->m_is_outgoing = src->m_is_outgoing; if (!src->m_incoming_transfers.empty()) { - tgt->m_incoming_transfers = vector>(); - for (const shared_ptr& transfer : src->m_incoming_transfers) { - shared_ptr transfer_copy = transfer->copy(transfer, make_shared()); + tgt->m_incoming_transfers = std::vector>(); + for (const std::shared_ptr& transfer : src->m_incoming_transfers) { + std::shared_ptr transfer_copy = transfer->copy(transfer, std::make_shared()); transfer_copy->m_tx = tgt; tgt->m_incoming_transfers.push_back(transfer_copy); } } if (src->m_outgoing_transfer != boost::none) { - shared_ptr transferCopy = src->m_outgoing_transfer.get()->copy(src->m_outgoing_transfer.get(), make_shared()); + std::shared_ptr transferCopy = src->m_outgoing_transfer.get()->copy(src->m_outgoing_transfer.get(), std::make_shared()); transferCopy->m_tx = tgt; tgt->m_outgoing_transfer = transferCopy; } @@ -250,12 +248,12 @@ namespace monero { return tgt; }; - void monero_tx_wallet::merge(const shared_ptr& self, const shared_ptr& other) { - merge(static_pointer_cast(self), static_pointer_cast(other)); + void monero_tx_wallet::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + merge(std::static_pointer_cast(self), std::static_pointer_cast(other)); } - void monero_tx_wallet::merge(const shared_ptr& self, const shared_ptr& other) { - if (this != self.get()) throw runtime_error("this != self"); + void monero_tx_wallet::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + if (this != self.get()) throw std::runtime_error("this != self"); if (self == other) return; // merge base classes @@ -263,7 +261,7 @@ namespace monero { // merge incoming transfers if (!other->m_incoming_transfers.empty()) { - for (const shared_ptr& transfer : other->m_incoming_transfers) { // NOTE: not using reference so shared_ptr is not deleted when tx is dereferenced + for (const std::shared_ptr& transfer : other->m_incoming_transfers) { // NOTE: not using reference so std::shared_ptr is not deleted when tx is dereferenced transfer->m_tx = self; merge_incoming_transfer(self->m_incoming_transfers, transfer); } @@ -289,27 +287,27 @@ namespace monero { m_extra_hex = gen_utils::reconcile(m_extra_hex, other->m_extra_hex); } - vector> monero_tx_wallet::get_transfers() const { + std::vector> monero_tx_wallet::get_transfers() const { monero_transfer_query query; return get_transfers(query); } - vector> monero_tx_wallet::get_transfers(const monero_transfer_query& query) const { - vector> transfers; + std::vector> monero_tx_wallet::get_transfers(const monero_transfer_query& query) const { + std::vector> transfers; if (m_outgoing_transfer != boost::none && query.meets_criteria(m_outgoing_transfer.get().get())) transfers.push_back(m_outgoing_transfer.get()); - for (const shared_ptr& transfer : m_incoming_transfers) if (query.meets_criteria(transfer.get())) transfers.push_back(transfer); + for (const std::shared_ptr& transfer : m_incoming_transfers) if (query.meets_criteria(transfer.get())) transfers.push_back(transfer); return transfers; } - vector> monero_tx_wallet::filter_transfers(const monero_transfer_query& query) { + std::vector> monero_tx_wallet::filter_transfers(const monero_transfer_query& query) { // collect outgoing transfer, erase if excluded - vector> transfers; + std::vector> transfers; if (m_outgoing_transfer != boost::none && query.meets_criteria(m_outgoing_transfer.get().get())) transfers.push_back(m_outgoing_transfer.get()); else m_outgoing_transfer = boost::none; // collect incoming transfers, erase if excluded - vector>::iterator iter = m_incoming_transfers.begin(); + std::vector>::iterator iter = m_incoming_transfers.begin(); while (iter != m_incoming_transfers.end()) { if (query.meets_criteria((*iter).get())) { transfers.push_back(*iter); @@ -321,25 +319,25 @@ namespace monero { return transfers; } - vector> monero_tx_wallet::get_outputs_wallet() const { + std::vector> monero_tx_wallet::get_outputs_wallet() const { monero_output_query query; return get_outputs_wallet(query); } - vector> monero_tx_wallet::get_outputs_wallet(const monero_output_query& query) const { - vector> outputs; - for (const shared_ptr& output : m_outputs) { - shared_ptr output_wallet = dynamic_pointer_cast(output); + std::vector> monero_tx_wallet::get_outputs_wallet(const monero_output_query& query) const { + std::vector> outputs; + for (const std::shared_ptr& output : m_outputs) { + std::shared_ptr output_wallet = std::dynamic_pointer_cast(output); if (query.meets_criteria(output_wallet.get())) outputs.push_back(output_wallet); } return outputs; } - vector> monero_tx_wallet::filter_outputs_wallet(const monero_output_query& query) { - vector> outputs; - vector>::iterator iter = m_outputs.begin(); + std::vector> monero_tx_wallet::filter_outputs_wallet(const monero_output_query& query) { + std::vector> outputs; + std::vector>::iterator iter = m_outputs.begin(); while (iter != m_outputs.end()) { - shared_ptr output_wallet = dynamic_pointer_cast(*iter); + std::shared_ptr output_wallet = std::dynamic_pointer_cast(*iter); if (query.meets_criteria(output_wallet.get())) { outputs.push_back(output_wallet); iter++; @@ -380,89 +378,89 @@ namespace monero { return root; } - void monero_tx_query::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& tx_query) { + void monero_tx_query::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& tx_query) { monero_tx_wallet::from_property_tree(node, tx_query); // initialize query from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("isOutgoing")) tx_query->m_is_outgoing = it->second.get_value(); - else if (key == string("isIncoming")) tx_query->m_is_incoming = it->second.get_value(); - else if (key == string("hashes")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) tx_query->m_hashes.push_back(it2->second.data()); - else if (key == string("hasPaymentId")) tx_query->m_has_payment_id = it->second.get_value(); - else if (key == string("paymentIds")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) tx_query->m_payment_ids.push_back(it2->second.data()); - else if (key == string("height")) tx_query->m_height = it->second.get_value(); - else if (key == string("minHeight")) tx_query->m_min_height = it->second.get_value(); - else if (key == string("maxHeight")) tx_query->m_max_height = it->second.get_value(); - else if (key == string("includeOutputs")) tx_query->m_include_outputs = it->second.get_value(); - else if (key == string("transferQuery")) { - tx_query->m_transfer_query = make_shared(); + std::string key = it->first; + if (key == std::string("isOutgoing")) tx_query->m_is_outgoing = it->second.get_value(); + else if (key == std::string("isIncoming")) tx_query->m_is_incoming = it->second.get_value(); + else if (key == std::string("hashes")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) tx_query->m_hashes.push_back(it2->second.data()); + else if (key == std::string("hasPaymentId")) tx_query->m_has_payment_id = it->second.get_value(); + else if (key == std::string("paymentIds")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) tx_query->m_payment_ids.push_back(it2->second.data()); + else if (key == std::string("height")) tx_query->m_height = it->second.get_value(); + else if (key == std::string("minHeight")) tx_query->m_min_height = it->second.get_value(); + else if (key == std::string("maxHeight")) tx_query->m_max_height = it->second.get_value(); + else if (key == std::string("includeOutputs")) tx_query->m_include_outputs = it->second.get_value(); + else if (key == std::string("transferQuery")) { + tx_query->m_transfer_query = std::make_shared(); monero_transfer_query::from_property_tree(it->second, tx_query->m_transfer_query.get()); tx_query->m_transfer_query.get()->m_tx_query = tx_query; } - else if (key == string("outputQuery")) { - tx_query->m_output_query = make_shared(); + else if (key == std::string("outputQuery")) { + tx_query->m_output_query = std::make_shared(); monero_output_query::from_property_tree(it->second, tx_query->m_output_query.get()); tx_query->m_output_query.get()->m_tx_query = tx_query; } } } - shared_ptr monero_tx_query::deserialize_from_block(const string& tx_query_json) { + std::shared_ptr monero_tx_query::deserialize_from_block(const std::string& tx_query_json) { - // deserialize tx query string to property rooted at block + // deserialize tx query std::string to property rooted at block std::istringstream iss = tx_query_json.empty() ? std::istringstream() : std::istringstream(tx_query_json); boost::property_tree::ptree block_node; boost::property_tree::read_json(iss, block_node); // convert query property tree to block - shared_ptr block = node_to_block_query(block_node); + std::shared_ptr block = node_to_block_query(block_node); // get tx query - shared_ptr tx_query = static_pointer_cast(block->m_txs[0]); + std::shared_ptr tx_query = std::static_pointer_cast(block->m_txs[0]); // return deserialized query return tx_query; } - shared_ptr monero_tx_query::copy(const shared_ptr& src, const shared_ptr& tgt) const { - return copy(static_pointer_cast(src), static_pointer_cast(tgt)); + std::shared_ptr monero_tx_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + return copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); }; - shared_ptr monero_tx_query::copy(const shared_ptr& src, const shared_ptr& tgt) const { - return copy(static_pointer_cast(src), static_pointer_cast(tgt)); + std::shared_ptr monero_tx_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + return copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); }; - shared_ptr monero_tx_query::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_tx_query::copy(const shared_ptr& src, const shared_ptr& tgt)"); - if (this != src.get()) throw runtime_error("this != src"); + std::shared_ptr monero_tx_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + MTRACE("monero_tx_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt)"); + if (this != src.get()) throw std::runtime_error("this != src"); // copy base class - monero_tx_wallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + monero_tx_wallet::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); // copy query extensions tgt->m_is_outgoing = src->m_is_outgoing; tgt->m_is_incoming = src->m_is_incoming; - if (!src->m_hashes.empty()) tgt->m_hashes = vector(src->m_hashes); + if (!src->m_hashes.empty()) tgt->m_hashes = std::vector(src->m_hashes); tgt-> m_has_payment_id = src->m_has_payment_id; - if (!src->m_payment_ids.empty()) tgt->m_payment_ids = vector(src->m_payment_ids); + if (!src->m_payment_ids.empty()) tgt->m_payment_ids = std::vector(src->m_payment_ids); tgt->m_height = src->m_height; tgt->m_min_height = src->m_min_height; tgt->m_max_height = src->m_max_height; tgt->m_include_outputs = src->m_include_outputs; if (src->m_transfer_query != boost::none) { - tgt->m_transfer_query = src->m_transfer_query.get()->copy(src->m_transfer_query.get(), make_shared()); + tgt->m_transfer_query = src->m_transfer_query.get()->copy(src->m_transfer_query.get(), std::make_shared()); tgt->m_transfer_query.get()->m_tx_query = tgt; } if (src->m_output_query != boost::none) { - tgt->m_output_query = src->m_output_query.get()->copy(src->m_output_query.get(), make_shared()); + tgt->m_output_query = src->m_output_query.get()->copy(src->m_output_query.get(), std::make_shared()); tgt->m_output_query.get()->m_tx_query = tgt; } return tgt; }; bool monero_tx_query::meets_criteria(monero_tx_wallet* tx, bool query_children) const { - if (tx == nullptr) throw runtime_error("nullptr given to monero_tx_query::meets_criteria()"); + if (tx == nullptr) throw std::runtime_error("nullptr given to monero_tx_query::meets_criteria()"); // filter on tx if (m_hash != boost::none && m_hash != tx->m_hash) return false; @@ -502,7 +500,7 @@ namespace monero { bool match_found = false; if (tx->m_outgoing_transfer != boost::none && m_transfer_query.get()->meets_criteria(tx->m_outgoing_transfer.get().get())) match_found = true; else if (!tx->m_incoming_transfers.empty()) { - for (const shared_ptr& incoming_transfer : tx->m_incoming_transfers) { + for (const std::shared_ptr& incoming_transfer : tx->m_incoming_transfers) { if (m_transfer_query.get()->meets_criteria(incoming_transfer.get(), false)) { match_found = true; break; @@ -516,8 +514,8 @@ namespace monero { if (m_output_query != boost::none) { if (tx->m_outputs.empty()) return false; bool match_found = false; - for (const shared_ptr& output : tx->m_outputs) { - shared_ptr vout_wallet = static_pointer_cast(output); + for (const std::shared_ptr& output : tx->m_outputs) { + std::shared_ptr vout_wallet = std::static_pointer_cast(output); if (m_output_query.get()->meets_criteria(vout_wallet.get(), false)) { match_found = true; break; @@ -541,7 +539,7 @@ namespace monero { rapidjson::Value value_num(rapidjson::kNumberType); if (m_amount != boost::none) monero_utils::addJsonMember("amount", m_amount.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_address != boost::none) monero_utils::addJsonMember("address", m_address.get(), allocator, root, value_str); @@ -549,17 +547,17 @@ namespace monero { return root; } - void monero_destination::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& destination) { + void monero_destination::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& destination) { for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("address")) destination->m_address = it->second.data(); - else if (key == string("amount")) destination->m_amount = it->second.get_value(); + std::string key = it->first; + if (key == std::string("address")) destination->m_address = it->second.data(); + else if (key == std::string("amount")) destination->m_amount = it->second.get_value(); } } - shared_ptr monero_destination::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_destination::copy(const shared_ptr& src, const shared_ptr& tgt)"); - if (this != src.get()) throw runtime_error("this != src"); + std::shared_ptr monero_destination::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + MTRACE("monero_destination::copy(const std::shared_ptr& src, const std::shared_ptr& tgt)"); + if (this != src.get()) throw std::runtime_error("this != src"); tgt->m_address = src->m_address; tgt->m_amount = src->m_amount; return tgt; @@ -572,7 +570,7 @@ namespace monero { // create root rapidjson::Value root(rapidjson::kObjectType); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_multisig_tx_hex != boost::none) monero_utils::addJsonMember("multisigTxHex", m_multisig_tx_hex.get(), allocator, root, value_str); if (m_unsigned_tx_hex != boost::none) monero_utils::addJsonMember("unsignedTxHex", m_unsigned_tx_hex.get(), allocator, root, value_str); @@ -585,7 +583,7 @@ namespace monero { return root; } - monero_tx_set monero_tx_set::deserialize(const string& tx_set_json) { + monero_tx_set monero_tx_set::deserialize(const std::string& tx_set_json) { // deserialize tx set to property std::istringstream iss = tx_set_json.empty() ? std::istringstream() : std::istringstream(tx_set_json); @@ -595,18 +593,18 @@ namespace monero { // initialize tx_set from property node monero_tx_set tx_set; for (boost::property_tree::ptree::const_iterator it = tx_set_node.begin(); it != tx_set_node.end(); ++it) { - string key = it->first; - if (key == string("unsignedTxHex")) tx_set.m_unsigned_tx_hex = it->second.data(); - else if (key == string("multisigTxHex")) tx_set.m_multisig_tx_hex = it->second.data(); - else if (key == string("txs")) { + std::string key = it->first; + if (key == std::string("unsignedTxHex")) tx_set.m_unsigned_tx_hex = it->second.data(); + else if (key == std::string("multisigTxHex")) tx_set.m_multisig_tx_hex = it->second.data(); + else if (key == std::string("txs")) { boost::property_tree::ptree txs_node = it->second; for (boost::property_tree::ptree::const_iterator it2 = txs_node.begin(); it2 != txs_node.end(); ++it2) { - shared_ptr tx_wallet = make_shared(); + std::shared_ptr tx_wallet = std::make_shared(); monero_tx_wallet::from_property_tree(it2->second, tx_wallet); tx_set.m_txs.push_back(tx_wallet); } } - else throw runtime_error("monero_utils::deserialize_tx_set() field '" + key + "' not supported"); + else throw std::runtime_error("monero_utils::deserialize_tx_set() field '" + key + "' not supported"); } return tx_set; @@ -629,17 +627,17 @@ namespace monero { return root; } - void monero_transfer::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& transfer) { + void monero_transfer::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& transfer) { // initialize transfer from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("accountIndex")) transfer->m_account_index = it->second.get_value(); + std::string key = it->first; + if (key == std::string("accountIndex")) transfer->m_account_index = it->second.get_value(); } } - shared_ptr monero_transfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_transfer::copy(const shared_ptr& src, const shared_ptr& tgt)"); + std::shared_ptr monero_transfer::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + MTRACE("monero_transfer::copy(const std::shared_ptr& src, const std::shared_ptr& tgt)"); tgt->m_tx = src->m_tx; // reference parent tx by default tgt->m_amount = src->m_amount; tgt->m_account_index = src->m_account_index; @@ -647,8 +645,8 @@ namespace monero { return tgt; } - void monero_transfer::merge(const shared_ptr& self, const shared_ptr& other) { - if (this != self.get()) throw runtime_error("this != self"); + void monero_transfer::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + if (this != self.get()) throw std::runtime_error("this != self"); if (self == other) return; // merge txs if they're different which comes back to merging transfers @@ -682,7 +680,7 @@ namespace monero { rapidjson::Value value_num(rapidjson::kNumberType); if (m_subaddress_index != boost::none) monero_utils::addJsonMember("subaddressIndex", m_subaddress_index.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_address != boost::none) monero_utils::addJsonMember("address", m_address.get(), allocator, root, value_str); @@ -690,22 +688,22 @@ namespace monero { return root; } - shared_ptr monero_incoming_transfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { - return copy(static_pointer_cast(src), static_pointer_cast(tgt)); + std::shared_ptr monero_incoming_transfer::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + return copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); } - shared_ptr monero_incoming_transfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { - cout << "monero_incoming_transfer::copy()" << endl; - throw runtime_error("monero_incoming_transfer::copy(inTransfer) not implemented"); + std::shared_ptr monero_incoming_transfer::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + std::cout << "monero_incoming_transfer::copy()" << std::endl; + throw std::runtime_error("monero_incoming_transfer::copy(inTransfer) not implemented"); }; boost::optional monero_incoming_transfer::is_incoming() const { return true; } - void monero_incoming_transfer::merge(const shared_ptr& self, const shared_ptr& other) { - merge(static_pointer_cast(self), static_pointer_cast(other)); + void monero_incoming_transfer::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + merge(std::static_pointer_cast(self), std::static_pointer_cast(other)); } - void monero_incoming_transfer::merge(const shared_ptr& self, const shared_ptr& other) { + void monero_incoming_transfer::merge(const std::shared_ptr& self, const std::shared_ptr& other) { if (self == other) return; monero_transfer::merge(self, other); m_subaddress_index = gen_utils::reconcile(m_subaddress_index, other->m_subaddress_index, "incoming transfer m_subaddress_index"); @@ -728,22 +726,22 @@ namespace monero { return root; } - shared_ptr monero_outgoing_transfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { - return copy(static_pointer_cast(src), static_pointer_cast(tgt)); + std::shared_ptr monero_outgoing_transfer::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + return copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); }; - shared_ptr monero_outgoing_transfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { - cout << "monero_outgoing_transfer::copy()" << endl; - throw runtime_error("monero_outgoing_transfer::copy(out_transfer) not implemented"); + std::shared_ptr monero_outgoing_transfer::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + std::cout << "monero_outgoing_transfer::copy()" << std::endl; + throw std::runtime_error("monero_outgoing_transfer::copy(out_transfer) not implemented"); }; boost::optional monero_outgoing_transfer::is_incoming() const { return false; } - void monero_outgoing_transfer::merge(const shared_ptr& self, const shared_ptr& other) { - merge(static_pointer_cast(self), static_pointer_cast(other)); + void monero_outgoing_transfer::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + merge(std::static_pointer_cast(self), std::static_pointer_cast(other)); } - void monero_outgoing_transfer::merge(const shared_ptr& self, const shared_ptr& other) { + void monero_outgoing_transfer::merge(const std::shared_ptr& self, const std::shared_ptr& other) { if (self == other) return; monero_transfer::merge(self, other); m_subaddress_indices = gen_utils::reconcile(m_subaddress_indices, other->m_subaddress_indices); @@ -766,7 +764,7 @@ namespace monero { if (m_is_incoming != boost::none) monero_utils::addJsonMember("isIncoming", m_is_incoming.get(), allocator, root); if (m_has_destinations != boost::none) monero_utils::addJsonMember("hasDestinations", m_has_destinations.get(), allocator, root); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_address != boost::none) monero_utils::addJsonMember("address", m_address.get(), allocator, root, value_str); @@ -779,45 +777,45 @@ namespace monero { return root; } - void monero_transfer_query::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& transfer_query) { + void monero_transfer_query::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& transfer_query) { monero_transfer::from_property_tree(node, transfer_query); // initialize query from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("isIncoming")) transfer_query->m_is_incoming = it->second.get_value(); - else if (key == string("address")) transfer_query->m_address = it->second.data(); - else if (key == string("addresses")) throw runtime_error("addresses not implemented"); - else if (key == string("subaddressIndex")) transfer_query->m_subaddress_index = it->second.get_value(); - else if (key == string("subaddressIndices")) { - vector m_subaddress_indices; + std::string key = it->first; + if (key == std::string("isIncoming")) transfer_query->m_is_incoming = it->second.get_value(); + else if (key == std::string("address")) transfer_query->m_address = it->second.data(); + else if (key == std::string("addresses")) throw std::runtime_error("addresses not implemented"); + else if (key == std::string("subaddressIndex")) transfer_query->m_subaddress_index = it->second.get_value(); + else if (key == std::string("subaddressIndices")) { + std::vector m_subaddress_indices; for (const auto& child : it->second) m_subaddress_indices.push_back(child.second.get_value()); transfer_query->m_subaddress_indices = m_subaddress_indices; } - else if (key == string("destinations")) throw runtime_error("destinations not implemented"); - else if (key == string("hasDestinations")) transfer_query->m_has_destinations = it->second.get_value(); - else if (key == string("txQuery")) throw runtime_error("txQuery not implemented"); + else if (key == std::string("destinations")) throw std::runtime_error("destinations not implemented"); + else if (key == std::string("hasDestinations")) transfer_query->m_has_destinations = it->second.get_value(); + else if (key == std::string("txQuery")) throw std::runtime_error("txQuery not implemented"); } } - shared_ptr monero_transfer_query::deserialize_from_block(const string& transfer_query_json) { + std::shared_ptr monero_transfer_query::deserialize_from_block(const std::string& transfer_query_json) { - // deserialize transfer query string to property rooted at block + // deserialize transfer query std::string to property rooted at block std::istringstream iss = transfer_query_json.empty() ? std::istringstream() : std::istringstream(transfer_query_json); boost::property_tree::ptree blockNode; boost::property_tree::read_json(iss, blockNode); // convert query property tree to block - shared_ptr block = node_to_block_query(blockNode); + std::shared_ptr block = node_to_block_query(blockNode); // return empty query if no txs - if (block->m_txs.empty()) return make_shared(); + if (block->m_txs.empty()) return std::make_shared(); // get tx query - shared_ptr tx_query = static_pointer_cast(block->m_txs[0]); + std::shared_ptr tx_query = std::static_pointer_cast(block->m_txs[0]); // get / create transfer query - shared_ptr transfer_query = tx_query->m_transfer_query == boost::none ? make_shared() : *tx_query->m_transfer_query; + std::shared_ptr transfer_query = tx_query->m_transfer_query == boost::none ? std::make_shared() : *tx_query->m_transfer_query; // set transfer query's tx query transfer_query->m_tx_query = tx_query; @@ -826,26 +824,26 @@ namespace monero { return transfer_query; } - shared_ptr monero_transfer_query::copy(const shared_ptr& src, const shared_ptr& tgt) const { - return copy(static_pointer_cast(src), static_pointer_cast(tgt)); + std::shared_ptr monero_transfer_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + return copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); }; - shared_ptr monero_transfer_query::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_transfer_query::copy(const shared_ptr& src, const shared_ptr& tgt)"); - if (this != src.get()) throw runtime_error("this != src"); + std::shared_ptr monero_transfer_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + MTRACE("monero_transfer_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt)"); + if (this != src.get()) throw std::runtime_error("this != src"); // copy base class - monero_transfer::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + monero_transfer::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); // copy extensions tgt->m_is_incoming = src->m_is_incoming; tgt->m_address = src->m_address; - if (!src->m_addresses.empty()) tgt->m_addresses = vector(src->m_addresses); + if (!src->m_addresses.empty()) tgt->m_addresses = std::vector(src->m_addresses); tgt->m_subaddress_index = src->m_subaddress_index; - if (!src->m_subaddress_indices.empty()) tgt->m_subaddress_indices = vector(src->m_subaddress_indices); + if (!src->m_subaddress_indices.empty()) tgt->m_subaddress_indices = std::vector(src->m_subaddress_indices); if (!src->m_destinations.empty()) { - for (const shared_ptr& destination : src->m_destinations) { - tgt->m_destinations.push_back(destination->copy(destination, make_shared())); + for (const std::shared_ptr& destination : src->m_destinations) { + tgt->m_destinations.push_back(destination->copy(destination, std::make_shared())); } } tgt->m_has_destinations = src->m_has_destinations; @@ -854,7 +852,7 @@ namespace monero { }; bool monero_transfer_query::meets_criteria(monero_transfer* transfer, bool query_parent) const { - if (transfer == nullptr) throw runtime_error("nullptr given to monero_transfer_query::meets_criteria()"); + if (transfer == nullptr) throw std::runtime_error("nullptr given to monero_transfer_query::meets_criteria()"); // filter on common fields if (is_incoming() != boost::none && *is_incoming() != *transfer->is_incoming()) return false; @@ -880,8 +878,8 @@ namespace monero { if (m_address != boost::none && (out_transfer->m_addresses.empty() || find(out_transfer->m_addresses.begin(), out_transfer->m_addresses.end(), *m_address) == out_transfer->m_addresses.end())) return false; // TODO: will filter all transfers if they don't contain addresses if (!m_addresses.empty()) { bool intersects = false; - for (const string& addressReq : m_addresses) { - for (const string& address : out_transfer->m_addresses) { + for (const std::string& addressReq : m_addresses) { + for (const std::string& address : out_transfer->m_addresses) { if (addressReq == address) { intersects = true; break; @@ -917,7 +915,7 @@ namespace monero { } // validate type - if (inTransfer == nullptr && out_transfer == nullptr) throw runtime_error("Transfer must be monero_incoming_transfer or monero_outgoing_transfer"); + if (inTransfer == nullptr && out_transfer == nullptr) throw std::runtime_error("Transfer must be monero_incoming_transfer or monero_outgoing_transfer"); // filter with tx query if (query_parent && m_tx_query != boost::none && !(*m_tx_query)->meets_criteria(transfer->m_tx.get(), false)) return false; @@ -946,28 +944,28 @@ namespace monero { return root; } - void monero_output_wallet::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& output_wallet) { + void monero_output_wallet::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& output_wallet) { monero_output::from_property_tree(node, output_wallet); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("accountIndex")) output_wallet->m_account_index = it->second.get_value(); - else if (key == string("subaddressIndex")) output_wallet->m_subaddress_index = it->second.get_value(); - else if (key == string("isSpent")) output_wallet->m_is_spent = it->second.get_value(); - else if (key == string("isFrozen")) output_wallet->m_is_frozen = it->second.get_value(); + std::string key = it->first; + if (key == std::string("accountIndex")) output_wallet->m_account_index = it->second.get_value(); + else if (key == std::string("subaddressIndex")) output_wallet->m_subaddress_index = it->second.get_value(); + else if (key == std::string("isSpent")) output_wallet->m_is_spent = it->second.get_value(); + else if (key == std::string("isFrozen")) output_wallet->m_is_frozen = it->second.get_value(); } } - shared_ptr monero_output_wallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { + std::shared_ptr monero_output_wallet::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { MTRACE("monero_output_wallet::copy(output)"); - return monero_output_wallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + return monero_output_wallet::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); }; - shared_ptr monero_output_wallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { + std::shared_ptr monero_output_wallet::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { MTRACE("monero_output_wallet::copy(output_wallet)"); - if (this != src.get()) throw runtime_error("this != src"); + if (this != src.get()) throw std::runtime_error("this != src"); // copy base class - monero_output::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + monero_output::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); // copy extensions tgt->m_account_index = src->m_account_index; @@ -977,13 +975,13 @@ namespace monero { return tgt; }; - void monero_output_wallet::merge(const shared_ptr& self, const shared_ptr& other) { - merge(static_pointer_cast(self), static_pointer_cast(other)); + void monero_output_wallet::merge(const std::shared_ptr& self, const std::shared_ptr& other) { + merge(std::static_pointer_cast(self), std::static_pointer_cast(other)); } - void monero_output_wallet::merge(const shared_ptr& self, const shared_ptr& other) { + void monero_output_wallet::merge(const std::shared_ptr& self, const std::shared_ptr& other) { MTRACE("monero_output_wallet::merge(self, other)"); - if (this != self.get()) throw runtime_error("this != self"); + if (this != self.get()) throw std::runtime_error("this != self"); if (self == other) return; // merge base classes @@ -1015,37 +1013,37 @@ namespace monero { return root; } - void monero_output_query::from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& output_query) { + void monero_output_query::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& output_query) { monero_output_wallet::from_property_tree(node, output_query); // initialize query from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) output_query->m_subaddress_indices.push_back(it2->second.get_value()); - else if (key == string("minAmount")) output_query->m_min_amount = it->second.get_value(); - else if (key == string("maxAmount")) output_query->m_max_amount = it->second.get_value(); - else if (key == string("txQuery")) {} // ignored + std::string key = it->first; + if (key == std::string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) output_query->m_subaddress_indices.push_back(it2->second.get_value()); + else if (key == std::string("minAmount")) output_query->m_min_amount = it->second.get_value(); + else if (key == std::string("maxAmount")) output_query->m_max_amount = it->second.get_value(); + else if (key == std::string("txQuery")) {} // ignored } } - shared_ptr monero_output_query::deserialize_from_block(const string& output_query_json) { + std::shared_ptr monero_output_query::deserialize_from_block(const std::string& output_query_json) { - // deserialize output query string to property rooted at block + // deserialize output query std::string to property rooted at block std::istringstream iss = output_query_json.empty() ? std::istringstream() : std::istringstream(output_query_json); boost::property_tree::ptree blockNode; boost::property_tree::read_json(iss, blockNode); // convert query property tree to block - shared_ptr block = node_to_block_query(blockNode); + std::shared_ptr block = node_to_block_query(blockNode); // empty query if no txs - if (block->m_txs.empty()) return make_shared(); + if (block->m_txs.empty()) return std::make_shared(); // get tx query - shared_ptr tx_query = static_pointer_cast(block->m_txs[0]); + std::shared_ptr tx_query = std::static_pointer_cast(block->m_txs[0]); // get / create output query - shared_ptr output_query = tx_query->m_output_query == boost::none ? make_shared() : *tx_query->m_output_query; + std::shared_ptr output_query = tx_query->m_output_query == boost::none ? std::make_shared() : *tx_query->m_output_query; // set output query's tx query output_query->m_tx_query = tx_query; @@ -1054,23 +1052,23 @@ namespace monero { return output_query; } - shared_ptr monero_output_query::copy(const shared_ptr& src, const shared_ptr& tgt) const { - return monero_output_query::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + std::shared_ptr monero_output_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + return monero_output_query::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); }; - shared_ptr monero_output_query::copy(const shared_ptr& src, const shared_ptr& tgt) const { - return monero_output_query::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + std::shared_ptr monero_output_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { + return monero_output_query::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); }; - shared_ptr monero_output_query::copy(const shared_ptr& src, const shared_ptr& tgt) const { + std::shared_ptr monero_output_query::copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const { MTRACE("monero_output_query::copy(output_query)"); - if (this != src.get()) throw runtime_error("this != src"); + if (this != src.get()) throw std::runtime_error("this != src"); // copy base class - monero_output_wallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + monero_output_wallet::copy(std::static_pointer_cast(src), std::static_pointer_cast(tgt)); // copy extensions - if (!src->m_subaddress_indices.empty()) tgt->m_subaddress_indices = vector(src->m_subaddress_indices); + if (!src->m_subaddress_indices.empty()) tgt->m_subaddress_indices = std::vector(src->m_subaddress_indices); tgt->m_min_amount = src->m_min_amount; tgt->m_max_amount = src->m_max_amount; tgt->m_tx_query = src->m_tx_query; @@ -1078,7 +1076,7 @@ namespace monero { }; bool monero_output_query::meets_criteria(monero_output_wallet* output, bool query_parent) const { - if (output == nullptr) throw runtime_error("nullptr given to monero_output_query::meets_criteria()"); + if (output == nullptr) throw std::runtime_error("nullptr given to monero_output_query::meets_criteria()"); // filter on output if (m_account_index != boost::none && (output->m_account_index == boost::none || *m_account_index != *output->m_account_index)) return false; @@ -1099,7 +1097,7 @@ namespace monero { if (m_max_amount != boost::none && (output->m_amount == boost::none || output->m_amount.get() > m_max_amount.get())) return false; // filter with tx query - if (query_parent && m_tx_query != boost::none && !(*m_tx_query)->meets_criteria(static_pointer_cast(output->m_tx).get(), false)) return false; + if (query_parent && m_tx_query != boost::none && !(*m_tx_query)->meets_criteria(std::static_pointer_cast(output->m_tx).get(), false)) return false; // output meets query return true; @@ -1111,8 +1109,8 @@ namespace monero { m_address = config.m_address; m_amount = config.m_amount; if (config.m_destinations.size() > 0) { - for (const shared_ptr& destination : config.m_destinations) { - m_destinations.push_back(destination->copy(destination, make_shared())); + for (const std::shared_ptr& destination : config.m_destinations) { + m_destinations.push_back(destination->copy(destination, std::make_shared())); } } m_payment_id = config.m_payment_id; @@ -1148,7 +1146,7 @@ namespace monero { if (m_unlock_time != boost::none) monero_utils::addJsonMember("unlockTime", m_unlock_time.get(), allocator, root, value_num); if (m_below_amount != boost::none) monero_utils::addJsonMember("belowAmount", m_below_amount.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_payment_id != boost::none) monero_utils::addJsonMember("paymentId", m_payment_id.get(), allocator, root, value_str); if (m_note != boost::none) monero_utils::addJsonMember("note", m_note.get(), allocator, root, value_str); @@ -1168,7 +1166,7 @@ namespace monero { return root; } - shared_ptr monero_tx_config::deserialize(const string& config_json) { + std::shared_ptr monero_tx_config::deserialize(const std::string& config_json) { // deserialize config json to property node std::istringstream iss = config_json.empty() ? std::istringstream() : std::istringstream(config_json); @@ -1176,53 +1174,53 @@ namespace monero { boost::property_tree::read_json(iss, node); // convert config property tree to monero_tx_config - shared_ptr config = make_shared(); + std::shared_ptr config = std::make_shared(); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("destinations")) { + std::string key = it->first; + if (key == std::string("destinations")) { boost::property_tree::ptree destinationsNode = it->second; for (boost::property_tree::ptree::const_iterator it2 = destinationsNode.begin(); it2 != destinationsNode.end(); ++it2) { - shared_ptr destination = make_shared(); + std::shared_ptr destination = std::make_shared(); monero_destination::from_property_tree(it2->second, destination); config->m_destinations.push_back(destination); } } - else if (key == string("paymentId")) config->m_payment_id = it->second.data(); - else if (key == string("priority")) { + else if (key == std::string("paymentId")) config->m_payment_id = it->second.data(); + else if (key == std::string("priority")) { uint32_t priority_num = it->second.get_value(); if (priority_num == 0) config->m_priority = monero_tx_priority::DEFAULT; else if (priority_num == 1) config->m_priority = monero_tx_priority::UNIMPORTANT; else if (priority_num == 2) config->m_priority = monero_tx_priority::NORMAL; else if (priority_num == 3) config->m_priority = monero_tx_priority::ELEVATED; - else throw runtime_error("Invalid priority number: " + std::to_string(priority_num)); + else throw std::runtime_error("Invalid priority number: " + std::to_string(priority_num)); } - else if (key == string("ringSize")) config->m_ring_size = it->second.get_value(); - else if (key == string("fee")) config->m_fee = it->second.get_value(); - else if (key == string("accountIndex")) config->m_account_index = it->second.get_value(); - else if (key == string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) config->m_subaddress_indices.push_back(it2->second.get_value()); - else if (key == string("unlockTime")) config->m_unlock_time = it->second.get_value(); - else if (key == string("canSplit")) config->m_can_split = it->second.get_value(); - else if (key == string("relay")) config->m_relay = it->second.get_value(); - else if (key == string("note")) config->m_note = it->second.data(); - else if (key == string("recipientName")) config->m_recipient_name = it->second.data(); - else if (key == string("belowAmount")) config->m_below_amount = it->second.get_value(); - else if (key == string("sweepEachSubaddress")) config->m_sweep_each_subaddress = it->second.get_value(); - else if (key == string("keyImage")) config->m_key_image = it->second.data(); + else if (key == std::string("ringSize")) config->m_ring_size = it->second.get_value(); + else if (key == std::string("fee")) config->m_fee = it->second.get_value(); + else if (key == std::string("accountIndex")) config->m_account_index = it->second.get_value(); + else if (key == std::string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) config->m_subaddress_indices.push_back(it2->second.get_value()); + else if (key == std::string("unlockTime")) config->m_unlock_time = it->second.get_value(); + else if (key == std::string("canSplit")) config->m_can_split = it->second.get_value(); + else if (key == std::string("relay")) config->m_relay = it->second.get_value(); + else if (key == std::string("note")) config->m_note = it->second.data(); + else if (key == std::string("recipientName")) config->m_recipient_name = it->second.data(); + else if (key == std::string("belowAmount")) config->m_below_amount = it->second.get_value(); + else if (key == std::string("sweepEachSubaddress")) config->m_sweep_each_subaddress = it->second.get_value(); + else if (key == std::string("keyImage")) config->m_key_image = it->second.data(); } return config; } - vector> monero_tx_config::get_normalized_destinations() const { + std::vector> monero_tx_config::get_normalized_destinations() const { if (m_address == boost::none && m_amount == boost::none) return m_destinations; else if (m_destinations.empty()) { - vector> destinations; + std::vector> destinations; destinations.push_back(std::make_shared(m_address, m_amount)); return destinations; } else { - if (m_destinations.size() > 1) throw runtime_error("Invalid tx configuration: single destination address/amount incompatible with multiple destinations"); - if (m_address != m_destinations[0]->m_address) throw runtime_error("Invalid tx configuration: single destination address does not match first destination address"); - if (m_amount != m_destinations[0]->m_amount) throw runtime_error("Invalid tx configuration: single destination amount does not match first destination amount"); + if (m_destinations.size() > 1) throw std::runtime_error("Invalid tx configuration: single destination address/amount incompatible with multiple destinations"); + if (m_address != m_destinations[0]->m_address) throw std::runtime_error("Invalid tx configuration: single destination address does not match first destination address"); + if (m_amount != m_destinations[0]->m_amount) throw std::runtime_error("Invalid tx configuration: single destination amount does not match first destination amount"); return m_destinations; } } @@ -1234,7 +1232,7 @@ namespace monero { // create root rapidjson::Value root(rapidjson::kObjectType); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); monero_utils::addJsonMember("standardAddress", m_standard_address, allocator, root, value_str); monero_utils::addJsonMember("paymentId", m_payment_id, allocator, root, value_str); @@ -1335,7 +1333,7 @@ namespace monero { // create root rapidjson::Value root(rapidjson::kObjectType); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_address != boost::none) monero_utils::addJsonMember("address", m_address.get(), allocator, root, value_str); if (m_multisig_hex != boost::none) monero_utils::addJsonMember("multisigHex", m_multisig_hex.get(), allocator, root, value_str); @@ -1348,7 +1346,7 @@ namespace monero { // create root rapidjson::Value root(rapidjson::kObjectType); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_signed_multisig_tx_hex != boost::none) monero_utils::addJsonMember("signedMultisigTxHex", m_signed_multisig_tx_hex.get(), allocator, root, value_str); @@ -1370,7 +1368,7 @@ namespace monero { rapidjson::Value value_num(rapidjson::kNumberType); if (m_index != boost::none) monero_utils::addJsonMember("index", m_index.get(), allocator, root, value_num); - // set string values + // set std::string values rapidjson::Value value_str(rapidjson::kStringType); if (m_address != boost::none) monero_utils::addJsonMember("address", m_address.get(), allocator, root, value_str); if (m_description != boost::none) monero_utils::addJsonMember("description", m_description.get(), allocator, root, value_str); diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index 900e3ac..7a76c5c 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -54,7 +54,6 @@ #include "daemon/monero_daemon_model.h" -using namespace std; using namespace monero; /** @@ -80,8 +79,8 @@ namespace monero { struct monero_subaddress : public serializable_struct { boost::optional m_account_index; boost::optional m_index; - boost::optional m_address; - boost::optional m_label; + boost::optional m_address; + boost::optional m_label; boost::optional m_balance; boost::optional m_unlocked_balance; boost::optional m_num_unspent_outputs; @@ -96,11 +95,11 @@ namespace monero { */ struct monero_account : public serializable_struct { boost::optional m_index; - boost::optional m_primary_address; + boost::optional m_primary_address; boost::optional m_balance; boost::optional m_unlocked_balance; - boost::optional m_tag; - vector m_subaddresses; + boost::optional m_tag; + std::vector m_subaddresses; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; }; @@ -109,13 +108,13 @@ namespace monero { * Models an outgoing transfer destination. */ struct monero_destination { - boost::optional m_address; + boost::optional m_address; boost::optional m_amount; - monero_destination(boost::optional address = boost::none, boost::optional amount = boost::none) : m_address(address), m_amount(amount) {} + monero_destination(boost::optional address = boost::none, boost::optional amount = boost::none) : m_address(address), m_amount(amount) {} rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& destination); - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& destination); + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; }; // forward declarations @@ -129,20 +128,20 @@ namespace monero { * TODO: m_is_incoming for api consistency */ struct monero_transfer : serializable_struct { - shared_ptr m_tx; + std::shared_ptr m_tx; boost::optional m_amount; boost::optional m_account_index; boost::optional m_num_suggested_confirmations; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& transfer); + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& transfer); virtual boost::optional is_incoming() const = 0; // derived class must implement - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; boost::optional is_outgoing() const { if (is_incoming() == boost::none) return boost::none; return !(*is_incoming()); } - void merge(const shared_ptr& self, const shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); }; /** @@ -150,30 +149,30 @@ namespace monero { */ struct monero_incoming_transfer : public monero_transfer { boost::optional m_subaddress_index; - boost::optional m_address; + boost::optional m_address; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; boost::optional is_incoming() const; - void merge(const shared_ptr& self, const shared_ptr& other); - void merge(const shared_ptr& self, const shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); }; /** * Models an outgoing transfer of funds from the wallet. */ struct monero_outgoing_transfer : public monero_transfer { - vector m_subaddress_indices; - vector m_addresses; - vector> m_destinations; + std::vector m_subaddress_indices; + std::vector m_addresses; + std::vector> m_destinations; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; boost::optional is_incoming() const; - void merge(const shared_ptr& self, const shared_ptr& other); - void merge(const shared_ptr& self, const shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); }; /** @@ -183,19 +182,19 @@ namespace monero { */ struct monero_transfer_query : public monero_transfer { boost::optional m_is_incoming; - boost::optional m_address; - vector m_addresses; + boost::optional m_address; + std::vector m_addresses; boost::optional m_subaddress_index; - vector m_subaddress_indices; - vector> m_destinations; + std::vector m_subaddress_indices; + std::vector> m_destinations; boost::optional m_has_destinations; - boost::optional> m_tx_query; + boost::optional> m_tx_query; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& transfer_query); - static shared_ptr deserialize_from_block(const string& transfer_query_json); - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& transfer_query); + static std::shared_ptr deserialize_from_block(const std::string& transfer_query_json); + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; boost::optional is_incoming() const; bool meets_criteria(monero_transfer* transfer, bool query_parent = true) const; }; @@ -210,11 +209,11 @@ namespace monero { boost::optional m_is_frozen; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& output_wallet); - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - void merge(const shared_ptr& self, const shared_ptr& other); - void merge(const shared_ptr& self, const shared_ptr& other); + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& output_wallet); + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + void merge(const std::shared_ptr& self, const std::shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); }; /** @@ -224,18 +223,18 @@ namespace monero { * All outputs are returned except those that do not meet the criteria defined in this query. */ struct monero_output_query : public monero_output_wallet { - vector m_subaddress_indices; + std::vector m_subaddress_indices; boost::optional m_min_amount; boost::optional m_max_amount; - boost::optional> m_tx_query; + boost::optional> m_tx_query; //boost::property_tree::ptree to_property_tree() const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& output_query); - static shared_ptr deserialize_from_block(const string& output_query_json); - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; // TODO: necessary to override all super classes? - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& output_query); + static std::shared_ptr deserialize_from_block(const std::string& output_query_json); + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; // TODO: necessary to override all super classes? + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; bool meets_criteria(monero_output_wallet* output, bool query_parent = true) const; }; @@ -243,32 +242,32 @@ namespace monero { * Models a Monero transaction in the context of a wallet. */ struct monero_tx_wallet : public monero_tx { - boost::optional> m_tx_set; + boost::optional> m_tx_set; boost::optional m_is_incoming; boost::optional m_is_outgoing; - vector> m_incoming_transfers; - boost::optional> m_outgoing_transfer; - boost::optional m_note; + std::vector> m_incoming_transfers; + boost::optional> m_outgoing_transfer; + boost::optional m_note; boost::optional m_is_locked; boost::optional m_input_sum; boost::optional m_output_sum; - boost::optional m_change_address; + boost::optional m_change_address; boost::optional m_change_amount; boost::optional m_num_dummy_outputs; - boost::optional m_extra_hex; + boost::optional m_extra_hex; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& tx_wallet); - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - void merge(const shared_ptr& self, const shared_ptr& other); - void merge(const shared_ptr& self, const shared_ptr& other); - vector> get_transfers() const; - vector> get_transfers(const monero_transfer_query& query) const; - vector> filter_transfers(const monero_transfer_query& query); - vector> get_outputs_wallet() const; - vector> get_outputs_wallet(const monero_output_query& query) const; - vector> filter_outputs_wallet(const monero_output_query& query); + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& tx_wallet); + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + void merge(const std::shared_ptr& self, const std::shared_ptr& other); + void merge(const std::shared_ptr& self, const std::shared_ptr& other); + std::vector> get_transfers() const; + std::vector> get_transfers(const monero_transfer_query& query) const; + std::vector> filter_transfers(const monero_transfer_query& query); + std::vector> get_outputs_wallet() const; + std::vector> get_outputs_wallet(const monero_output_query& query) const; + std::vector> filter_outputs_wallet(const monero_output_query& query); }; /** @@ -279,22 +278,22 @@ namespace monero { struct monero_tx_query : public monero_tx_wallet { boost::optional m_is_outgoing; boost::optional m_is_incoming; - vector m_hashes; + std::vector m_hashes; boost::optional m_has_payment_id; - vector m_payment_ids; + std::vector m_payment_ids; boost::optional m_height; boost::optional m_min_height; boost::optional m_max_height; boost::optional m_include_outputs; - boost::optional> m_transfer_query; - boost::optional> m_output_query; + boost::optional> m_transfer_query; + boost::optional> m_output_query; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr& tx_query); - static shared_ptr deserialize_from_block(const string& tx_query_json); - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; // TODO: necessary to override all super classes? - shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr& tx_query); + static std::shared_ptr deserialize_from_block(const std::string& tx_query_json); + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; // TODO: necessary to override all super classes? + std::shared_ptr copy(const std::shared_ptr& src, const std::shared_ptr& tgt) const; bool meets_criteria(monero_tx_wallet* tx, bool query_children = true) const; }; @@ -303,27 +302,27 @@ namespace monero { * sign and submit the transactions. * * For example, multisig transactions created from send_txs() share a common - * hex string which is needed in order to sign and submit the multisig + * hex std::string which is needed in order to sign and submit the multisig * transactions. */ struct monero_tx_set : public serializable_struct { - vector> m_txs; - boost::optional m_signed_tx_hex; - boost::optional m_unsigned_tx_hex; - boost::optional m_multisig_tx_hex; + std::vector> m_txs; + boost::optional m_signed_tx_hex; + boost::optional m_unsigned_tx_hex; + boost::optional m_multisig_tx_hex; //boost::property_tree::ptree to_property_tree() const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static monero_tx_set deserialize(const string& tx_set_json); + static monero_tx_set deserialize(const std::string& tx_set_json); }; /** * Monero integrated address model. */ struct monero_integrated_address : public serializable_struct { - string m_standard_address; - string m_payment_id; - string m_integrated_address; + std::string m_standard_address; + std::string m_payment_id; + std::string m_integrated_address; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; }; @@ -342,30 +341,30 @@ namespace monero { * Configures a transaction to send, sweep, or create a payment URI. */ struct monero_tx_config : public serializable_struct { - boost::optional m_address; + boost::optional m_address; boost::optional m_amount; - vector> m_destinations; - boost::optional m_payment_id; + std::vector> m_destinations; + boost::optional m_payment_id; boost::optional m_priority; boost::optional m_ring_size; boost::optional m_fee; boost::optional m_account_index; - vector m_subaddress_indices; + std::vector m_subaddress_indices; boost::optional m_unlock_time; boost::optional m_can_split; boost::optional m_relay; - boost::optional m_note; - boost::optional m_recipient_name; + boost::optional m_note; + boost::optional m_recipient_name; boost::optional m_below_amount; boost::optional m_sweep_each_subaddress; - boost::optional m_key_image; + boost::optional m_key_image; monero_tx_config() {} monero_tx_config(const monero_tx_config& config); monero_tx_config copy() const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static shared_ptr deserialize(const string& config_json); - vector> get_normalized_destinations() const; + static std::shared_ptr deserialize(const std::string& config_json); + std::vector> get_normalized_destinations() const; }; /** @@ -427,8 +426,8 @@ namespace monero { * participants to create the wallet. */ struct monero_multisig_init_result : serializable_struct { - boost::optional m_address; - boost::optional m_multisig_hex; + boost::optional m_address; + boost::optional m_multisig_hex; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; }; @@ -437,8 +436,8 @@ namespace monero { * Models the result of signing multisig tx hex. */ struct monero_multisig_sign_result : serializable_struct { - boost::optional m_signed_multisig_tx_hex; - vector m_tx_hashes; + boost::optional m_signed_multisig_tx_hex; + std::vector m_tx_hashes; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; }; @@ -448,12 +447,12 @@ namespace monero { */ struct monero_address_book_entry : serializable_struct { boost::optional m_index; // TODO: not boost::optional - boost::optional m_address; - boost::optional m_description; - boost::optional m_payment_id; + boost::optional m_address; + boost::optional m_description; + boost::optional m_payment_id; monero_address_book_entry() {} - monero_address_book_entry(uint64_t index, const string& address, const string& description, const string& payment_id) : m_index(index), m_address(address), m_description(description), m_payment_id(payment_id) {} + monero_address_book_entry(uint64_t index, const std::string& address, const std::string& description, const std::string& payment_id) : m_index(index), m_address(address), m_description(description), m_payment_id(payment_id) {} rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; }; }