remove using namespace std and qualify std:: namespaces

This commit is contained in:
woodser
2020-05-18 16:24:22 -04:00
parent 583e11d663
commit dd31aa5d67
14 changed files with 1399 additions and 1418 deletions
-2
View File
@@ -54,8 +54,6 @@
#include "monero_daemon_model.h"
using namespace std;
/**
* Public library interface.
*/
+113 -113
View File
@@ -64,8 +64,8 @@ namespace monero {
// ----------------------- UNDECLARED PRIVATE HELPERS -----------------------
void merge_tx(vector<shared_ptr<monero_tx>>& txs, const shared_ptr<monero_tx>& tx) {
for (const shared_ptr<monero_tx>& aTx : txs) {
void merge_tx(std::vector<std::shared_ptr<monero_tx>>& txs, const std::shared_ptr<monero_tx>& tx) {
for (const std::shared_ptr<monero_tx>& 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<monero_block_header>& self, const shared_ptr<monero_block_header>& other) {
if (this != self.get()) throw runtime_error("this != self");
void monero_block_header::merge(const std::shared_ptr<monero_block_header>& self, const std::shared_ptr<monero_block_header>& 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<monero_block_header>& self, const shared_ptr<monero_block_header>& other) {
merge(static_pointer_cast<monero_block>(self), static_pointer_cast<monero_block>(other));
void monero_block::merge(const std::shared_ptr<monero_block_header>& self, const std::shared_ptr<monero_block_header>& other) {
merge(std::static_pointer_cast<monero_block>(self), std::static_pointer_cast<monero_block>(other));
}
void monero_block::merge(const shared_ptr<monero_block>& self, const shared_ptr<monero_block>& other) {
if (this != self.get()) throw runtime_error("this != self");
void monero_block::merge(const std::shared_ptr<monero_block>& self, const std::shared_ptr<monero_block>& 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<monero_tx> otherTx : other->m_txs) { // NOTE: not using reference so shared_ptr is not deleted when block is dereferenced
for (const std::shared_ptr<monero_tx> 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<monero_tx> tx) {
void monero_tx::from_property_tree(const boost::property_tree::ptree& node, std::shared_ptr<monero_tx> 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<bool>();
else if (key == string("paymentId")) tx->m_payment_id = it->second.data();
else if (key == string("fee")) tx->m_fee = it->second.get_value<uint64_t>();
else if (key == string("mixin")) throw runtime_error("mixin deserialization not implemented");
else if (key == string("relay")) tx->m_relay = it->second.get_value<bool>();
else if (key == string("isRelayed")) tx->m_is_relayed = it->second.get_value<bool>();
else if (key == string("isConfirmed")) tx->m_is_confirmed = it->second.get_value<bool>();
else if (key == string("inTxPool")) tx->m_in_tx_pool = it->second.get_value<bool>();
else if (key == string("numConfirmations")) tx->m_num_confirmations = it->second.get_value<uint64_t>();
else if (key == string("unlockTime")) tx->m_unlock_time = it->second.get_value<uint64_t>();
else if (key == string("lastRelayedTimestamp")) tx->m_last_relayed_timestamp = it->second.get_value<uint64_t>();
else if (key == string("receivedTimestamp")) tx->m_received_timestamp = it->second.get_value<uint64_t>();
else if (key == string("isDoubleSpendSeen")) tx->m_is_double_spend_seen = it->second.get_value<bool>();
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<bool>();
else if (key == string("isFailed")) tx->m_is_failed = it->second.get_value<bool>();
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<bool>();
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<uint64_t>();
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<bool>();
else if (key == std::string("isRelayed")) tx->m_is_relayed = it->second.get_value<bool>();
else if (key == std::string("isConfirmed")) tx->m_is_confirmed = it->second.get_value<bool>();
else if (key == std::string("inTxPool")) tx->m_in_tx_pool = it->second.get_value<bool>();
else if (key == std::string("numConfirmations")) tx->m_num_confirmations = it->second.get_value<uint64_t>();
else if (key == std::string("unlockTime")) tx->m_unlock_time = it->second.get_value<uint64_t>();
else if (key == std::string("lastRelayedTimestamp")) tx->m_last_relayed_timestamp = it->second.get_value<uint64_t>();
else if (key == std::string("receivedTimestamp")) tx->m_received_timestamp = it->second.get_value<uint64_t>();
else if (key == std::string("isDoubleSpendSeen")) tx->m_is_double_spend_seen = it->second.get_value<bool>();
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<bool>();
else if (key == std::string("isFailed")) tx->m_is_failed = it->second.get_value<bool>();
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> monero_tx::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const {
MTRACE("monero_tx::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt)");
std::shared_ptr<monero_tx> monero_tx::copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const {
MTRACE("monero_tx::copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& 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<shared_ptr<monero_output>>();
for (const shared_ptr<monero_output>& input : src->m_inputs) {
shared_ptr<monero_output> input_copy = input->copy(input, make_shared<monero_output>());
tgt->m_inputs = std::vector<std::shared_ptr<monero_output>>();
for (const std::shared_ptr<monero_output>& input : src->m_inputs) {
std::shared_ptr<monero_output> input_copy = input->copy(input, std::make_shared<monero_output>());
input_copy->m_tx = tgt;
tgt->m_inputs.push_back(input_copy);
}
}
if (!src->m_outputs.empty()) {
tgt->m_outputs = vector<shared_ptr<monero_output>>();
for (const shared_ptr<monero_output>& output : src->m_outputs) {
shared_ptr<monero_output> output_copy = output->copy(output, make_shared<monero_output>());
tgt->m_outputs = std::vector<std::shared_ptr<monero_output>>();
for (const std::shared_ptr<monero_output>& output : src->m_outputs) {
std::shared_ptr<monero_output> output_copy = output->copy(output, std::make_shared<monero_output>());
output_copy->m_tx = tgt;
tgt->m_outputs.push_back(output_copy);
}
}
if (!src->m_output_indices.empty()) tgt->m_output_indices = vector<uint32_t>(src->m_output_indices);
if (!src->m_output_indices.empty()) tgt->m_output_indices = std::vector<uint32_t>(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<string>(src->m_signatures);
if (!src->m_signatures.empty()) tgt->m_signatures = std::vector<std::string>(src->m_signatures);
return tgt;
}
@@ -400,19 +400,19 @@ namespace monero {
return *((*m_block)->m_height);
}
void monero_tx::merge(const shared_ptr<monero_tx>& self, const shared_ptr<monero_tx>& other) {
if (this != self.get()) throw runtime_error("this != self");
void monero_tx::merge(const std::shared_ptr<monero_tx>& self, const std::shared_ptr<monero_tx>& 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<monero_block>();
m_block = std::make_shared<monero_block>();
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<monero_block>();
other->m_block = std::make_shared<monero_block>();
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<monero_output>& merger : other->m_inputs) {
for (const std::shared_ptr<monero_output>& merger : other->m_inputs) {
bool merged = false;
merger->m_tx = self;
for (const shared_ptr<monero_output>& mergee : m_inputs) {
for (const std::shared_ptr<monero_output>& 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<monero_output>& output : other->m_outputs) output->m_tx = self;
for (const std::shared_ptr<monero_output>& 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<monero_output>& output : this->m_outputs) if (output->m_index != boost::none) num_indices++;
for (const shared_ptr<monero_output>& output : other->m_outputs) if (output->m_index != boost::none) num_indices++;
for (const std::shared_ptr<monero_output>& output : this->m_outputs) if (output->m_index != boost::none) num_indices++;
for (const std::shared_ptr<monero_output>& 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<monero_output>& merger : other->m_outputs) {
for (const std::shared_ptr<monero_output>& merger : other->m_outputs) {
bool merged = false;
merger->m_tx = self;
for (const shared_ptr<monero_output>& mergee : this->m_outputs) {
for (const std::shared_ptr<monero_output>& 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<monero_output> output : m_outputs) {
for (const std::shared_ptr<monero_output> 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<monero_output>& output : other->m_outputs) {
for (const std::shared_ptr<monero_output>& 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<monero_output>& merger : other->m_outputs) {
for (const std::shared_ptr<monero_output>& merger : other->m_outputs) {
bool merged = false;
merger->m_tx = self;
for (const shared_ptr<monero_output>& mergee : m_outputs) {
for (const std::shared_ptr<monero_output>& 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<monero_key_image>& key_image) {
void monero_key_image::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_key_image>& 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<shared_ptr<monero_key_image>> monero_key_image::deserialize_key_images(const string& key_images_json) {
std::vector<std::shared_ptr<monero_key_image>> 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<shared_ptr<monero_key_image>> key_images;
std::vector<std::shared_ptr<monero_key_image>> 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<monero_key_image> key_image = make_shared<monero_key_image>();
std::shared_ptr<monero_key_image> key_image = std::make_shared<monero_key_image>();
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> monero_key_image::copy(const shared_ptr<monero_key_image>& src, const shared_ptr<monero_key_image>& tgt) const {
if (this != src.get()) throw runtime_error("this != src");
std::shared_ptr<monero_key_image> monero_key_image::copy(const std::shared_ptr<monero_key_image>& src, const std::shared_ptr<monero_key_image>& 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<monero_key_image>& self, const shared_ptr<monero_key_image>& other) {
throw runtime_error("Not implemented");
void monero_key_image::merge(const std::shared_ptr<monero_key_image>& self, const std::shared_ptr<monero_key_image>& 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<monero_output>& output) {
void monero_output::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output>& 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<monero_key_image>();
std::string key = it->first;
if (key == std::string("keyImage")) {
output->m_key_image = std::make_shared<monero_key_image>();
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<uint64_t>();
else if (key == string("index")) output->m_index = it->second.get_value<uint32_t>();
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<uint64_t>();
else if (key == std::string("index")) output->m_index = it->second.get_value<uint32_t>();
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> monero_output::copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const {
if (this != src.get()) throw runtime_error("this != src");
std::shared_ptr<monero_output> monero_output::copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& 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<monero_key_image>());
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<monero_key_image>());
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<uint64_t>(src->m_ring_output_indices);
if (!src->m_ring_output_indices.empty()) tgt->m_ring_output_indices = std::vector<uint64_t>(src->m_ring_output_indices);
tgt->m_stealth_public_key = src->m_stealth_public_key;
return tgt;
}
void monero_output::merge(const shared_ptr<monero_output>& self, const shared_ptr<monero_output>& other) {
if (this != self.get()) throw runtime_error("this != self");
void monero_output::merge(const std::shared_ptr<monero_output>& self, const std::shared_ptr<monero_output>& 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
+54 -56
View File
@@ -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<string> m_uri;
boost::optional<string> m_username;
boost::optional<string> m_password;
boost::optional<std::string> m_uri;
boost::optional<std::string> m_username;
boost::optional<std::string> m_password;
monero_rpc_connection(const boost::optional<string>& uri = boost::none, const boost::optional<string>& username = boost::none, const boost::optional<string>& password = boost::none) : m_uri(uri), m_username(username), m_password(password) {}
monero_rpc_connection(const boost::optional<std::string>& uri = boost::none, const boost::optional<std::string>& username = boost::none, const boost::optional<std::string>& 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<string> m_hash;
boost::optional<std::string> m_hash;
boost::optional<uint64_t> m_height;
boost::optional<uint64_t> m_timestamp;
boost::optional<uint64_t> m_size;
@@ -139,41 +137,41 @@ namespace monero {
boost::optional<uint32_t> m_major_version;
boost::optional<uint32_t> m_minor_version;
boost::optional<uint32_t> m_nonce;
boost::optional<string> m_miner_tx_hash;
boost::optional<std::string> m_miner_tx_hash;
boost::optional<uint32_t> m_num_txs;
boost::optional<bool> m_orphan_status;
boost::optional<string> m_prev_hash;
boost::optional<std::string> m_prev_hash;
boost::optional<uint64_t> m_reward;
boost::optional<string> m_pow_hash;
boost::optional<std::string> m_pow_hash;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
virtual void merge(const shared_ptr<monero_block_header>& self, const shared_ptr<monero_block_header>& other);
virtual void merge(const std::shared_ptr<monero_block_header>& self, const std::shared_ptr<monero_block_header>& other);
};
/**
* Models a Monero block in the blockchain.
*/
struct monero_block : public monero_block_header {
boost::optional<string> m_hex;
boost::optional<shared_ptr<monero_tx>> m_miner_tx;
vector<shared_ptr<monero_tx>> m_txs;
vector<string> m_tx_hashes;
boost::optional<std::string> m_hex;
boost::optional<std::shared_ptr<monero_tx>> m_miner_tx;
std::vector<std::shared_ptr<monero_tx>> m_txs;
std::vector<std::string> m_tx_hashes;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
void merge(const shared_ptr<monero_block_header>& self, const shared_ptr<monero_block_header>& other);
void merge(const shared_ptr<monero_block>& self, const shared_ptr<monero_block>& other);
void merge(const std::shared_ptr<monero_block_header>& self, const std::shared_ptr<monero_block_header>& other);
void merge(const std::shared_ptr<monero_block>& self, const std::shared_ptr<monero_block>& 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<shared_ptr<monero_block>> m_block;
boost::optional<string> m_hash;
static const std::string DEFAULT_PAYMENT_ID; // default payment id "0000000000000000"
boost::optional<std::shared_ptr<monero_block>> m_block;
boost::optional<std::string> m_hash;
boost::optional<uint32_t> m_version;
boost::optional<bool> m_is_miner_tx;
boost::optional<string> m_payment_id;
boost::optional<std::string> m_payment_id;
boost::optional<uint64_t> m_fee;
boost::optional<uint32_t> m_ring_size;
boost::optional<bool> m_relay;
@@ -185,33 +183,33 @@ namespace monero {
boost::optional<uint64_t> m_last_relayed_timestamp;
boost::optional<uint64_t> m_received_timestamp;
boost::optional<bool> m_is_double_spend_seen;
boost::optional<string> m_key;
boost::optional<string> m_full_hex;
boost::optional<string> m_pruned_hex;
boost::optional<string> m_prunable_hex;
boost::optional<string> m_prunable_hash;
boost::optional<std::string> m_key;
boost::optional<std::string> m_full_hex;
boost::optional<std::string> m_pruned_hex;
boost::optional<std::string> m_prunable_hex;
boost::optional<std::string> m_prunable_hash;
boost::optional<uint64_t> m_size;
boost::optional<uint64_t> m_weight;
vector<shared_ptr<monero_output>> m_inputs;
vector<shared_ptr<monero_output>> m_outputs;
vector<uint32_t> m_output_indices;
boost::optional<string> m_metadata;
boost::optional<string> m_common_tx_sets;
vector<uint8_t> m_extra;
boost::optional<string> m_rct_signatures; // TODO: implement
boost::optional<string> m_rct_sig_prunable; // TODO: implement
std::vector<std::shared_ptr<monero_output>> m_inputs;
std::vector<std::shared_ptr<monero_output>> m_outputs;
std::vector<uint32_t> m_output_indices;
boost::optional<std::string> m_metadata;
boost::optional<std::string> m_common_tx_sets;
std::vector<uint8_t> m_extra;
boost::optional<std::string> m_rct_signatures; // TODO: implement
boost::optional<std::string> m_rct_sig_prunable; // TODO: implement
boost::optional<bool> m_is_kept_by_block;
boost::optional<bool> m_is_failed;
boost::optional<uint64_t> m_last_failed_height;
boost::optional<string> m_last_failed_hash;
boost::optional<std::string> m_last_failed_hash;
boost::optional<uint64_t> m_max_used_block_height;
boost::optional<string> m_max_used_block_hash;
vector<string> m_signatures;
boost::optional<std::string> m_max_used_block_hash;
std::vector<std::string> 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<monero_tx> tx);
shared_ptr<monero_tx> copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const;
virtual void merge(const shared_ptr<monero_tx>& self, const shared_ptr<monero_tx>& other);
static void from_property_tree(const boost::property_tree::ptree& node, std::shared_ptr<monero_tx> tx);
std::shared_ptr<monero_tx> copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const;
virtual void merge(const std::shared_ptr<monero_tx>& self, const std::shared_ptr<monero_tx>& other);
boost::optional<uint64_t> get_height() const;
};
@@ -219,30 +217,30 @@ namespace monero {
* Models a Monero key image.
*/
struct monero_key_image : public serializable_struct {
boost::optional<string> m_hex;
boost::optional<string> m_signature;
boost::optional<std::string> m_hex;
boost::optional<std::string> 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<monero_key_image>& key_image);
static vector<shared_ptr<monero_key_image>> deserialize_key_images(const string& key_images_json); // TODO: remove this specialty util used once
shared_ptr<monero_key_image> copy(const shared_ptr<monero_key_image>& src, const shared_ptr<monero_key_image>& tgt) const;
void merge(const shared_ptr<monero_key_image>& self, const shared_ptr<monero_key_image>& other);
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_key_image>& key_image);
static std::vector<std::shared_ptr<monero_key_image>> deserialize_key_images(const std::string& key_images_json); // TODO: remove this specialty util used once
std::shared_ptr<monero_key_image> copy(const std::shared_ptr<monero_key_image>& src, const std::shared_ptr<monero_key_image>& tgt) const;
void merge(const std::shared_ptr<monero_key_image>& self, const std::shared_ptr<monero_key_image>& other);
};
/**
* Models a Monero transaction output.
*/
struct monero_output : public serializable_struct {
shared_ptr<monero_tx> m_tx;
boost::optional<shared_ptr<monero_key_image>> m_key_image;
std::shared_ptr<monero_tx> m_tx;
boost::optional<std::shared_ptr<monero_key_image>> m_key_image;
boost::optional<uint64_t> m_amount;
boost::optional<uint64_t> m_index;
vector<uint64_t> m_ring_output_indices;
boost::optional<string> m_stealth_public_key;
std::vector<uint64_t> m_ring_output_indices;
boost::optional<std::string> 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<monero_output>& output);
shared_ptr<monero_output> copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const;
virtual void merge(const shared_ptr<monero_output>& self, const shared_ptr<monero_output>& other);
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output>& output);
std::shared_ptr<monero_output> copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const;
virtual void merge(const std::shared_ptr<monero_output>& self, const std::shared_ptr<monero_output>& other);
};
}
-2
View File
@@ -51,5 +51,3 @@
*/
#include "gen_utils.h"
using namespace std;
+15 -17
View File
@@ -62,13 +62,11 @@
*/
namespace gen_utils
{
using namespace std;
// ------------------------- VALUE RECONCILATION- ---------------------------
// TODO: refactor common template code
template <class T, typename std::enable_if<std::is_same<T, string>::value, T>::type* = nullptr>
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, boost::optional<bool> resolve_defined, boost::optional<bool> resolve_true, boost::optional<bool> resolve_max, const string& err_msg = "") {
template <class T, typename std::enable_if<std::is_same<T, std::string>::value, T>::type* = nullptr>
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, boost::optional<bool> resolve_defined, boost::optional<bool> resolve_true, boost::optional<bool> 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 <class T, typename std::enable_if<std::is_same<T, string>::value, T>::type* = nullptr>
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, const string& err_msg = "") {
template <class T, typename std::enable_if<std::is_same<T, std::string>::value, T>::type* = nullptr>
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, const std::string& err_msg = "") {
return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg);
}
template <class T, typename std::enable_if<std::is_integral<T>::value, T>::type* = nullptr>
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, boost::optional<bool> resolve_defined, boost::optional<bool> resolve_true, boost::optional<bool> resolve_max, const string& err_msg = "") {
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, boost::optional<bool> resolve_defined, boost::optional<bool> resolve_true, boost::optional<bool> 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 <class T, typename std::enable_if<std::is_integral<T>::value, T>::type* = nullptr>
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, const string& err_msg = "") {
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, const std::string& err_msg = "") {
return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg);
}
template <class T, typename std::enable_if<std::is_same<T, bool>::value, T>::type>
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, boost::optional<bool> resolve_defined, boost::optional<bool> resolve_true, boost::optional<bool> resolve_max, const string& err_msg = "") {
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, boost::optional<bool> resolve_defined, boost::optional<bool> resolve_true, boost::optional<bool> 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 <class T, typename std::enable_if<std::is_same<T, bool>::value, T>::type>
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, const string& err_msg = "") {
boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2, const std::string& err_msg = "") {
return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg);
}
template <class T>
vector<T> reconcile(const vector<T>& v1, const vector<T>& v2, const string& err_msg = "") {
std::vector<T> reconcile(const std::vector<T>& v1, const std::vector<T>& 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 */
+25 -26
View File
@@ -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<rapidjson::StringBuffer> 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<string>& strs) {
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<std::string>& 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<uint8_t>& nums) {
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint8_t>& 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<uint32_t>& nums) {
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint32_t>& 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<uint64_t>& nums) {
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint64_t>& 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_block> monero_utils::cn_block_to_block(const cryptonote::block& cn_block) {
std::shared_ptr<monero_block> 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<monero_block> block = make_shared<monero_block>();
std::cout << cryptonote::obj_to_json_str(temp) << std::endl;
std::shared_ptr<monero_block> block = std::make_shared<monero_block>();
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_block> monero_utils::cn_block_to_block(const cryptonote::block
return block;
}
shared_ptr<monero_tx> monero_utils::cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet) {
shared_ptr<monero_tx> tx = init_as_tx_wallet ? make_shared<monero_tx_wallet>() : make_shared<monero_tx>();
std::shared_ptr<monero_tx> monero_utils::cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet) {
std::shared_ptr<monero_tx> tx = init_as_tx_wallet ? std::make_shared<monero_tx_wallet>() : std::make_shared<monero_tx>();
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_tx> 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<monero_output> input = init_as_tx_wallet ? make_shared<monero_output_wallet>() : make_shared<monero_output>();
std::shared_ptr<monero_output> input = init_as_tx_wallet ? std::make_shared<monero_output_wallet>() : std::make_shared<monero_output>();
input->m_tx = tx;
tx->m_inputs.push_back(input);
const txin_to_key& txin = boost::get<txin_to_key>(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<monero_key_image>();
input->m_key_image = std::make_shared<monero_key_image>();
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<monero_output> output = init_as_tx_wallet ? make_shared<monero_output_wallet>() : make_shared<monero_output>();
std::shared_ptr<monero_output> output = init_as_tx_wallet ? std::make_shared<monero_output_wallet>() : std::make_shared<monero_output>();
output->m_tx = tx;
tx->m_outputs.push_back(output);
output->m_amount = cnVout.amount;
+25 -26
View File
@@ -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 <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<shared_ptr<T>>& vals) {
template <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<std::shared_ptr<T>>& 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 <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<T>& vals) {
template <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<T>& 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<string>& strs);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint8_t>& nums);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint32_t>& nums);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint64_t>& nums);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<std::string>& strs);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint8_t>& nums);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint32_t>& nums);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint64_t>& 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<monero_block> cn_block_to_block(const cryptonote::block& cn_block);
std::shared_ptr<monero_block> 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<monero_tx> cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet = false);
std::shared_ptr<monero_tx> 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<monero_block> block) {
for (shared_ptr<monero_tx>& tx : block->m_txs) {
static void free(std::shared_ptr<monero_block> block) {
for (std::shared_ptr<monero_tx>& tx : block->m_txs) {
tx->m_block.reset();
monero_tx_wallet* tx_wallet = dynamic_cast<monero_tx_wallet*>(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<monero_transfer> transfer : tx_wallet->m_incoming_transfers) transfer->m_tx.reset();
for (shared_ptr<monero_output> output : tx_wallet->m_outputs) output->m_tx.reset();
for (shared_ptr<monero_output> input : tx_wallet->m_inputs) {
for (std::shared_ptr<monero_transfer> transfer : tx_wallet->m_incoming_transfers) transfer->m_tx.reset();
for (std::shared_ptr<monero_output> output : tx_wallet->m_outputs) output->m_tx.reset();
for (std::shared_ptr<monero_output> 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<shared_ptr<monero_block>> blocks) {
for (shared_ptr<monero_block>& block : blocks) monero_utils::free(block);
static void free(std::vector<std::shared_ptr<monero_block>> blocks) {
for (std::shared_ptr<monero_block>& block : blocks) monero_utils::free(block);
}
}
#endif /* monero_utils_h */
+187 -188
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+77 -79
View File
@@ -59,8 +59,6 @@
#include <boost/thread/thread.hpp>
#include <boost/thread/condition_variable.hpp>
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<epee::net_utils::http::http_client_factory> 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<epee::net_utils::http::http_client_factory> 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<epee::net_utils::http::http_client_factory> 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<epee::net_utils::http::http_client_factory> 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<epee::net_utils::http::http_client_factory> 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<epee::net_utils::http::http_client_factory> 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<epee::net_utils::http::http_client_factory> 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<epee::net_utils::http::http_client_factory> 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<string> get_mnemonic_languages();
static std::vector<std::string> 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<monero_rpc_connection>& connection) override;
boost::optional<monero_rpc_connection> 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<monero_wallet_listener*> get_listeners() override;
std::set<monero_wallet_listener*> 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<monero_account> get_accounts(bool include_subaddresses, const string& tag) const override;
std::vector<monero_account> 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<monero_subaddress> get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const override;
monero_subaddress create_subaddress(uint32_t account_idx, const string& label = "") override;
vector<shared_ptr<monero_tx_wallet>> get_txs() const override;
vector<shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query) const override;
vector<shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query, vector<string>& missing_tx_hashes) const override;
vector<shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const override;
vector<shared_ptr<monero_output_wallet>> 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<shared_ptr<monero_key_image>> get_key_images() const override;
shared_ptr<monero_key_image_import_result> import_key_images(const vector<shared_ptr<monero_key_image>>& key_images) override;
vector<shared_ptr<monero_tx_wallet>> create_txs(const monero_tx_config& config) override;
vector<shared_ptr<monero_tx_wallet>> sweep_unlocked(const monero_tx_config& config) override;
shared_ptr<monero_tx_wallet> sweep_output(const monero_tx_config& config) override;
vector<shared_ptr<monero_tx_wallet>> sweep_dust(bool relay = false) override;
vector<string> relay_txs(const vector<string>& tx_metadatas) override;
monero_account create_account(const std::string& label = "") override;
std::vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const override;
monero_subaddress create_subaddress(uint32_t account_idx, const std::string& label = "") override;
std::vector<std::shared_ptr<monero_tx_wallet>> get_txs() const override;
std::vector<std::shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query) const override;
std::vector<std::shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query, std::vector<std::string>& missing_tx_hashes) const override;
std::vector<std::shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const override;
std::vector<std::shared_ptr<monero_output_wallet>> 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<std::shared_ptr<monero_key_image>> get_key_images() const override;
std::shared_ptr<monero_key_image_import_result> import_key_images(const std::vector<std::shared_ptr<monero_key_image>>& key_images) override;
std::vector<std::shared_ptr<monero_tx_wallet>> create_txs(const monero_tx_config& config) override;
std::vector<std::shared_ptr<monero_tx_wallet>> sweep_unlocked(const monero_tx_config& config) override;
std::shared_ptr<monero_tx_wallet> sweep_output(const monero_tx_config& config) override;
std::vector<std::shared_ptr<monero_tx_wallet>> sweep_dust(bool relay = false) override;
std::vector<std::string> relay_txs(const std::vector<std::string>& 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<string> 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<monero_check_tx> 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<monero_check_tx> 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<monero_check_reserve> 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<string> get_tx_notes(const vector<string>& tx_hashes) const override;
void set_tx_note(const string& tx_hash, const string& note) override;
void set_tx_notes(const vector<string>& tx_hashes, const vector<string>& notes) override;
vector<monero_address_book_entry> get_address_book_entries(const vector<uint64_t>& 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<std::string> 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<monero_check_tx> 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<monero_check_tx> 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<monero_check_reserve> 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<std::string> get_tx_notes(const std::vector<std::string>& 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<std::string>& tx_hashes, const std::vector<std::string>& notes) override;
std::vector<monero_address_book_entry> get_address_book_entries(const std::vector<uint64_t>& 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<monero_tx_config> 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<monero_tx_config> 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<uint64_t> num_threads, boost::optional<bool> background_mining, boost::optional<bool> 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<string>& multisig_hexes, int threshold, const string& password) override;
monero_multisig_init_result exchange_multisig_keys(const vector<string>& mutisig_hexes, const string& password) override;
string get_multisig_hex() override;
int import_multisig_hex(const vector<string>& multisig_hexes) override;
monero_multisig_sign_result sign_multisig_tx_hex(const string& multisig_tx_hex) override;
vector<string> 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<std::string>& multisig_hexes, int threshold, const std::string& password) override;
monero_multisig_init_result exchange_multisig_keys(const std::vector<std::string>& mutisig_hexes, const std::string& password) override;
std::string get_multisig_hex() override;
int import_multisig_hex(const std::vector<std::string>& multisig_hexes) override;
monero_multisig_sign_result sign_multisig_tx_hex(const std::string& multisig_tx_hex) override;
std::vector<std::string> 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<tools::wallet2> m_w2; // internal wallet implementation
unique_ptr<wallet2_listener> m_w2_listener; // internal wallet implementation listener
set<monero_wallet_listener*> m_listeners; // external wallet listeners
std::unique_ptr<tools::wallet2> m_w2; // internal wallet implementation
std::unique_ptr<wallet2_listener> m_w2_listener; // internal wallet implementation listener
std::set<monero_wallet_listener*> m_listeners; // external wallet listeners
void init_common();
vector<monero_subaddress> get_subaddresses_aux(uint32_t account_idx, const vector<uint32_t>& subaddress_indices, const vector<tools::wallet2::transfer_details>& transfers) const;
vector<shared_ptr<monero_transfer>> get_transfers_aux(const monero_transfer_query& query) const;
vector<shared_ptr<monero_output_wallet>> get_outputs_aux(const monero_output_query& query) const;
vector<shared_ptr<monero_tx_wallet>> sweep_account(const monero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked()
std::vector<monero_subaddress> get_subaddresses_aux(uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices, const std::vector<tools::wallet2::transfer_details>& transfers) const;
std::vector<std::shared_ptr<monero_transfer>> get_transfers_aux(const monero_transfer_query& query) const;
std::vector<std::shared_ptr<monero_output_wallet>> get_outputs_aux(const monero_output_query& query) const;
std::vector<std::shared_ptr<monero_tx_wallet>> sweep_account(const monero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked()
// blockchain sync management
mutable std::atomic<bool> m_is_synced; // whether or not wallet is synced
+44 -45
View File
@@ -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<cryptonote::network_type>(network_type), address)) throw runtime_error("failed to parse address");
if (!cryptonote::get_account_address_from_str(info, static_cast<cryptonote::network_type>(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<const crypto::secret_key*>(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<const crypto::secret_key*>(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<string> monero_wallet_keys::get_mnemonic_languages() {
vector<string> languages;
std::vector<std::string> monero_wallet_keys::get_mnemonic_languages() {
std::vector<std::string> 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<cryptonote::network_type>(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_subaddress> monero_wallet_keys::get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const {
std::vector<monero_subaddress> monero_wallet_keys::get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& 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<monero_subaddress> subaddresses;
std::vector<monero_subaddress> 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
}
+24 -25
View File
@@ -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<string> get_mnemonic_languages();
static std::vector<std::string> 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<monero_subaddress> get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& 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<monero_subaddress> get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& 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();
};
+222 -224
View File
@@ -56,8 +56,6 @@
#include "utils/monero_utils.h"
#include <iostream>
using namespace std;
/**
* Public library interface.
*/
@@ -65,8 +63,8 @@ namespace monero {
// ----------------------- UNDECLARED PRIVATE HELPERS -----------------------
void merge_incoming_transfer(vector<shared_ptr<monero_incoming_transfer>>& transfers, const shared_ptr<monero_incoming_transfer>& transfer) {
for (const shared_ptr<monero_incoming_transfer>& aTransfer : transfers) {
void merge_incoming_transfer(std::vector<std::shared_ptr<monero_incoming_transfer>>& transfers, const std::shared_ptr<monero_incoming_transfer>& transfer) {
for (const std::shared_ptr<monero_incoming_transfer>& 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<monero_block> node_to_block_query(const boost::property_tree::ptree& node) {
shared_ptr<monero_block> block = make_shared<monero_block>();
std::shared_ptr<monero_block> node_to_block_query(const boost::property_tree::ptree& node) {
std::shared_ptr<monero_block> block = std::make_shared<monero_block>();
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<monero_tx_query> tx_query = make_shared<monero_tx_query>();
std::shared_ptr<monero_tx_query> tx_query = std::make_shared<monero_tx_query>();
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<monero_tx_wallet>& tx_wallet) {
void monero_tx_wallet::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_wallet>& 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<bool>();
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<bool>();
// TODO: deserialize other fields
}
}
shared_ptr<monero_tx_wallet> monero_tx_wallet::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const {
MTRACE("monero_tx_wallet::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt)");
return monero_tx_wallet::copy(static_pointer_cast<monero_tx_wallet>(src), static_pointer_cast<monero_tx_wallet>(tgt));
std::shared_ptr<monero_tx_wallet> monero_tx_wallet::copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const {
MTRACE("monero_tx_wallet::copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt)");
return monero_tx_wallet::copy(std::static_pointer_cast<monero_tx_wallet>(src), std::static_pointer_cast<monero_tx_wallet>(tgt));
};
shared_ptr<monero_tx_wallet> monero_tx_wallet::copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt) const {
MTRACE("monero_tx_wallet::copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
std::shared_ptr<monero_tx_wallet> monero_tx_wallet::copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt) const {
MTRACE("monero_tx_wallet::copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt)");
if (this != src.get()) throw std::runtime_error("this != src");
// copy base class
monero_tx::copy(static_pointer_cast<monero_tx>(src), static_pointer_cast<monero_tx>(tgt));
monero_tx::copy(std::static_pointer_cast<monero_tx>(src), std::static_pointer_cast<monero_tx>(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<shared_ptr<monero_incoming_transfer>>();
for (const shared_ptr<monero_incoming_transfer>& transfer : src->m_incoming_transfers) {
shared_ptr<monero_incoming_transfer> transfer_copy = transfer->copy(transfer, make_shared<monero_incoming_transfer>());
tgt->m_incoming_transfers = std::vector<std::shared_ptr<monero_incoming_transfer>>();
for (const std::shared_ptr<monero_incoming_transfer>& transfer : src->m_incoming_transfers) {
std::shared_ptr<monero_incoming_transfer> transfer_copy = transfer->copy(transfer, std::make_shared<monero_incoming_transfer>());
transfer_copy->m_tx = tgt;
tgt->m_incoming_transfers.push_back(transfer_copy);
}
}
if (src->m_outgoing_transfer != boost::none) {
shared_ptr<monero_outgoing_transfer> transferCopy = src->m_outgoing_transfer.get()->copy(src->m_outgoing_transfer.get(), make_shared<monero_outgoing_transfer>());
std::shared_ptr<monero_outgoing_transfer> transferCopy = src->m_outgoing_transfer.get()->copy(src->m_outgoing_transfer.get(), std::make_shared<monero_outgoing_transfer>());
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<monero_tx>& self, const shared_ptr<monero_tx>& other) {
merge(static_pointer_cast<monero_tx_wallet>(self), static_pointer_cast<monero_tx_wallet>(other));
void monero_tx_wallet::merge(const std::shared_ptr<monero_tx>& self, const std::shared_ptr<monero_tx>& other) {
merge(std::static_pointer_cast<monero_tx_wallet>(self), std::static_pointer_cast<monero_tx_wallet>(other));
}
void monero_tx_wallet::merge(const shared_ptr<monero_tx_wallet>& self, const shared_ptr<monero_tx_wallet>& other) {
if (this != self.get()) throw runtime_error("this != self");
void monero_tx_wallet::merge(const std::shared_ptr<monero_tx_wallet>& self, const std::shared_ptr<monero_tx_wallet>& 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<monero_incoming_transfer>& transfer : other->m_incoming_transfers) { // NOTE: not using reference so shared_ptr is not deleted when tx is dereferenced
for (const std::shared_ptr<monero_incoming_transfer>& 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<shared_ptr<monero_transfer>> monero_tx_wallet::get_transfers() const {
std::vector<std::shared_ptr<monero_transfer>> monero_tx_wallet::get_transfers() const {
monero_transfer_query query;
return get_transfers(query);
}
vector<shared_ptr<monero_transfer>> monero_tx_wallet::get_transfers(const monero_transfer_query& query) const {
vector<shared_ptr<monero_transfer>> transfers;
std::vector<std::shared_ptr<monero_transfer>> monero_tx_wallet::get_transfers(const monero_transfer_query& query) const {
std::vector<std::shared_ptr<monero_transfer>> 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<monero_transfer>& transfer : m_incoming_transfers) if (query.meets_criteria(transfer.get())) transfers.push_back(transfer);
for (const std::shared_ptr<monero_transfer>& transfer : m_incoming_transfers) if (query.meets_criteria(transfer.get())) transfers.push_back(transfer);
return transfers;
}
vector<shared_ptr<monero_transfer>> monero_tx_wallet::filter_transfers(const monero_transfer_query& query) {
std::vector<std::shared_ptr<monero_transfer>> monero_tx_wallet::filter_transfers(const monero_transfer_query& query) {
// collect outgoing transfer, erase if excluded
vector<shared_ptr<monero_transfer>> transfers;
std::vector<std::shared_ptr<monero_transfer>> 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<shared_ptr<monero_incoming_transfer>>::iterator iter = m_incoming_transfers.begin();
std::vector<std::shared_ptr<monero_incoming_transfer>>::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<shared_ptr<monero_output_wallet>> monero_tx_wallet::get_outputs_wallet() const {
std::vector<std::shared_ptr<monero_output_wallet>> monero_tx_wallet::get_outputs_wallet() const {
monero_output_query query;
return get_outputs_wallet(query);
}
vector<shared_ptr<monero_output_wallet>> monero_tx_wallet::get_outputs_wallet(const monero_output_query& query) const {
vector<shared_ptr<monero_output_wallet>> outputs;
for (const shared_ptr<monero_output>& output : m_outputs) {
shared_ptr<monero_output_wallet> output_wallet = dynamic_pointer_cast<monero_output_wallet>(output);
std::vector<std::shared_ptr<monero_output_wallet>> monero_tx_wallet::get_outputs_wallet(const monero_output_query& query) const {
std::vector<std::shared_ptr<monero_output_wallet>> outputs;
for (const std::shared_ptr<monero_output>& output : m_outputs) {
std::shared_ptr<monero_output_wallet> output_wallet = std::dynamic_pointer_cast<monero_output_wallet>(output);
if (query.meets_criteria(output_wallet.get())) outputs.push_back(output_wallet);
}
return outputs;
}
vector<shared_ptr<monero_output_wallet>> monero_tx_wallet::filter_outputs_wallet(const monero_output_query& query) {
vector<shared_ptr<monero_output_wallet>> outputs;
vector<shared_ptr<monero_output>>::iterator iter = m_outputs.begin();
std::vector<std::shared_ptr<monero_output_wallet>> monero_tx_wallet::filter_outputs_wallet(const monero_output_query& query) {
std::vector<std::shared_ptr<monero_output_wallet>> outputs;
std::vector<std::shared_ptr<monero_output>>::iterator iter = m_outputs.begin();
while (iter != m_outputs.end()) {
shared_ptr<monero_output_wallet> output_wallet = dynamic_pointer_cast<monero_output_wallet>(*iter);
std::shared_ptr<monero_output_wallet> output_wallet = std::dynamic_pointer_cast<monero_output_wallet>(*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<monero_tx_query>& tx_query) {
void monero_tx_query::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_query>& 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<bool>();
else if (key == string("isIncoming")) tx_query->m_is_incoming = it->second.get_value<bool>();
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<bool>();
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<uint64_t>();
else if (key == string("minHeight")) tx_query->m_min_height = it->second.get_value<uint64_t>();
else if (key == string("maxHeight")) tx_query->m_max_height = it->second.get_value<uint64_t>();
else if (key == string("includeOutputs")) tx_query->m_include_outputs = it->second.get_value<bool>();
else if (key == string("transferQuery")) {
tx_query->m_transfer_query = make_shared<monero_transfer_query>();
std::string key = it->first;
if (key == std::string("isOutgoing")) tx_query->m_is_outgoing = it->second.get_value<bool>();
else if (key == std::string("isIncoming")) tx_query->m_is_incoming = it->second.get_value<bool>();
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<bool>();
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<uint64_t>();
else if (key == std::string("minHeight")) tx_query->m_min_height = it->second.get_value<uint64_t>();
else if (key == std::string("maxHeight")) tx_query->m_max_height = it->second.get_value<uint64_t>();
else if (key == std::string("includeOutputs")) tx_query->m_include_outputs = it->second.get_value<bool>();
else if (key == std::string("transferQuery")) {
tx_query->m_transfer_query = std::make_shared<monero_transfer_query>();
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<monero_output_query>();
else if (key == std::string("outputQuery")) {
tx_query->m_output_query = std::make_shared<monero_output_query>();
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> monero_tx_query::deserialize_from_block(const string& tx_query_json) {
std::shared_ptr<monero_tx_query> 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<monero_block> block = node_to_block_query(block_node);
std::shared_ptr<monero_block> block = node_to_block_query(block_node);
// get tx query
shared_ptr<monero_tx_query> tx_query = static_pointer_cast<monero_tx_query>(block->m_txs[0]);
std::shared_ptr<monero_tx_query> tx_query = std::static_pointer_cast<monero_tx_query>(block->m_txs[0]);
// return deserialized query
return tx_query;
}
shared_ptr<monero_tx_query> monero_tx_query::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const {
return copy(static_pointer_cast<monero_tx_query>(src), static_pointer_cast<monero_tx_query>(tgt));
std::shared_ptr<monero_tx_query> monero_tx_query::copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const {
return copy(std::static_pointer_cast<monero_tx_query>(src), std::static_pointer_cast<monero_tx_query>(tgt));
};
shared_ptr<monero_tx_query> monero_tx_query::copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt) const {
return copy(static_pointer_cast<monero_tx_query>(src), static_pointer_cast<monero_tx_query>(tgt));
std::shared_ptr<monero_tx_query> monero_tx_query::copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt) const {
return copy(std::static_pointer_cast<monero_tx_query>(src), std::static_pointer_cast<monero_tx_query>(tgt));
};
shared_ptr<monero_tx_query> monero_tx_query::copy(const shared_ptr<monero_tx_query>& src, const shared_ptr<monero_tx_query>& tgt) const {
MTRACE("monero_tx_query::copy(const shared_ptr<monero_tx_query>& src, const shared_ptr<monero_tx_query>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
std::shared_ptr<monero_tx_query> monero_tx_query::copy(const std::shared_ptr<monero_tx_query>& src, const std::shared_ptr<monero_tx_query>& tgt) const {
MTRACE("monero_tx_query::copy(const std::shared_ptr<monero_tx_query>& src, const std::shared_ptr<monero_tx_query>& tgt)");
if (this != src.get()) throw std::runtime_error("this != src");
// copy base class
monero_tx_wallet::copy(static_pointer_cast<monero_tx>(src), static_pointer_cast<monero_tx>(tgt));
monero_tx_wallet::copy(std::static_pointer_cast<monero_tx>(src), std::static_pointer_cast<monero_tx>(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<string>(src->m_hashes);
if (!src->m_hashes.empty()) tgt->m_hashes = std::vector<std::string>(src->m_hashes);
tgt-> m_has_payment_id = src->m_has_payment_id;
if (!src->m_payment_ids.empty()) tgt->m_payment_ids = vector<string>(src->m_payment_ids);
if (!src->m_payment_ids.empty()) tgt->m_payment_ids = std::vector<std::string>(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<monero_transfer_query>());
tgt->m_transfer_query = src->m_transfer_query.get()->copy(src->m_transfer_query.get(), std::make_shared<monero_transfer_query>());
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<monero_output_query>());
tgt->m_output_query = src->m_output_query.get()->copy(src->m_output_query.get(), std::make_shared<monero_output_query>());
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<monero_incoming_transfer>& incoming_transfer : tx->m_incoming_transfers) {
for (const std::shared_ptr<monero_incoming_transfer>& 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<monero_output>& output : tx->m_outputs) {
shared_ptr<monero_output_wallet> vout_wallet = static_pointer_cast<monero_output_wallet>(output);
for (const std::shared_ptr<monero_output>& output : tx->m_outputs) {
std::shared_ptr<monero_output_wallet> vout_wallet = std::static_pointer_cast<monero_output_wallet>(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<monero_destination>& destination) {
void monero_destination::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_destination>& 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<uint64_t>();
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<uint64_t>();
}
}
shared_ptr<monero_destination> monero_destination::copy(const shared_ptr<monero_destination>& src, const shared_ptr<monero_destination>& tgt) const {
MTRACE("monero_destination::copy(const shared_ptr<monero_destination>& src, const shared_ptr<monero_destination>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
std::shared_ptr<monero_destination> monero_destination::copy(const std::shared_ptr<monero_destination>& src, const std::shared_ptr<monero_destination>& tgt) const {
MTRACE("monero_destination::copy(const std::shared_ptr<monero_destination>& src, const std::shared_ptr<monero_destination>& 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<monero_tx_wallet> tx_wallet = make_shared<monero_tx_wallet>();
std::shared_ptr<monero_tx_wallet> tx_wallet = std::make_shared<monero_tx_wallet>();
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<monero_transfer>& transfer) {
void monero_transfer::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_transfer>& 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<uint32_t>();
std::string key = it->first;
if (key == std::string("accountIndex")) transfer->m_account_index = it->second.get_value<uint32_t>();
}
}
shared_ptr<monero_transfer> monero_transfer::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const {
MTRACE("monero_transfer::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt)");
std::shared_ptr<monero_transfer> monero_transfer::copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const {
MTRACE("monero_transfer::copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& 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<monero_transfer>& self, const shared_ptr<monero_transfer>& other) {
if (this != self.get()) throw runtime_error("this != self");
void monero_transfer::merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& 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> monero_incoming_transfer::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const {
return copy(static_pointer_cast<monero_incoming_transfer>(src), static_pointer_cast<monero_incoming_transfer>(tgt));
std::shared_ptr<monero_incoming_transfer> monero_incoming_transfer::copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const {
return copy(std::static_pointer_cast<monero_incoming_transfer>(src), std::static_pointer_cast<monero_incoming_transfer>(tgt));
}
shared_ptr<monero_incoming_transfer> monero_incoming_transfer::copy(const shared_ptr<monero_incoming_transfer>& src, const shared_ptr<monero_incoming_transfer>& tgt) const {
cout << "monero_incoming_transfer::copy()" << endl;
throw runtime_error("monero_incoming_transfer::copy(inTransfer) not implemented");
std::shared_ptr<monero_incoming_transfer> monero_incoming_transfer::copy(const std::shared_ptr<monero_incoming_transfer>& src, const std::shared_ptr<monero_incoming_transfer>& tgt) const {
std::cout << "monero_incoming_transfer::copy()" << std::endl;
throw std::runtime_error("monero_incoming_transfer::copy(inTransfer) not implemented");
};
boost::optional<bool> monero_incoming_transfer::is_incoming() const { return true; }
void monero_incoming_transfer::merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other) {
merge(static_pointer_cast<monero_incoming_transfer>(self), static_pointer_cast<monero_incoming_transfer>(other));
void monero_incoming_transfer::merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other) {
merge(std::static_pointer_cast<monero_incoming_transfer>(self), std::static_pointer_cast<monero_incoming_transfer>(other));
}
void monero_incoming_transfer::merge(const shared_ptr<monero_incoming_transfer>& self, const shared_ptr<monero_incoming_transfer>& other) {
void monero_incoming_transfer::merge(const std::shared_ptr<monero_incoming_transfer>& self, const std::shared_ptr<monero_incoming_transfer>& 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> monero_outgoing_transfer::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const {
return copy(static_pointer_cast<monero_outgoing_transfer>(src), static_pointer_cast<monero_outgoing_transfer>(tgt));
std::shared_ptr<monero_outgoing_transfer> monero_outgoing_transfer::copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const {
return copy(std::static_pointer_cast<monero_outgoing_transfer>(src), std::static_pointer_cast<monero_outgoing_transfer>(tgt));
};
shared_ptr<monero_outgoing_transfer> monero_outgoing_transfer::copy(const shared_ptr<monero_outgoing_transfer>& src, const shared_ptr<monero_outgoing_transfer>& 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> monero_outgoing_transfer::copy(const std::shared_ptr<monero_outgoing_transfer>& src, const std::shared_ptr<monero_outgoing_transfer>& tgt) const {
std::cout << "monero_outgoing_transfer::copy()" << std::endl;
throw std::runtime_error("monero_outgoing_transfer::copy(out_transfer) not implemented");
};
boost::optional<bool> monero_outgoing_transfer::is_incoming() const { return false; }
void monero_outgoing_transfer::merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other) {
merge(static_pointer_cast<monero_outgoing_transfer>(self), static_pointer_cast<monero_outgoing_transfer>(other));
void monero_outgoing_transfer::merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other) {
merge(std::static_pointer_cast<monero_outgoing_transfer>(self), std::static_pointer_cast<monero_outgoing_transfer>(other));
}
void monero_outgoing_transfer::merge(const shared_ptr<monero_outgoing_transfer>& self, const shared_ptr<monero_outgoing_transfer>& other) {
void monero_outgoing_transfer::merge(const std::shared_ptr<monero_outgoing_transfer>& self, const std::shared_ptr<monero_outgoing_transfer>& 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<monero_transfer_query>& transfer_query) {
void monero_transfer_query::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_transfer_query>& 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<bool>();
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<uint32_t>();
else if (key == string("subaddressIndices")) {
vector<uint32_t> m_subaddress_indices;
std::string key = it->first;
if (key == std::string("isIncoming")) transfer_query->m_is_incoming = it->second.get_value<bool>();
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<uint32_t>();
else if (key == std::string("subaddressIndices")) {
std::vector<uint32_t> m_subaddress_indices;
for (const auto& child : it->second) m_subaddress_indices.push_back(child.second.get_value<uint32_t>());
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<bool>();
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<bool>();
else if (key == std::string("txQuery")) throw std::runtime_error("txQuery not implemented");
}
}
shared_ptr<monero_transfer_query> monero_transfer_query::deserialize_from_block(const string& transfer_query_json) {
std::shared_ptr<monero_transfer_query> 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<monero_block> block = node_to_block_query(blockNode);
std::shared_ptr<monero_block> block = node_to_block_query(blockNode);
// return empty query if no txs
if (block->m_txs.empty()) return make_shared<monero_transfer_query>();
if (block->m_txs.empty()) return std::make_shared<monero_transfer_query>();
// get tx query
shared_ptr<monero_tx_query> tx_query = static_pointer_cast<monero_tx_query>(block->m_txs[0]);
std::shared_ptr<monero_tx_query> tx_query = std::static_pointer_cast<monero_tx_query>(block->m_txs[0]);
// get / create transfer query
shared_ptr<monero_transfer_query> transfer_query = tx_query->m_transfer_query == boost::none ? make_shared<monero_transfer_query>() : *tx_query->m_transfer_query;
std::shared_ptr<monero_transfer_query> transfer_query = tx_query->m_transfer_query == boost::none ? std::make_shared<monero_transfer_query>() : *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> monero_transfer_query::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const {
return copy(static_pointer_cast<monero_transfer_query>(src), static_pointer_cast<monero_transfer>(tgt));
std::shared_ptr<monero_transfer_query> monero_transfer_query::copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const {
return copy(std::static_pointer_cast<monero_transfer_query>(src), std::static_pointer_cast<monero_transfer>(tgt));
};
shared_ptr<monero_transfer_query> monero_transfer_query::copy(const shared_ptr<monero_transfer_query>& src, const shared_ptr<monero_transfer_query>& tgt) const {
MTRACE("monero_transfer_query::copy(const shared_ptr<monero_transfer_query>& src, const shared_ptr<monero_transfer_query>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
std::shared_ptr<monero_transfer_query> monero_transfer_query::copy(const std::shared_ptr<monero_transfer_query>& src, const std::shared_ptr<monero_transfer_query>& tgt) const {
MTRACE("monero_transfer_query::copy(const std::shared_ptr<monero_transfer_query>& src, const std::shared_ptr<monero_transfer_query>& tgt)");
if (this != src.get()) throw std::runtime_error("this != src");
// copy base class
monero_transfer::copy(static_pointer_cast<monero_transfer>(src), static_pointer_cast<monero_transfer>(tgt));
monero_transfer::copy(std::static_pointer_cast<monero_transfer>(src), std::static_pointer_cast<monero_transfer>(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<string>(src->m_addresses);
if (!src->m_addresses.empty()) tgt->m_addresses = std::vector<std::string>(src->m_addresses);
tgt->m_subaddress_index = src->m_subaddress_index;
if (!src->m_subaddress_indices.empty()) tgt->m_subaddress_indices = vector<uint32_t>(src->m_subaddress_indices);
if (!src->m_subaddress_indices.empty()) tgt->m_subaddress_indices = std::vector<uint32_t>(src->m_subaddress_indices);
if (!src->m_destinations.empty()) {
for (const shared_ptr<monero_destination>& destination : src->m_destinations) {
tgt->m_destinations.push_back(destination->copy(destination, make_shared<monero_destination>()));
for (const std::shared_ptr<monero_destination>& destination : src->m_destinations) {
tgt->m_destinations.push_back(destination->copy(destination, std::make_shared<monero_destination>()));
}
}
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<monero_output_wallet>& output_wallet) {
void monero_output_wallet::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_wallet>& 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<uint32_t>();
else if (key == string("subaddressIndex")) output_wallet->m_subaddress_index = it->second.get_value<uint32_t>();
else if (key == string("isSpent")) output_wallet->m_is_spent = it->second.get_value<bool>();
else if (key == string("isFrozen")) output_wallet->m_is_frozen = it->second.get_value<bool>();
std::string key = it->first;
if (key == std::string("accountIndex")) output_wallet->m_account_index = it->second.get_value<uint32_t>();
else if (key == std::string("subaddressIndex")) output_wallet->m_subaddress_index = it->second.get_value<uint32_t>();
else if (key == std::string("isSpent")) output_wallet->m_is_spent = it->second.get_value<bool>();
else if (key == std::string("isFrozen")) output_wallet->m_is_frozen = it->second.get_value<bool>();
}
}
shared_ptr<monero_output_wallet> monero_output_wallet::copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const {
std::shared_ptr<monero_output_wallet> monero_output_wallet::copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const {
MTRACE("monero_output_wallet::copy(output)");
return monero_output_wallet::copy(static_pointer_cast<monero_output_wallet>(src), static_pointer_cast<monero_output_wallet>(tgt));
return monero_output_wallet::copy(std::static_pointer_cast<monero_output_wallet>(src), std::static_pointer_cast<monero_output_wallet>(tgt));
};
shared_ptr<monero_output_wallet> monero_output_wallet::copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const {
std::shared_ptr<monero_output_wallet> monero_output_wallet::copy(const std::shared_ptr<monero_output_wallet>& src, const std::shared_ptr<monero_output_wallet>& 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<monero_output>(src), static_pointer_cast<monero_output>(tgt));
monero_output::copy(std::static_pointer_cast<monero_output>(src), std::static_pointer_cast<monero_output>(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<monero_output>& self, const shared_ptr<monero_output>& other) {
merge(static_pointer_cast<monero_output_wallet>(self), static_pointer_cast<monero_output_wallet>(other));
void monero_output_wallet::merge(const std::shared_ptr<monero_output>& self, const std::shared_ptr<monero_output>& other) {
merge(std::static_pointer_cast<monero_output_wallet>(self), std::static_pointer_cast<monero_output_wallet>(other));
}
void monero_output_wallet::merge(const shared_ptr<monero_output_wallet>& self, const shared_ptr<monero_output_wallet>& other) {
void monero_output_wallet::merge(const std::shared_ptr<monero_output_wallet>& self, const std::shared_ptr<monero_output_wallet>& 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<monero_output_query>& output_query) {
void monero_output_query::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_query>& 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<uint32_t>());
else if (key == string("minAmount")) output_query->m_min_amount = it->second.get_value<uint64_t>();
else if (key == string("maxAmount")) output_query->m_max_amount = it->second.get_value<uint64_t>();
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<uint32_t>());
else if (key == std::string("minAmount")) output_query->m_min_amount = it->second.get_value<uint64_t>();
else if (key == std::string("maxAmount")) output_query->m_max_amount = it->second.get_value<uint64_t>();
else if (key == std::string("txQuery")) {} // ignored
}
}
shared_ptr<monero_output_query> monero_output_query::deserialize_from_block(const string& output_query_json) {
std::shared_ptr<monero_output_query> 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<monero_block> block = node_to_block_query(blockNode);
std::shared_ptr<monero_block> block = node_to_block_query(blockNode);
// empty query if no txs
if (block->m_txs.empty()) return make_shared<monero_output_query>();
if (block->m_txs.empty()) return std::make_shared<monero_output_query>();
// get tx query
shared_ptr<monero_tx_query> tx_query = static_pointer_cast<monero_tx_query>(block->m_txs[0]);
std::shared_ptr<monero_tx_query> tx_query = std::static_pointer_cast<monero_tx_query>(block->m_txs[0]);
// get / create output query
shared_ptr<monero_output_query> output_query = tx_query->m_output_query == boost::none ? make_shared<monero_output_query>() : *tx_query->m_output_query;
std::shared_ptr<monero_output_query> output_query = tx_query->m_output_query == boost::none ? std::make_shared<monero_output_query>() : *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> monero_output_query::copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const {
return monero_output_query::copy(static_pointer_cast<monero_output_query>(src), static_pointer_cast<monero_output_query>(tgt));
std::shared_ptr<monero_output_query> monero_output_query::copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const {
return monero_output_query::copy(std::static_pointer_cast<monero_output_query>(src), std::static_pointer_cast<monero_output_query>(tgt));
};
shared_ptr<monero_output_query> monero_output_query::copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const {
return monero_output_query::copy(static_pointer_cast<monero_output_query>(src), static_pointer_cast<monero_output_query>(tgt));
std::shared_ptr<monero_output_query> monero_output_query::copy(const std::shared_ptr<monero_output_wallet>& src, const std::shared_ptr<monero_output_wallet>& tgt) const {
return monero_output_query::copy(std::static_pointer_cast<monero_output_query>(src), std::static_pointer_cast<monero_output_query>(tgt));
};
shared_ptr<monero_output_query> monero_output_query::copy(const shared_ptr<monero_output_query>& src, const shared_ptr<monero_output_query>& tgt) const {
std::shared_ptr<monero_output_query> monero_output_query::copy(const std::shared_ptr<monero_output_query>& src, const std::shared_ptr<monero_output_query>& 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<monero_output>(src), static_pointer_cast<monero_output>(tgt));
monero_output_wallet::copy(std::static_pointer_cast<monero_output>(src), std::static_pointer_cast<monero_output>(tgt));
// copy extensions
if (!src->m_subaddress_indices.empty()) tgt->m_subaddress_indices = vector<uint32_t>(src->m_subaddress_indices);
if (!src->m_subaddress_indices.empty()) tgt->m_subaddress_indices = std::vector<uint32_t>(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<monero_tx_wallet>(output->m_tx).get(), false)) return false;
if (query_parent && m_tx_query != boost::none && !(*m_tx_query)->meets_criteria(std::static_pointer_cast<monero_tx_wallet>(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<monero_destination>& destination : config.m_destinations) {
m_destinations.push_back(destination->copy(destination, make_shared<monero_destination>()));
for (const std::shared_ptr<monero_destination>& destination : config.m_destinations) {
m_destinations.push_back(destination->copy(destination, std::make_shared<monero_destination>()));
}
}
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> monero_tx_config::deserialize(const string& config_json) {
std::shared_ptr<monero_tx_config> 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<monero_tx_config> config = make_shared<monero_tx_config>();
std::shared_ptr<monero_tx_config> config = std::make_shared<monero_tx_config>();
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<monero_destination> destination = make_shared<monero_destination>();
std::shared_ptr<monero_destination> destination = std::make_shared<monero_destination>();
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<uint32_t>();
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<uint32_t>();
else if (key == string("fee")) config->m_fee = it->second.get_value<uint64_t>();
else if (key == string("accountIndex")) config->m_account_index = it->second.get_value<uint32_t>();
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<uint32_t>());
else if (key == string("unlockTime")) config->m_unlock_time = it->second.get_value<uint64_t>();
else if (key == string("canSplit")) config->m_can_split = it->second.get_value<bool>();
else if (key == string("relay")) config->m_relay = it->second.get_value<bool>();
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<uint64_t>();
else if (key == string("sweepEachSubaddress")) config->m_sweep_each_subaddress = it->second.get_value<bool>();
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<uint32_t>();
else if (key == std::string("fee")) config->m_fee = it->second.get_value<uint64_t>();
else if (key == std::string("accountIndex")) config->m_account_index = it->second.get_value<uint32_t>();
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<uint32_t>());
else if (key == std::string("unlockTime")) config->m_unlock_time = it->second.get_value<uint64_t>();
else if (key == std::string("canSplit")) config->m_can_split = it->second.get_value<bool>();
else if (key == std::string("relay")) config->m_relay = it->second.get_value<bool>();
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<uint64_t>();
else if (key == std::string("sweepEachSubaddress")) config->m_sweep_each_subaddress = it->second.get_value<bool>();
else if (key == std::string("keyImage")) config->m_key_image = it->second.data();
}
return config;
}
vector<shared_ptr<monero_destination>> monero_tx_config::get_normalized_destinations() const {
std::vector<std::shared_ptr<monero_destination>> 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<shared_ptr<monero_destination>> destinations;
std::vector<std::shared_ptr<monero_destination>> destinations;
destinations.push_back(std::make_shared<monero_destination>(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);
+98 -99
View File
@@ -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<uint32_t> m_account_index;
boost::optional<uint32_t> m_index;
boost::optional<string> m_address;
boost::optional<string> m_label;
boost::optional<std::string> m_address;
boost::optional<std::string> m_label;
boost::optional<uint64_t> m_balance;
boost::optional<uint64_t> m_unlocked_balance;
boost::optional<uint64_t> m_num_unspent_outputs;
@@ -96,11 +95,11 @@ namespace monero {
*/
struct monero_account : public serializable_struct {
boost::optional<uint32_t> m_index;
boost::optional<string> m_primary_address;
boost::optional<std::string> m_primary_address;
boost::optional<uint64_t> m_balance;
boost::optional<uint64_t> m_unlocked_balance;
boost::optional<string> m_tag;
vector<monero_subaddress> m_subaddresses;
boost::optional<std::string> m_tag;
std::vector<monero_subaddress> 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<string> m_address;
boost::optional<std::string> m_address;
boost::optional<uint64_t> m_amount;
monero_destination(boost::optional<string> address = boost::none, boost::optional<uint64_t> amount = boost::none) : m_address(address), m_amount(amount) {}
monero_destination(boost::optional<std::string> address = boost::none, boost::optional<uint64_t> 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<monero_destination>& destination);
shared_ptr<monero_destination> copy(const shared_ptr<monero_destination>& src, const shared_ptr<monero_destination>& tgt) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_destination>& destination);
std::shared_ptr<monero_destination> copy(const std::shared_ptr<monero_destination>& src, const std::shared_ptr<monero_destination>& tgt) const;
};
// forward declarations
@@ -129,20 +128,20 @@ namespace monero {
* TODO: m_is_incoming for api consistency
*/
struct monero_transfer : serializable_struct {
shared_ptr<monero_tx_wallet> m_tx;
std::shared_ptr<monero_tx_wallet> m_tx;
boost::optional<uint64_t> m_amount;
boost::optional<uint32_t> m_account_index;
boost::optional<uint64_t> 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<monero_transfer>& transfer);
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_transfer>& transfer);
virtual boost::optional<bool> is_incoming() const = 0; // derived class must implement
shared_ptr<monero_transfer> copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const;
std::shared_ptr<monero_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const;
boost::optional<bool> is_outgoing() const {
if (is_incoming() == boost::none) return boost::none;
return !(*is_incoming());
}
void merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other);
void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other);
};
/**
@@ -150,30 +149,30 @@ namespace monero {
*/
struct monero_incoming_transfer : public monero_transfer {
boost::optional<uint32_t> m_subaddress_index;
boost::optional<string> m_address;
boost::optional<std::string> m_address;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
shared_ptr<monero_incoming_transfer> copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const;
shared_ptr<monero_incoming_transfer> copy(const shared_ptr<monero_incoming_transfer>& src, const shared_ptr<monero_incoming_transfer>& tgt) const;
std::shared_ptr<monero_incoming_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const;
std::shared_ptr<monero_incoming_transfer> copy(const std::shared_ptr<monero_incoming_transfer>& src, const std::shared_ptr<monero_incoming_transfer>& tgt) const;
boost::optional<bool> is_incoming() const;
void merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other);
void merge(const shared_ptr<monero_incoming_transfer>& self, const shared_ptr<monero_incoming_transfer>& other);
void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other);
void merge(const std::shared_ptr<monero_incoming_transfer>& self, const std::shared_ptr<monero_incoming_transfer>& other);
};
/**
* Models an outgoing transfer of funds from the wallet.
*/
struct monero_outgoing_transfer : public monero_transfer {
vector<uint32_t> m_subaddress_indices;
vector<string> m_addresses;
vector<shared_ptr<monero_destination>> m_destinations;
std::vector<uint32_t> m_subaddress_indices;
std::vector<std::string> m_addresses;
std::vector<std::shared_ptr<monero_destination>> m_destinations;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
shared_ptr<monero_outgoing_transfer> copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const;
shared_ptr<monero_outgoing_transfer> copy(const shared_ptr<monero_outgoing_transfer>& src, const shared_ptr<monero_outgoing_transfer>& tgt) const;
std::shared_ptr<monero_outgoing_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const;
std::shared_ptr<monero_outgoing_transfer> copy(const std::shared_ptr<monero_outgoing_transfer>& src, const std::shared_ptr<monero_outgoing_transfer>& tgt) const;
boost::optional<bool> is_incoming() const;
void merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other);
void merge(const shared_ptr<monero_outgoing_transfer>& self, const shared_ptr<monero_outgoing_transfer>& other);
void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other);
void merge(const std::shared_ptr<monero_outgoing_transfer>& self, const std::shared_ptr<monero_outgoing_transfer>& other);
};
/**
@@ -183,19 +182,19 @@ namespace monero {
*/
struct monero_transfer_query : public monero_transfer {
boost::optional<bool> m_is_incoming;
boost::optional<string> m_address;
vector<string> m_addresses;
boost::optional<std::string> m_address;
std::vector<std::string> m_addresses;
boost::optional<uint32_t> m_subaddress_index;
vector<uint32_t> m_subaddress_indices;
vector<shared_ptr<monero_destination>> m_destinations;
std::vector<uint32_t> m_subaddress_indices;
std::vector<std::shared_ptr<monero_destination>> m_destinations;
boost::optional<bool> m_has_destinations;
boost::optional<shared_ptr<monero_tx_query>> m_tx_query;
boost::optional<std::shared_ptr<monero_tx_query>> 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<monero_transfer_query>& transfer_query);
static shared_ptr<monero_transfer_query> deserialize_from_block(const string& transfer_query_json);
shared_ptr<monero_transfer_query> copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const;
shared_ptr<monero_transfer_query> copy(const shared_ptr<monero_transfer_query>& src, const shared_ptr<monero_transfer_query>& tgt) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_transfer_query>& transfer_query);
static std::shared_ptr<monero_transfer_query> deserialize_from_block(const std::string& transfer_query_json);
std::shared_ptr<monero_transfer_query> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const;
std::shared_ptr<monero_transfer_query> copy(const std::shared_ptr<monero_transfer_query>& src, const std::shared_ptr<monero_transfer_query>& tgt) const;
boost::optional<bool> is_incoming() const;
bool meets_criteria(monero_transfer* transfer, bool query_parent = true) const;
};
@@ -210,11 +209,11 @@ namespace monero {
boost::optional<bool> 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<monero_output_wallet>& output_wallet);
shared_ptr<monero_output_wallet> copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const;
shared_ptr<monero_output_wallet> copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const;
void merge(const shared_ptr<monero_output>& self, const shared_ptr<monero_output>& other);
void merge(const shared_ptr<monero_output_wallet>& self, const shared_ptr<monero_output_wallet>& other);
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_wallet>& output_wallet);
std::shared_ptr<monero_output_wallet> copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const;
std::shared_ptr<monero_output_wallet> copy(const std::shared_ptr<monero_output_wallet>& src, const std::shared_ptr<monero_output_wallet>& tgt) const;
void merge(const std::shared_ptr<monero_output>& self, const std::shared_ptr<monero_output>& other);
void merge(const std::shared_ptr<monero_output_wallet>& self, const std::shared_ptr<monero_output_wallet>& 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<uint32_t> m_subaddress_indices;
std::vector<uint32_t> m_subaddress_indices;
boost::optional<uint64_t> m_min_amount;
boost::optional<uint64_t> m_max_amount;
boost::optional<shared_ptr<monero_tx_query>> m_tx_query;
boost::optional<std::shared_ptr<monero_tx_query>> 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<monero_output_query>& output_query);
static shared_ptr<monero_output_query> deserialize_from_block(const string& output_query_json);
shared_ptr<monero_output_query> copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const;
shared_ptr<monero_output_query> copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const; // TODO: necessary to override all super classes?
shared_ptr<monero_output_query> copy(const shared_ptr<monero_output_query>& src, const shared_ptr<monero_output_query>& tgt) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_query>& output_query);
static std::shared_ptr<monero_output_query> deserialize_from_block(const std::string& output_query_json);
std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const;
std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output_wallet>& src, const std::shared_ptr<monero_output_wallet>& tgt) const; // TODO: necessary to override all super classes?
std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output_query>& src, const std::shared_ptr<monero_output_query>& 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<shared_ptr<monero_tx_set>> m_tx_set;
boost::optional<std::shared_ptr<monero_tx_set>> m_tx_set;
boost::optional<bool> m_is_incoming;
boost::optional<bool> m_is_outgoing;
vector<shared_ptr<monero_incoming_transfer>> m_incoming_transfers;
boost::optional<shared_ptr<monero_outgoing_transfer>> m_outgoing_transfer;
boost::optional<string> m_note;
std::vector<std::shared_ptr<monero_incoming_transfer>> m_incoming_transfers;
boost::optional<std::shared_ptr<monero_outgoing_transfer>> m_outgoing_transfer;
boost::optional<std::string> m_note;
boost::optional<bool> m_is_locked;
boost::optional<uint64_t> m_input_sum;
boost::optional<uint64_t> m_output_sum;
boost::optional<string> m_change_address;
boost::optional<std::string> m_change_address;
boost::optional<uint64_t> m_change_amount;
boost::optional<uint32_t> m_num_dummy_outputs;
boost::optional<string> m_extra_hex;
boost::optional<std::string> 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<monero_tx_wallet>& tx_wallet);
shared_ptr<monero_tx_wallet> copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const;
shared_ptr<monero_tx_wallet> copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt) const;
void merge(const shared_ptr<monero_tx>& self, const shared_ptr<monero_tx>& other);
void merge(const shared_ptr<monero_tx_wallet>& self, const shared_ptr<monero_tx_wallet>& other);
vector<shared_ptr<monero_transfer>> get_transfers() const;
vector<shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const;
vector<shared_ptr<monero_transfer>> filter_transfers(const monero_transfer_query& query);
vector<shared_ptr<monero_output_wallet>> get_outputs_wallet() const;
vector<shared_ptr<monero_output_wallet>> get_outputs_wallet(const monero_output_query& query) const;
vector<shared_ptr<monero_output_wallet>> filter_outputs_wallet(const monero_output_query& query);
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_wallet>& tx_wallet);
std::shared_ptr<monero_tx_wallet> copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const;
std::shared_ptr<monero_tx_wallet> copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt) const;
void merge(const std::shared_ptr<monero_tx>& self, const std::shared_ptr<monero_tx>& other);
void merge(const std::shared_ptr<monero_tx_wallet>& self, const std::shared_ptr<monero_tx_wallet>& other);
std::vector<std::shared_ptr<monero_transfer>> get_transfers() const;
std::vector<std::shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const;
std::vector<std::shared_ptr<monero_transfer>> filter_transfers(const monero_transfer_query& query);
std::vector<std::shared_ptr<monero_output_wallet>> get_outputs_wallet() const;
std::vector<std::shared_ptr<monero_output_wallet>> get_outputs_wallet(const monero_output_query& query) const;
std::vector<std::shared_ptr<monero_output_wallet>> filter_outputs_wallet(const monero_output_query& query);
};
/**
@@ -279,22 +278,22 @@ namespace monero {
struct monero_tx_query : public monero_tx_wallet {
boost::optional<bool> m_is_outgoing;
boost::optional<bool> m_is_incoming;
vector<string> m_hashes;
std::vector<std::string> m_hashes;
boost::optional<bool> m_has_payment_id;
vector<string> m_payment_ids;
std::vector<std::string> m_payment_ids;
boost::optional<uint64_t> m_height;
boost::optional<uint64_t> m_min_height;
boost::optional<uint64_t> m_max_height;
boost::optional<uint64_t> m_include_outputs;
boost::optional<shared_ptr<monero_transfer_query>> m_transfer_query;
boost::optional<shared_ptr<monero_output_query>> m_output_query;
boost::optional<std::shared_ptr<monero_transfer_query>> m_transfer_query;
boost::optional<std::shared_ptr<monero_output_query>> 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<monero_tx_query>& tx_query);
static shared_ptr<monero_tx_query> deserialize_from_block(const string& tx_query_json);
shared_ptr<monero_tx_query> copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const;
shared_ptr<monero_tx_query> copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt) const; // TODO: necessary to override all super classes?
shared_ptr<monero_tx_query> copy(const shared_ptr<monero_tx_query>& src, const shared_ptr<monero_tx_query>& tgt) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_query>& tx_query);
static std::shared_ptr<monero_tx_query> deserialize_from_block(const std::string& tx_query_json);
std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const;
std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt) const; // TODO: necessary to override all super classes?
std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx_query>& src, const std::shared_ptr<monero_tx_query>& 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<shared_ptr<monero_tx_wallet>> m_txs;
boost::optional<string> m_signed_tx_hex;
boost::optional<string> m_unsigned_tx_hex;
boost::optional<string> m_multisig_tx_hex;
std::vector<std::shared_ptr<monero_tx_wallet>> m_txs;
boost::optional<std::string> m_signed_tx_hex;
boost::optional<std::string> m_unsigned_tx_hex;
boost::optional<std::string> 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<string> m_address;
boost::optional<std::string> m_address;
boost::optional<uint64_t> m_amount;
vector<shared_ptr<monero_destination>> m_destinations;
boost::optional<string> m_payment_id;
std::vector<std::shared_ptr<monero_destination>> m_destinations;
boost::optional<std::string> m_payment_id;
boost::optional<monero_tx_priority> m_priority;
boost::optional<uint32_t> m_ring_size;
boost::optional<uint64_t> m_fee;
boost::optional<uint32_t> m_account_index;
vector<uint32_t> m_subaddress_indices;
std::vector<uint32_t> m_subaddress_indices;
boost::optional<uint64_t> m_unlock_time;
boost::optional<bool> m_can_split;
boost::optional<bool> m_relay;
boost::optional<string> m_note;
boost::optional<string> m_recipient_name;
boost::optional<std::string> m_note;
boost::optional<std::string> m_recipient_name;
boost::optional<uint64_t> m_below_amount;
boost::optional<bool> m_sweep_each_subaddress;
boost::optional<string> m_key_image;
boost::optional<std::string> 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<monero_tx_config> deserialize(const string& config_json);
vector<shared_ptr<monero_destination>> get_normalized_destinations() const;
static std::shared_ptr<monero_tx_config> deserialize(const std::string& config_json);
std::vector<std::shared_ptr<monero_destination>> get_normalized_destinations() const;
};
/**
@@ -427,8 +426,8 @@ namespace monero {
* participants to create the wallet.
*/
struct monero_multisig_init_result : serializable_struct {
boost::optional<string> m_address;
boost::optional<string> m_multisig_hex;
boost::optional<std::string> m_address;
boost::optional<std::string> 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<string> m_signed_multisig_tx_hex;
vector<string> m_tx_hashes;
boost::optional<std::string> m_signed_multisig_tx_hex;
std::vector<std::string> 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<uint64_t> m_index; // TODO: not boost::optional
boost::optional<string> m_address;
boost::optional<string> m_description;
boost::optional<string> m_payment_id;
boost::optional<std::string> m_address;
boost::optional<std::string> m_description;
boost::optional<std::string> 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;
};
}