diff --git a/src/daemon/monero_daemon_model.cpp b/src/daemon/monero_daemon_model.cpp index 7dc5d67..53c4ee6 100644 --- a/src/daemon/monero_daemon_model.cpp +++ b/src/daemon/monero_daemon_model.cpp @@ -92,19 +92,19 @@ namespace monero { if (timestamp != boost::none) node.put("timestamp", *timestamp); if (size != boost::none) node.put("size", *size); if (weight != boost::none) node.put("weight", *weight); - if (longTermWeight != boost::none) node.put("longTermWeight", *longTermWeight); + if (long_term_weight != boost::none) node.put("long_term_weight", *long_term_weight); if (depth != boost::none) node.put("depth", *depth); if (difficulty != boost::none) node.put("difficulty", *difficulty); - if (cumulativeDifficulty != boost::none) node.put("cumulativeDifficulty", *height); - if (majorVersion != boost::none) node.put("majorVersion", *majorVersion); - if (minorVersion != boost::none) node.put("minorVersion", *minorVersion); + if (cumulative_difficulty != boost::none) node.put("cumulative_difficulty", *height); + if (major_version != boost::none) node.put("major_version", *major_version); + if (minor_version != boost::none) node.put("minor_version", *minor_version); if (nonce != boost::none) node.put("nonce", *nonce); - if (minerTxId != boost::none) node.put("minerTxId", *minerTxId); - if (numTxs != boost::none) node.put("numTxs", *numTxs); - if (orphanStatus != boost::none) node.put("orphanStatus", *orphanStatus); - if (prevId != boost::none) node.put("prevId", *prevId); + if (miner_tx_id != boost::none) node.put("miner_tx_id", *miner_tx_id); + if (num_txs != boost::none) node.put("num_txs", *num_txs); + if (orphan_status != boost::none) node.put("orphan_status", *orphan_status); + if (prev_id != boost::none) node.put("prev_id", *prev_id); if (reward != boost::none) node.put("reward", *reward); - if (powHash != boost::none) node.put("powHash", *powHash); + if (pow_hash != boost::none) node.put("pow_hash", *pow_hash); return node; } @@ -116,19 +116,19 @@ namespace monero { timestamp = monero_utils::reconcile(timestamp, other->timestamp, boost::none, boost::none, true, "block header timestamp"); // timestamp can increase size = monero_utils::reconcile(size, other->size, "block header size"); weight = monero_utils::reconcile(weight, other->weight, "block header weight"); - longTermWeight = monero_utils::reconcile(longTermWeight, other->longTermWeight, "block header long term weight"); + long_term_weight = monero_utils::reconcile(long_term_weight, other->long_term_weight, "block header long term weight"); depth = monero_utils::reconcile(depth, other->depth, "block header depth"); difficulty = monero_utils::reconcile(difficulty, other->difficulty, "difficulty"); - cumulativeDifficulty = monero_utils::reconcile(cumulativeDifficulty, other->cumulativeDifficulty, "cumulativeDifficulty"); - majorVersion = monero_utils::reconcile(majorVersion, other->majorVersion, "majorVersion"); - minorVersion = monero_utils::reconcile(minorVersion, other->minorVersion, "minorVersion"); + cumulative_difficulty = monero_utils::reconcile(cumulative_difficulty, other->cumulative_difficulty, "cumulative_difficulty"); + major_version = monero_utils::reconcile(major_version, other->major_version, "major_version"); + minor_version = monero_utils::reconcile(minor_version, other->minor_version, "minor_version"); nonce = monero_utils::reconcile(nonce, other->nonce, "nonce"); - minerTxId = monero_utils::reconcile(minerTxId, other->minerTxId); - numTxs = monero_utils::reconcile(numTxs, other->numTxs, "block header numTxs"); - orphanStatus = monero_utils::reconcile(orphanStatus, other->orphanStatus); - prevId = monero_utils::reconcile(prevId, other->prevId); + miner_tx_id = monero_utils::reconcile(miner_tx_id, other->miner_tx_id); + num_txs = monero_utils::reconcile(num_txs, other->num_txs, "block header num_txs"); + orphan_status = monero_utils::reconcile(orphan_status, other->orphan_status); + prev_id = monero_utils::reconcile(prev_id, other->prev_id); reward = monero_utils::reconcile(reward, other->reward, "block header reward"); - powHash = monero_utils::reconcile(powHash, other->powHash); + pow_hash = monero_utils::reconcile(pow_hash, other->pow_hash); } // ----------------------------- MONERO BLOCK ------------------------------- @@ -136,9 +136,9 @@ namespace monero { boost::property_tree::ptree monero_block::to_property_tree() const { boost::property_tree::ptree node = monero_block_header::to_property_tree(); if (hex != boost::none) node.put("hex", *hex); - if (minerTx != boost::none) node.add_child("minerTx", (*minerTx)->to_property_tree()); + if (miner_tx != boost::none) node.add_child("miner_tx", (*miner_tx)->to_property_tree()); if (!txs.empty()) node.add_child("txs", monero_utils::to_property_tree(txs)); - if (!txIds.empty()) node.add_child("txIds", monero_utils::to_property_tree(txIds)); + if (!tx_ids.empty()) node.add_child("tx_ids", monero_utils::to_property_tree(tx_ids)); return node; } @@ -155,13 +155,13 @@ namespace monero { // merge reconcilable block extensions hex = monero_utils::reconcile(hex, other->hex); - txIds = monero_utils::reconcile(txIds, other->txIds); + tx_ids = monero_utils::reconcile(tx_ids, other->tx_ids); // merge miner tx - if (minerTx == boost::none) minerTx = other->minerTx; - if (other->minerTx != boost::none) { - other->minerTx.get()->block = self; - minerTx.get()->merge(minerTx.get(), other->minerTx.get()); + if (miner_tx == boost::none) miner_tx = other->miner_tx; + if (other->miner_tx != boost::none) { + other->miner_tx.get()->block = self; + miner_tx.get()->merge(miner_tx.get(), other->miner_tx.get()); } // merge non-miner txs @@ -179,24 +179,24 @@ namespace monero { MTRACE("monero_tx::copy(const shared_ptr& src, const shared_ptr& tgt)"); tgt->id = src->id; tgt->version = src->version; - tgt->isMinerTx = src->isMinerTx; - tgt->paymentId = src->paymentId; + tgt->is_miner_tx = src->is_miner_tx; + tgt->payment_id = src->payment_id; tgt->fee = src->fee; tgt->mixin = src->mixin; - tgt->doNotRelay = src->doNotRelay; - tgt->isRelayed = src->isRelayed; - tgt->isConfirmed = src->isConfirmed; - tgt->inTxPool = src->inTxPool; - tgt->numConfirmations = src->numConfirmations; - tgt->unlockTime = src->unlockTime; - tgt->lastRelayedTimestamp = src->lastRelayedTimestamp; - tgt->receivedTimestamp = src->receivedTimestamp; - tgt->isDoubleSpendSeen = src->isDoubleSpendSeen; + tgt->do_not_relay = src->do_not_relay; + tgt->is_relayed = src->is_relayed; + tgt->is_confirmed = src->is_confirmed; + tgt->in_tx_pool = src->in_tx_pool; + tgt->num_confirmations = src->num_confirmations; + tgt->unlock_time = src->unlock_time; + tgt->last_relayed_timestamp = src->last_relayed_timestamp; + tgt->received_timestamp = src->received_timestamp; + tgt->is_double_spend_seen = src->is_double_spend_seen; tgt->key = src->key; - tgt->fullHex = src->fullHex; - tgt->prunedHex = src->prunedHex; - tgt->prunableHex = src->prunableHex; - tgt->prunableHash = src->prunableHash; + tgt->full_hex = src->full_hex; + tgt->pruned_hex = src->pruned_hex; + tgt->prunable_hex = src->prunable_hex; + tgt->prunable_hash = src->prunable_hash; tgt->size = src->size; tgt->weight = src->weight; if (!src->vins.empty()) { @@ -215,18 +215,18 @@ namespace monero { tgt->vouts.push_back(voutCopy); } } - if (!src->outputIndices.empty()) tgt->outputIndices = vector(src->outputIndices); + if (!src->m_output_indices.empty()) tgt->m_output_indices = vector(src->m_output_indices); tgt->metadata = src->metadata; - tgt->commonTxSets = src->commonTxSets; + tgt->common_tx_sets = src->common_tx_sets; if (!src->extra.empty()) throw runtime_error("extra deep copy not implemented"); // TODO: implement extra - tgt->rctSignatures = src->rctSignatures; - tgt->rctSigPrunable = src->rctSigPrunable; - tgt->isKeptByBlock = src->isKeptByBlock; - tgt->isFailed = src->isFailed; - tgt->lastFailedHeight = src->lastFailedHeight; - tgt->lastFailedId = src->lastFailedId; - tgt->maxUsedBlockHeight = src->maxUsedBlockHeight; - tgt->maxUsedBlockId = src->maxUsedBlockId; + tgt->rct_signatures = src->rct_signatures; + tgt->rct_sig_prunable = src->rct_sig_prunable; + tgt->is_kept_by_block = src->is_kept_by_block; + tgt->is_failed = src->is_failed; + tgt->last_failed_height = src->last_failed_height; + tgt->last_failed_id = src->last_failed_id; + tgt->max_used_block_height = src->max_used_block_height; + tgt->max_used_block_id = src->max_used_block_id; if (!src->signatures.empty()) tgt->signatures = vector(src->signatures); return tgt; } @@ -235,40 +235,40 @@ namespace monero { boost::property_tree::ptree node; if (id != boost::none) node.put("id", *id); if (version != boost::none) node.put("version", *version); - if (isMinerTx != boost::none) node.put("isMinerTx", *isMinerTx); - if (paymentId != boost::none) node.put("paymentId", *paymentId); + if (is_miner_tx != boost::none) node.put("is_miner_tx", *is_miner_tx); + if (payment_id != boost::none) node.put("payment_id", *payment_id); if (fee != boost::none) node.put("fee", *fee); if (mixin != boost::none) node.put("mixin", *mixin); - if (doNotRelay != boost::none) node.put("doNotRelay", *doNotRelay); - if (isRelayed != boost::none) node.put("isRelayed", *isRelayed); - if (isConfirmed != boost::none) node.put("isConfirmed", *isConfirmed); - if (inTxPool != boost::none) node.put("inTxPool", *inTxPool); - if (numConfirmations != boost::none) node.put("numConfirmations", *numConfirmations); - if (unlockTime != boost::none) node.put("unlockTime", *unlockTime); - if (lastRelayedTimestamp != boost::none) node.put("lastRelayedTimestamp", *lastRelayedTimestamp); - if (receivedTimestamp != boost::none) node.put("receivedTimestamp", *receivedTimestamp); - if (isDoubleSpendSeen != boost::none) node.put("isDoubleSpendSeen", *isDoubleSpendSeen); + if (do_not_relay != boost::none) node.put("do_not_relay", *do_not_relay); + if (is_relayed != boost::none) node.put("is_relayed", *is_relayed); + if (is_confirmed != boost::none) node.put("is_confirmed", *is_confirmed); + if (in_tx_pool != boost::none) node.put("in_tx_pool", *in_tx_pool); + if (num_confirmations != boost::none) node.put("num_confirmations", *num_confirmations); + if (unlock_time != boost::none) node.put("unlock_time", *unlock_time); + if (last_relayed_timestamp != boost::none) node.put("last_relayed_timestamp", *last_relayed_timestamp); + if (received_timestamp != boost::none) node.put("received_timestamp", *received_timestamp); + if (is_double_spend_seen != boost::none) node.put("is_double_spend_seen", *is_double_spend_seen); if (key != boost::none) node.put("key", *key); - if (fullHex != boost::none) node.put("fullHex", *fullHex); - if (prunedHex != boost::none) node.put("prunedHex", *prunedHex); - if (prunableHex != boost::none) node.put("prunableHex", *prunableHex); - if (prunableHash != boost::none) node.put("prunableHash", *prunableHash); + if (full_hex != boost::none) node.put("full_hex", *full_hex); + if (pruned_hex != boost::none) node.put("pruned_hex", *pruned_hex); + if (prunable_hex != boost::none) node.put("prunable_hex", *prunable_hex); + if (prunable_hash != boost::none) node.put("prunable_hash", *prunable_hash); if (size != boost::none) node.put("size", *size); if (weight != boost::none) node.put("weight", *weight); if (!vins.empty()) node.add_child("vins", monero_utils::to_property_tree(vins)); if (!vouts.empty()) node.add_child("vouts", monero_utils::to_property_tree(vouts)); - if (!outputIndices.empty()) throw runtime_error("outputIndices not implemented"); + if (!m_output_indices.empty()) throw runtime_error("m_output_indices not implemented"); if (metadata != boost::none) node.put("metadata", *metadata); - if (commonTxSets != boost::none) throw runtime_error("commonTxSets not implemented"); + if (common_tx_sets != boost::none) throw runtime_error("common_tx_sets not implemented"); if (!extra.empty()) node.add_child("extra", monero_utils::to_property_tree(extra)); - if (rctSignatures != boost::none) throw runtime_error("rctSignatures not implemented"); - if (rctSigPrunable != boost::none) throw runtime_error("rctSigPrunable not implemented"); - if (isKeptByBlock != boost::none) node.put("isKeptByBlock", *isKeptByBlock); - if (isFailed != boost::none) node.put("isFailed", *isFailed); - if (lastFailedHeight != boost::none) node.put("lastFailedHeight", *lastFailedHeight); - if (lastFailedId != boost::none) node.put("lastFailedId", *lastFailedId); - if (maxUsedBlockHeight != boost::none) node.put("maxUsedBlockHeight", *maxUsedBlockHeight); - if (maxUsedBlockId != boost::none) node.put("maxUsedBlockId", *maxUsedBlockId); + if (rct_signatures != boost::none) throw runtime_error("rct_signatures not implemented"); + if (rct_sig_prunable != boost::none) throw runtime_error("rct_sig_prunable not implemented"); + if (is_kept_by_block != boost::none) node.put("is_kept_by_block", *is_kept_by_block); + if (is_failed != boost::none) node.put("is_failed", *is_failed); + if (last_failed_height != boost::none) node.put("last_failed_height", *last_failed_height); + if (last_failed_id != boost::none) node.put("last_failed_id", *last_failed_id); + if (max_used_block_height != boost::none) node.put("max_used_block_height", *max_used_block_height); + if (max_used_block_id != boost::none) node.put("max_used_block_id", *max_used_block_id); if (!signatures.empty()) throw runtime_error("signatures not implemented"); return node; } @@ -301,35 +301,35 @@ namespace monero { // otherwise merge tx fields id = monero_utils::reconcile(id, other->id); version = monero_utils::reconcile(version, other->version); - paymentId = monero_utils::reconcile(paymentId, other->paymentId); + payment_id = monero_utils::reconcile(payment_id, other->payment_id); fee = monero_utils::reconcile(fee, other->fee, "tx fee"); mixin = monero_utils::reconcile(mixin, other->mixin, "tx mixin"); - isConfirmed = monero_utils::reconcile(isConfirmed, other->isConfirmed); - doNotRelay = monero_utils::reconcile(doNotRelay, other->doNotRelay); - isRelayed = monero_utils::reconcile(isRelayed, other->isRelayed); - isDoubleSpendSeen = monero_utils::reconcile(isDoubleSpendSeen, other->isDoubleSpendSeen); + is_confirmed = monero_utils::reconcile(is_confirmed, other->is_confirmed); + do_not_relay = monero_utils::reconcile(do_not_relay, other->do_not_relay); + is_relayed = monero_utils::reconcile(is_relayed, other->is_relayed); + is_double_spend_seen = monero_utils::reconcile(is_double_spend_seen, other->is_double_spend_seen); key = monero_utils::reconcile(key, other->key); - fullHex = monero_utils::reconcile(fullHex, other->fullHex); - prunedHex = monero_utils::reconcile(prunedHex, other->prunedHex); - prunableHex = monero_utils::reconcile(prunableHex, other->prunableHex); - prunableHash = monero_utils::reconcile(prunableHash, other->prunableHash); + full_hex = monero_utils::reconcile(full_hex, other->full_hex); + pruned_hex = monero_utils::reconcile(pruned_hex, other->pruned_hex); + prunable_hex = monero_utils::reconcile(prunable_hex, other->prunable_hex); + prunable_hash = monero_utils::reconcile(prunable_hash, other->prunable_hash); size = monero_utils::reconcile(size, other->size, "tx size"); weight = monero_utils::reconcile(weight, other->weight, "tx weight"); - //outputIndices = monero_utils::reconcile(outputIndices, other->outputIndices); // TODO + //m_output_indices = monero_utils::reconcile(m_output_indices, other->m_output_indices); // TODO metadata = monero_utils::reconcile(metadata, other->metadata); - commonTxSets = monero_utils::reconcile(commonTxSets, other->commonTxSets); + common_tx_sets = monero_utils::reconcile(common_tx_sets, other->common_tx_sets); //extra = monero_utils::reconcile(extra, other->extra); // TODO - rctSignatures = monero_utils::reconcile(rctSignatures, other->rctSignatures); - rctSigPrunable = monero_utils::reconcile(rctSigPrunable, other->rctSigPrunable); - isKeptByBlock = monero_utils::reconcile(isKeptByBlock, other->isKeptByBlock); - isFailed = monero_utils::reconcile(isFailed, other->isFailed); - lastFailedHeight = monero_utils::reconcile(lastFailedHeight, other->lastFailedHeight, "lastFailedHeight"); - lastFailedId = monero_utils::reconcile(lastFailedId, other->lastFailedId); - maxUsedBlockHeight = monero_utils::reconcile(maxUsedBlockHeight, other->maxUsedBlockHeight, "maxUsedBlockHeight"); - maxUsedBlockId = monero_utils::reconcile(maxUsedBlockId, other->maxUsedBlockId); + rct_signatures = monero_utils::reconcile(rct_signatures, other->rct_signatures); + rct_sig_prunable = monero_utils::reconcile(rct_sig_prunable, other->rct_sig_prunable); + is_kept_by_block = monero_utils::reconcile(is_kept_by_block, other->is_kept_by_block); + is_failed = monero_utils::reconcile(is_failed, other->is_failed); + last_failed_height = monero_utils::reconcile(last_failed_height, other->last_failed_height, "last_failed_height"); + last_failed_id = monero_utils::reconcile(last_failed_id, other->last_failed_id); + max_used_block_height = monero_utils::reconcile(max_used_block_height, other->max_used_block_height, "max_used_block_height"); + max_used_block_id = monero_utils::reconcile(max_used_block_id, other->max_used_block_id); //signatures = monero_utils::reconcile(signatures, other->signatures); // TODO - unlockTime = monero_utils::reconcile(unlockTime, other->unlockTime, "unlockTime"); - numConfirmations = monero_utils::reconcile(numConfirmations, other->numConfirmations, "numConfirmations"); + unlock_time = monero_utils::reconcile(unlock_time, other->unlock_time, "unlock_time"); + num_confirmations = monero_utils::reconcile(num_confirmations, other->num_confirmations, "num_confirmations"); // merge vins if (!other->vins.empty()) { @@ -337,7 +337,7 @@ namespace monero { bool merged = false; merger->tx = self; for (const shared_ptr& mergee : vins) { - if ((*mergee->keyImage)->hex == (*merger->keyImage)->hex) { + if ((*mergee->key_image)->hex == (*merger->key_image)->hex) { mergee->merge(mergee, merger); merged = true; break; @@ -356,14 +356,14 @@ namespace monero { // determine if key images present int numKeyImages = 0; for (const shared_ptr vout : vouts) { - if (vout->keyImage != boost::none) { - if ((*vout->keyImage)->hex == boost::none) throw runtime_error("Key image hex cannot be null"); + if (vout->key_image != boost::none) { + if ((*vout->key_image)->hex == boost::none) throw runtime_error("Key image hex cannot be null"); numKeyImages++; } } for (const shared_ptr& vout : other->vouts) { - if (vout->keyImage != boost::none) { - if ((*vout->keyImage)->hex == boost::none) throw runtime_error("Key image hex cannot be null"); + if (vout->key_image != boost::none) { + if ((*vout->key_image)->hex == boost::none) throw runtime_error("Key image hex cannot be null"); numKeyImages++; } } @@ -375,7 +375,7 @@ namespace monero { bool merged = false; merger->tx = self; for (const shared_ptr& mergee : vouts) { - if ((*mergee->keyImage)->hex == (*merger->keyImage)->hex) { + if ((*mergee->key_image)->hex == (*merger->key_image)->hex) { mergee->merge(mergee, merger); merged = true; break; @@ -396,14 +396,14 @@ namespace monero { } // handle unrelayed -> relayed -> confirmed - if (*isConfirmed) { - inTxPool = false; - receivedTimestamp = boost::none; - lastRelayedTimestamp = boost::none; + if (*is_confirmed) { + in_tx_pool = false; + received_timestamp = boost::none; + last_relayed_timestamp = boost::none; } else { - inTxPool = monero_utils::reconcile(inTxPool, other->inTxPool, boost::none, true, boost::none); // unrelayed -> tx pool - receivedTimestamp = monero_utils::reconcile(receivedTimestamp, other->receivedTimestamp, boost::none, boost::none, false, "receivedTimestamp"); // take earliest receive time - lastRelayedTimestamp = monero_utils::reconcile(lastRelayedTimestamp, other->lastRelayedTimestamp, boost::none, boost::none, true, "lastRelayedTimestamp"); // take latest relay time + in_tx_pool = monero_utils::reconcile(in_tx_pool, other->in_tx_pool, boost::none, true, boost::none); // unrelayed -> tx pool + received_timestamp = monero_utils::reconcile(received_timestamp, other->received_timestamp, boost::none, boost::none, false, "received_timestamp"); // take earliest receive time + last_relayed_timestamp = monero_utils::reconcile(last_relayed_timestamp, other->last_relayed_timestamp, boost::none, boost::none, true, "last_relayed_timestamp"); // take latest relay time } } @@ -432,21 +432,21 @@ namespace monero { shared_ptr monero_output::copy(const shared_ptr& src, const shared_ptr& tgt) const { if (this != src.get()) throw runtime_error("this != src"); tgt->tx = src->tx; // reference same parent tx by default - if (src->keyImage != boost::none) tgt->keyImage = src->keyImage.get()->copy(src->keyImage.get(), make_shared()); + if (src->key_image != boost::none) tgt->key_image = src->key_image.get()->copy(src->key_image.get(), make_shared()); tgt->amount = src->amount; tgt->index = src->index; - if (!src->ringOutputIndices.empty()) tgt->ringOutputIndices = vector(src->ringOutputIndices); - tgt->stealthPublicKey = src->stealthPublicKey; + if (!src->ring_output_indices.empty()) tgt->ring_output_indices = vector(src->ring_output_indices); + tgt->stealth_public_key = src->stealth_public_key; return tgt; } boost::property_tree::ptree monero_output::to_property_tree() const { boost::property_tree::ptree node; - if (keyImage != boost::none) node.add_child("keyImage", (*keyImage)->to_property_tree()); + if (key_image != boost::none) node.add_child("key_image", (*key_image)->to_property_tree()); if (amount != boost::none) node.put("amount", *amount); if (index != boost::none) node.put("index", *index); - if (!ringOutputIndices.empty()) node.add_child("ringOutputIndices", monero_utils::to_property_tree(ringOutputIndices)); - if (stealthPublicKey != boost::none) node.put("stealthPublicKey", *stealthPublicKey); + if (!ring_output_indices.empty()) node.add_child("ring_output_indices", monero_utils::to_property_tree(ring_output_indices)); + if (stealth_public_key != boost::none) node.put("stealth_public_key", *stealth_public_key); return node; } @@ -461,8 +461,8 @@ namespace monero { } // otherwise merge output fields - if (keyImage == boost::none) keyImage = other->keyImage; - else if (other->keyImage != boost::none) keyImage.get()->merge(keyImage.get(), other->keyImage.get()); + if (key_image == boost::none) key_image = other->key_image; + else if (other->key_image != boost::none) key_image.get()->merge(key_image.get(), other->key_image.get()); amount = monero_utils::reconcile(amount, other->amount, "output amount"); index = monero_utils::reconcile(index, other->index, "output index"); } diff --git a/src/daemon/monero_daemon_model.h b/src/daemon/monero_daemon_model.h index 088000a..43ca228 100644 --- a/src/daemon/monero_daemon_model.h +++ b/src/daemon/monero_daemon_model.h @@ -97,9 +97,9 @@ namespace monero { * TODO: switch to boost::optional */ struct monero_rpc_connection { - string uri; - boost::optional username; - boost::optional password; + string m_uri; + boost::optional m_username; + boost::optional m_password; monero_rpc_connection(const string& uri = "", const boost::optional& username = boost::none, const boost::optional& password = boost::none) : uri(uri), username(username), password(password) {} }; @@ -113,24 +113,24 @@ 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 id; - boost::optional height; - boost::optional timestamp; - boost::optional size; - boost::optional weight; - boost::optional longTermWeight; + boost::optional m_id; + boost::optional m_height; + boost::optional m_timestamp; + boost::optional m_size; + boost::optional m_weight; + boost::optional long_term_weight; boost::optional depth; boost::optional difficulty; - boost::optional cumulativeDifficulty; - boost::optional majorVersion; - boost::optional minorVersion; + boost::optional cumulative_difficulty; + boost::optional major_version; + boost::optional minor_version; boost::optional nonce; - boost::optional minerTxId; - boost::optional numTxs; - boost::optional orphanStatus; - boost::optional prevId; + boost::optional miner_tx_id; + boost::optional num_txs; + boost::optional orphan_status; + boost::optional prev_id; boost::optional reward; - boost::optional powHash; + boost::optional pow_hash; boost::property_tree::ptree to_property_tree() const; virtual void merge(const shared_ptr& self, const shared_ptr& other); @@ -141,9 +141,9 @@ namespace monero { */ struct monero_block : public monero_block_header { boost::optional hex; - boost::optional> minerTx; + boost::optional> miner_tx; vector> txs; - vector txIds; + vector tx_ids; boost::property_tree::ptree to_property_tree() const; void merge(const shared_ptr& self, const shared_ptr& other); @@ -158,40 +158,40 @@ namespace monero { boost::optional> block; boost::optional id; boost::optional version; - boost::optional isMinerTx; - boost::optional paymentId; + boost::optional is_miner_tx; + boost::optional payment_id; boost::optional fee; boost::optional mixin; - boost::optional doNotRelay; - boost::optional isRelayed; - boost::optional isConfirmed; - boost::optional inTxPool; - boost::optional numConfirmations; - boost::optional unlockTime; - boost::optional lastRelayedTimestamp; - boost::optional receivedTimestamp; - boost::optional isDoubleSpendSeen; + boost::optional do_not_relay; + boost::optional is_relayed; + boost::optional is_confirmed; + boost::optional in_tx_pool; + boost::optional num_confirmations; + boost::optional unlock_time; + boost::optional last_relayed_timestamp; + boost::optional received_timestamp; + boost::optional is_double_spend_seen; boost::optional key; - boost::optional fullHex; - boost::optional prunedHex; - boost::optional prunableHex; - boost::optional prunableHash; + boost::optional full_hex; + boost::optional pruned_hex; + boost::optional prunable_hex; + boost::optional prunable_hash; boost::optional size; boost::optional weight; vector> vins; vector> vouts; - vector outputIndices; + vector m_output_indices; boost::optional metadata; - boost::optional commonTxSets; + boost::optional common_tx_sets; vector extra; - boost::optional rctSignatures; // TODO: implement - boost::optional rctSigPrunable; // TODO: implement - boost::optional isKeptByBlock; - boost::optional isFailed; - boost::optional lastFailedHeight; - boost::optional lastFailedId; - boost::optional maxUsedBlockHeight; - boost::optional maxUsedBlockId; + boost::optional rct_signatures; // TODO: implement + boost::optional rct_sig_prunable; // TODO: implement + boost::optional is_kept_by_block; + boost::optional is_failed; + boost::optional last_failed_height; + boost::optional last_failed_id; + boost::optional max_used_block_height; + boost::optional max_used_block_id; vector signatures; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; @@ -217,11 +217,11 @@ namespace monero { */ struct monero_output : public serializable_struct { shared_ptr tx; - boost::optional> keyImage; + boost::optional> key_image; boost::optional amount; boost::optional index; - vector ringOutputIndices; - boost::optional stealthPublicKey; + vector ring_output_indices; + boost::optional stealth_public_key; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree to_property_tree() const; diff --git a/src/utils/monero_utils.cpp b/src/utils/monero_utils.cpp index c45eb9c..883a66d 100644 --- a/src/utils/monero_utils.cpp +++ b/src/utils/monero_utils.cpp @@ -61,139 +61,139 @@ using namespace monero_utils; // ------------------------------- INNER HELPERS ------------------------------ -void nodeToTransfer(const boost::property_tree::ptree& node, shared_ptr transfer) { +void node_to_transfer(const boost::property_tree::ptree& node, shared_ptr transfer) { // initialize transfer from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; - if (key == string("accountIndex")) transfer->accountIndex = it->second.get_value(); + if (key == string("account_index")) transfer->account_index = it->second.get_value(); } } -shared_ptr nodeToTransferRequest(const boost::property_tree::ptree& node) { - shared_ptr transferRequest = make_shared(); - nodeToTransfer(node, transferRequest); +shared_ptr node_to_transfer_request(const boost::property_tree::ptree& node) { + shared_ptr transfer_request = make_shared(); + node_to_transfer(node, transfer_request); // initialize request from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; - if (key == string("isIncoming")) transferRequest->isIncoming = it->second.get_value(); - else if (key == string("address")) transferRequest->address = it->second.data(); + if (key == string("is_incoming")) transfer_request->is_incoming = it->second.get_value(); + else if (key == string("address")) transfer_request->address = it->second.data(); else if (key == string("addresses")) throw runtime_error("addresses not implemented"); - else if (key == string("subaddressIndex")) transferRequest->subaddressIndex = it->second.get_value(); - else if (key == string("subaddressIndices")) { - vector subaddressIndices; - for (const auto& child : it->second) subaddressIndices.push_back(child.second.get_value()); - transferRequest->subaddressIndices = subaddressIndices; + else if (key == string("subaddress_index")) transfer_request->subaddress_index = it->second.get_value(); + else if (key == string("subaddress_indices")) { + vector subaddress_indices; + for (const auto& child : it->second) subaddress_indices.push_back(child.second.get_value()); + transfer_request->subaddress_indices = subaddress_indices; } else if (key == string("destinations")) throw runtime_error("destinations not implemented"); - else if (key == string("hasDestinations")) transferRequest->hasDestinations = it->second.get_value(); - else if (key == string("txRequest")) throw runtime_error("txRequest not implemented"); + else if (key == string("has_destinations")) transfer_request->has_destinations = it->second.get_value(); + else if (key == string("tx_request")) throw runtime_error("tx_request not implemented"); } - return transferRequest; + return transfer_request; } -shared_ptr nodeToKeyImage(const boost::property_tree::ptree& node) { +shared_ptr node_to_key_image(const boost::property_tree::ptree& node) { // initialize key image from node - shared_ptr keyImage = make_shared(); + shared_ptr key_image = make_shared(); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; - if (key == string("hex")) keyImage->hex = it->second.data(); - else if (key == string("signature")) keyImage->signature = it->second.data(); + if (key == string("hex")) key_image->hex = it->second.data(); + else if (key == string("signature")) key_image->signature = it->second.data(); } - return keyImage; + return key_image; } -void nodeToOutput(const boost::property_tree::ptree& node, shared_ptr output) { +void node_to_output(const boost::property_tree::ptree& node, shared_ptr output) { // initialize output from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; - if (key == string("keyImage")) output->keyImage = nodeToKeyImage(it->second); + if (key == string("key_image")) output->key_image = node_to_key_image(it->second); else if (key == string("amount")) output->amount = it->second.get_value(); else if (key == string("index")) output->index = it->second.get_value(); - else if (key == string("ringOutputIndices")) throw runtime_error("nodeToTx() deserialize ringOutputIndices not implemented"); - else if (key == string("stealthPublicKey")) throw runtime_error("nodeToTx() deserialize stealthPublicKey not implemented"); + else if (key == string("ring_output_indices")) throw runtime_error("node_to_tx() deserialize ring_output_indices not implemented"); + else if (key == string("stealth_public_key")) throw runtime_error("node_to_tx() deserialize stealth_public_key not implemented"); } } -void nodeToOutputWallet(const boost::property_tree::ptree& node, shared_ptr outputWallet) { - nodeToOutput(node, outputWallet); +void node_to_output_wallet(const boost::property_tree::ptree& node, shared_ptr output_wallet) { + node_to_output(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")) outputWallet->accountIndex = it->second.get_value(); - else if (key == string("subaddressIndex")) outputWallet->subaddressIndex = it->second.get_value(); - else if (key == string("isSpent")) outputWallet->isSpent = it->second.get_value(); - else if (key == string("isUnlocked")) outputWallet->isUnlocked = it->second.get_value(); - else if (key == string("isFrozen")) outputWallet->isFrozen = it->second.get_value(); + if (key == string("account_index")) output_wallet->account_index = it->second.get_value(); + else if (key == string("subaddress_index")) output_wallet->subaddress_index = it->second.get_value(); + else if (key == string("is_spent")) output_wallet->is_spent = it->second.get_value(); + else if (key == string("is_unlocked")) output_wallet->is_unlocked = it->second.get_value(); + else if (key == string("is_frozen")) output_wallet->is_frozen = it->second.get_value(); } } -shared_ptr nodeToOutputRequest(const boost::property_tree::ptree& node) { - shared_ptr outputRequest = make_shared(); - nodeToOutputWallet(node, outputRequest); +shared_ptr node_to_output_request(const boost::property_tree::ptree& node) { + shared_ptr output_request = make_shared(); + node_to_output_wallet(node, output_request); // initialize request 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) outputRequest->subaddressIndices.push_back(it2->second.get_value()); - else if (key == string("txRequest")) {} // ignored + if (key == string("subaddress_indices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) output_request->subaddress_indices.push_back(it2->second.get_value()); + else if (key == string("tx_request")) {} // ignored } - return outputRequest; + return output_request; } -void nodeToTx(const boost::property_tree::ptree& node, shared_ptr tx) { +void node_to_tx(const boost::property_tree::ptree& node, shared_ptr tx) { // initialize tx from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; if (key == string("id")) tx->id = it->second.data(); else if (key == string("version")) throw runtime_error("version deserializationn not implemented"); - else if (key == string("isMinerTx")) tx->isMinerTx = it->second.get_value(); - else if (key == string("paymentId")) throw runtime_error("paymentId deserializationn not implemented"); + else if (key == string("is_miner_tx")) tx->is_miner_tx = it->second.get_value(); + else if (key == string("payment_id")) throw runtime_error("payment_id deserializationn not implemented"); else if (key == string("fee")) throw runtime_error("fee deserialization not implemented"); else if (key == string("mixin")) throw runtime_error("mixin deserialization not implemented"); - else if (key == string("doNotRelay")) tx->doNotRelay = it->second.get_value(); - else if (key == string("isRelayed")) tx->isRelayed = it->second.get_value(); - else if (key == string("isConfirmed")) tx->isConfirmed = it->second.get_value(); - else if (key == string("inTxPool")) tx->inTxPool = it->second.get_value(); - else if (key == string("numConfirmations")) throw runtime_error("numConfirmations deserialization not implemented"); - else if (key == string("unlockTime")) throw runtime_error("unlockTime deserialization not implemented"); - else if (key == string("lastRelayedTimestamp")) throw runtime_error("lastRelayedTimestamp deserialization not implemented"); - else if (key == string("receivedTimestamp")) throw runtime_error("receivedTimestamp deserializationn not implemented"); - else if (key == string("isDoubleSpendSeen")) tx->isDoubleSpendSeen = it->second.get_value(); + else if (key == string("do_not_relay")) tx->do_not_relay = it->second.get_value(); + else if (key == string("is_relayed")) tx->is_relayed = it->second.get_value(); + else if (key == string("is_confirmed")) tx->is_confirmed = it->second.get_value(); + else if (key == string("in_tx_pool")) tx->in_tx_pool = it->second.get_value(); + else if (key == string("num_confirmations")) throw runtime_error("num_confirmations deserialization not implemented"); + else if (key == string("unlock_time")) throw runtime_error("unlock_time deserialization not implemented"); + else if (key == string("last_relayed_timestamp")) throw runtime_error("last_relayed_timestamp deserialization not implemented"); + else if (key == string("received_timestamp")) throw runtime_error("received_timestamp deserializationn not implemented"); + else if (key == string("is_double_spend_seen")) tx->is_double_spend_seen = it->second.get_value(); else if (key == string("key")) tx->key = it->second.data(); - else if (key == string("fullHex")) tx->fullHex = it->second.data(); - else if (key == string("prunedHex")) tx->prunedHex = it->second.data(); - else if (key == string("prunableHex")) tx->prunableHex = it->second.data(); - else if (key == string("prunableHash")) tx->prunableHash = it->second.data(); + else if (key == string("full_hex")) tx->full_hex = it->second.data(); + else if (key == string("pruned_hex")) tx->pruned_hex = it->second.data(); + else if (key == string("prunable_hex")) tx->prunable_hex = it->second.data(); + else if (key == string("prunable_hash")) tx->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("vins")) throw runtime_error("vins deserializationn not implemented"); else if (key == string("vouts")) throw runtime_error("vouts deserializationn not implemented"); - else if (key == string("outputIndices")) throw runtime_error("outputIndices deserialization not implemented"); + else if (key == string("m_output_indices")) throw runtime_error("m_output_indices deserialization not implemented"); else if (key == string("metadata")) throw runtime_error("metadata deserialization not implemented"); - else if (key == string("commonTxSets")) throw runtime_error("commonTxSets deserialization not implemented"); + else if (key == string("common_tx_sets")) throw runtime_error("common_tx_sets 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->isKeptByBlock = it->second.get_value(); - else if (key == string("isFailed")) tx->isFailed = it->second.get_value(); - else if (key == string("lastFailedHeight")) throw runtime_error("lastFailedHeight deserialization not implemented"); - else if (key == string("lastFailedId")) tx->lastFailedId = it->second.data(); - else if (key == string("maxUsedBlockHeight")) throw runtime_error("maxUsedBlockHeight deserialization not implemented"); - else if (key == string("maxUsedBlockId")) tx->maxUsedBlockId = it->second.data(); + else if (key == string("rct_signatures")) throw runtime_error("rct_signatures deserialization not implemented"); + else if (key == string("rct_sig_prunable")) throw runtime_error("rct_sig_prunable deserialization not implemented"); + else if (key == string("is_kept_by_block")) tx->is_kept_by_block = it->second.get_value(); + else if (key == string("is_failed")) tx->is_failed = it->second.get_value(); + else if (key == string("last_failed_height")) throw runtime_error("last_failed_height deserialization not implemented"); + else if (key == string("last_failed_id")) tx->last_failed_id = it->second.data(); + else if (key == string("max_used_block_height")) throw runtime_error("max_used_block_height deserialization not implemented"); + else if (key == string("max_used_block_id")) tx->max_used_block_id = it->second.data(); else if (key == string("signatures")) throw runtime_error("signatures deserialization not implemented"); } } // TODO: fill this out -void nodeToTxWallet(const boost::property_tree::ptree& node, shared_ptr txWallet) { - nodeToTx(node, txWallet); +void node_to_tx_wallet(const boost::property_tree::ptree& node, shared_ptr tx_wallet) { + node_to_tx(node, tx_wallet); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; @@ -202,29 +202,29 @@ void nodeToTxWallet(const boost::property_tree::ptree& node, shared_ptr nodeToTxRequest(const boost::property_tree::ptree& node) { - shared_ptr txRequest = make_shared(); - nodeToTxWallet(node, txRequest); + shared_ptr tx_request = make_shared(); + node_to_tx_wallet(node, tx_request); // initialize request from node for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; - if (key == string("isOutgoing")) txRequest->isOutgoing = it->second.get_value(); - else if (key == string("isIncoming")) txRequest->isIncoming = it->second.get_value(); - else if (key == string("txIds")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) txRequest->txIds.push_back(it2->second.data()); - else if (key == string("hasPaymentId")) txRequest->hasPaymentId = it->second.get_value(); - else if (key == string("paymentIds")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) txRequest->paymentIds.push_back(it2->second.data()); - else if (key == string("height")) txRequest->height = it->second.get_value(); - else if (key == string("minHeight")) txRequest->minHeight = it->second.get_value(); - else if (key == string("maxHeight")) txRequest->maxHeight = it->second.get_value(); - else if (key == string("includeOutputs")) txRequest->includeOutputs = it->second.get_value(); - else if (key == string("transferRequest")) txRequest->transferRequest = nodeToTransferRequest(it->second); - else if (key == string("outputRequest")) txRequest->outputRequest = nodeToOutputRequest(it->second); + if (key == string("is_outgoing")) tx_request->is_outgoing = it->second.get_value(); + else if (key == string("is_incoming")) tx_request->is_incoming = it->second.get_value(); + else if (key == string("tx_ids")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) tx_request->tx_ids.push_back(it2->second.data()); + else if (key == string("has_payment_id")) tx_request->has_payment_id = it->second.get_value(); + else if (key == string("payment_ids")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) tx_request->payment_ids.push_back(it2->second.data()); + else if (key == string("height")) tx_request->height = it->second.get_value(); + else if (key == string("min_height")) tx_request->min_height = it->second.get_value(); + else if (key == string("max_height")) tx_request->max_height = it->second.get_value(); + else if (key == string("include_outputs")) tx_request->include_outputs = it->second.get_value(); + else if (key == string("transfer_request")) tx_request->transfer_request = node_to_transfer_request(it->second); + else if (key == string("output_request")) tx_request->output_request = node_to_output_request(it->second); } - return txRequest; + return tx_request; } -shared_ptr nodeToBlockRequest(const boost::property_tree::ptree& node) { +shared_ptr node_to_block_request(const boost::property_tree::ptree& node) { shared_ptr block = make_shared(); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; @@ -238,7 +238,7 @@ shared_ptr nodeToBlockRequest(const boost::property_tree::ptree& n return block; } -shared_ptr nodeToDestination(const boost::property_tree::ptree& node) { +shared_ptr node_to_destination(const boost::property_tree::ptree& node) { shared_ptr destination = make_shared(); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; @@ -250,19 +250,19 @@ shared_ptr nodeToDestination(const boost::property_tree::ptr // ------------------------- PUBLIC STATIC UTILITIES -------------------------- -void monero_utils::jsonToBinary(const std::string &json, std::string &bin) { +void monero_utils::json_to_binary(const std::string &json, std::string &bin) { epee::serialization::portable_storage ps; ps.load_from_json(json); ps.store_to_binary(bin); } -void monero_utils::binaryToJson(const std::string &bin, std::string &json) { +void monero_utils::binary_to_json(const std::string &bin, std::string &json) { epee::serialization::portable_storage ps; ps.load_from_binary(bin); ps.dump_as_json(json); } -void monero_utils::binaryBlocksToJson(const std::string &bin, std::string &json) { +void monero_utils::binary_blocks_to_json(const std::string &bin, std::string &json) { // load binary rpc response to struct cryptonote::COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response resp_struct; @@ -314,7 +314,7 @@ void monero_utils::binaryBlocksToJson(const std::string &bin, std::string &json) json = ss.str(); } -shared_ptr monero_utils::deserializeTxRequest(const string& txRequestStr) { +shared_ptr monero_utils::deserialize_tx_request(const string& txRequestStr) { // deserialize tx request string to property rooted at block std::istringstream iss = txRequestStr.empty() ? std::istringstream() : std::istringstream(txRequestStr); @@ -322,73 +322,73 @@ shared_ptr monero_utils::deserializeTxRequest(const string& t boost::property_tree::read_json(iss, blockNode); // convert request property tree to block - shared_ptr block = nodeToBlockRequest(blockNode); + shared_ptr block = node_to_block_request(blockNode); // get tx request - shared_ptr txRequest = static_pointer_cast(block->txs[0]); + shared_ptr tx_request = static_pointer_cast(block->txs[0]); // return deserialized request - return txRequest; + return tx_request; } -shared_ptr monero_utils::deserializeTransferRequest(const string& transferRequestStr) { +shared_ptr monero_utils::deserialize_transfer_request(const string& transfer_request_str) { // deserialize transfer request string to property rooted at block - std::istringstream iss = transferRequestStr.empty() ? std::istringstream() : std::istringstream(transferRequestStr); + std::istringstream iss = transfer_request_str.empty() ? std::istringstream() : std::istringstream(transfer_request_str); boost::property_tree::ptree blockNode; boost::property_tree::read_json(iss, blockNode); // convert request property tree to block - shared_ptr block = nodeToBlockRequest(blockNode); + shared_ptr block = node_to_block_request(blockNode); // return mpty request if no txs if (block->txs.empty()) return make_shared(); // get tx request - shared_ptr txRequest = static_pointer_cast(block->txs[0]); + shared_ptr tx_request = static_pointer_cast(block->txs[0]); // get / create transfer request - shared_ptr transferRequest = txRequest->transferRequest == boost::none ? make_shared() : *txRequest->transferRequest; + shared_ptr transfer_request = tx_request->transfer_request == boost::none ? make_shared() : *tx_request->transfer_request; // transfer request references tx request but not the other way around to avoid circular loop // TODO: could add check within meetsCriterias() - transferRequest->txRequest = txRequest; - txRequest->transferRequest = boost::none; + transfer_request->tx_request = tx_request; + tx_request->transfer_request = boost::none; // return deserialized request - return transferRequest; + return transfer_request; } -shared_ptr monero_utils::deserializeOutputRequest(const string& outputRequestStr) { +shared_ptr monero_utils::deserialize_output_request(const string& output_request_str) { // deserialize output request string to property rooted at block - std::istringstream iss = outputRequestStr.empty() ? std::istringstream() : std::istringstream(outputRequestStr); + std::istringstream iss = output_request_str.empty() ? std::istringstream() : std::istringstream(output_request_str); boost::property_tree::ptree blockNode; boost::property_tree::read_json(iss, blockNode); // convert request property tree to block - shared_ptr block = nodeToBlockRequest(blockNode); + shared_ptr block = node_to_block_request(blockNode); // empty request if no txs if (block->txs.empty()) return make_shared(); // get tx request - shared_ptr txRequest = static_pointer_cast(block->txs[0]); + shared_ptr tx_request = static_pointer_cast(block->txs[0]); // get / create output request - shared_ptr outputRequest = txRequest->outputRequest == boost::none ? make_shared() : *txRequest->outputRequest; + shared_ptr output_request = tx_request->output_request == boost::none ? make_shared() : *tx_request->output_request; // output request references tx request but not the other way around to avoid circular loop // TODO: could add check within meetsCriterias() - outputRequest->txRequest = txRequest; - txRequest->outputRequest = boost::none; + output_request->tx_request = tx_request; + tx_request->output_request = boost::none; // return deserialized request - return outputRequest; + return output_request; } -shared_ptr monero_utils::deserializeSendRequest(const string& sendRequestStr) { +shared_ptr monero_utils::deserialize_send_request(const string& send_request_str) { // deserialize send request json to property node - std::istringstream iss = sendRequestStr.empty() ? std::istringstream() : std::istringstream(sendRequestStr); + std::istringstream iss = send_request_str.empty() ? std::istringstream() : std::istringstream(send_request_str); boost::property_tree::ptree node; boost::property_tree::read_json(iss, node); @@ -399,33 +399,33 @@ shared_ptr monero_utils::deserializeSendRequest(const strin if (key == string("destinations")) { boost::property_tree::ptree destinationsNode = it->second; for (boost::property_tree::ptree::const_iterator it2 = destinationsNode.begin(); it2 != destinationsNode.end(); ++it2) { - sendRequest->destinations.push_back(nodeToDestination(it2->second)); + sendRequest->destinations.push_back(node_to_destination(it2->second)); } } - else if (key == string("paymentId")) sendRequest->paymentId = it->second.data(); - else if (key == string("priority")) throw runtime_error("deserializeSendRequest() paymentId not implemented"); + else if (key == string("payment_id")) sendRequest->payment_id = it->second.data(); + else if (key == string("priority")) throw runtime_error("deserialize_send_request() payment_id not implemented"); else if (key == string("mixin")) sendRequest->mixin = it->second.get_value(); else if (key == string("ringSize")) sendRequest->ringSize = it->second.get_value(); else if (key == string("fee")) sendRequest->fee = it->second.get_value(); - else if (key == string("accountIndex")) sendRequest->accountIndex = it->second.get_value(); - else if (key == string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) sendRequest->subaddressIndices.push_back(it2->second.get_value()); - else if (key == string("unlockTime")) sendRequest->unlockTime = it->second.get_value(); - else if (key == string("canSplit")) sendRequest->canSplit = it->second.get_value(); - else if (key == string("doNotRelay")) sendRequest->doNotRelay = it->second.get_value(); + else if (key == string("account_index")) sendRequest->account_index = it->second.get_value(); + else if (key == string("subaddress_indices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) sendRequest->subaddress_indices.push_back(it2->second.get_value()); + else if (key == string("unlock_time")) sendRequest->unlock_time = it->second.get_value(); + else if (key == string("can_split")) sendRequest->can_split = it->second.get_value(); + else if (key == string("do_not_relay")) sendRequest->do_not_relay = it->second.get_value(); else if (key == string("note")) sendRequest->note = it->second.data(); - else if (key == string("recipientName")) sendRequest->recipientName = it->second.data(); - else if (key == string("belowAmount")) sendRequest->belowAmount = it->second.get_value(); - else if (key == string("sweepEachSubaddress")) sendRequest->sweepEachSubaddress = it->second.get_value(); - else if (key == string("keyImage")) sendRequest->keyImage = it->second.data(); + else if (key == string("receipient_name")) sendRequest->receipient_name = it->second.data(); + else if (key == string("below_amount")) sendRequest->below_amount = it->second.get_value(); + else if (key == string("sweep_each_subaddress")) sendRequest->sweep_each_subaddress = it->second.get_value(); + else if (key == string("key_image")) sendRequest->key_image = it->second.data(); } return sendRequest; } -vector> monero_utils::deserializeKeyImages(const string& keyImagesJson) { +vector> monero_utils::deserialize_key_images(const string& key_images_json) { // deserialize json to property node - std::istringstream iss = keyImagesJson.empty() ? std::istringstream() : std::istringstream(keyImagesJson); + std::istringstream iss = key_images_json.empty() ? std::istringstream() : std::istringstream(key_images_json); boost::property_tree::ptree node; boost::property_tree::read_json(iss, node); @@ -435,10 +435,10 @@ vector> monero_utils::deserializeKeyImages(const st string key = it->first; if (key == string("keyImages")) { for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) { - keyImages.push_back(nodeToKeyImage(it2->second)); + keyImages.push_back(node_to_key_image(it2->second)); } } - else MWARNING("WARNING MoneroWalletJni::deserializeKeyImages() unrecognized key: " << key); + else MWARNING("WARNING MoneroWalletJni::deserialize_key_images() unrecognized key: " << key); } return keyImages; } @@ -491,53 +491,53 @@ boost::property_tree::ptree monero_utils::to_property_tree(const vector monero_utils::cnBlockToBlock(const cryptonote::block& cnBlock) { - cryptonote::block temp = cnBlock; +shared_ptr monero_utils::cn_block_to_block(const cryptonote::block& cn_block) { + cryptonote::block temp = cn_block; cout << cryptonote::obj_to_json_str(temp) << endl; shared_ptr block = make_shared(); - block->majorVersion = cnBlock.major_version; - block->minorVersion = cnBlock.minor_version; - block->timestamp = cnBlock.timestamp; - block->prevId = epee::string_tools::pod_to_hex(cnBlock.prev_id); - block->nonce = cnBlock.nonce; - block->minerTx = monero_utils::cnTxToTx(cnBlock.miner_tx); - for (const crypto::hash& txHash : cnBlock.tx_hashes) { - block->txIds.push_back(epee::string_tools::pod_to_hex(txHash)); + block->major_version = cn_block.major_version; + block->minor_version = cn_block.minor_version; + block->timestamp = cn_block.timestamp; + block->prev_id = epee::string_tools::pod_to_hex(cn_block.prev_id); + block->nonce = cn_block.nonce; + block->miner_tx = monero_utils::cn_tx_to_tx(cn_block.miner_tx); + for (const crypto::hash& txHash : cn_block.tx_hashes) { + block->tx_ids.push_back(epee::string_tools::pod_to_hex(txHash)); } return block; } -shared_ptr monero_utils::cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet) { - shared_ptr tx = initAsTxWallet ? make_shared() : make_shared(); - tx->version = cnTx.version; - tx->unlockTime = cnTx.unlock_time; - tx->id = epee::string_tools::pod_to_hex(cnTx.hash); - tx->extra = cnTx.extra; +shared_ptr monero_utils::cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet) { + shared_ptr tx = init_as_tx_wallet ? make_shared() : make_shared(); + tx->version = cn_tx.version; + tx->unlock_time = cn_tx.unlock_time; + tx->id = epee::string_tools::pod_to_hex(cn_tx.hash); + tx->extra = cn_tx.extra; // init vins - for (const txin_v& cnVin : cnTx.vin) { + for (const txin_v& cnVin : cn_tx.vin) { if (cnVin.which() != 0 && cnVin.which() != 3) throw runtime_error("Unsupported variant type"); - if (tx->isMinerTx == boost::none) tx->isMinerTx = cnVin.which() == 0; + if (tx->is_miner_tx == boost::none) tx->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 vin = initAsTxWallet ? make_shared() : make_shared(); + shared_ptr vin = init_as_tx_wallet ? make_shared() : make_shared(); vin->tx = tx; tx->vins.push_back(vin); const txin_to_key& txin = boost::get(cnVin); vin->amount = txin.amount; - vin->ringOutputIndices = txin.key_offsets; + vin->ring_output_indices = txin.key_offsets; crypto::key_image cnKeyImage = txin.k_image; - vin->keyImage = make_shared(); - vin->keyImage.get()->hex = epee::string_tools::pod_to_hex(cnKeyImage); + vin->key_image = make_shared(); + vin->key_image.get()->hex = epee::string_tools::pod_to_hex(cnKeyImage); } // init vouts - for (const tx_out& cnVout : cnTx.vout) { - shared_ptr vout = initAsTxWallet ? make_shared() : make_shared(); + for (const tx_out& cnVout : cn_tx.vout) { + shared_ptr vout = init_as_tx_wallet ? make_shared() : make_shared(); vout->tx = tx; tx->vouts.push_back(vout); vout->amount = cnVout.amount; const crypto::public_key& cnStealthPublicKey = boost::get(cnVout.target).key; - vout->stealthPublicKey = epee::string_tools::pod_to_hex(cnStealthPublicKey); + vout->stealth_public_key = epee::string_tools::pod_to_hex(cnStealthPublicKey); } return tx; diff --git a/src/utils/monero_utils.h b/src/utils/monero_utils.h index bef6b94..1cdd5b3 100644 --- a/src/utils/monero_utils.h +++ b/src/utils/monero_utils.h @@ -50,8 +50,8 @@ * Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers */ -#ifndef MoneroUtils_h -#define MoneroUtils_h +#ifndef monero_utils_h +#define monero_utils_h #include "wallet/monero_wallet.h" #include "cryptonote_basic/cryptonote_basic.h" @@ -66,41 +66,41 @@ namespace monero_utils using namespace std; using namespace cryptonote; - void jsonToBinary(const std::string &json, std::string &bin); + void json_to_binary(const std::string &json, std::string &bin); - void binaryToJson(const std::string &bin, std::string &json); + void binary_to_json(const std::string &bin, std::string &json); - void binaryBlocksToJson(const std::string &bin, std::string &json); + void binary_blocks_to_json(const std::string &bin, std::string &json); - shared_ptr deserializeTxRequest(const string& txRequestStr); + shared_ptr deserialize_tx_request(const string& txRequestStr); - shared_ptr deserializeTransferRequest(const string& transferRequestStr); + shared_ptr deserialize_transfer_request(const string& transfer_request_str); - shared_ptr deserializeOutputRequest(const string& outputRequestStr); + shared_ptr deserialize_output_request(const string& output_request_str); - shared_ptr deserializeSendRequest(const string& sendRequestStr); + shared_ptr deserialize_send_request(const string& send_request_str); - vector> deserializeKeyImages(const string& keyImagesJson); + vector> deserialize_key_images(const string& key_images_json); string serialize(const boost::property_tree::ptree& node); /** * Convert a Monero Core cryptonote::block to a block in this library's native model. * - * @param cnBlock is the Core block to convert + * @param cn_block is the Core block to convert * @return a block in this library's native model */ - shared_ptr cnBlockToBlock(const cryptonote::block& cnBlock); + shared_ptr cn_block_to_block(const cryptonote::block& cn_block); /** * Convert a Monero Core crpytonote::transaction to a transaction in this library's * native model. * - * @param cnTx is the Core transaction to convert - * @param initAsTxWallet specifies if a monero_tx xor monero_tx_wallet should be initialized + * @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 cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet = false); + shared_ptr cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet = false); /** * Modified from core_rpc_server.cpp to return a string. @@ -145,75 +145,75 @@ namespace monero_utils // TODO: refactor common template code template ::value, T>::type* = nullptr> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolveDefined, boost::optional resolveTrue, boost::optional resolveMax, const string& errMsg = "") { + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const string& err_msg = "") { // check for equality if (val1 == val2) return val1; // resolve one value none if (val1 == boost::none || val2 == boost::none) { - if (resolveDefined != boost::none && *resolveDefined == false) return boost::none; + if (resolve_defined != boost::none && *resolve_defined == false) return boost::none; else return val1 == boost::none ? val2 : val1; } - throw runtime_error(string("Cannot reconcile strings: ") + to_string(val1) + string(" vs ") + to_string(val2) + (!errMsg.empty() ? string(". ") + errMsg : string(""))); + throw runtime_error(string("Cannot reconcile strings: ") + to_string(val1) + string(" vs ") + to_string(val2) + (!err_msg.empty() ? string(". ") + err_msg : string(""))); } template ::value, T>::type* = nullptr> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& errMsg = "") { - return reconcile(val1, val2, boost::none, boost::none, boost::none, errMsg); + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& err_msg = "") { + return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg); } template ::value, T>::type* = nullptr> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolveDefined, boost::optional resolveTrue, boost::optional resolveMax, const string& errMsg = "") { + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const string& err_msg = "") { // check for equality if (val1 == val2) return val1; // resolve one value none if (val1 == boost::none || val2 == boost::none) { - if (resolveDefined != boost::none && *resolveDefined == false) return boost::none; + if (resolve_defined != boost::none && *resolve_defined == false) return boost::none; else return val1 == boost::none ? val2 : val1; } // resolve different numbers - if (resolveMax != boost::none) { - return *resolveMax ? max(*val1, *val2) : min(*val1, *val2); + if (resolve_max != boost::none) { + return *resolve_max ? max(*val1, *val2) : min(*val1, *val2); } - // throw runtime_error("Cannot reconcile values " + val1 + " and " + val2 + " with config: [" + resolveDefined + ", " + resolveTrue + ", " + resolveMax + "]", val1, val2); - throw runtime_error(string("Cannot reconcile integrals: ") + to_string(val1) + string(" vs ") + to_string(val2) + (!errMsg.empty() ? string(". ") + errMsg : string(""))); + // 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(""))); } template ::value, T>::type* = nullptr> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& errMsg = "") { - return reconcile(val1, val2, boost::none, boost::none, boost::none, errMsg); + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& err_msg = "") { + return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg); } template ::value, T>::type> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolveDefined, boost::optional resolveTrue, boost::optional resolveMax, const string& errMsg = "") { + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolve_defined, boost::optional resolve_true, boost::optional resolve_max, const string& err_msg = "") { // check for equality if (val1 == val2) return val1; // resolve one value none if (val1 == boost::none || val2 == boost::none) { - if (resolveDefined != boost::none && *resolveDefined == false) return boost::none; + if (resolve_defined != boost::none && *resolve_defined == false) return boost::none; else return val1 == boost::none ? val2 : val1; } // resolve different booleans - if (resolveTrue != boost::none) { - return val1 == resolveTrue ? val1 : val2; // if resolve true, return true, else return false + 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) + (!errMsg.empty() ? string(". ") + errMsg : string(""))); + throw runtime_error(string("Cannot reconcile booleans: ") + to_string(val1) + string(" vs ") + to_string(val2) + (!err_msg.empty() ? string(". ") + err_msg : string(""))); } } template ::value, T>::type> - boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& errMsg = "") { - return reconcile(val1, val2, boost::none, boost::none, boost::none, errMsg); + boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, const string& err_msg = "") { + return reconcile(val1, val2, boost::none, boost::none, boost::none, err_msg); } template - vector reconcile(const vector& v1, const vector& v2, const string& errMsg = "") { + vector reconcile(const vector& v1, const vector& v2, const string& err_msg = "") { // check for equality if (v1 == v2) return v1; @@ -223,7 +223,7 @@ namespace monero_utils if (v2.empty()) return v1; // otherwise cannot reconcile - throw runtime_error("Cannot reconcile vectors" + (!errMsg.empty() ? string(". ") + errMsg : string(""))); + throw runtime_error("Cannot reconcile vectors" + (!err_msg.empty() ? string(". ") + err_msg : string(""))); } // template @@ -231,4 +231,4 @@ namespace monero_utils // return reconcile(val1, val2, boost::none, boost::none, boost::none); // } } -#endif /* MoneroUtils_h */ +#endif /* monero_utils_h */ diff --git a/src/wallet/monero_wallet.cpp b/src/wallet/monero_wallet.cpp index f57a649..be3a120 100644 --- a/src/wallet/monero_wallet.cpp +++ b/src/wallet/monero_wallet.cpp @@ -98,40 +98,40 @@ namespace monero { tx->block = block; block->txs.push_back(tx); tx->id = string_tools::pod_to_hex(pd.m_tx_hash); - tx->paymentId = string_tools::pod_to_hex(payment_id); - if (tx->paymentId->substr(16).find_first_not_of('0') == std::string::npos) tx->paymentId = tx->paymentId->substr(0, 16); // TODO monero core: this should be part of core wallet - if (tx->paymentId == monero_tx::DEFAULT_PAYMENT_ID) tx->paymentId = boost::none; // clear default payment id - tx->unlockTime = pd.m_unlock_time; + tx->payment_id = string_tools::pod_to_hex(payment_id); + if (tx->payment_id->substr(16).find_first_not_of('0') == std::string::npos) tx->payment_id = tx->payment_id->substr(0, 16); // TODO monero core: this should be part of core wallet + if (tx->payment_id == monero_tx::DEFAULT_PAYMENT_ID) tx->payment_id = boost::none; // clear default payment id + tx->unlock_time = pd.m_unlock_time; tx->fee = pd.m_fee; tx->note = wallet2.get_tx_note(pd.m_tx_hash); if (tx->note->empty()) tx->note = boost::none; // clear empty note - tx->isMinerTx = pd.m_coinbase ? true : false; - tx->isConfirmed = true; - tx->isFailed = false; - tx->isRelayed = true; - tx->inTxPool = false; - tx->doNotRelay = false; - tx->isDoubleSpendSeen = false; + tx->is_miner_tx = pd.m_coinbase ? true : false; + tx->is_confirmed = true; + tx->is_failed = false; + tx->is_relayed = true; + tx->in_tx_pool = false; + tx->do_not_relay = false; + tx->is_double_spend_seen = false; - // compute numConfirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 + // compute num_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 // TODO: factor out this duplicate code with buildTxWithOutgoingTransfer() - if (*block->height >= height || (*block->height == 0 && !*tx->inTxPool)) tx->numConfirmations = 0; - else tx->numConfirmations = height - *block->height; + if (*block->height >= height || (*block->height == 0 && !*tx->in_tx_pool)) tx->num_confirmations = 0; + else tx->num_confirmations = height - *block->height; // construct transfer shared_ptr incomingTransfer = make_shared(); incomingTransfer->tx = tx; - tx->incomingTransfers.push_back(incomingTransfer); + tx->incoming_transfers.push_back(incomingTransfer); incomingTransfer->amount = pd.m_amount; - incomingTransfer->accountIndex = pd.m_subaddr_index.major; - incomingTransfer->subaddressIndex = pd.m_subaddr_index.minor; + incomingTransfer->account_index = pd.m_subaddr_index.major; + incomingTransfer->subaddress_index = pd.m_subaddr_index.minor; incomingTransfer->address = wallet2.get_subaddress_as_str(pd.m_subaddr_index); - // compute numSuggestedConfirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 `set_confirmations` but it should be encapsulated in wallet2 + // compute num_suggested_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 `set_confirmations` but it should be encapsulated in wallet2 // TODO: factor out this duplicate code with buildTxWithOutgoingTransfer() uint64_t blockReward = wallet2.get_last_block_reward(); - if (blockReward == 0) incomingTransfer->numSuggestedConfirmations = 0; - else incomingTransfer->numSuggestedConfirmations = (*incomingTransfer->amount + blockReward - 1) / blockReward; + if (blockReward == 0) incomingTransfer->num_suggested_confirmations = 0; + else incomingTransfer->num_suggested_confirmations = (*incomingTransfer->amount + blockReward - 1) / blockReward; // return pointer to new tx return tx; @@ -149,61 +149,61 @@ namespace monero { tx->block = block; block->txs.push_back(tx); tx->id = string_tools::pod_to_hex(txid); - tx->paymentId = string_tools::pod_to_hex(pd.m_payment_id); - if (tx->paymentId->substr(16).find_first_not_of('0') == std::string::npos) tx->paymentId = tx->paymentId->substr(0, 16); // TODO monero core: this should be part of core wallet - if (tx->paymentId == monero_tx::DEFAULT_PAYMENT_ID) tx->paymentId = boost::none; // clear default payment id - tx->unlockTime = pd.m_unlock_time; + tx->payment_id = string_tools::pod_to_hex(pd.m_payment_id); + if (tx->payment_id->substr(16).find_first_not_of('0') == std::string::npos) tx->payment_id = tx->payment_id->substr(0, 16); // TODO monero core: this should be part of core wallet + if (tx->payment_id == monero_tx::DEFAULT_PAYMENT_ID) tx->payment_id = boost::none; // clear default payment id + tx->unlock_time = pd.m_unlock_time; tx->fee = pd.m_amount_in - pd.m_amount_out; tx->note = wallet2.get_tx_note(txid); if (tx->note->empty()) tx->note = boost::none; // clear empty note - tx->isMinerTx = false; - tx->isConfirmed = true; - tx->isFailed = false; - tx->isRelayed = true; - tx->inTxPool = false; - tx->doNotRelay = false; - tx->isDoubleSpendSeen = false; + tx->is_miner_tx = false; + tx->is_confirmed = true; + tx->is_failed = false; + tx->is_relayed = true; + tx->in_tx_pool = false; + tx->do_not_relay = false; + tx->is_double_spend_seen = false; - // compute numConfirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 - if (*block->height >= height || (*block->height == 0 && !*tx->inTxPool)) tx->numConfirmations = 0; - else tx->numConfirmations = height - *block->height; + // compute num_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 + if (*block->height >= height || (*block->height == 0 && !*tx->in_tx_pool)) tx->num_confirmations = 0; + else tx->num_confirmations = height - *block->height; // construct transfer - shared_ptr outgoingTransfer = make_shared(); - outgoingTransfer->tx = tx; - tx->outgoingTransfer = outgoingTransfer; + shared_ptr outgoing_transfer = make_shared(); + outgoing_transfer->tx = tx; + tx->outgoing_transfer = outgoing_transfer; uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known - outgoingTransfer->amount = pd.m_amount_in - change - *tx->fee; - outgoingTransfer->accountIndex = pd.m_subaddr_account; - vector subaddressIndices; + outgoing_transfer->amount = pd.m_amount_in - change - *tx->fee; + outgoing_transfer->account_index = pd.m_subaddr_account; + vector subaddress_indices; vector addresses; for (uint32_t i: pd.m_subaddr_indices) { - subaddressIndices.push_back(i); + subaddress_indices.push_back(i); addresses.push_back(wallet2.get_subaddress_as_str({pd.m_subaddr_account, i})); } - outgoingTransfer->subaddressIndices = subaddressIndices; - outgoingTransfer->addresses = addresses; + outgoing_transfer->subaddress_indices = subaddress_indices; + outgoing_transfer->addresses = addresses; // initialize destinations for (const auto &d: pd.m_dests) { shared_ptr destination = make_shared(); destination->amount = d.amount; destination->address = d.original.empty() ? cryptonote::get_account_address_as_str(wallet2.nettype(), d.is_subaddress, d.addr) : d.original; - outgoingTransfer->destinations.push_back(destination); + outgoing_transfer->destinations.push_back(destination); } // replace transfer amount with destination sum // TODO monero core: confirmed tx from/to same account has amount 0 but cached transfer destinations - if (*outgoingTransfer->amount == 0 && !outgoingTransfer->destinations.empty()) { + if (*outgoing_transfer->amount == 0 && !outgoing_transfer->destinations.empty()) { uint64_t amount = 0; - for (const shared_ptr& destination : outgoingTransfer->destinations) amount += *destination->amount; - outgoingTransfer->amount = amount; + for (const shared_ptr& destination : outgoing_transfer->destinations) amount += *destination->amount; + outgoing_transfer->amount = amount; } - // compute numSuggestedConfirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 + // compute num_suggested_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 uint64_t blockReward = wallet2.get_last_block_reward(); - if (blockReward == 0) outgoingTransfer->numSuggestedConfirmations = 0; - else outgoingTransfer->numSuggestedConfirmations = (*outgoingTransfer->amount + blockReward - 1) / blockReward; + if (blockReward == 0) outgoing_transfer->num_suggested_confirmations = 0; + else outgoing_transfer->num_suggested_confirmations = (*outgoing_transfer->amount + blockReward - 1) / blockReward; // return pointer to new tx return tx; @@ -215,35 +215,35 @@ namespace monero { const tools::wallet2::payment_details &pd = ppd.m_pd; shared_ptr tx = make_shared(); tx->id = string_tools::pod_to_hex(pd.m_tx_hash); - tx->paymentId = string_tools::pod_to_hex(payment_id); - if (tx->paymentId->substr(16).find_first_not_of('0') == std::string::npos) tx->paymentId = tx->paymentId->substr(0, 16); // TODO monero core: this should be part of core wallet - if (tx->paymentId == monero_tx::DEFAULT_PAYMENT_ID) tx->paymentId = boost::none; // clear default payment id - tx->unlockTime = pd.m_unlock_time; + tx->payment_id = string_tools::pod_to_hex(payment_id); + if (tx->payment_id->substr(16).find_first_not_of('0') == std::string::npos) tx->payment_id = tx->payment_id->substr(0, 16); // TODO monero core: this should be part of core wallet + if (tx->payment_id == monero_tx::DEFAULT_PAYMENT_ID) tx->payment_id = boost::none; // clear default payment id + tx->unlock_time = pd.m_unlock_time; tx->fee = pd.m_fee; tx->note = wallet2.get_tx_note(pd.m_tx_hash); if (tx->note->empty()) tx->note = boost::none; // clear empty note - tx->isMinerTx = false; - tx->isConfirmed = false; - tx->isFailed = false; - tx->isRelayed = true; - tx->inTxPool = true; - tx->doNotRelay = false; - tx->isDoubleSpendSeen = ppd.m_double_spend_seen; - tx->numConfirmations = 0; + tx->is_miner_tx = false; + tx->is_confirmed = false; + tx->is_failed = false; + tx->is_relayed = true; + tx->in_tx_pool = true; + tx->do_not_relay = false; + tx->is_double_spend_seen = ppd.m_double_spend_seen; + tx->num_confirmations = 0; // construct transfer shared_ptr incomingTransfer = make_shared(); incomingTransfer->tx = tx; - tx->incomingTransfers.push_back(incomingTransfer); + tx->incoming_transfers.push_back(incomingTransfer); incomingTransfer->amount = pd.m_amount; - incomingTransfer->accountIndex = pd.m_subaddr_index.major; - incomingTransfer->subaddressIndex = pd.m_subaddr_index.minor; + incomingTransfer->account_index = pd.m_subaddr_index.major; + incomingTransfer->subaddress_index = pd.m_subaddr_index.minor; incomingTransfer->address = wallet2.get_subaddress_as_str(pd.m_subaddr_index); - // compute numSuggestedConfirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 + // compute num_suggested_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 uint64_t blockReward = wallet2.get_last_block_reward(); - if (blockReward == 0) incomingTransfer->numSuggestedConfirmations = 0; - else incomingTransfer->numSuggestedConfirmations = (*incomingTransfer->amount + blockReward - 1) / blockReward; + if (blockReward == 0) incomingTransfer->num_suggested_confirmations = 0; + else incomingTransfer->num_suggested_confirmations = (*incomingTransfer->amount + blockReward - 1) / blockReward; // return pointer to new tx return tx; @@ -253,58 +253,58 @@ namespace monero { // construct tx shared_ptr tx = make_shared(); - tx->isFailed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed; + tx->is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed; tx->id = string_tools::pod_to_hex(txid); - tx->paymentId = string_tools::pod_to_hex(pd.m_payment_id); - if (tx->paymentId->substr(16).find_first_not_of('0') == std::string::npos) tx->paymentId = tx->paymentId->substr(0, 16); // TODO monero core: this should be part of core wallet - if (tx->paymentId == monero_tx::DEFAULT_PAYMENT_ID) tx->paymentId = boost::none; // clear default payment id - tx->unlockTime = pd.m_tx.unlock_time; + tx->payment_id = string_tools::pod_to_hex(pd.m_payment_id); + if (tx->payment_id->substr(16).find_first_not_of('0') == std::string::npos) tx->payment_id = tx->payment_id->substr(0, 16); // TODO monero core: this should be part of core wallet + if (tx->payment_id == monero_tx::DEFAULT_PAYMENT_ID) tx->payment_id = boost::none; // clear default payment id + tx->unlock_time = pd.m_tx.unlock_time; tx->fee = pd.m_amount_in - pd.m_amount_out; tx->note = wallet2.get_tx_note(txid); if (tx->note->empty()) tx->note = boost::none; // clear empty note - tx->isMinerTx = false; - tx->isConfirmed = false; - tx->isRelayed = !tx->isFailed.get(); - tx->inTxPool = !tx->isFailed.get(); - tx->doNotRelay = false; - if (!tx->isFailed.get() && tx->isRelayed.get()) tx->isDoubleSpendSeen = false; // TODO: test and handle if true - tx->numConfirmations = 0; + tx->is_miner_tx = false; + tx->is_confirmed = false; + tx->is_relayed = !tx->is_failed.get(); + tx->in_tx_pool = !tx->is_failed.get(); + tx->do_not_relay = false; + if (!tx->is_failed.get() && tx->is_relayed.get()) tx->is_double_spend_seen = false; // TODO: test and handle if true + tx->num_confirmations = 0; // construct transfer - shared_ptr outgoingTransfer = make_shared(); - outgoingTransfer->tx = tx; - tx->outgoingTransfer = outgoingTransfer; - outgoingTransfer->amount = pd.m_amount_in - pd.m_change - tx->fee.get(); - outgoingTransfer->accountIndex = pd.m_subaddr_account; - vector subaddressIndices; + shared_ptr outgoing_transfer = make_shared(); + outgoing_transfer->tx = tx; + tx->outgoing_transfer = outgoing_transfer; + outgoing_transfer->amount = pd.m_amount_in - pd.m_change - tx->fee.get(); + outgoing_transfer->account_index = pd.m_subaddr_account; + vector subaddress_indices; vector addresses; for (uint32_t i: pd.m_subaddr_indices) { - subaddressIndices.push_back(i); + subaddress_indices.push_back(i); addresses.push_back(wallet2.get_subaddress_as_str({pd.m_subaddr_account, i})); } - outgoingTransfer->subaddressIndices = subaddressIndices; - outgoingTransfer->addresses = addresses; + outgoing_transfer->subaddress_indices = subaddress_indices; + outgoing_transfer->addresses = addresses; // initialize destinations for (const auto &d: pd.m_dests) { shared_ptr destination = make_shared(); destination->amount = d.amount; destination->address = d.original.empty() ? cryptonote::get_account_address_as_str(wallet2.nettype(), d.is_subaddress, d.addr) : d.original; - outgoingTransfer->destinations.push_back(destination); + outgoing_transfer->destinations.push_back(destination); } // replace transfer amount with destination sum // TODO monero core: confirmed tx from/to same account has amount 0 but cached transfer destinations - if (*outgoingTransfer->amount == 0 && !outgoingTransfer->destinations.empty()) { + if (*outgoing_transfer->amount == 0 && !outgoing_transfer->destinations.empty()) { uint64_t amount = 0; - for (const shared_ptr& destination : outgoingTransfer->destinations) amount += *destination->amount; - outgoingTransfer->amount = amount; + for (const shared_ptr& destination : outgoing_transfer->destinations) amount += *destination->amount; + outgoing_transfer->amount = amount; } - // compute numSuggestedConfirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 + // compute num_suggested_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 uint64_t blockReward = wallet2.get_last_block_reward(); - if (blockReward == 0) outgoingTransfer->numSuggestedConfirmations = 0; - else outgoingTransfer->numSuggestedConfirmations = (*outgoingTransfer->amount + blockReward - 1) / blockReward; + if (blockReward == 0) outgoing_transfer->num_suggested_confirmations = 0; + else outgoing_transfer->num_suggested_confirmations = (*outgoing_transfer->amount + blockReward - 1) / blockReward; // return pointer to new tx return tx; @@ -321,12 +321,12 @@ namespace monero { tx->block = block; block->txs.push_back(tx); tx->id = epee::string_tools::pod_to_hex(td.m_txid); - tx->isConfirmed = true; - tx->isFailed = false; - tx->isRelayed = true; - tx->inTxPool = false; - tx->doNotRelay = false; - tx->isDoubleSpendSeen = false; + tx->is_confirmed = true; + tx->is_failed = false; + tx->is_relayed = true; + tx->in_tx_pool = false; + tx->do_not_relay = false; + tx->is_double_spend_seen = false; // construct vout shared_ptr vout = make_shared(); @@ -334,14 +334,14 @@ namespace monero { tx->vouts.push_back(vout); vout->amount = td.amount(); vout->index = td.m_global_output_index; - vout->accountIndex = td.m_subaddr_index.major; - vout->subaddressIndex = td.m_subaddr_index.minor; - vout->isSpent = td.m_spent; - vout->isUnlocked = wallet2.is_transfer_unlocked(td); - vout->isFrozen = td.m_frozen; + vout->account_index = td.m_subaddr_index.major; + vout->subaddress_index = td.m_subaddr_index.minor; + vout->is_spent = td.m_spent; + vout->is_unlocked = wallet2.is_transfer_unlocked(td); + vout->is_frozen = td.m_frozen; if (td.m_key_image_known) { - vout->keyImage = make_shared(); - vout->keyImage.get()->hex = epee::string_tools::pod_to_hex(td.m_key_image); + vout->key_image = make_shared(); + vout->key_image.get()->hex = epee::string_tools::pod_to_hex(td.m_key_image); } // return pointer to new tx @@ -408,8 +408,8 @@ namespace monero { if (txHeightLessThan(transfer1->tx, transfer2->tx)) return true; // compare by account and subaddress index - if (transfer1->accountIndex.get() < transfer2->accountIndex.get()) return true; - else if (transfer1->accountIndex.get() == transfer2->accountIndex.get()) return transfer1->subaddressIndex.get() < transfer2->subaddressIndex.get(); + if (transfer1->account_index.get() < transfer2->account_index.get()) return true; + else if (transfer1->account_index.get() == transfer2->account_index.get()) return transfer1->subaddress_index.get() < transfer2->subaddress_index.get(); else return false; } @@ -424,10 +424,10 @@ namespace monero { if (txHeightLessThan(ow1->tx, ow2->tx)) return true; // compare by account index, subaddress index, and output - if (ow1->accountIndex.get() < ow2->accountIndex.get()) return true; - else if (ow1->accountIndex.get() == ow2->accountIndex.get()) { - if (ow1->subaddressIndex.get() < ow2->subaddressIndex.get()) return true; - if (ow1->subaddressIndex.get() == ow2->subaddressIndex.get() && ow1->index.get() < ow2->index.get()) return true; + if (ow1->account_index.get() < ow2->account_index.get()) return true; + else if (ow1->account_index.get() == ow2->account_index.get()) { + if (ow1->subaddress_index.get() < ow2->subaddress_index.get()) return true; + if (ow1->subaddress_index.get() == ow2->subaddress_index.get() && ow1->index.get() < ow2->index.get()) return true; } return false; } @@ -696,7 +696,7 @@ namespace monero { updateListening(); } - virtual void on_new_block(uint64_t height, const cryptonote::block& cnBlock) { + virtual void on_new_block(uint64_t height, const cryptonote::block& cn_block) { // notify listener of block if (listener != boost::none) listener->on_new_block(height); @@ -711,24 +711,24 @@ namespace monero { } } - virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cnTx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time) { + virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cn_tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time) { MTRACE("Wallet2Listener::on_money_received()"); if (listener == boost::none) return; // create native library tx shared_ptr block = make_shared(); block->height = height; - shared_ptr tx = static_pointer_cast(monero_utils::cnTxToTx(cnTx, true)); + shared_ptr tx = static_pointer_cast(monero_utils::cn_tx_to_tx(cn_tx, true)); block->txs.push_back(tx); tx->block = block; tx->id = epee::string_tools::pod_to_hex(txid); - tx->unlockTime = unlock_time; + tx->unlock_time = unlock_time; shared_ptr output = make_shared(); tx->vouts.push_back(output); output->tx = tx; output->amount = amount; - output->accountIndex = subaddr_index.major; - output->subaddressIndex = subaddr_index.minor; + output->account_index = subaddr_index.major; + output->subaddress_index = subaddr_index.minor; // notify listener of output listener->on_output_received(*output); @@ -741,7 +741,7 @@ namespace monero { // create native library tx shared_ptr block = make_shared(); block->height = height; - shared_ptr tx = static_pointer_cast(monero_utils::cnTxToTx(cnTxIn, true)); + shared_ptr tx = static_pointer_cast(monero_utils::cn_tx_to_tx(cnTxIn, true)); block->txs.push_back(tx); tx->block = block; tx->id = epee::string_tools::pod_to_hex(txid); @@ -749,8 +749,8 @@ namespace monero { tx->vins.push_back(output); output->tx = tx; output->amount = amount; - output->accountIndex = subaddr_index.major; - output->subaddressIndex = subaddr_index.minor; + output->account_index = subaddr_index.major; + output->subaddress_index = subaddr_index.minor; // notify listener of output listener->on_output_spent(*output); @@ -1028,54 +1028,54 @@ namespace monero { // return indices in subaddress monero_subaddress subaddress; cryptonote::subaddress_index cnIndex = *index; - subaddress.accountIndex = cnIndex.major; + subaddress.account_index = cnIndex.major; subaddress.index = cnIndex.minor; return subaddress; } - monero_integrated_address monero_wallet::get_integrated_address(const string& standardAddress, const string& paymentId) const { - MTRACE("get_integrated_address(" << standardAddress << ", " << paymentId << ")"); + monero_integrated_address monero_wallet::get_integrated_address(const string& standard_address, const string& payment_id) const { + MTRACE("get_integrated_address(" << standard_address << ", " << payment_id << ")"); // TODO monero-core: this logic is based on wallet_rpc_server::on_make_integrated_address() and should be moved to wallet so this is unecessary for api users // randomly generate payment id if not given, else validate crypto::hash8 paymentIdH8; - if (paymentId.empty()) { + if (payment_id.empty()) { paymentIdH8 = crypto::rand(); } else { - if (!tools::wallet2::parse_short_payment_id(paymentId, paymentIdH8)) throw runtime_error("Invalid payment ID: " + paymentId); + if (!tools::wallet2::parse_short_payment_id(payment_id, paymentIdH8)) throw runtime_error("Invalid payment ID: " + payment_id); } // use primary address if standard address not given, else validate - if (standardAddress.empty()) { + if (standard_address.empty()) { return decode_integrated_address(wallet2->get_integrated_address_as_str(paymentIdH8)); } else { // validate standard address cryptonote::address_parse_info info; - if (!cryptonote::get_account_address_from_str(info, wallet2->nettype(), standardAddress)) throw runtime_error("Invalid address: " + standardAddress); + if (!cryptonote::get_account_address_from_str(info, wallet2->nettype(), standard_address)) throw runtime_error("Invalid address: " + standard_address); if (info.is_subaddress) throw runtime_error("Subaddress shouldn't be used"); if (info.has_payment_id) throw runtime_error("Already integrated address"); - if (paymentId.empty()) throw runtime_error("Payment ID shouldn't be left unspecified"); + if (payment_id.empty()) throw runtime_error("Payment ID shouldn't be left unspecified"); // create integrated address from given standard address return decode_integrated_address(cryptonote::get_account_integrated_address_as_str(wallet2->nettype(), info.address, paymentIdH8)); } } - monero_integrated_address monero_wallet::decode_integrated_address(const string& integratedAddress) const { - MTRACE("decode_integrated_address(" << integratedAddress << ")"); + monero_integrated_address monero_wallet::decode_integrated_address(const string& integrated_address) const { + MTRACE("decode_integrated_address(" << integrated_address << ")"); // validate integrated address cryptonote::address_parse_info info; - if (!cryptonote::get_account_address_from_str(info, wallet2->nettype(), integratedAddress)) throw runtime_error("Invalid integrated address: " + integratedAddress); + if (!cryptonote::get_account_address_from_str(info, wallet2->nettype(), integrated_address)) throw runtime_error("Invalid integrated address: " + integrated_address); if (!info.has_payment_id) throw runtime_error("Address is not an integrated address"); // initialize and return result monero_integrated_address result; - result.standardAddress = cryptonote::get_account_address_as_str(wallet2->nettype(), info.is_subaddress, info.address); - result.paymentId = epee::string_tools::pod_to_hex(info.payment_id); - result.integratedAddress = integratedAddress; + result.standard_address = cryptonote::get_account_address_as_str(wallet2->nettype(), info.is_subaddress, info.address); + result.payment_id = epee::string_tools::pod_to_hex(info.payment_id); + result.integrated_address = integrated_address; return result; } @@ -1238,9 +1238,9 @@ namespace monero { for (uint32_t accountIdx = 0; accountIdx < wallet2->get_num_subaddress_accounts(); accountIdx++) { monero_account account; account.index = accountIdx; - account.primaryAddress = get_address(accountIdx, 0); + account.primary_address = get_address(accountIdx, 0); account.balance = wallet2->balance(accountIdx); - account.unlockedBalance = wallet2->unlocked_balance(accountIdx); + account.unlocked_balance = wallet2->unlocked_balance(accountIdx); if (includeSubaddresses) account.subaddresses = getSubaddressesAux(accountIdx, vector(), transfers); accounts.push_back(account); } @@ -1262,9 +1262,9 @@ namespace monero { // build and return account monero_account account; account.index = accountIdx; - account.primaryAddress = get_address(accountIdx, 0); + account.primary_address = get_address(accountIdx, 0); account.balance = wallet2->balance(accountIdx); - account.unlockedBalance = wallet2->unlocked_balance(accountIdx); + account.unlocked_balance = wallet2->unlocked_balance(accountIdx); if (includeSubaddresses) account.subaddresses = getSubaddressesAux(accountIdx, vector(), transfers); return account; } @@ -1278,9 +1278,9 @@ namespace monero { // initialize and return result monero_account account; account.index = wallet2->get_num_subaddress_accounts() - 1; - account.primaryAddress = wallet2->get_subaddress_as_str({account.index.get(), 0}); + account.primary_address = wallet2->get_subaddress_as_str({account.index.get(), 0}); account.balance = 0; - account.unlockedBalance = 0; + account.unlocked_balance = 0; return account; } @@ -1288,13 +1288,13 @@ namespace monero { return get_subaddresses(accountIdx, vector()); } - vector monero_wallet::get_subaddresses(const uint32_t accountIdx, const vector& subaddressIndices) const { + vector monero_wallet::get_subaddresses(const uint32_t accountIdx, const vector& subaddress_indices) const { MTRACE("get_subaddresses(" << accountIdx << ", ...)"); - MTRACE("Subaddress indices size: " << subaddressIndices.size()); + MTRACE("Subaddress indices size: " << subaddress_indices.size()); vector transfers; wallet2->get_transfers(transfers); - return getSubaddressesAux(accountIdx, subaddressIndices, transfers); + return getSubaddressesAux(accountIdx, subaddress_indices, transfers); } monero_subaddress monero_wallet::getSubaddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const { @@ -1311,15 +1311,15 @@ namespace monero { // initialize and return result monero_subaddress subaddress; - subaddress.accountIndex = accountIdx; + subaddress.account_index = accountIdx; subaddress.index = wallet2->get_num_subaddresses(accountIdx) - 1; subaddress.address = wallet2->get_subaddress_as_str({accountIdx, subaddress.index.get()}); subaddress.label = label; subaddress.balance = 0; - subaddress.unlockedBalance = 0; - subaddress.numUnspentOutputs = 0; - subaddress.isUsed = false; - subaddress.numBlocksToUnlock = 0; + subaddress.unlocked_balance = 0; + subaddress.num_unspent_outputs = 0; + subaddress.is_used = false; + subaddress.num_blocks_to_unlock = 0; return subaddress; } @@ -1334,19 +1334,19 @@ namespace monero { // copy and normalize tx request shared_ptr requestSp = make_shared(request); // convert to shared pointer for copy shared_ptr req = requestSp->copy(requestSp, make_shared()); - if (req->transferRequest == boost::none) req->transferRequest = make_shared(); - shared_ptr transferReq = req->transferRequest.get(); + if (req->transfer_request == boost::none) req->transfer_request = make_shared(); + shared_ptr transferReq = req->transfer_request.get(); // print req if (req->block != boost::none) MTRACE("Tx req's rooted at [block]: " << req->block.get()->serialize()); else MTRACE("Tx req: " << req->serialize()); // temporarily disable transfer request - req->transferRequest = boost::none; + req->transfer_request = boost::none; // fetch all transfers that meet tx request monero_transfer_request tempTransferReq; - tempTransferReq.txRequest = make_shared(*req); + tempTransferReq.tx_request = make_shared(*req); vector> transfers = get_transfers(tempTransferReq); // collect unique txs from transfers while retaining order @@ -1368,8 +1368,8 @@ namespace monero { // fetch and merge outputs if requested monero_output_request tempOutputReq; - tempOutputReq.txRequest = make_shared(*req); - if (req->includeOutputs != boost::none && *req->includeOutputs) { + tempOutputReq.tx_request = make_shared(*req); + if (req->include_outputs != boost::none && *req->include_outputs) { // fetch outputs vector> outputs = get_outputs(tempOutputReq); @@ -1386,7 +1386,7 @@ namespace monero { } // filter txs that don't meet transfer req // TODO: port this updated version to js - req->transferRequest = transferReq; + req->transfer_request = transferReq; vector> txsRequested; vector>::iterator txIter = txs.begin(); while (txIter != txs.end()) { @@ -1402,8 +1402,8 @@ namespace monero { txs = txsRequested; // verify all specified tx ids found - if (!req->txIds.empty()) { - for (const string& txId : req->txIds) { + if (!req->tx_ids.empty()) { + for (const string& txId : req->tx_ids) { bool found = false; for (const shared_ptr& tx : txs) { if (txId == *tx->id) { @@ -1418,13 +1418,13 @@ namespace monero { // special case: re-fetch txs if inconsistency caused by needing to make multiple wallet calls // TODO monero core: offer wallet.get_txs(...) for (const shared_ptr& tx : txs) { - if (*tx->isConfirmed && tx->block == boost::none) return get_txs(*req); + if (*tx->is_confirmed && tx->block == boost::none) return get_txs(*req); } // otherwise order txs if tx ids given then return - if (!req->txIds.empty()) { + if (!req->tx_ids.empty()) { vector> orderedTxs; - for (const string& txId : req->txIds) { + for (const string& txId : req->tx_ids) { map>::const_iterator txIter = txMap.find(txId); orderedTxs.push_back(txIter->second); } @@ -1437,50 +1437,50 @@ namespace monero { MTRACE("monero_wallet::get_transfers(request)"); // LOG request - if (request.txRequest != boost::none) { - if ((*request.txRequest)->block == boost::none) MTRACE("Transfer request's tx request rooted at [tx]:" << (*request.txRequest)->serialize()); - else MTRACE("Transfer request's tx request rooted at [block]: " << (*(*request.txRequest)->block)->serialize()); + if (request.tx_request != boost::none) { + if ((*request.tx_request)->block == boost::none) MTRACE("Transfer request's tx request rooted at [tx]:" << (*request.tx_request)->serialize()); + else MTRACE("Transfer request's tx request rooted at [block]: " << (*(*request.tx_request)->block)->serialize()); } // copy and normalize request shared_ptr req; - if (request.txRequest == boost::none) req = request.copy(make_shared(request), make_shared()); + if (request.tx_request == boost::none) req = request.copy(make_shared(request), make_shared()); else { - shared_ptr txReq = request.txRequest.get()->copy(request.txRequest.get(), make_shared()); - if (request.txRequest.get()->transferRequest != boost::none && request.txRequest.get()->transferRequest.get().get() == &request) { - req = txReq->transferRequest.get(); + shared_ptr txReq = request.tx_request.get()->copy(request.tx_request.get(), make_shared()); + if (request.tx_request.get()->transfer_request != boost::none && request.tx_request.get()->transfer_request.get().get() == &request) { + req = txReq->transfer_request.get(); } else { - if (request.txRequest.get()->transferRequest != boost::none) throw new runtime_error("Transfer request's tx request must be a circular reference or null"); + if (request.tx_request.get()->transfer_request != boost::none) throw new runtime_error("Transfer request's tx request must be a circular reference or null"); shared_ptr requestSp = make_shared(request); // convert request to shared pointer for copy req = requestSp->copy(requestSp, make_shared()); - req->txRequest = txReq; + req->tx_request = txReq; } } - if (req->txRequest == boost::none) req->txRequest = make_shared(); - shared_ptr txReq = req->txRequest.get(); - txReq->transferRequest = boost::none; // break circular link for meetsCriteria() + if (req->tx_request == boost::none) req->tx_request = make_shared(); + shared_ptr txReq = req->tx_request.get(); + txReq->transfer_request = boost::none; // break circular link for meetsCriteria() // build parameters for wallet2->get_payments() - uint64_t minHeight = txReq->minHeight == boost::none ? 0 : *txReq->minHeight; - uint64_t maxHeight = txReq->maxHeight == boost::none ? CRYPTONOTE_MAX_BLOCK_NUMBER : min((uint64_t) CRYPTONOTE_MAX_BLOCK_NUMBER, *txReq->maxHeight); - if (minHeight > 0) minHeight--; // TODO monero core: wallet2::get_payments() min_height is exclusive, so manually offset to match intended range (issues 5751, #5598) - boost::optional accountIndex = boost::none; - if (req->accountIndex != boost::none) accountIndex = *req->accountIndex; - std::set subaddressIndices; - for (int i = 0; i < req->subaddressIndices.size(); i++) { - subaddressIndices.insert(req->subaddressIndices[i]); + uint64_t min_height = txReq->min_height == boost::none ? 0 : *txReq->min_height; + uint64_t max_height = txReq->max_height == boost::none ? CRYPTONOTE_MAX_BLOCK_NUMBER : min((uint64_t) CRYPTONOTE_MAX_BLOCK_NUMBER, *txReq->max_height); + if (min_height > 0) min_height--; // TODO monero core: wallet2::get_payments() min_height is exclusive, so manually offset to match intended range (issues 5751, #5598) + boost::optional account_index = boost::none; + if (req->account_index != boost::none) account_index = *req->account_index; + std::set subaddress_indices; + for (int i = 0; i < req->subaddress_indices.size(); i++) { + subaddress_indices.insert(req->subaddress_indices[i]); } // translate from monero_tx_request to in, out, pending, pool, failed terminology used by monero-wallet-rpc - bool canBeConfirmed = !boolEquals(false, txReq->isConfirmed) && !boolEquals(true, txReq->inTxPool) && !boolEquals(true, txReq->isFailed) && !boolEquals(false, txReq->isRelayed); - bool canBeInTxPool = !boolEquals(true, txReq->isConfirmed) && !boolEquals(false, txReq->inTxPool) && !boolEquals(true, txReq->isFailed) && !boolEquals(false, txReq->isRelayed) && txReq->get_height() == boost::none && txReq->minHeight == boost::none; - bool canBeIncoming = !boolEquals(false, req->isIncoming) && !boolEquals(true, req->getIsOutgoing()) && !boolEquals(true, req->hasDestinations); - bool canBeOutgoing = !boolEquals(false, req->getIsOutgoing()) && !boolEquals(true, req->isIncoming); + bool canBeConfirmed = !boolEquals(false, txReq->is_confirmed) && !boolEquals(true, txReq->in_tx_pool) && !boolEquals(true, txReq->is_failed) && !boolEquals(false, txReq->is_relayed); + bool canBeInTxPool = !boolEquals(true, txReq->is_confirmed) && !boolEquals(false, txReq->in_tx_pool) && !boolEquals(true, txReq->is_failed) && !boolEquals(false, txReq->is_relayed) && txReq->get_height() == boost::none && txReq->min_height == boost::none; + bool canBeIncoming = !boolEquals(false, req->is_incoming) && !boolEquals(true, req->getIsOutgoing()) && !boolEquals(true, req->has_destinations); + bool canBeOutgoing = !boolEquals(false, req->getIsOutgoing()) && !boolEquals(true, req->is_incoming); bool isIn = canBeIncoming && canBeConfirmed; bool isOut = canBeOutgoing && canBeConfirmed; bool isPending = canBeOutgoing && canBeInTxPool; bool isPool = canBeIncoming && canBeInTxPool; - bool isFailed = !boolEquals(false, txReq->isFailed) && !boolEquals(true, txReq->isConfirmed) && !boolEquals(true, txReq->inTxPool); + bool is_failed = !boolEquals(false, txReq->is_failed) && !boolEquals(true, txReq->is_confirmed) && !boolEquals(true, txReq->in_tx_pool); // cache unique txs and blocks uint64_t height = get_height(); @@ -1490,7 +1490,7 @@ namespace monero { // get confirmed incoming transfers if (isIn) { std::list> payments; - wallet2->get_payments(payments, minHeight, maxHeight, accountIndex, subaddressIndices); + wallet2->get_payments(payments, min_height, max_height, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { shared_ptr tx = buildTxWithIncomingTransfer(*wallet2, height, i->first, i->second); merge_tx(tx, txMap, blockMap, false); @@ -1500,7 +1500,7 @@ namespace monero { // get confirmed outgoing transfers if (isOut) { std::list> payments; - wallet2->get_payments_out(payments, minHeight, maxHeight, accountIndex, subaddressIndices); + wallet2->get_payments_out(payments, min_height, max_height, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { shared_ptr tx = buildTxWithOutgoingTransfer(*wallet2, height, i->first, i->second); merge_tx(tx, txMap, blockMap, false); @@ -1508,12 +1508,12 @@ namespace monero { } // get unconfirmed or failed outgoing transfers - if (isPending || isFailed) { + if (isPending || is_failed) { std::list> upayments; - wallet2->get_unconfirmed_payments_out(upayments, accountIndex, subaddressIndices); + wallet2->get_unconfirmed_payments_out(upayments, account_index, subaddress_indices); for (std::list>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) { shared_ptr tx = buildTxWithOutgoingTransferUnconfirmed(*wallet2, i->first, i->second); - if (txReq->isFailed != boost::none && txReq->isFailed.get() != tx->isFailed.get()) continue; // skip merging if tx unrequested + if (txReq->is_failed != boost::none && txReq->is_failed.get() != tx->is_failed.get()) continue; // skip merging if tx unrequested merge_tx(tx, txMap, blockMap, false); } } @@ -1522,7 +1522,7 @@ namespace monero { if (isPool) { wallet2->update_pool_state(); // TODO monero-core: this should be encapsulated in wallet when unconfirmed transfers requested std::list> payments; - wallet2->get_unconfirmed_payments(payments, accountIndex, subaddressIndices); + wallet2->get_unconfirmed_payments(payments, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { shared_ptr tx = buildTxWithIncomingTransferUnconfirmed(*wallet2, i->first, i->second); merge_tx(tx, txMap, blockMap, false); @@ -1541,25 +1541,25 @@ namespace monero { for (const shared_ptr& tx : txs) { // sort transfers - sort(tx->incomingTransfers.begin(), tx->incomingTransfers.end(), incomingTransferBefore); + sort(tx->incoming_transfers.begin(), tx->incoming_transfers.end(), incomingTransferBefore); // collect outgoing transfer, erase if filtered TODO: js does not erase unrequested data, port to js - if (tx->outgoingTransfer != boost::none && req->meetsCriteria(tx->outgoingTransfer.get().get())) transfers.push_back(tx->outgoingTransfer.get()); - else tx->outgoingTransfer = boost::none; + if (tx->outgoing_transfer != boost::none && req->meetsCriteria(tx->outgoing_transfer.get().get())) transfers.push_back(tx->outgoing_transfer.get()); + else tx->outgoing_transfer = boost::none; // collect incoming transfers, erase if unrequested - vector>::iterator iter = tx->incomingTransfers.begin(); - while (iter != tx->incomingTransfers.end()) { + vector>::iterator iter = tx->incoming_transfers.begin(); + while (iter != tx->incoming_transfers.end()) { if (req->meetsCriteria((*iter).get())) { transfers.push_back(*iter); iter++; } else { - iter = tx->incomingTransfers.erase(iter); + iter = tx->incoming_transfers.erase(iter); } } // remove unrequested txs from block - if (tx->block != boost::none && tx->outgoingTransfer == boost::none && tx->incomingTransfers.empty()) { + if (tx->block != boost::none && tx->outgoing_transfer == boost::none && tx->incoming_transfers.empty()) { tx->block.get()->txs.erase(std::remove(tx->block.get()->txs.begin(), tx->block.get()->txs.end(), tx), tx->block.get()->txs.end()); // TODO, no way to use const_iterator? } } @@ -1573,28 +1573,28 @@ namespace monero { // print request MTRACE("Output request: " << request.serialize()); - if (request.txRequest != boost::none) { - if ((*request.txRequest)->block == boost::none) MTRACE("Output request's tx request rooted at [tx]:" << (*request.txRequest)->serialize()); - else MTRACE("Output request's tx request rooted at [block]: " << (*(*request.txRequest)->block)->serialize()); + if (request.tx_request != boost::none) { + if ((*request.tx_request)->block == boost::none) MTRACE("Output request's tx request rooted at [tx]:" << (*request.tx_request)->serialize()); + else MTRACE("Output request's tx request rooted at [block]: " << (*(*request.tx_request)->block)->serialize()); } // copy and normalize request shared_ptr req; - if (request.txRequest == boost::none) req = request.copy(make_shared(request), make_shared()); + if (request.tx_request == boost::none) req = request.copy(make_shared(request), make_shared()); else { - shared_ptr txReq = request.txRequest.get()->copy(request.txRequest.get(), make_shared()); - if (request.txRequest.get()->outputRequest != boost::none && request.txRequest.get()->outputRequest.get().get() == &request) { - req = txReq->outputRequest.get(); + shared_ptr txReq = request.tx_request.get()->copy(request.tx_request.get(), make_shared()); + if (request.tx_request.get()->output_request != boost::none && request.tx_request.get()->output_request.get().get() == &request) { + req = txReq->output_request.get(); } else { - if (request.txRequest.get()->outputRequest != boost::none) throw new runtime_error("Output request's tx request must be a circular reference or null"); + if (request.tx_request.get()->output_request != boost::none) throw new runtime_error("Output request's tx request must be a circular reference or null"); shared_ptr requestSp = make_shared(request); // convert request to shared pointer for copy req = requestSp->copy(requestSp, make_shared()); - req->txRequest = txReq; + req->tx_request = txReq; } } - if (req->txRequest == boost::none) req->txRequest = make_shared(); - shared_ptr txReq = req->txRequest.get(); - txReq->outputRequest = boost::none; // break circular link for meetsCriteria() + if (req->tx_request == boost::none) req->tx_request = make_shared(); + shared_ptr txReq = req->tx_request.get(); + txReq->output_request = boost::none; // break circular link for meetsCriteria() // get output data from wallet2 tools::wallet2::transfer_container outputsW2; @@ -1664,10 +1664,10 @@ namespace monero { vector> keyImages; std::pair>> ski = wallet2->export_key_images(true); for (size_t n = 0; n < ski.second.size(); ++n) { - shared_ptr keyImage = make_shared(); - keyImages.push_back(keyImage); - keyImage->hex = epee::string_tools::pod_to_hex(ski.second[n].first); - keyImage->signature = epee::string_tools::pod_to_hex(ski.second[n].second); + shared_ptr key_image = make_shared(); + keyImages.push_back(key_image); + key_image->hex = epee::string_tools::pod_to_hex(ski.second[n].first); + key_image->signature = epee::string_tools::pod_to_hex(ski.second[n].second); } return keyImages; } @@ -1694,8 +1694,8 @@ namespace monero { // translate results shared_ptr result = make_shared(); result->height = height; - result->spentAmount = spent; - result->unspentAmount = unspent; + result->spent_amount = spent; + result->unspent_amount = unspent; return result; } @@ -1708,7 +1708,7 @@ namespace monero { epee::json_rpc::error err; // prepare parameters for wallet rpc's validate_transfer() - string paymentId = request.paymentId == boost::none ? string("") : request.paymentId.get(); + string payment_id = request.payment_id == boost::none ? string("") : request.payment_id.get(); list trDestinations; for (const shared_ptr& destination : request.destinations) { tools::wallet_rpc::transfer_destination trDestination; @@ -1720,25 +1720,25 @@ namespace monero { // validate the requested txs and populate dsts & extra std::vector dsts; std::vector extra; - if (!validate_transfer(wallet2.get(), trDestinations, paymentId, dsts, extra, true, err)) { + if (!validate_transfer(wallet2.get(), trDestinations, payment_id, dsts, extra, true, err)) { throw runtime_error("Need to handle send_split() validate_transfer error"); // TODO } // prepare parameters for wallet2's create_transactions_2() uint64_t mixin = wallet2->adjust_mixin(request.ringSize == boost::none ? 0 : request.ringSize.get() - 1); uint32_t priority = wallet2->adjust_priority(request.priority == boost::none ? 0 : request.priority.get()); - uint64_t unlockTime = request.unlockTime == boost::none ? 0 : request.unlockTime.get(); - if (request.accountIndex == boost::none) throw runtime_error("Must specify the account index to send from"); - uint32_t accountIndex = request.accountIndex.get(); - std::set subaddressIndices; - for (const uint32_t& subaddressIdx : request.subaddressIndices) subaddressIndices.insert(subaddressIdx); + uint64_t unlock_time = request.unlock_time == boost::none ? 0 : request.unlock_time.get(); + if (request.account_index == boost::none) throw runtime_error("Must specify the account index to send from"); + uint32_t account_index = request.account_index.get(); + std::set subaddress_indices; + for (const uint32_t& subaddressIdx : request.subaddress_indices) subaddress_indices.insert(subaddressIdx); // prepare transactions - vector ptx_vector = wallet2->create_transactions_2(dsts, mixin, unlockTime, priority, extra, accountIndex, subaddressIndices); + vector ptx_vector = wallet2->create_transactions_2(dsts, mixin, unlock_time, priority, extra, account_index, subaddress_indices); if (ptx_vector.empty()) throw runtime_error("No transaction created"); // check if request cannot be fulfilled due to splitting - if (request.canSplit != boost::none && request.canSplit.get() == false && ptx_vector.size() != 1) { + if (request.can_split != boost::none && request.can_split.get() == false && ptx_vector.size() != 1) { throw runtime_error("Transaction would be too large. Try send_split()"); } @@ -1746,7 +1746,7 @@ namespace monero { bool getTxKeys = true; bool getTxHex = true; bool getTxMetadata = true; - bool doNotRelay = request.doNotRelay == boost::none ? false : request.doNotRelay.get(); + bool do_not_relay = request.do_not_relay == boost::none ? false : request.do_not_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() list txKeys; @@ -1754,22 +1754,22 @@ namespace monero { list txFees; string multisigTxSet; string unsignedTxSet; - list txIds; + list tx_ids; list txBlobs; list txMetadatas; - if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, doNotRelay, txIds, getTxHex, txBlobs, getTxMetadata, txMetadatas, err)) { + if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, do_not_relay, tx_ids, getTxHex, txBlobs, getTxMetadata, txMetadatas, err)) { throw runtime_error("need to handle error filling response!"); // TODO } // build sent txs from results // TODO: break this into separate utility function vector> txs; - auto txIdsIter = txIds.begin(); + auto txIdsIter = tx_ids.begin(); auto txKeysIter = txKeys.begin(); auto txAmountsIter = txAmounts.begin(); auto txFeesIter = txFees.begin(); auto txBlobsIter = txBlobs.begin(); auto txMetadatasIter = txMetadatas.begin(); - while (txIdsIter != txIds.end()) { + while (txIdsIter != tx_ids.end()) { // init tx with outgoing transfer from filled values shared_ptr tx = make_shared(); @@ -1777,27 +1777,27 @@ namespace monero { tx->id = *txIdsIter; tx->key = *txKeysIter; tx->fee = *txFeesIter; - tx->fullHex = *txBlobsIter; + tx->full_hex = *txBlobsIter; tx->metadata = *txMetadatasIter; shared_ptr outTransfer = make_shared(); - tx->outgoingTransfer = outTransfer; + tx->outgoing_transfer = outTransfer; outTransfer->amount = *txAmountsIter; // init other known fields - tx->paymentId = request.paymentId; - tx->isConfirmed = false; - tx->isMinerTx = false; - tx->isFailed = false; // TODO: test and handle if true - tx->doNotRelay = request.doNotRelay != boost::none && request.doNotRelay.get() == true; - tx->isRelayed = tx->doNotRelay.get() != true; - tx->inTxPool = !tx->doNotRelay.get(); - if (!tx->isFailed.get() && tx->isRelayed.get()) tx->isDoubleSpendSeen = false; // TODO: test and handle if true - tx->numConfirmations = 0; + tx->payment_id = request.payment_id; + tx->is_confirmed = false; + tx->is_miner_tx = false; + tx->is_failed = false; // TODO: test and handle if true + tx->do_not_relay = request.do_not_relay != boost::none && request.do_not_relay.get() == true; + tx->is_relayed = tx->do_not_relay.get() != true; + tx->in_tx_pool = !tx->do_not_relay.get(); + if (!tx->is_failed.get() && tx->is_relayed.get()) tx->is_double_spend_seen = false; // TODO: test and handle if true + tx->num_confirmations = 0; tx->mixin = request.mixin; - tx->unlockTime = request.unlockTime == boost::none ? 0 : request.unlockTime.get(); - if (tx->isRelayed.get()) tx->lastRelayedTimestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 - outTransfer->accountIndex = request.accountIndex; - if (request.subaddressIndices.size() == 1) outTransfer->subaddressIndices.push_back(request.subaddressIndices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here + tx->unlock_time = request.unlock_time == boost::none ? 0 : request.unlock_time.get(); + if (tx->is_relayed.get()) tx->last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 + outTransfer->account_index = request.account_index; + if (request.subaddress_indices.size() == 1) outTransfer->subaddress_indices.push_back(request.subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here outTransfer->destinations = request.destinations; // iterate to next element @@ -1816,11 +1816,11 @@ namespace monero { MTRACE("monero_send_request: " << request.serialize()); // validate input request - if (request.keyImage == boost::none || request.keyImage.get().empty()) throw runtime_error("Must provide key image of output to sweep"); + if (request.key_image == boost::none || request.key_image.get().empty()) throw runtime_error("Must provide key image of output to sweep"); if (request.destinations.size() != 1 || request.destinations[0]->address == boost::none || request.destinations[0]->address.get().empty()) throw runtime_error("Must provide exactly one destination to sweep output to"); // validate the transfer requested and populate dsts & extra - string paymentId = request.paymentId == boost::none ? string("") : request.paymentId.get(); + string payment_id = request.payment_id == boost::none ? string("") : request.payment_id.get(); std::vector dsts; std::vector extra; std::list destination; @@ -1828,22 +1828,22 @@ namespace monero { destination.back().amount = 0; destination.back().address = request.destinations[0]->address.get(); epee::json_rpc::error er; - if (!validate_transfer(wallet2.get(), destination, paymentId, dsts, extra, true, er)) { + if (!validate_transfer(wallet2.get(), destination, payment_id, dsts, extra, true, er)) { //throw runtime_error(er); // TODO throw runtime_error("Handle validate_transfer error!"); } // validate key image crypto::key_image ki; - if (!epee::string_tools::hex_to_pod(request.keyImage.get(), ki)) { + if (!epee::string_tools::hex_to_pod(request.key_image.get(), ki)) { throw runtime_error("failed to parse key image"); } // create transaction uint64_t mixin = wallet2->adjust_mixin(request.ringSize == boost::none ? 0 : request.ringSize.get() - 1); uint32_t priority = wallet2->adjust_priority(request.priority == boost::none ? 0 : request.priority.get()); - uint64_t unlockTime = request.unlockTime == boost::none ? 0 : request.unlockTime.get(); - std::vector ptx_vector = wallet2->create_transactions_single(ki, dsts[0].addr, dsts[0].is_subaddress, 1, mixin, unlockTime, priority, extra); + uint64_t unlock_time = request.unlock_time == boost::none ? 0 : request.unlock_time.get(); + std::vector ptx_vector = wallet2->create_transactions_single(ki, dsts[0].addr, dsts[0].is_subaddress, 1, mixin, unlock_time, priority, extra); // validate created transaction if (ptx_vector.empty()) throw runtime_error("No outputs found"); @@ -1855,7 +1855,7 @@ namespace monero { bool getTxKeys = true; bool getTxHex = true; bool getTxMetadata = true; - bool doNotRelay = request.doNotRelay == boost::none ? false : request.doNotRelay.get(); + bool do_not_relay = request.do_not_relay == boost::none ? false : request.do_not_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() list txKeys; @@ -1863,22 +1863,22 @@ namespace monero { list txFees; string multisigTxSet; string unsignedTxSet; - list txIds; + list tx_ids; list txBlobs; list txMetadatas; - if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, doNotRelay, txIds, getTxHex, txBlobs, getTxMetadata, txMetadatas, er)) { + if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, do_not_relay, tx_ids, getTxHex, txBlobs, getTxMetadata, txMetadatas, er)) { throw runtime_error("need to handle error filling response!"); // TODO: return err message } // build sent txs from results // TODO: use common utility with send_split() to avoid code duplication vector> txs; - auto txIdsIter = txIds.begin(); + auto txIdsIter = tx_ids.begin(); auto txKeysIter = txKeys.begin(); auto txAmountsIter = txAmounts.begin(); auto txFeesIter = txFees.begin(); auto txBlobsIter = txBlobs.begin(); auto txMetadatasIter = txMetadatas.begin(); - while (txIdsIter != txIds.end()) { + while (txIdsIter != tx_ids.end()) { // init tx with outgoing transfer from filled values shared_ptr tx = make_shared(); @@ -1886,27 +1886,27 @@ namespace monero { tx->id = *txIdsIter; tx->key = *txKeysIter; tx->fee = *txFeesIter; - tx->fullHex = *txBlobsIter; + tx->full_hex = *txBlobsIter; tx->metadata = *txMetadatasIter; shared_ptr outTransfer = make_shared(); - tx->outgoingTransfer = outTransfer; + tx->outgoing_transfer = outTransfer; outTransfer->amount = *txAmountsIter; // init other known fields - tx->paymentId = request.paymentId; - tx->isConfirmed = false; - tx->isMinerTx = false; - tx->isFailed = false; // TODO: test and handle if true - tx->doNotRelay = request.doNotRelay != boost::none && request.doNotRelay.get() == true; - tx->isRelayed = tx->doNotRelay.get() != true; - tx->inTxPool = !tx->doNotRelay.get(); - if (!tx->isFailed.get() && tx->isRelayed.get()) tx->isDoubleSpendSeen = false; // TODO: test and handle if true - tx->numConfirmations = 0; + tx->payment_id = request.payment_id; + tx->is_confirmed = false; + tx->is_miner_tx = false; + tx->is_failed = false; // TODO: test and handle if true + tx->do_not_relay = request.do_not_relay != boost::none && request.do_not_relay.get() == true; + tx->is_relayed = tx->do_not_relay.get() != true; + tx->in_tx_pool = !tx->do_not_relay.get(); + if (!tx->is_failed.get() && tx->is_relayed.get()) tx->is_double_spend_seen = false; // TODO: test and handle if true + tx->num_confirmations = 0; tx->mixin = request.mixin; - tx->unlockTime = request.unlockTime == boost::none ? 0 : request.unlockTime.get(); - if (tx->isRelayed.get()) tx->lastRelayedTimestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 - outTransfer->accountIndex = request.accountIndex; - if (request.subaddressIndices.size() == 1) outTransfer->subaddressIndices.push_back(request.subaddressIndices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here + tx->unlock_time = request.unlock_time == boost::none ? 0 : request.unlock_time.get(); + if (tx->is_relayed.get()) tx->last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 + outTransfer->account_index = request.account_index; + if (request.subaddress_indices.size() == 1) outTransfer->subaddress_indices.push_back(request.subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here outTransfer->destinations = request.destinations; outTransfer->destinations[0]->amount = *txAmountsIter; @@ -1924,7 +1924,7 @@ namespace monero { return txs[0]; } - vector> monero_wallet::sweep_dust(bool doNotRelay) { + vector> monero_wallet::sweep_dust(bool do_not_relay) { MTRACE("monero_wallet::sweep_dust()"); // create transaction to fill @@ -1941,23 +1941,23 @@ namespace monero { list txFees; string multisigTxSet; string unsignedTxSet; - list txIds; + list tx_ids; list txBlobs; list txMetadatas; epee::json_rpc::error er; - if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, doNotRelay, txIds, getTxHex, txBlobs, getTxMetadata, txMetadatas, er)) { + if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, do_not_relay, tx_ids, getTxHex, txBlobs, getTxMetadata, txMetadatas, er)) { throw runtime_error("need to handle error filling response!"); // TODO: return err message } // build sent txs from results // TODO: use common utility with send_split() to avoid code duplication vector> txs; - auto txIdsIter = txIds.begin(); + auto txIdsIter = tx_ids.begin(); auto txKeysIter = txKeys.begin(); auto txAmountsIter = txAmounts.begin(); auto txFeesIter = txFees.begin(); auto txBlobsIter = txBlobs.begin(); auto txMetadatasIter = txMetadatas.begin(); - while (txIdsIter != txIds.end()) { + while (txIdsIter != tx_ids.end()) { // init tx with outgoing transfer from filled values shared_ptr tx = make_shared(); @@ -1965,24 +1965,24 @@ namespace monero { tx->id = *txIdsIter; tx->key = *txKeysIter; tx->fee = *txFeesIter; - tx->fullHex = *txBlobsIter; + tx->full_hex = *txBlobsIter; tx->metadata = *txMetadatasIter; shared_ptr outTransfer = make_shared(); - tx->outgoingTransfer = outTransfer; + tx->outgoing_transfer = outTransfer; outTransfer->amount = *txAmountsIter; // init other known fields - tx->isConfirmed = false; - tx->isMinerTx = false; - tx->isFailed = false; // TODO: test and handle if true - tx->doNotRelay = doNotRelay; - tx->isRelayed = tx->doNotRelay.get() != true; - tx->inTxPool = !tx->doNotRelay.get(); - if (!tx->isFailed.get() && tx->isRelayed.get()) tx->isDoubleSpendSeen = false; // TODO: test and handle if true - tx->numConfirmations = 0; + tx->is_confirmed = false; + tx->is_miner_tx = false; + tx->is_failed = false; // TODO: test and handle if true + tx->do_not_relay = do_not_relay; + tx->is_relayed = tx->do_not_relay.get() != true; + tx->in_tx_pool = !tx->do_not_relay.get(); + if (!tx->is_failed.get() && tx->is_relayed.get()) tx->is_double_spend_seen = false; // TODO: test and handle if true + tx->num_confirmations = 0; //tx->mixin = request.mixin; // TODO: how to get? - tx->unlockTime = 0; - if (tx->isRelayed.get()) tx->lastRelayedTimestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 + tx->unlock_time = 0; + if (tx->is_relayed.get()) tx->last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 outTransfer->destinations[0]->amount = *txAmountsIter; // iterate to next element @@ -2001,7 +2001,7 @@ namespace monero { MTRACE("relay_txs()"); // relay each metadata as a tx - vector txIds; + vector tx_ids; for (const auto& txMetadata : txMetadatas) { // parse tx metadata hex @@ -2028,11 +2028,11 @@ namespace monero { } // collect resulting id - txIds.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx))); + tx_ids.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx))); } // return relayed tx ids - return txIds; + return tx_ids; } string monero_wallet::get_tx_note(const string& txId) const { @@ -2045,10 +2045,10 @@ namespace monero { return wallet2->get_tx_note(txHash); } - vector monero_wallet::get_tx_notes(const vector& txIds) const { + vector monero_wallet::get_tx_notes(const vector& tx_ids) const { MTRACE("monero_wallet::get_tx_notes()"); vector txNotes; - for (const auto& txId : txIds) txNotes.push_back(get_tx_note(txId)); + for (const auto& txId : tx_ids) txNotes.push_back(get_tx_note(txId)); return txNotes; } @@ -2062,11 +2062,11 @@ namespace monero { wallet2->set_tx_note(txHash, note); } - void monero_wallet::set_tx_notes(const vector& txIds, const vector& txNotes) { + void monero_wallet::set_tx_notes(const vector& tx_ids, const vector& txNotes) { MTRACE("monero_wallet::set_tx_notes()"); - if (txIds.size() != txNotes.size()) throw runtime_error("Different amount of txids and notes"); - for (int i = 0; i < txIds.size(); i++) { - set_tx_note(txIds[i], txNotes[i]); + if (tx_ids.size() != txNotes.size()) throw runtime_error("Different amount of txids and notes"); + for (int i = 0; i < tx_ids.size(); i++) { + set_tx_note(tx_ids[i], txNotes[i]); } } @@ -2162,15 +2162,15 @@ namespace monero { } // initialize and return tx check using wallet2 - uint64_t receivedAmount; - bool inTxPool; - uint64_t numConfirmations; - wallet2->check_tx_key(txHash, tx_key, additionalTxKeys, info.address, receivedAmount, inTxPool, numConfirmations); + uint64_t received_amount; + bool in_tx_pool; + uint64_t num_confirmations; + wallet2->check_tx_key(txHash, tx_key, additionalTxKeys, info.address, received_amount, in_tx_pool, num_confirmations); shared_ptr checkTx = make_shared(); - checkTx->isGood = true; // check is good if we get this far - checkTx->receivedAmount = receivedAmount; - checkTx->inTxPool = inTxPool; - checkTx->numConfirmations = numConfirmations; + checkTx->is_good = true; // check is good if we get this far + checkTx->received_amount = received_amount; + checkTx->in_tx_pool = in_tx_pool; + checkTx->num_confirmations = num_confirmations; return checkTx; } @@ -2209,14 +2209,14 @@ namespace monero { // initialize and return tx check using wallet2 shared_ptr checkTx = make_shared(); - uint64_t receivedAmount; - bool inTxPool; - uint64_t numConfirmations; - checkTx->isGood = wallet2->check_tx_proof(txHash, info.address, info.is_subaddress, message, signature, receivedAmount, inTxPool, numConfirmations); - if (checkTx->isGood) { - checkTx->receivedAmount = receivedAmount; - checkTx->inTxPool = inTxPool; - checkTx->numConfirmations = numConfirmations; + uint64_t received_amount; + bool in_tx_pool; + uint64_t num_confirmations; + checkTx->is_good = wallet2->check_tx_proof(txHash, info.address, info.is_subaddress, message, signature, received_amount, in_tx_pool, num_confirmations); + if (checkTx->is_good) { + checkTx->received_amount = received_amount; + checkTx->in_tx_pool = in_tx_pool; + checkTx->num_confirmations = num_confirmations; } return checkTx; } @@ -2271,12 +2271,12 @@ namespace monero { // initialize check reserve using wallet2 shared_ptr checkReserve = make_shared(); - uint64_t totalAmount; - uint64_t unconfirmedSpentAmount; - checkReserve->isGood = wallet2->check_reserve_proof(info.address, message, signature, totalAmount, unconfirmedSpentAmount); - if (checkReserve->isGood) { - checkReserve->totalAmount = totalAmount; - checkReserve->unconfirmedSpentAmount = unconfirmedSpentAmount; + uint64_t total_amount; + uint64_t unconfirmed_spent_amount; + checkReserve->is_good = wallet2->check_reserve_proof(info.address, message, signature, total_amount, unconfirmed_spent_amount); + if (checkReserve->is_good) { + checkReserve->total_amount = total_amount; + checkReserve->unconfirmed_spent_amount = unconfirmed_spent_amount; } return checkReserve; } @@ -2291,14 +2291,14 @@ namespace monero { // prepare wallet2 params string address = request.destinations.at(0)->address.get(); - string paymentId = request.paymentId == boost::none ? "" : request.paymentId.get(); + string payment_id = request.payment_id == boost::none ? "" : request.payment_id.get(); uint64_t amount = request.destinations.at(0)->amount.get(); string note = request.note == boost::none ? "" : request.note.get(); - string recipientName = request.recipientName == boost::none ? "" : request.recipientName.get(); + string receipient_name = request.receipient_name == boost::none ? "" : request.receipient_name.get(); // make uri using wallet2 std::string error; - string uri = wallet2->make_uri(address, paymentId, amount, note, recipientName, error); + string uri = wallet2->make_uri(address, payment_id, amount, note, receipient_name, error); if (uri.empty()) throw runtime_error("Cannot make URI from supplied parameters: " + error); return uri; } @@ -2308,13 +2308,13 @@ namespace monero { // decode uri to parameters string address; - string paymentId; + string payment_id; uint64_t amount = 0; string note; - string recipientName; + string receipient_name; vector unknownParameters; string error; - if (!wallet2->parse_uri(uri, address, paymentId, amount, note, recipientName, unknownParameters, error)) { + if (!wallet2->parse_uri(uri, address, payment_id, amount, note, receipient_name, unknownParameters, error)) { throw runtime_error("Error parsing URI: " + error); } @@ -2324,9 +2324,9 @@ namespace monero { sendRequest->destinations.push_back(destination); if (!address.empty()) destination->address = address; destination->amount = amount; - if (!paymentId.empty()) sendRequest->paymentId = paymentId; + if (!payment_id.empty()) sendRequest->payment_id = payment_id; if (!note.empty()) sendRequest->note = note; - if (!recipientName.empty()) sendRequest->recipientName = recipientName; + if (!receipient_name.empty()) sendRequest->receipient_name = receipient_name; if (!unknownParameters.empty()) MWARNING("WARNING in monero_wallet::parse_payment_uri: URI contains unknown parameters which are discarded"); // TODO: return unknown parameters? return sendRequest; } @@ -2438,8 +2438,8 @@ namespace monero { bool rescan = rescanOnSync.exchange(false); boost::lock_guard guarg(syncMutex); // synchronize sync() and syncAsync() monero_sync_result result; - result.numBlocksFetched = 0; - result.receivedMoney = false; + result.num_blocks_fetched = 0; + result.received_money = false; do { // skip if daemon is not connected or synced if (isConnected && get_is_daemon_synced()) { @@ -2467,14 +2467,14 @@ namespace monero { // sync wallet and return result wallet2Listener->onSyncStart(syncStartHeight, listener); monero_sync_result result; - wallet2->refresh(wallet2->is_trusted_daemon(), syncStartHeight, result.numBlocksFetched, result.receivedMoney, true); + wallet2->refresh(wallet2->is_trusted_daemon(), syncStartHeight, result.num_blocks_fetched, result.received_money, true); if (!isSynced) isSynced = true; wallet2Listener->onSyncEnd(); return result; } // private helper to initialize subaddresses using transfer details - vector monero_wallet::getSubaddressesAux(const uint32_t accountIdx, const vector& subaddressIndices, const vector& transfers) const { + vector monero_wallet::getSubaddressesAux(const uint32_t accountIdx, const vector& subaddress_indices, const vector& transfers) const { vector subaddresses; // get balances per subaddress as maps @@ -2483,18 +2483,18 @@ namespace monero { // get all indices if no indices given vector subaddressIndicesReq; - if (subaddressIndices.empty()) { + if (subaddress_indices.empty()) { for (uint32_t subaddressIdx = 0; subaddressIdx < wallet2->get_num_subaddresses(accountIdx); subaddressIdx++) { subaddressIndicesReq.push_back(subaddressIdx); } } else { - subaddressIndicesReq = subaddressIndices; + subaddressIndicesReq = subaddress_indices; } // initialize subaddresses at indices for (uint32_t subaddressIndicesIdx = 0; subaddressIndicesIdx < subaddressIndicesReq.size(); subaddressIndicesIdx++) { monero_subaddress subaddress; - subaddress.accountIndex = accountIdx; + subaddress.account_index = accountIdx; uint32_t subaddressIdx = subaddressIndicesReq.at(subaddressIndicesIdx); subaddress.index = subaddressIdx; subaddress.address = get_address(accountIdx, subaddressIdx); @@ -2502,11 +2502,11 @@ namespace monero { auto iter1 = balancePerSubaddress.find(subaddressIdx); subaddress.balance = iter1 == balancePerSubaddress.end() ? 0 : iter1->second; auto iter2 = unlockedBalancePerSubaddress.find(subaddressIdx); - subaddress.unlockedBalance = iter2 == unlockedBalancePerSubaddress.end() ? 0 : iter2->second.first; + subaddress.unlocked_balance = iter2 == unlockedBalancePerSubaddress.end() ? 0 : iter2->second.first; cryptonote::subaddress_index index = {accountIdx, subaddressIdx}; - subaddress.numUnspentOutputs = count_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return !td.m_spent && td.m_subaddr_index == index; }); - subaddress.isUsed = find_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return td.m_subaddr_index == index; }) != transfers.end(); - subaddress.numBlocksToUnlock = iter1 == balancePerSubaddress.end() ? 0 : iter2->second.second; + subaddress.num_unspent_outputs = count_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return !td.m_spent && td.m_subaddr_index == index; }); + subaddress.is_used = find_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return td.m_subaddr_index == index; }) != transfers.end(); + subaddress.num_blocks_to_unlock = iter1 == balancePerSubaddress.end() ? 0 : iter2->second.second; subaddresses.push_back(subaddress); } diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 4dc0f77..d602931 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -375,19 +375,19 @@ namespace monero { /** * Get an integrated address from a standard address and a payment id. * - * @param standardAddress is the integrated addresse's standard address (defaults to wallet's primary address) - * @param paymentId is the integrated addresse's payment id (defaults to randomly generating new payment id) + * @param standard_address is the integrated addresse's standard address (defaults to wallet's primary address) + * @param payment_id is the integrated addresse's payment id (defaults to randomly generating new payment id) * @return the integrated address */ - monero_integrated_address get_integrated_address(const string& standardAddress = "", const string& paymentId = "") const; + monero_integrated_address get_integrated_address(const string& standard_address = "", const string& payment_id = "") const; /** * Decode an integrated address to get its standard address and payment id. * - * @param integratedAddress is an integrated address to decode + * @param integrated_address is an integrated address to decode * @return the decoded integrated address including standard address and payment id */ - monero_integrated_address decode_integrated_address(const string& integratedAddress) const; + monero_integrated_address decode_integrated_address(const string& integrated_address) const; /** * Set the wallet's listener to receive wallet notifications. @@ -599,10 +599,10 @@ namespace monero { * Get subaddresses in an account. * * @param accountIdx specifies the account to get subaddresses within - * @param subaddressIndices are specific subaddresses to get (optional) + * @param subaddress_indices are specific subaddresses to get (optional) * @return the retrieved subaddresses */ - vector get_subaddresses(const uint32_t accountIdx, const vector& subaddressIndices) const; + vector get_subaddresses(const uint32_t accountIdx, const vector& subaddress_indices) const; /** * Get a subaddress. @@ -641,10 +641,10 @@ namespace monero { // /** // * Get wallet transactions by id. // * -// * @param txIds are ids of transactions to get +// * @param tx_ids are ids of transactions to get // * @return the identified transactions // */ -// public List get_txs(Collection txIds); +// public List get_txs(Collection tx_ids); /** * Get wallet transactions. Wallet transactions contain one or more @@ -791,24 +791,24 @@ namespace monero { // * Create and relay a transaction which transfers funds from this wallet to // * a destination address. // * -// * @param accountIndex is the index of the account to draw funds from +// * @param account_index is the index of the account to draw funds from // * @param address is the destination address to send funds to // * @param sendAmount is the amount being sent // * @return the resulting transaction // */ -// public monero_tx_wallet send(int accountIndex, string address, BigInteger sendAmount); +// public monero_tx_wallet send(int account_index, string address, BigInteger sendAmount); // // /** // * Create and relay a transaction which transfers funds from this wallet to // * a destination address. // * -// * @param accountIndex is the index of the account to draw funds from +// * @param account_index is the index of the account to draw funds from // * @param address is the destination address to send funds to // * @param sendAmount is the amount being sent // * @param priority is the send priority (default normal) // * @return the resulting transaction // */ -// public monero_tx_wallet send(int accountIndex, string address, BigInteger sendAmount, monero_send_priority priority); +// public monero_tx_wallet send(int account_index, string address, BigInteger sendAmount, monero_send_priority priority); // // /** // * Create and relay (depending on configuration) one or more transactions @@ -823,24 +823,24 @@ namespace monero { // * Create and relay one or more transactions which transfer funds from this // * wallet to one or more destination. // * -// * @param accountIndex is the index of the account to draw funds from +// * @param account_index is the index of the account to draw funds from // * @param address is the destination address to send funds to // * @param sendAmount is the amount being sent // * @return the resulting transactions // */ -// public List send_split(int accountIndex, string address, BigInteger sendAmount); +// public List send_split(int account_index, string address, BigInteger sendAmount); // // /** // * Create and relay one or more transactions which transfer funds from this // * wallet to one or more destination. // * -// * @param accountIndex is the index of the account to draw funds from +// * @param account_index is the index of the account to draw funds from // * @param address is the destination address to send funds to // * @param sendAmount is the amount being sent // * @param priority is the send priority (default normal) // * @return the resulting transactions // */ -// public List send_split(int accountIndex, string address, BigInteger sendAmount, monero_send_priority priority); +// public List send_split(int account_index, string address, BigInteger sendAmount, monero_send_priority priority); /** * Sweep an output with a given key image. @@ -854,20 +854,20 @@ namespace monero { // * Sweep an output with a given key image. // * // * @param address is the destination address to send to -// * @param keyImage is the key image hex of the output to sweep +// * @param key_image is the key image hex of the output to sweep // * @return the resulting transaction from sweeping an output // */ -// public monero_tx_wallet sweep_output(string address, string keyImage); +// public monero_tx_wallet sweep_output(string address, string key_image); // // /** // * Sweep an output with a given key image. // * // * @param address is the destination address to send to -// * @param keyImage is the key image hex of the output to sweep +// * @param key_image is the key image hex of the output to sweep // * @param priority is the transaction priority (optional) // * @return the resulting transaction from sweeping an output // */ -// public monero_tx_wallet sweep_output(string address, string keyImage, monero_send_priority priority); +// public monero_tx_wallet sweep_output(string address, string key_image, monero_send_priority priority); // // /** // * Sweep a subaddress's unlocked funds to an address. @@ -916,10 +916,10 @@ namespace monero { /** * Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix. * - * @param doNotRelay specifies if the resulting transaction should not be relayed (defaults to false i.e. relayed) + * @param do_not_relay specifies if the resulting transaction should not be relayed (defaults to false i.e. relayed) * @return the resulting transactions from sweeping dust */ - vector> sweep_dust(bool doNotRelay = false); + vector> sweep_dust(bool do_not_relay = false); // // /** // * Relay a transaction previously created without relaying. @@ -948,10 +948,10 @@ namespace monero { /** * Get notes for multiple transactions. * - * @param txIds identify the transactions to get notes for + * @param tx_ids identify the transactions to get notes for * @preturns notes for the transactions */ - vector get_tx_notes(const vector& txIds) const; + vector get_tx_notes(const vector& tx_ids) const; /** * Set a note for a specific transaction. @@ -964,10 +964,10 @@ namespace monero { /** * Set notes for multiple transactions. * - * @param txIds specify the transactions to set notes for + * @param tx_ids specify the transactions to set notes for * @param notes are the notes to set for the transactions */ - void set_tx_notes(const vector& txIds, const vector& notes); + void set_tx_notes(const vector& tx_ids, const vector& notes); /** * Sign a message. @@ -1119,10 +1119,10 @@ namespace monero { // * // * @param address is the entry address // * @param description is the entry description (optional) -// * @param paymentId is the entry paymet id (optional) +// * @param payment_id is the entry paymet id (optional) // * @return the index of the added entry // */ -// public int addAddressBookEntry(string address, string description, string paymentId); +// public int addAddressBookEntry(string address, string description, string payment_id); // // /** // * Delete an address book entry. @@ -1234,7 +1234,7 @@ namespace monero { boost::optional listener = boost::none; // wallet's external listener void initCommon(); - vector getSubaddressesAux(uint32_t accountIdx, const vector& subaddressIndices, const vector& transfers) const; + vector getSubaddressesAux(uint32_t accountIdx, const vector& subaddress_indices, const vector& transfers) const; // blockchain sync management mutable std::atomic isSynced; // whether or not wallet is synced diff --git a/src/wallet/monero_wallet_model.cpp b/src/wallet/monero_wallet_model.cpp index 5880115..29924d2 100644 --- a/src/wallet/monero_wallet_model.cpp +++ b/src/wallet/monero_wallet_model.cpp @@ -65,9 +65,9 @@ namespace monero { // ----------------------- UNDECLARED PRIVATE HELPERS ----------------------- - void mergeIncomingTransfer(vector>& transfers, const shared_ptr& transfer) { + void merge_incoming_transfer(vector>& transfers, const shared_ptr& transfer) { for (const shared_ptr& aTransfer : transfers) { - if (aTransfer->accountIndex.get() == transfer->accountIndex.get() && aTransfer->subaddressIndex.get() == transfer->subaddressIndex.get()) { + if (aTransfer->account_index.get() == transfer->account_index.get() && aTransfer->subaddress_index.get() == transfer->subaddress_index.get()) { aTransfer->merge(aTransfer, transfer); return; } @@ -80,9 +80,9 @@ namespace monero { boost::property_tree::ptree monero_account::to_property_tree() const { boost::property_tree::ptree node; if (index != boost::none) node.put("index", *index); - if (primaryAddress != boost::none) node.put("primaryAddress", *primaryAddress); + if (primary_address != boost::none) node.put("primary_address", *primary_address); if (balance != boost::none) node.put("balance", *balance); - if (unlockedBalance != boost::none) node.put("unlockedBalance", *unlockedBalance); + if (unlocked_balance != boost::none) node.put("unlocked_balance", *unlocked_balance); if (!subaddresses.empty()) node.add_child("subaddresses", monero_utils::to_property_tree(subaddresses)); return node; } @@ -91,15 +91,15 @@ namespace monero { boost::property_tree::ptree monero_subaddress::to_property_tree() const { boost::property_tree::ptree node; - if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); + if (account_index != boost::none) node.put("account_index", *account_index); if (index != boost::none) node.put("index", *index); if (address != boost::none) node.put("address", *address); if (label != boost::none) node.put("label", *label); if (balance != boost::none) node.put("balance", *balance); - if (unlockedBalance != boost::none) node.put("unlockedBalance", *unlockedBalance); - if (numUnspentOutputs != boost::none) node.put("numUnspentOutputs", *numUnspentOutputs); - if (isUsed != boost::none) node.put("isUsed", *isUsed); - if (numBlocksToUnlock != boost::none) node.put("numBlocksToUnlock", *numBlocksToUnlock); + if (unlocked_balance != boost::none) node.put("unlocked_balance", *unlocked_balance); + if (num_unspent_outputs != boost::none) node.put("num_unspent_outputs", *num_unspent_outputs); + if (is_used != boost::none) node.put("is_used", *is_used); + if (num_blocks_to_unlock != boost::none) node.put("num_blocks_to_unlock", *num_blocks_to_unlock); return node; } @@ -118,18 +118,18 @@ namespace monero { monero_tx::copy(static_pointer_cast(src), static_pointer_cast(tgt)); // copy wallet extensions - if (!src->incomingTransfers.empty()) { - tgt->incomingTransfers = vector>(); - for (const shared_ptr& transfer : src->incomingTransfers) { + if (!src->incoming_transfers.empty()) { + tgt->incoming_transfers = vector>(); + for (const shared_ptr& transfer : src->incoming_transfers) { shared_ptr transferCopy = transfer->copy(transfer, make_shared()); transferCopy->tx = tgt; - tgt->incomingTransfers.push_back(transferCopy); + tgt->incoming_transfers.push_back(transferCopy); } } - if (src->outgoingTransfer != boost::none) { - shared_ptr transferCopy = src->outgoingTransfer.get()->copy(src->outgoingTransfer.get(), make_shared()); + if (src->outgoing_transfer != boost::none) { + shared_ptr transferCopy = src->outgoing_transfer.get()->copy(src->outgoing_transfer.get(), make_shared()); transferCopy->tx = tgt; - tgt->outgoingTransfer = transferCopy; + tgt->outgoing_transfer = transferCopy; } tgt->note = src->note; @@ -138,18 +138,18 @@ namespace monero { boost::property_tree::ptree monero_tx_wallet::to_property_tree() const { boost::property_tree::ptree node = monero_tx::to_property_tree(); - if (!incomingTransfers.empty()) node.add_child("incomingTransfers", monero_utils::to_property_tree(incomingTransfers)); - if (outgoingTransfer != boost::none) node.add_child("outgoingTransfer", (*outgoingTransfer)->to_property_tree()); + if (!incoming_transfers.empty()) node.add_child("incoming_transfers", monero_utils::to_property_tree(incoming_transfers)); + if (outgoing_transfer != boost::none) node.add_child("outgoing_transfer", (*outgoing_transfer)->to_property_tree()); if (note != boost::none) node.put("note", *note); return node; } bool monero_tx_wallet::getIsOutgoing() const { - return outgoingTransfer != boost::none; + return outgoing_transfer != boost::none; } bool monero_tx_wallet::getIsIncoming() const { - return !incomingTransfers.empty(); + return !incoming_transfers.empty(); } void monero_tx_wallet::merge(const shared_ptr& self, const shared_ptr& other) { @@ -167,18 +167,18 @@ namespace monero { note = monero_utils::reconcile(note, other->note); // merge incoming transfers - if (!other->incomingTransfers.empty()) { - for (const shared_ptr& transfer : other->incomingTransfers) { // NOTE: not using reference so shared_ptr is not deleted when tx is dereferenced + if (!other->incoming_transfers.empty()) { + for (const shared_ptr& transfer : other->incoming_transfers) { // NOTE: not using reference so shared_ptr is not deleted when tx is dereferenced transfer->tx = self; - mergeIncomingTransfer(self->incomingTransfers, transfer); + merge_incoming_transfer(self->incoming_transfers, transfer); } } // merge outgoing transfer - if (other->outgoingTransfer != boost::none) { - other->outgoingTransfer.get()->tx = self; - if (self->outgoingTransfer == boost::none) self->outgoingTransfer = other->outgoingTransfer; - else self->outgoingTransfer.get()->merge(self->outgoingTransfer.get(), other->outgoingTransfer.get()); + if (other->outgoing_transfer != boost::none) { + other->outgoing_transfer.get()->tx = self; + if (self->outgoing_transfer == boost::none) self->outgoing_transfer = other->outgoing_transfer; + else self->outgoing_transfer.get()->merge(self->outgoing_transfer.get(), other->outgoing_transfer.get()); } } @@ -200,32 +200,32 @@ namespace monero { monero_tx_wallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); // copy request extensions - tgt->isOutgoing = src->isOutgoing; - tgt->isIncoming = src->isIncoming; - if (!src->txIds.empty()) tgt->txIds = vector(src->txIds); - tgt-> hasPaymentId = src->hasPaymentId; - if (!src->paymentIds.empty()) tgt->paymentIds = vector(src->paymentIds); + tgt->is_outgoing = src->is_outgoing; + tgt->is_incoming = src->is_incoming; + if (!src->tx_ids.empty()) tgt->tx_ids = vector(src->tx_ids); + tgt-> has_payment_id = src->has_payment_id; + if (!src->payment_ids.empty()) tgt->payment_ids = vector(src->payment_ids); tgt->height = src->height; - tgt->minHeight = src->minHeight; - tgt->maxHeight = src->maxHeight; - tgt->includeOutputs = src->includeOutputs; - if (src->transferRequest != boost::none) tgt->transferRequest = src->transferRequest.get()->copy(src->transferRequest.get(), make_shared()); - if (src->outputRequest != boost::none) tgt->outputRequest = src->outputRequest.get()->copy(src->outputRequest.get(), make_shared()); + tgt->min_height = src->min_height; + tgt->max_height = src->max_height; + tgt->include_outputs = src->include_outputs; + if (src->transfer_request != boost::none) tgt->transfer_request = src->transfer_request.get()->copy(src->transfer_request.get(), make_shared()); + if (src->output_request != boost::none) tgt->output_request = src->output_request.get()->copy(src->output_request.get(), make_shared()); return tgt; }; boost::property_tree::ptree monero_tx_request::to_property_tree() const { boost::property_tree::ptree node = monero_tx_wallet::to_property_tree(); - if (isOutgoing != boost::none) node.put("isOutgoing", *isOutgoing); - if (isIncoming != boost::none) node.put("isIncoming", *isIncoming); - if (!txIds.empty()) node.add_child("txIds", monero_utils::to_property_tree(txIds)); - if (hasPaymentId != boost::none) node.put("hasPaymentId", *hasPaymentId); - if (!paymentIds.empty()) node.add_child("paymentIds", monero_utils::to_property_tree(paymentIds)); + if (is_outgoing != boost::none) node.put("is_outgoing", *is_outgoing); + if (is_incoming != boost::none) node.put("is_incoming", *is_incoming); + if (!tx_ids.empty()) node.add_child("tx_ids", monero_utils::to_property_tree(tx_ids)); + if (has_payment_id != boost::none) node.put("has_payment_id", *has_payment_id); + if (!payment_ids.empty()) node.add_child("payment_ids", monero_utils::to_property_tree(payment_ids)); if (height != boost::none) node.put("height", *height); - if (minHeight != boost::none) node.put("minHeight", *minHeight); - if (maxHeight != boost::none) node.put("maxHeight", *maxHeight); - if (includeOutputs != boost::none) node.put("includeOutputs", *includeOutputs); - if (transferRequest != boost::none) node.add_child("transferRequest", (*transferRequest)->to_property_tree()); + if (min_height != boost::none) node.put("min_height", *min_height); + if (max_height != boost::none) node.put("max_height", *max_height); + if (include_outputs != boost::none) node.put("include_outputs", *include_outputs); + if (transfer_request != boost::none) node.add_child("transfer_request", (*transfer_request)->to_property_tree()); return node; } @@ -234,20 +234,20 @@ namespace monero { // filter on tx if (id != boost::none && id != tx->id) return false; - if (paymentId != boost::none && paymentId != tx->paymentId) return false; - if (isConfirmed != boost::none && isConfirmed != tx->isConfirmed) return false; - if (inTxPool != boost::none && inTxPool != tx->inTxPool) return false; - if (doNotRelay != boost::none && doNotRelay != tx->doNotRelay) return false; - if (isFailed != boost::none && isFailed != tx->isFailed) return false; - if (isMinerTx != boost::none && isMinerTx != tx->isMinerTx) return false; + if (payment_id != boost::none && payment_id != tx->payment_id) return false; + if (is_confirmed != boost::none && is_confirmed != tx->is_confirmed) return false; + if (in_tx_pool != boost::none && in_tx_pool != tx->in_tx_pool) return false; + if (do_not_relay != boost::none && do_not_relay != tx->do_not_relay) return false; + if (is_failed != boost::none && is_failed != tx->is_failed) return false; + if (is_miner_tx != boost::none && is_miner_tx != tx->is_miner_tx) return false; // at least one transfer must meet transfer request if defined - if (transferRequest != boost::none) { + if (transfer_request != boost::none) { bool matchFound = false; - if (tx->outgoingTransfer != boost::none && (*transferRequest)->meetsCriteria((*tx->outgoingTransfer).get())) matchFound = true; - else if (!tx->incomingTransfers.empty()) { - for (const shared_ptr& incomingTransfer : tx->incomingTransfers) { - if ((*transferRequest)->meetsCriteria(incomingTransfer.get())) { + if (tx->outgoing_transfer != boost::none && (*transfer_request)->meetsCriteria((*tx->outgoing_transfer).get())) matchFound = true; + else if (!tx->incoming_transfers.empty()) { + for (const shared_ptr& incomingTransfer : tx->incoming_transfers) { + if ((*transfer_request)->meetsCriteria(incomingTransfer.get())) { matchFound = true; break; } @@ -257,24 +257,24 @@ namespace monero { } // filter on having a payment id - if (hasPaymentId != boost::none) { - if (*hasPaymentId && tx->paymentId == boost::none) return false; - if (!*hasPaymentId && tx->paymentId != boost::none) return false; + if (has_payment_id != boost::none) { + if (*has_payment_id && tx->payment_id == boost::none) return false; + if (!*has_payment_id && tx->payment_id != boost::none) return false; } // filter on incoming - if (isIncoming != boost::none && isIncoming != tx->getIsIncoming()) return false; + if (is_incoming != boost::none && is_incoming != tx->getIsIncoming()) return false; // filter on outgoing - if (isOutgoing != boost::none && isOutgoing != tx->getIsOutgoing()) return false; + if (is_outgoing != boost::none && is_outgoing != tx->getIsOutgoing()) return false; // filter on remaining fields boost::optional txHeight = tx->get_height(); - if (!txIds.empty() && find(txIds.begin(), txIds.end(), *tx->id) == txIds.end()) return false; - if (!paymentIds.empty() && (tx->paymentId == boost::none || find(paymentIds.begin(), paymentIds.end(), *tx->paymentId) == paymentIds.end())) return false; + if (!tx_ids.empty() && find(tx_ids.begin(), tx_ids.end(), *tx->id) == tx_ids.end()) return false; + if (!payment_ids.empty() && (tx->payment_id == boost::none || find(payment_ids.begin(), payment_ids.end(), *tx->payment_id) == payment_ids.end())) return false; if (height != boost::none && (txHeight == boost::none || *txHeight != *height)) return false; - if (minHeight != boost::none && (txHeight == boost::none || *txHeight < *minHeight)) return false; - if (maxHeight != boost::none && (txHeight == boost::none || *txHeight > *maxHeight)) return false; + if (min_height != boost::none && (txHeight == boost::none || *txHeight < *min_height)) return false; + if (max_height != boost::none && (txHeight == boost::none || *txHeight > *max_height)) return false; // transaction meets request criteria return true; @@ -303,16 +303,16 @@ namespace monero { MTRACE("monero_transfer::copy(const shared_ptr& src, const shared_ptr& tgt)"); tgt->tx = src->tx; // reference parent tx by default tgt->amount = src->amount; - tgt->accountIndex = src->accountIndex; - tgt->numSuggestedConfirmations = src->numSuggestedConfirmations; + tgt->account_index = src->account_index; + tgt->num_suggested_confirmations = src->num_suggested_confirmations; return tgt; } boost::property_tree::ptree monero_transfer::to_property_tree() const { boost::property_tree::ptree node; if (amount != boost::none) node.put("amount", *amount); - if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); - if (numSuggestedConfirmations != boost::none) node.put("numSuggestedConfirmations", *numSuggestedConfirmations); + if (account_index != boost::none) node.put("account_index", *account_index); + if (num_suggested_confirmations != boost::none) node.put("num_suggested_confirmations", *num_suggested_confirmations); return node; } @@ -327,16 +327,16 @@ namespace monero { } // otherwise merge transfer fields - accountIndex = monero_utils::reconcile(accountIndex, other->accountIndex, "acountIndex"); + account_index = monero_utils::reconcile(account_index, other->account_index, "acountIndex"); - // TODO monero core: failed tx in pool (after testUpdateLockedDifferentAccounts()) causes non-originating saved wallets to return duplicate incoming transfers but one has amount/numSuggestedConfirmations of 0 + // TODO monero core: failed tx in pool (after testUpdateLockedDifferentAccounts()) causes non-originating saved wallets to return duplicate incoming transfers but one has amount/num_suggested_confirmations of 0 if (amount != boost::none && other->amount != boost::none && *amount != *other->amount && (*amount == 0 || *other->amount == 0)) { - accountIndex = monero_utils::reconcile(accountIndex, other->accountIndex, boost::none, boost::none, true, "acountIndex"); - numSuggestedConfirmations = monero_utils::reconcile(numSuggestedConfirmations, other->numSuggestedConfirmations, boost::none, boost::none, true, "numSuggestedConfirmations"); - MWARNING("WARNING: failed tx in pool causes non-originating wallets to return duplicate incoming transfers but with one amount/numSuggestedConfirmations of 0"); + account_index = monero_utils::reconcile(account_index, other->account_index, boost::none, boost::none, true, "acountIndex"); + num_suggested_confirmations = monero_utils::reconcile(num_suggested_confirmations, other->num_suggested_confirmations, boost::none, boost::none, true, "num_suggested_confirmations"); + MWARNING("WARNING: failed tx in pool causes non-originating wallets to return duplicate incoming transfers but with one amount/num_suggested_confirmations of 0"); } else { amount = monero_utils::reconcile(amount, other->amount, "transfer amount"); - numSuggestedConfirmations = monero_utils::reconcile(numSuggestedConfirmations, other->numSuggestedConfirmations, boost::none, boost::none, false, "numSuggestedConfirmations"); + num_suggested_confirmations = monero_utils::reconcile(num_suggested_confirmations, other->num_suggested_confirmations, boost::none, boost::none, false, "num_suggested_confirmations"); } } @@ -357,7 +357,7 @@ namespace monero { boost::property_tree::ptree monero_incoming_transfer::to_property_tree() const { boost::property_tree::ptree node = monero_transfer::to_property_tree(); - if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex); + if (subaddress_index != boost::none) node.put("subaddress_index", *subaddress_index); if (address != boost::none) node.put("address", *address); return node; } @@ -369,7 +369,7 @@ namespace monero { void monero_incoming_transfer::merge(const shared_ptr& self, const shared_ptr& other) { if (self == other) return; monero_transfer::merge(self, other); - subaddressIndex = monero_utils::reconcile(subaddressIndex, other->subaddressIndex, "incoming transfer subaddressIndex"); + subaddress_index = monero_utils::reconcile(subaddress_index, other->subaddress_index, "incoming transfer subaddress_index"); address = monero_utils::reconcile(address, other->address); } @@ -387,7 +387,7 @@ namespace monero { boost::property_tree::ptree monero_outgoing_transfer::to_property_tree() const { boost::property_tree::ptree node = monero_transfer::to_property_tree(); - if (!subaddressIndices.empty()) node.add_child("subaddressIndices", monero_utils::to_property_tree(subaddressIndices)); + if (!subaddress_indices.empty()) node.add_child("subaddress_indices", monero_utils::to_property_tree(subaddress_indices)); if (!addresses.empty()) node.add_child("addresses", monero_utils::to_property_tree(addresses)); if (!destinations.empty()) node.add_child("destinations", monero_utils::to_property_tree(destinations)); return node; @@ -400,7 +400,7 @@ namespace monero { void monero_outgoing_transfer::merge(const shared_ptr& self, const shared_ptr& other) { if (self == other) return; monero_transfer::merge(self, other); - subaddressIndices = monero_utils::reconcile(subaddressIndices, other->subaddressIndices); + subaddress_indices = monero_utils::reconcile(subaddress_indices, other->subaddress_indices); addresses = monero_utils::reconcile(addresses, other->addresses); destinations = monero_utils::reconcile(destinations, other->destinations); } @@ -419,30 +419,30 @@ namespace monero { monero_transfer::copy(static_pointer_cast(src), static_pointer_cast(tgt)); // copy extensions - tgt->isIncoming = src->isIncoming; + tgt->is_incoming = src->is_incoming; tgt->address = src->address; if (!src->addresses.empty()) tgt->addresses = vector(src->addresses); - tgt->subaddressIndex = src->subaddressIndex; - if (!src->subaddressIndices.empty()) tgt->subaddressIndices = vector(src->subaddressIndices); + tgt->subaddress_index = src->subaddress_index; + if (!src->subaddress_indices.empty()) tgt->subaddress_indices = vector(src->subaddress_indices); if (!src->destinations.empty()) { for (const shared_ptr& destination : src->destinations) { tgt->destinations.push_back(destination->copy(destination, make_shared())); } } - tgt->hasDestinations = src->hasDestinations; - tgt->txRequest = src->txRequest; + tgt->has_destinations = src->has_destinations; + tgt->tx_request = src->tx_request; return tgt; }; - boost::optional monero_transfer_request::getIsIncoming() const { return isIncoming; } + boost::optional monero_transfer_request::getIsIncoming() const { return is_incoming; } boost::property_tree::ptree monero_transfer_request::to_property_tree() const { boost::property_tree::ptree node = monero_transfer::to_property_tree(); - if (getIsIncoming() != boost::none) node.put("isIncoming", *getIsIncoming()); + if (getIsIncoming() != boost::none) node.put("is_incoming", *getIsIncoming()); if (address != boost::none) node.put("address", *address); - if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex); - if (hasDestinations != boost::none) node.put("hasDestinations", *hasDestinations); - if (!subaddressIndices.empty()) node.add_child("subaddressIndices", monero_utils::to_property_tree(subaddressIndices)); + if (subaddress_index != boost::none) node.put("subaddress_index", *subaddress_index); + if (has_destinations != boost::none) node.put("has_destinations", *has_destinations); + if (!subaddress_indices.empty()) node.add_child("subaddress_indices", monero_utils::to_property_tree(subaddress_indices)); if (!addresses.empty()) node.add_child("addresses", monero_utils::to_property_tree(addresses)); if (!destinations.empty()) node.add_child("destinations", monero_utils::to_property_tree(destinations)); return node; @@ -450,22 +450,22 @@ namespace monero { bool monero_transfer_request::meetsCriteria(monero_transfer* transfer) const { if (transfer == nullptr) throw runtime_error("transfer is null"); - if (txRequest != boost::none && (*txRequest)->transferRequest != boost::none) throw runtime_error("Transfer request's tx request cannot have a circular transfer request"); // TODO: could auto detect and handle this. port to java/js + if (tx_request != boost::none && (*tx_request)->transfer_request != boost::none) throw runtime_error("Transfer request's tx request cannot have a circular transfer request"); // TODO: could auto detect and handle this. port to java/js // filter on common fields if (getIsIncoming() != boost::none && *getIsIncoming() != *transfer->getIsIncoming()) return false; if (getIsOutgoing() != boost::none && getIsOutgoing() != transfer->getIsOutgoing()) return false; if (amount != boost::none && *amount != *transfer->amount) return false; - if (accountIndex != boost::none && *accountIndex != *transfer->accountIndex) return false; + if (account_index != boost::none && *account_index != *transfer->account_index) return false; // filter on incoming fields monero_incoming_transfer* inTransfer = dynamic_cast(transfer); if (inTransfer != nullptr) { - if (hasDestinations != boost::none) return false; + if (has_destinations != boost::none) return false; if (address != boost::none && *address != *inTransfer->address) return false; if (!addresses.empty() && find(addresses.begin(), addresses.end(), *inTransfer->address) == addresses.end()) return false; - if (subaddressIndex != boost::none && *subaddressIndex != *inTransfer->subaddressIndex) return false; - if (!subaddressIndices.empty() && find(subaddressIndices.begin(), subaddressIndices.end(), *inTransfer->subaddressIndex) == subaddressIndices.end()) return false; + if (subaddress_index != boost::none && *subaddress_index != *inTransfer->subaddress_index) return false; + if (!subaddress_indices.empty() && find(subaddress_indices.begin(), subaddress_indices.end(), *inTransfer->subaddress_index) == subaddress_indices.end()) return false; } // filter on outgoing fields @@ -488,12 +488,12 @@ namespace monero { } // filter on subaddress indices - if (subaddressIndex != boost::none && (outTransfer->subaddressIndices.empty() || find(outTransfer->subaddressIndices.begin(), outTransfer->subaddressIndices.end(), *subaddressIndex) == outTransfer->subaddressIndices.end())) return false; // TODO: will filter all transfers if they don't contain subaddress indices - if (!subaddressIndices.empty()) { + if (subaddress_index != boost::none && (outTransfer->subaddress_indices.empty() || find(outTransfer->subaddress_indices.begin(), outTransfer->subaddress_indices.end(), *subaddress_index) == outTransfer->subaddress_indices.end())) return false; // TODO: will filter all transfers if they don't contain subaddress indices + if (!subaddress_indices.empty()) { bool intersects = false; - for (const uint32_t& subaddressIndexReq : subaddressIndices) { - for (const uint32_t& subaddressIndex : outTransfer->subaddressIndices) { - if (subaddressIndexReq == subaddressIndex) { + for (const uint32_t& subaddressIndexReq : subaddress_indices) { + for (const uint32_t& subaddress_index : outTransfer->subaddress_indices) { + if (subaddressIndexReq == subaddress_index) { intersects = true; break; } @@ -503,9 +503,9 @@ namespace monero { } // filter on having destinations - if (hasDestinations != boost::none) { - if (*hasDestinations && outTransfer->destinations.empty()) return false; - if (!*hasDestinations && !outTransfer->destinations.empty()) return false; + if (has_destinations != boost::none) { + if (*has_destinations && outTransfer->destinations.empty()) return false; + if (!*has_destinations && !outTransfer->destinations.empty()) return false; } // filter on destinations TODO: start with test for this @@ -516,7 +516,7 @@ namespace monero { if (inTransfer == nullptr && outTransfer == nullptr) throw runtime_error("Transfer must be monero_incoming_transfer or monero_outgoing_transfer"); // filter with tx request - if (txRequest != boost::none && !(*txRequest)->meetsCriteria(transfer->tx.get())) return false; + if (tx_request != boost::none && !(*tx_request)->meetsCriteria(transfer->tx.get())) return false; return true; } @@ -528,28 +528,28 @@ namespace monero { }; shared_ptr monero_output_wallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_output_wallet::copy(outputWallet)"); + MTRACE("monero_output_wallet::copy(output_wallet)"); if (this != src.get()) throw runtime_error("this != src"); // copy base class monero_output::copy(static_pointer_cast(src), static_pointer_cast(tgt)); // copy extensions - tgt->accountIndex = src->accountIndex; - tgt->subaddressIndex = src->subaddressIndex; - tgt->isSpent = src->isSpent; - tgt->isUnlocked = src->isUnlocked; - tgt->isFrozen = src->isFrozen; + tgt->account_index = src->account_index; + tgt->subaddress_index = src->subaddress_index; + tgt->is_spent = src->is_spent; + tgt->is_unlocked = src->is_unlocked; + tgt->is_frozen = src->is_frozen; return tgt; }; boost::property_tree::ptree monero_output_wallet::to_property_tree() const { boost::property_tree::ptree node = monero_output::to_property_tree(); - if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); - if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex); - if (isSpent != boost::none) node.put("isSpent", *isSpent); - if (isUnlocked != boost::none) node.put("isUnlocked", *isUnlocked); - if (isFrozen != boost::none) node.put("isFrozen", *isFrozen); + if (account_index != boost::none) node.put("account_index", *account_index); + if (subaddress_index != boost::none) node.put("subaddress_index", *subaddress_index); + if (is_spent != boost::none) node.put("is_spent", *is_spent); + if (is_unlocked != boost::none) node.put("is_unlocked", *is_unlocked); + if (is_frozen != boost::none) node.put("is_frozen", *is_frozen); return node; } @@ -572,44 +572,44 @@ namespace monero { }; shared_ptr monero_output_request::copy(const shared_ptr& src, const shared_ptr& tgt) const { - MTRACE("monero_output_request::copy(outputRequest)"); + MTRACE("monero_output_request::copy(output_request)"); if (this != src.get()) throw runtime_error("this != src"); // copy base class monero_output_wallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); // copy extensions - if (!src->subaddressIndices.empty()) tgt->subaddressIndices = vector(src->subaddressIndices); + if (!src->subaddress_indices.empty()) tgt->subaddress_indices = vector(src->subaddress_indices); return tgt; }; boost::property_tree::ptree monero_output_request::to_property_tree() const { boost::property_tree::ptree node = monero_output_wallet::to_property_tree(); - if (!subaddressIndices.empty()) node.add_child("subaddressIndices", monero_utils::to_property_tree(subaddressIndices)); + if (!subaddress_indices.empty()) node.add_child("subaddress_indices", monero_utils::to_property_tree(subaddress_indices)); return node; } bool monero_output_request::meetsCriteria(monero_output_wallet* output) const { // filter on output - if (accountIndex != boost::none && *accountIndex != *output->accountIndex) return false; - if (subaddressIndex != boost::none && *subaddressIndex != *output->subaddressIndex) return false; + if (account_index != boost::none && *account_index != *output->account_index) return false; + if (subaddress_index != boost::none && *subaddress_index != *output->subaddress_index) return false; if (amount != boost::none && *amount != *output->amount) return false; - if (isSpent != boost::none && *isSpent != *output->isSpent) return false; - if (isUnlocked != boost::none && *isUnlocked != *output->isUnlocked) return false; + if (is_spent != boost::none && *is_spent != *output->is_spent) return false; + if (is_unlocked != boost::none && *is_unlocked != *output->is_unlocked) return false; // filter on output key image - if (keyImage != boost::none) { - if (output->keyImage == boost::none) return false; - if ((*keyImage)->hex != boost::none && ((*output->keyImage)->hex == boost::none || *(*keyImage)->hex != *(*output->keyImage)->hex)) return false; - if ((*keyImage)->signature != boost::none && ((*output->keyImage)->signature == boost::none || *(*keyImage)->signature != *(*output->keyImage)->signature)) return false; + if (key_image != boost::none) { + if (output->key_image == boost::none) return false; + if ((*key_image)->hex != boost::none && ((*output->key_image)->hex == boost::none || *(*key_image)->hex != *(*output->key_image)->hex)) return false; + if ((*key_image)->signature != boost::none && ((*output->key_image)->signature == boost::none || *(*key_image)->signature != *(*output->key_image)->signature)) return false; } // filter on extensions - if (!subaddressIndices.empty() && find(subaddressIndices.begin(), subaddressIndices.end(), *output->subaddressIndex) == subaddressIndices.end()) return false; + if (!subaddress_indices.empty() && find(subaddress_indices.begin(), subaddress_indices.end(), *output->subaddress_index) == subaddress_indices.end()) return false; // filter with tx request - if (txRequest != boost::none && !(*txRequest)->meetsCriteria(static_pointer_cast(output->tx).get())) return false; + if (tx_request != boost::none && !(*tx_request)->meetsCriteria(static_pointer_cast(output->tx).get())) return false; // output meets request return true; @@ -620,20 +620,20 @@ namespace monero { boost::property_tree::ptree monero_send_request::to_property_tree() const { boost::property_tree::ptree node; if (!destinations.empty()) node.add_child("destinations", monero_utils::to_property_tree(destinations)); - if (paymentId != boost::none) node.put("paymentId", *paymentId); + if (payment_id != boost::none) node.put("payment_id", *payment_id); if (priority != boost::none) node.put("priority", *priority); if (mixin != boost::none) node.put("mixin", *mixin); if (ringSize != boost::none) node.put("ringSize", *ringSize); - if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); - if (!subaddressIndices.empty()) node.add_child("subaddressIndices", monero_utils::to_property_tree(subaddressIndices)); - if (unlockTime != boost::none) node.put("unlockTime", *unlockTime); - if (canSplit != boost::none) node.put("canSplit", *canSplit); - if (doNotRelay != boost::none) node.put("doNotRelay", *doNotRelay); + if (account_index != boost::none) node.put("account_index", *account_index); + if (!subaddress_indices.empty()) node.add_child("subaddress_indices", monero_utils::to_property_tree(subaddress_indices)); + if (unlock_time != boost::none) node.put("unlock_time", *unlock_time); + if (can_split != boost::none) node.put("can_split", *can_split); + if (do_not_relay != boost::none) node.put("do_not_relay", *do_not_relay); if (note != boost::none) node.put("note", *note); - if (recipientName != boost::none) node.put("recipientName", *recipientName); - if (belowAmount != boost::none) node.put("belowAmount", *belowAmount); - if (sweepEachSubaddress != boost::none) node.put("sweepEachSubaddress", *sweepEachSubaddress); - if (keyImage != boost::none) node.put("keyImage", *keyImage); + if (receipient_name != boost::none) node.put("receipient_name", *receipient_name); + if (below_amount != boost::none) node.put("below_amount", *below_amount); + if (sweep_each_subaddress != boost::none) node.put("sweep_each_subaddress", *sweep_each_subaddress); + if (key_image != boost::none) node.put("key_image", *key_image); return node; } @@ -641,9 +641,9 @@ namespace monero { boost::property_tree::ptree monero_integrated_address::to_property_tree() const { boost::property_tree::ptree node; - node.put("standardAddress", standardAddress); - node.put("paymentId", paymentId); - node.put("integratedAddress", integratedAddress); + node.put("standard_address", standard_address); + node.put("payment_id", payment_id); + node.put("integrated_address", integrated_address); return node; } @@ -652,8 +652,8 @@ namespace monero { boost::property_tree::ptree monero_key_image_import_result::to_property_tree() const { boost::property_tree::ptree node; if (height != boost::none) node.put("height", *height); - if (spentAmount != boost::none) node.put("spentAmount", *spentAmount); - if (unspentAmount != boost::none) node.put("unspentAmount", *unspentAmount); + if (spent_amount != boost::none) node.put("spent_amount", *spent_amount); + if (unspent_amount != boost::none) node.put("unspent_amount", *unspent_amount); return node; } @@ -661,7 +661,7 @@ namespace monero { boost::property_tree::ptree monero_check::to_property_tree() const { boost::property_tree::ptree node; - node.put("isGood", isGood); + node.put("is_good", is_good); return node; } @@ -669,9 +669,9 @@ namespace monero { boost::property_tree::ptree monero_check_tx::to_property_tree() const { boost::property_tree::ptree node = monero_check::to_property_tree();; - if (inTxPool != boost::none) node.put("inTxPool", *inTxPool); - if (numConfirmations != boost::none) node.put("numConfirmations", *numConfirmations); - if (receivedAmount != boost::none) node.put("receivedAmount", *receivedAmount); + if (in_tx_pool != boost::none) node.put("in_tx_pool", *in_tx_pool); + if (num_confirmations != boost::none) node.put("num_confirmations", *num_confirmations); + if (received_amount != boost::none) node.put("received_amount", *received_amount); return node; } @@ -679,8 +679,8 @@ namespace monero { boost::property_tree::ptree monero_check_reserve::to_property_tree() const { boost::property_tree::ptree node = monero_check::to_property_tree(); - if (totalAmount != boost::none) node.put("totalAmount", *totalAmount); - if (unconfirmedSpentAmount != boost::none) node.put("unconfirmedSpentAmount", *unconfirmedSpentAmount); + if (total_amount != boost::none) node.put("total_amount", *total_amount); + if (unconfirmed_spent_amount != boost::none) node.put("unconfirmed_spent_amount", *unconfirmed_spent_amount); return node; } } diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index 4f0e27d..2c43ad2 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -66,35 +66,35 @@ namespace monero { * Models a result of syncing a wallet. */ struct monero_sync_result { - uint64_t numBlocksFetched; - bool receivedMoney; + uint64_t num_blocks_fetched; + bool received_money; monero_sync_result() {} - monero_sync_result(const uint64_t numBlocksFetched, const bool receivedMoney) : numBlocksFetched(numBlocksFetched), receivedMoney(receivedMoney) {} + monero_sync_result(const uint64_t num_blocks_fetched, const bool received_money) : num_blocks_fetched(num_blocks_fetched), received_money(received_money) {} }; /** * Models a Monero subaddress. */ struct monero_subaddress : public serializable_struct { - boost::optional accountIndex; + boost::optional account_index; boost::optional index; boost::optional address; boost::optional label; boost::optional balance; - boost::optional unlockedBalance; - boost::optional numUnspentOutputs; - boost::optional isUsed; - boost::optional numBlocksToUnlock; + boost::optional unlocked_balance; + boost::optional num_unspent_outputs; + boost::optional is_used; + boost::optional num_blocks_to_unlock; // BEGIN_KV_SERIALIZE_MAP() -// KV_SERIALIZE(accountIndex) +// KV_SERIALIZE(account_index) // KV_SERIALIZE(index) // KV_SERIALIZE(address) // KV_SERIALIZE(label) // KV_SERIALIZE(balance) -// KV_SERIALIZE(unlockedBalance) -// KV_SERIALIZE(numUnspentOutputs) -// KV_SERIALIZE(isUsed) -// KV_SERIALIZE(numBlocksToUnlock) +// KV_SERIALIZE(unlocked_balance) +// KV_SERIALIZE(num_unspent_outputs) +// KV_SERIALIZE(is_used) +// KV_SERIALIZE(num_blocks_to_unlock) // END_KV_SERIALIZE_MAP() boost::property_tree::ptree to_property_tree() const; @@ -106,17 +106,17 @@ namespace monero { */ struct monero_account : public serializable_struct { boost::optional index; - boost::optional primaryAddress; + boost::optional primary_address; boost::optional balance; - boost::optional unlockedBalance; + boost::optional unlocked_balance; boost::optional tag; vector subaddresses; // BEGIN_KV_SERIALIZE_MAP() // KV_SERIALIZE(index) -// KV_SERIALIZE(primaryAddress) +// KV_SERIALIZE(primary_address) // KV_SERIALIZE(label) // KV_SERIALIZE(balance) -// KV_SERIALIZE(unlockedBalance) +// KV_SERIALIZE(unlocked_balance) // KV_SERIALIZE(tag) // KV_SERIALIZE(subaddresses) // END_KV_SERIALIZE_MAP() @@ -145,8 +145,8 @@ namespace monero { struct monero_transfer : serializable_struct { shared_ptr tx; boost::optional amount; - boost::optional accountIndex; - boost::optional numSuggestedConfirmations; + boost::optional account_index; + boost::optional num_suggested_confirmations; virtual boost::optional getIsIncoming() const = 0; // derived class must implement shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; @@ -162,7 +162,7 @@ namespace monero { * Models an incoming transfer of funds to the wallet. */ struct monero_incoming_transfer : public monero_transfer { - boost::optional subaddressIndex; + boost::optional subaddress_index; boost::optional address; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; @@ -177,7 +177,7 @@ namespace monero { * Models an outgoing transfer of funds from the wallet. */ struct monero_outgoing_transfer : public monero_transfer { - vector subaddressIndices; + vector subaddress_indices; vector addresses; vector> destinations; @@ -195,14 +195,14 @@ namespace monero { * All transfers are returned except those that do not meet the criteria defined in this request. */ struct monero_transfer_request : public monero_transfer { - boost::optional isIncoming; + boost::optional is_incoming; boost::optional address; vector addresses; - boost::optional subaddressIndex; - vector subaddressIndices; + boost::optional subaddress_index; + vector subaddress_indices; vector> destinations; - boost::optional hasDestinations; - boost::optional> txRequest; + boost::optional has_destinations; + boost::optional> tx_request; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; @@ -215,11 +215,11 @@ namespace monero { * Models a Monero output with wallet extensions. */ struct monero_output_wallet : public monero_output { - boost::optional accountIndex; - boost::optional subaddressIndex; - boost::optional isSpent; - boost::optional isUnlocked; - boost::optional isFrozen; + boost::optional account_index; + boost::optional subaddress_index; + boost::optional is_spent; + boost::optional is_unlocked; + boost::optional is_frozen; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; @@ -235,8 +235,8 @@ namespace monero { * All outputs are returned except those that do not meet the criteria defined in this request. */ struct monero_output_request : public monero_output_wallet { - vector subaddressIndices; - boost::optional> txRequest; + vector subaddress_indices; + boost::optional> tx_request; // TODO: necessary to override all super classes? shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; @@ -250,8 +250,8 @@ namespace monero { * Models a Monero transaction in the context of a wallet. */ struct monero_tx_wallet : public monero_tx { - vector> incomingTransfers; - boost::optional> outgoingTransfer; + vector> incoming_transfers; + boost::optional> outgoing_transfer; boost::optional note; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; @@ -269,17 +269,17 @@ namespace monero { * All transactions are returned except those that do not meet the criteria defined in this request. */ struct monero_tx_request : public monero_tx_wallet { - boost::optional isOutgoing; - boost::optional isIncoming; - vector txIds; - boost::optional hasPaymentId; - vector paymentIds; + boost::optional is_outgoing; + boost::optional is_incoming; + vector tx_ids; + boost::optional has_payment_id; + vector payment_ids; boost::optional height; - boost::optional minHeight; - boost::optional maxHeight; - boost::optional includeOutputs; - boost::optional> transferRequest; - boost::optional> outputRequest; + boost::optional min_height; + boost::optional max_height; + boost::optional include_outputs; + boost::optional> transfer_request; + boost::optional> output_request; // TODO: necessary to override all super classes? shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; @@ -293,9 +293,9 @@ namespace monero { * Monero integrated address model. */ struct monero_integrated_address : public serializable_struct { - string standardAddress; - string paymentId; - string integratedAddress; + string standard_address; + string payment_id; + string integrated_address; boost::property_tree::ptree to_property_tree() const; }; @@ -315,21 +315,21 @@ namespace monero { */ struct monero_send_request : public serializable_struct { vector> destinations; - boost::optional paymentId; + boost::optional payment_id; boost::optional priority; boost::optional mixin; boost::optional ringSize; boost::optional fee; - boost::optional accountIndex; - vector subaddressIndices; - boost::optional unlockTime; - boost::optional canSplit; - boost::optional doNotRelay; + boost::optional account_index; + vector subaddress_indices; + boost::optional unlock_time; + boost::optional can_split; + boost::optional do_not_relay; boost::optional note; - boost::optional recipientName; - boost::optional belowAmount; - boost::optional sweepEachSubaddress; - boost::optional keyImage; + boost::optional receipient_name; + boost::optional below_amount; + boost::optional sweep_each_subaddress; + boost::optional key_image; boost::property_tree::ptree to_property_tree() const; }; @@ -339,8 +339,8 @@ namespace monero { */ struct monero_key_image_import_result : public serializable_struct { boost::optional height; - boost::optional spentAmount; - boost::optional unspentAmount; + boost::optional spent_amount; + boost::optional unspent_amount; boost::property_tree::ptree to_property_tree() const; }; @@ -349,7 +349,7 @@ namespace monero { * Base class for results from checking a transaction or reserve proof. */ struct monero_check : public serializable_struct { - bool isGood; + bool is_good; boost::property_tree::ptree to_property_tree() const; }; @@ -358,9 +358,9 @@ namespace monero { * Results from checking a transaction key. */ struct monero_check_tx : public monero_check { - boost::optional inTxPool; - boost::optional numConfirmations; - boost::optional receivedAmount; + boost::optional in_tx_pool; + boost::optional num_confirmations; + boost::optional received_amount; boost::property_tree::ptree to_property_tree() const; }; @@ -369,8 +369,8 @@ namespace monero { * Results from checking a reserve proof. */ struct monero_check_reserve : public monero_check { - boost::optional totalAmount; - boost::optional unconfirmedSpentAmount; + boost::optional total_amount; + boost::optional unconfirmed_spent_amount; boost::property_tree::ptree to_property_tree() const; }; diff --git a/test/scratchpad.cpp b/test/scratchpad.cpp index ac4ad2a..007e612 100644 --- a/test/scratchpad.cpp +++ b/test/scratchpad.cpp @@ -80,25 +80,25 @@ int main(int argc, const char* argv[]) { MINFO(txs[i]->serialize()); } -// shared_ptr transferRequest = shared_ptr(new monero_transfer_request()); -// transferRequest->accountIndex = 0; -// shared_ptr txRequest = shared_ptr(new monero_tx_request()); -// txRequest->isConfirmed = true; -// transferRequest->txRequest = txRequest; -// //txRequest->transferRequest = transferRequest; -// vector> transfers = wallet->get_transfers(*transferRequest); +// shared_ptr transfer_request = shared_ptr(new monero_transfer_request()); +// transfer_request->account_index = 0; +// shared_ptr tx_request = shared_ptr(new monero_tx_request()); +// tx_request->is_confirmed = true; +// transfer_request->tx_request = tx_request; +// //tx_request->transfer_request = transfer_request; +// vector> transfers = wallet->get_transfers(*transfer_request); // if (transfers.empty()) throw runtime_error("Transfers should not be empty"); // for (const shared_ptr& transfer : transfers) { -// if (*transfer->accountIndex != 0) throw runtime_error("Account should be 0"); -// if (!*transfer->tx->isConfirmed) throw runtime_error("Transfer should be confirmed"); +// if (*transfer->account_index != 0) throw runtime_error("Account should be 0"); +// if (!*transfer->tx->is_confirmed) throw runtime_error("Transfer should be confirmed"); // } -// shared_ptr txRequest = shared_ptr(new monero_tx_request()); -// txRequest->isConfirmed = true; -// vector> txs = wallet->get_txs(*txRequest); +// shared_ptr tx_request = shared_ptr(new monero_tx_request()); +// tx_request->is_confirmed = true; +// vector> txs = wallet->get_txs(*tx_request); // if (txs.empty()) throw runtime_error("Txs should not be empty"); // for (const shared_ptr& tx : txs) { -// if (!*tx->isConfirmed) throw runtime_error("Tx should be confirmed"); +// if (!*tx->is_confirmed) throw runtime_error("Tx should be confirmed"); // }