file names and methods switched from camelcase to underscores

This commit is contained in:
woodser
2019-08-03 11:11:50 -04:00
parent e959db9709
commit dc2ad44a17
11 changed files with 949 additions and 949 deletions
@@ -52,7 +52,7 @@
#pragma once
#include "MoneroDaemonModel.h"
#include "monero_daemon_model.h"
using namespace std;
@@ -50,9 +50,9 @@
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/
#include "MoneroDaemonModel.h"
#include "monero_daemon_model.h"
#include "utils/MoneroUtils.h"
#include "utils/monero_utils.h"
#include "include_base_utils.h"
#include "common/util.h"
@@ -63,8 +63,8 @@ namespace monero {
// ----------------------- UNDECLARED PRIVATE HELPERS -----------------------
void mergeTx(vector<shared_ptr<MoneroTx>>& txs, const shared_ptr<MoneroTx>& tx) {
for (const shared_ptr<MoneroTx>& aTx : txs) {
void merge_tx(vector<shared_ptr<monero_tx>>& txs, const shared_ptr<monero_tx>& tx) {
for (const shared_ptr<monero_tx>& aTx : txs) {
if (aTx->id.get() == tx->id.get()) {
aTx->merge(aTx, tx);
return;
@@ -75,17 +75,17 @@ namespace monero {
// ------------------------- INITIALIZE CONSTANTS ---------------------------
const string MoneroTx::DEFAULT_PAYMENT_ID = string("0000000000000000");
const string monero_tx::DEFAULT_PAYMENT_ID = string("0000000000000000");
// ------------------------- SERIALIZABLE STRUCT ----------------------------
string SerializableStruct::serialize() const {
return MoneroUtils::serialize(toPropertyTree());
string serializable_struct::serialize() const {
return monero_utils::serialize(to_property_tree());
}
// ------------------------- MONERO BLOCK HEADER ----------------------------
boost::property_tree::ptree MoneroBlockHeader::toPropertyTree() const {
boost::property_tree::ptree monero_block_header::to_property_tree() const {
boost::property_tree::ptree node;
if (id != boost::none) node.put("id", *id);
if (height != boost::none) node.put("height", *height);
@@ -108,54 +108,54 @@ namespace monero {
return node;
}
void MoneroBlockHeader::merge(const shared_ptr<MoneroBlockHeader>& self, const shared_ptr<MoneroBlockHeader>& other) {
void monero_block_header::merge(const shared_ptr<monero_block_header>& self, const shared_ptr<monero_block_header>& other) {
if (this != self.get()) throw runtime_error("this != self");
if (self == other) return;
id = MoneroUtils::reconcile(id, other->id);
height = MoneroUtils::reconcile(height, other->height, boost::none, boost::none, true, "block height"); // height can increase
timestamp = MoneroUtils::reconcile(timestamp, other->timestamp, boost::none, boost::none, true, "block header timestamp"); // timestamp can increase
size = MoneroUtils::reconcile(size, other->size, "block header size");
weight = MoneroUtils::reconcile(weight, other->weight, "block header weight");
longTermWeight = MoneroUtils::reconcile(longTermWeight, other->longTermWeight, "block header long term weight");
depth = MoneroUtils::reconcile(depth, other->depth, "block header depth");
difficulty = MoneroUtils::reconcile(difficulty, other->difficulty, "difficulty");
cumulativeDifficulty = MoneroUtils::reconcile(cumulativeDifficulty, other->cumulativeDifficulty, "cumulativeDifficulty");
majorVersion = MoneroUtils::reconcile(majorVersion, other->majorVersion, "majorVersion");
minorVersion = MoneroUtils::reconcile(minorVersion, other->minorVersion, "minorVersion");
nonce = MoneroUtils::reconcile(nonce, other->nonce, "nonce");
minerTxId = MoneroUtils::reconcile(minerTxId, other->minerTxId);
numTxs = MoneroUtils::reconcile(numTxs, other->numTxs, "block header numTxs");
orphanStatus = MoneroUtils::reconcile(orphanStatus, other->orphanStatus);
prevId = MoneroUtils::reconcile(prevId, other->prevId);
reward = MoneroUtils::reconcile(reward, other->reward, "block header reward");
powHash = MoneroUtils::reconcile(powHash, other->powHash);
id = monero_utils::reconcile(id, other->id);
height = monero_utils::reconcile(height, other->height, boost::none, boost::none, true, "block height"); // height can increase
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");
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");
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);
reward = monero_utils::reconcile(reward, other->reward, "block header reward");
powHash = monero_utils::reconcile(powHash, other->powHash);
}
// ----------------------------- MONERO BLOCK -------------------------------
boost::property_tree::ptree MoneroBlock::toPropertyTree() const {
boost::property_tree::ptree node = MoneroBlockHeader::toPropertyTree();
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)->toPropertyTree());
if (!txs.empty()) node.add_child("txs", MoneroUtils::toPropertyTree(txs));
if (!txIds.empty()) node.add_child("txIds", MoneroUtils::toPropertyTree(txIds));
if (minerTx != boost::none) node.add_child("minerTx", (*minerTx)->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));
return node;
}
void MoneroBlock::merge(const shared_ptr<MoneroBlockHeader>& self, const shared_ptr<MoneroBlockHeader>& other) {
merge(static_pointer_cast<MoneroBlock>(self), static_pointer_cast<MoneroBlock>(other));
void monero_block::merge(const shared_ptr<monero_block_header>& self, const shared_ptr<monero_block_header>& other) {
merge(static_pointer_cast<monero_block>(self), static_pointer_cast<monero_block>(other));
}
void MoneroBlock::merge(const shared_ptr<MoneroBlock>& self, const shared_ptr<MoneroBlock>& other) {
void monero_block::merge(const shared_ptr<monero_block>& self, const shared_ptr<monero_block>& other) {
if (this != self.get()) throw runtime_error("this != self");
if (self == other) return;
// merge header fields
MoneroBlockHeader::merge(self, other);
monero_block_header::merge(self, other);
// merge reconcilable block extensions
hex = MoneroUtils::reconcile(hex, other->hex);
txIds = MoneroUtils::reconcile(txIds, other->txIds);
hex = monero_utils::reconcile(hex, other->hex);
txIds = monero_utils::reconcile(txIds, other->txIds);
// merge miner tx
if (minerTx == boost::none) minerTx = other->minerTx;
@@ -166,17 +166,17 @@ namespace monero {
// merge non-miner txs
if (!other->txs.empty()) {
for (const shared_ptr<MoneroTx> otherTx : other->txs) { // NOTE: not using reference so shared_ptr is not deleted when block is dereferenced
for (const shared_ptr<monero_tx> otherTx : other->txs) { // NOTE: not using reference so shared_ptr is not deleted when block is dereferenced
otherTx->block = self;
mergeTx(self->txs, otherTx);
merge_tx(self->txs, otherTx);
}
}
}
// ------------------------------- MONERO TX --------------------------------
shared_ptr<MoneroTx> MoneroTx::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const {
MTRACE("MoneroTx::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt)");
shared_ptr<monero_tx> monero_tx::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const {
MTRACE("monero_tx::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt)");
tgt->id = src->id;
tgt->version = src->version;
tgt->isMinerTx = src->isMinerTx;
@@ -200,17 +200,17 @@ namespace monero {
tgt->size = src->size;
tgt->weight = src->weight;
if (!src->vins.empty()) {
tgt->vins = vector<shared_ptr<MoneroOutput>>();
for (const shared_ptr<MoneroOutput>& vin : src->vins) {
shared_ptr<MoneroOutput> vinCopy = vin->copy(vin, make_shared<MoneroOutput>());
tgt->vins = vector<shared_ptr<monero_output>>();
for (const shared_ptr<monero_output>& vin : src->vins) {
shared_ptr<monero_output> vinCopy = vin->copy(vin, make_shared<monero_output>());
vinCopy->tx = tgt;
tgt->vins.push_back(vinCopy);
}
}
if (!src->vouts.empty()) {
tgt->vouts = vector<shared_ptr<MoneroOutput>>();
for (const shared_ptr<MoneroOutput>& vout : src->vouts) {
shared_ptr<MoneroOutput> voutCopy = vout->copy(vout, make_shared<MoneroOutput>());
tgt->vouts = vector<shared_ptr<monero_output>>();
for (const shared_ptr<monero_output>& vout : src->vouts) {
shared_ptr<monero_output> voutCopy = vout->copy(vout, make_shared<monero_output>());
voutCopy->tx = tgt;
tgt->vouts.push_back(voutCopy);
}
@@ -231,7 +231,7 @@ namespace monero {
return tgt;
}
boost::property_tree::ptree MoneroTx::toPropertyTree() const {
boost::property_tree::ptree monero_tx::to_property_tree() const {
boost::property_tree::ptree node;
if (id != boost::none) node.put("id", *id);
if (version != boost::none) node.put("version", *version);
@@ -255,12 +255,12 @@ namespace monero {
if (prunableHash != boost::none) node.put("prunableHash", *prunableHash);
if (size != boost::none) node.put("size", *size);
if (weight != boost::none) node.put("weight", *weight);
if (!vins.empty()) node.add_child("vins", MoneroUtils::toPropertyTree(vins));
if (!vouts.empty()) node.add_child("vouts", MoneroUtils::toPropertyTree(vouts));
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 (metadata != boost::none) node.put("metadata", *metadata);
if (commonTxSets != boost::none) throw runtime_error("commonTxSets not implemented");
if (!extra.empty()) node.add_child("extra", MoneroUtils::toPropertyTree(extra));
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);
@@ -273,70 +273,70 @@ namespace monero {
return node;
}
boost::optional<uint64_t> MoneroTx::getHeight() const {
boost::optional<uint64_t> monero_tx::get_height() const {
if (block == boost::none) return boost::none;
return *((*block)->height);
}
void MoneroTx::merge(const shared_ptr<MoneroTx>& self, const shared_ptr<MoneroTx>& other) {
void monero_tx::merge(const shared_ptr<monero_tx>& self, const shared_ptr<monero_tx>& other) {
if (this != self.get()) throw runtime_error("this != self");
if (self == other) return;
// merge blocks if they're different which comes back to merging txs
if (block != other->block) {
if (block == boost::none) {
block = make_shared<MoneroBlock>();
block = make_shared<monero_block>();
block.get()->txs.push_back(self);
block.get()->height = other->getHeight();
block.get()->height = other->get_height();
}
if (other->block == boost::none) {
other->block = make_shared<MoneroBlock>();
other->block = make_shared<monero_block>();
other->block.get()->txs.push_back(other);
other->block.get()->height = self->getHeight();
other->block.get()->height = self->get_height();
}
block.get()->merge(block.get(), other->block.get());
return;
}
// otherwise merge tx fields
id = MoneroUtils::reconcile(id, other->id);
version = MoneroUtils::reconcile(version, other->version);
paymentId = MoneroUtils::reconcile(paymentId, other->paymentId);
fee = MoneroUtils::reconcile(fee, other->fee, "tx fee");
mixin = MoneroUtils::reconcile(mixin, other->mixin, "tx mixin");
isConfirmed = MoneroUtils::reconcile(isConfirmed, other->isConfirmed);
doNotRelay = MoneroUtils::reconcile(doNotRelay, other->doNotRelay);
isRelayed = MoneroUtils::reconcile(isRelayed, other->isRelayed);
isDoubleSpendSeen = MoneroUtils::reconcile(isDoubleSpendSeen, other->isDoubleSpendSeen);
key = MoneroUtils::reconcile(key, other->key);
fullHex = MoneroUtils::reconcile(fullHex, other->fullHex);
prunedHex = MoneroUtils::reconcile(prunedHex, other->prunedHex);
prunableHex = MoneroUtils::reconcile(prunableHex, other->prunableHex);
prunableHash = MoneroUtils::reconcile(prunableHash, other->prunableHash);
size = MoneroUtils::reconcile(size, other->size, "tx size");
weight = MoneroUtils::reconcile(weight, other->weight, "tx weight");
//outputIndices = MoneroUtils::reconcile(outputIndices, other->outputIndices); // TODO
metadata = MoneroUtils::reconcile(metadata, other->metadata);
commonTxSets = MoneroUtils::reconcile(commonTxSets, other->commonTxSets);
//extra = MoneroUtils::reconcile(extra, other->extra); // TODO
rctSignatures = MoneroUtils::reconcile(rctSignatures, other->rctSignatures);
rctSigPrunable = MoneroUtils::reconcile(rctSigPrunable, other->rctSigPrunable);
isKeptByBlock = MoneroUtils::reconcile(isKeptByBlock, other->isKeptByBlock);
isFailed = MoneroUtils::reconcile(isFailed, other->isFailed);
lastFailedHeight = MoneroUtils::reconcile(lastFailedHeight, other->lastFailedHeight, "lastFailedHeight");
lastFailedId = MoneroUtils::reconcile(lastFailedId, other->lastFailedId);
maxUsedBlockHeight = MoneroUtils::reconcile(maxUsedBlockHeight, other->maxUsedBlockHeight, "maxUsedBlockHeight");
maxUsedBlockId = MoneroUtils::reconcile(maxUsedBlockId, other->maxUsedBlockId);
//signatures = MoneroUtils::reconcile(signatures, other->signatures); // TODO
unlockTime = MoneroUtils::reconcile(unlockTime, other->unlockTime, "unlockTime");
numConfirmations = MoneroUtils::reconcile(numConfirmations, other->numConfirmations, "numConfirmations");
id = monero_utils::reconcile(id, other->id);
version = monero_utils::reconcile(version, other->version);
paymentId = monero_utils::reconcile(paymentId, other->paymentId);
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);
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);
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
metadata = monero_utils::reconcile(metadata, other->metadata);
commonTxSets = monero_utils::reconcile(commonTxSets, other->commonTxSets);
//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);
//signatures = monero_utils::reconcile(signatures, other->signatures); // TODO
unlockTime = monero_utils::reconcile(unlockTime, other->unlockTime, "unlockTime");
numConfirmations = monero_utils::reconcile(numConfirmations, other->numConfirmations, "numConfirmations");
// merge vins
if (!other->vins.empty()) {
for (const shared_ptr<MoneroOutput>& merger : other->vins) {
for (const shared_ptr<monero_output>& merger : other->vins) {
bool merged = false;
merger->tx = self;
for (const shared_ptr<MoneroOutput>& mergee : vins) {
for (const shared_ptr<monero_output>& mergee : vins) {
if ((*mergee->keyImage)->hex == (*merger->keyImage)->hex) {
mergee->merge(mergee, merger);
merged = true;
@@ -349,19 +349,19 @@ namespace monero {
// merge vouts
if (!other->vouts.empty()) {
for (const shared_ptr<MoneroOutput>& vout : other->vouts) vout->tx = self;
for (const shared_ptr<monero_output>& vout : other->vouts) vout->tx = self;
if (vouts.empty()) vouts = other->vouts;
else {
// determine if key images present
int numKeyImages = 0;
for (const shared_ptr<MoneroOutput> vout : vouts) {
for (const shared_ptr<monero_output> vout : vouts) {
if (vout->keyImage != boost::none) {
if ((*vout->keyImage)->hex == boost::none) throw runtime_error("Key image hex cannot be null");
numKeyImages++;
}
}
for (const shared_ptr<MoneroOutput>& vout : other->vouts) {
for (const shared_ptr<monero_output>& vout : other->vouts) {
if (vout->keyImage != boost::none) {
if ((*vout->keyImage)->hex == boost::none) throw runtime_error("Key image hex cannot be null");
numKeyImages++;
@@ -371,10 +371,10 @@ namespace monero {
// merge by key images
if (numKeyImages > 0) {
for (const shared_ptr<MoneroOutput>& merger : other->vouts) {
for (const shared_ptr<monero_output>& merger : other->vouts) {
bool merged = false;
merger->tx = self;
for (const shared_ptr<MoneroOutput>& mergee : vouts) {
for (const shared_ptr<monero_output>& mergee : vouts) {
if ((*mergee->keyImage)->hex == (*merger->keyImage)->hex) {
mergee->merge(mergee, merger);
merged = true;
@@ -401,38 +401,38 @@ namespace monero {
receivedTimestamp = boost::none;
lastRelayedTimestamp = boost::none;
} else {
inTxPool = MoneroUtils::reconcile(inTxPool, other->inTxPool, boost::none, true, boost::none); // unrelayed -> tx pool
receivedTimestamp = MoneroUtils::reconcile(receivedTimestamp, other->receivedTimestamp, boost::none, boost::none, false, "receivedTimestamp"); // take earliest receive time
lastRelayedTimestamp = MoneroUtils::reconcile(lastRelayedTimestamp, other->lastRelayedTimestamp, boost::none, boost::none, true, "lastRelayedTimestamp"); // take latest relay time
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
}
}
// --------------------------- MONERO KEY IMAGE -----------------------------
shared_ptr<MoneroKeyImage> MoneroKeyImage::copy(const shared_ptr<MoneroKeyImage>& src, const shared_ptr<MoneroKeyImage>& tgt) const {
shared_ptr<monero_key_image> monero_key_image::copy(const shared_ptr<monero_key_image>& src, const shared_ptr<monero_key_image>& tgt) const {
if (this != src.get()) throw runtime_error("this != src");
tgt->hex = src->hex;
tgt->signature = src->signature;
return tgt;
}
boost::property_tree::ptree MoneroKeyImage::toPropertyTree() const {
boost::property_tree::ptree monero_key_image::to_property_tree() const {
boost::property_tree::ptree node;
if (hex != boost::none) node.put("hex", *hex);
if (signature != boost::none) node.put("signature", *signature);
return node;
}
void MoneroKeyImage::merge(const shared_ptr<MoneroKeyImage>& self, const shared_ptr<MoneroKeyImage>& other) {
void monero_key_image::merge(const shared_ptr<monero_key_image>& self, const shared_ptr<monero_key_image>& other) {
throw runtime_error("Not implemented");
}
// ------------------------------ MONERO OUTPUT -----------------------------
shared_ptr<MoneroOutput> MoneroOutput::copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const {
shared_ptr<monero_output> monero_output::copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const {
if (this != src.get()) throw runtime_error("this != src");
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<MoneroKeyImage>());
if (src->keyImage != boost::none) tgt->keyImage = src->keyImage.get()->copy(src->keyImage.get(), make_shared<monero_key_image>());
tgt->amount = src->amount;
tgt->index = src->index;
if (!src->ringOutputIndices.empty()) tgt->ringOutputIndices = vector<uint64_t>(src->ringOutputIndices);
@@ -440,17 +440,17 @@ namespace monero {
return tgt;
}
boost::property_tree::ptree MoneroOutput::toPropertyTree() const {
boost::property_tree::ptree monero_output::to_property_tree() const {
boost::property_tree::ptree node;
if (keyImage != boost::none) node.add_child("keyImage", (*keyImage)->toPropertyTree());
if (keyImage != boost::none) node.add_child("keyImage", (*keyImage)->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", MoneroUtils::toPropertyTree(ringOutputIndices));
if (!ringOutputIndices.empty()) node.add_child("ringOutputIndices", monero_utils::to_property_tree(ringOutputIndices));
if (stealthPublicKey != boost::none) node.put("stealthPublicKey", *stealthPublicKey);
return node;
}
void MoneroOutput::merge(const shared_ptr<MoneroOutput>& self, const shared_ptr<MoneroOutput>& other) {
void monero_output::merge(const shared_ptr<monero_output>& self, const shared_ptr<monero_output>& other) {
if (this != self.get()) throw runtime_error("this != self");
if (self == other) return;
@@ -463,7 +463,7 @@ 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());
amount = MoneroUtils::reconcile(amount, other->amount, "output amount");
index = MoneroUtils::reconcile(index, other->index, "output index");
amount = monero_utils::reconcile(amount, other->amount, "output amount");
index = monero_utils::reconcile(index, other->index, "output index");
}
}
@@ -65,7 +65,7 @@ namespace monero {
/**
* Base struct which can be serialized.
*/
struct SerializableStruct {
struct serializable_struct {
/**
* Serializes the struct to a json string.
@@ -79,7 +79,7 @@ namespace monero {
*
* @return the converted property tree
*/
virtual boost::property_tree::ptree toPropertyTree() const = 0;
virtual boost::property_tree::ptree to_property_tree() const = 0;
};
/**
@@ -96,23 +96,23 @@ namespace monero {
*
* TODO: switch to boost::optional<string>
*/
struct MoneroRpcConnection {
struct monero_rpc_connection {
string uri;
boost::optional<string> username;
boost::optional<string> password;
MoneroRpcConnection(const string& uri = "", const boost::optional<string>& username = boost::none, const boost::optional<string>& password = boost::none) : uri(uri), username(username), password(password) {}
monero_rpc_connection(const string& uri = "", const boost::optional<string>& username = boost::none, const boost::optional<string>& password = boost::none) : uri(uri), username(username), password(password) {}
};
// forward declarations
struct MoneroTx;
struct MoneroOutput;
struct monero_tx;
struct monero_output;
/**
* Models a Monero block header which contains information about the block.
*
* TODO: a header that is transmitted may have fewer fields like cryptonote::block_header; separate?
*/
struct MoneroBlockHeader : public SerializableStruct {
struct monero_block_header : public serializable_struct {
boost::optional<string> id;
boost::optional<uint64_t> height;
boost::optional<uint64_t> timestamp;
@@ -132,30 +132,30 @@ namespace monero {
boost::optional<uint64_t> reward;
boost::optional<string> powHash;
boost::property_tree::ptree toPropertyTree() const;
virtual void merge(const shared_ptr<MoneroBlockHeader>& self, const shared_ptr<MoneroBlockHeader>& other);
boost::property_tree::ptree to_property_tree() const;
virtual void merge(const shared_ptr<monero_block_header>& self, const shared_ptr<monero_block_header>& other);
};
/**
* Models a Monero block in the blockchain.
*/
struct MoneroBlock : public MoneroBlockHeader {
struct monero_block : public monero_block_header {
boost::optional<string> hex;
boost::optional<shared_ptr<MoneroTx>> minerTx;
vector<shared_ptr<MoneroTx>> txs;
boost::optional<shared_ptr<monero_tx>> minerTx;
vector<shared_ptr<monero_tx>> txs;
vector<string> txIds;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroBlockHeader>& self, const shared_ptr<MoneroBlockHeader>& other);
void merge(const shared_ptr<MoneroBlock>& self, const shared_ptr<MoneroBlock>& other);
boost::property_tree::ptree to_property_tree() const;
void merge(const shared_ptr<monero_block_header>& self, const shared_ptr<monero_block_header>& other);
void merge(const shared_ptr<monero_block>& self, const shared_ptr<monero_block>& other);
};
/**
* Models a Monero transaction on the blockchain.
*/
struct MoneroTx : public SerializableStruct {
struct monero_tx : public serializable_struct {
static const string DEFAULT_PAYMENT_ID; // default payment id "0000000000000000"
boost::optional<shared_ptr<MoneroBlock>> block;
boost::optional<shared_ptr<monero_block>> block;
boost::optional<string> id;
boost::optional<uint32_t> version;
boost::optional<bool> isMinerTx;
@@ -178,8 +178,8 @@ namespace monero {
boost::optional<string> prunableHash;
boost::optional<uint32_t> size;
boost::optional<uint32_t> weight;
vector<shared_ptr<MoneroOutput>> vins;
vector<shared_ptr<MoneroOutput>> vouts;
vector<shared_ptr<monero_output>> vins;
vector<shared_ptr<monero_output>> vouts;
vector<uint32_t> outputIndices;
boost::optional<string> metadata;
boost::optional<string> commonTxSets;
@@ -194,37 +194,37 @@ namespace monero {
boost::optional<string> maxUsedBlockId;
vector<string> signatures;
shared_ptr<MoneroTx> copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
virtual void merge(const shared_ptr<MoneroTx>& self, const shared_ptr<MoneroTx>& other);
boost::optional<uint64_t> getHeight() const;
shared_ptr<monero_tx> copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const;
boost::property_tree::ptree to_property_tree() const;
virtual void merge(const shared_ptr<monero_tx>& self, const shared_ptr<monero_tx>& other);
boost::optional<uint64_t> get_height() const;
};
/**
* Models a Monero key image.
*/
struct MoneroKeyImage : public SerializableStruct {
struct monero_key_image : public serializable_struct {
boost::optional<string> hex;
boost::optional<string> signature;
shared_ptr<MoneroKeyImage> copy(const shared_ptr<MoneroKeyImage>& src, const shared_ptr<MoneroKeyImage>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroKeyImage>& self, const shared_ptr<MoneroKeyImage>& other);
shared_ptr<monero_key_image> copy(const shared_ptr<monero_key_image>& src, const shared_ptr<monero_key_image>& tgt) const;
boost::property_tree::ptree to_property_tree() const;
void merge(const shared_ptr<monero_key_image>& self, const shared_ptr<monero_key_image>& other);
};
/**
* Models a Monero transaction output.
*/
struct MoneroOutput : public SerializableStruct {
shared_ptr<MoneroTx> tx;
boost::optional<shared_ptr<MoneroKeyImage>> keyImage;
struct monero_output : public serializable_struct {
shared_ptr<monero_tx> tx;
boost::optional<shared_ptr<monero_key_image>> keyImage;
boost::optional<uint64_t> amount;
boost::optional<uint64_t> index;
vector<uint64_t> ringOutputIndices;
boost::optional<string> stealthPublicKey;
shared_ptr<MoneroOutput> copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
virtual void merge(const shared_ptr<MoneroOutput>& self, const shared_ptr<MoneroOutput>& other);
shared_ptr<monero_output> copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const;
boost::property_tree::ptree to_property_tree() const;
virtual void merge(const shared_ptr<monero_output>& self, const shared_ptr<monero_output>& other);
};
}
@@ -50,18 +50,18 @@
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/
#include "MoneroUtils.h"
#include "monero_utils.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "storages/portable_storage_template_helper.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
using namespace std;
using namespace cryptonote;
using namespace MoneroUtils;
using namespace monero_utils;
// ------------------------------- INNER HELPERS ------------------------------
void nodeToTransfer(const boost::property_tree::ptree& node, shared_ptr<MoneroTransfer> transfer) {
void nodeToTransfer(const boost::property_tree::ptree& node, shared_ptr<monero_transfer> transfer) {
// initialize transfer from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
@@ -70,8 +70,8 @@ void nodeToTransfer(const boost::property_tree::ptree& node, shared_ptr<MoneroTr
}
}
shared_ptr<MoneroTransferRequest> nodeToTransferRequest(const boost::property_tree::ptree& node) {
shared_ptr<MoneroTransferRequest> transferRequest = make_shared<MoneroTransferRequest>();
shared_ptr<monero_transfer_request> nodeToTransferRequest(const boost::property_tree::ptree& node) {
shared_ptr<monero_transfer_request> transferRequest = make_shared<monero_transfer_request>();
nodeToTransfer(node, transferRequest);
// initialize request from node
@@ -94,10 +94,10 @@ shared_ptr<MoneroTransferRequest> nodeToTransferRequest(const boost::property_tr
return transferRequest;
}
shared_ptr<MoneroKeyImage> nodeToKeyImage(const boost::property_tree::ptree& node) {
shared_ptr<monero_key_image> nodeToKeyImage(const boost::property_tree::ptree& node) {
// initialize key image from node
shared_ptr<MoneroKeyImage> keyImage = make_shared<MoneroKeyImage>();
shared_ptr<monero_key_image> keyImage = make_shared<monero_key_image>();
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();
@@ -107,7 +107,7 @@ shared_ptr<MoneroKeyImage> nodeToKeyImage(const boost::property_tree::ptree& nod
return keyImage;
}
void nodeToOutput(const boost::property_tree::ptree& node, shared_ptr<MoneroOutput> output) {
void nodeToOutput(const boost::property_tree::ptree& node, shared_ptr<monero_output> output) {
// initialize output from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
@@ -120,7 +120,7 @@ void nodeToOutput(const boost::property_tree::ptree& node, shared_ptr<MoneroOutp
}
}
void nodeToOutputWallet(const boost::property_tree::ptree& node, shared_ptr<MoneroOutputWallet> outputWallet) {
void nodeToOutputWallet(const boost::property_tree::ptree& node, shared_ptr<monero_output_wallet> outputWallet) {
nodeToOutput(node, outputWallet);
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
@@ -132,8 +132,8 @@ void nodeToOutputWallet(const boost::property_tree::ptree& node, shared_ptr<Mone
}
}
shared_ptr<MoneroOutputRequest> nodeToOutputRequest(const boost::property_tree::ptree& node) {
shared_ptr<MoneroOutputRequest> outputRequest = make_shared<MoneroOutputRequest>();
shared_ptr<monero_output_request> nodeToOutputRequest(const boost::property_tree::ptree& node) {
shared_ptr<monero_output_request> outputRequest = make_shared<monero_output_request>();
nodeToOutputWallet(node, outputRequest);
// initialize request from node
@@ -146,7 +146,7 @@ shared_ptr<MoneroOutputRequest> nodeToOutputRequest(const boost::property_tree::
return outputRequest;
}
void nodeToTx(const boost::property_tree::ptree& node, shared_ptr<MoneroTx> tx) {
void nodeToTx(const boost::property_tree::ptree& node, shared_ptr<monero_tx> tx) {
// initialize tx from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
@@ -192,7 +192,7 @@ void nodeToTx(const boost::property_tree::ptree& node, shared_ptr<MoneroTx> tx)
}
// TODO: fill this out
void nodeToTxWallet(const boost::property_tree::ptree& node, shared_ptr<MoneroTxWallet> txWallet) {
void nodeToTxWallet(const boost::property_tree::ptree& node, shared_ptr<monero_tx_wallet> txWallet) {
nodeToTx(node, txWallet);
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
@@ -201,8 +201,8 @@ void nodeToTxWallet(const boost::property_tree::ptree& node, shared_ptr<MoneroTx
}
}
shared_ptr<MoneroTxRequest> nodeToTxRequest(const boost::property_tree::ptree& node) {
shared_ptr<MoneroTxRequest> txRequest = make_shared<MoneroTxRequest>();
shared_ptr<monero_tx_request> nodeToTxRequest(const boost::property_tree::ptree& node) {
shared_ptr<monero_tx_request> txRequest = make_shared<monero_tx_request>();
nodeToTxWallet(node, txRequest);
// initialize request from node
@@ -224,8 +224,8 @@ shared_ptr<MoneroTxRequest> nodeToTxRequest(const boost::property_tree::ptree& n
return txRequest;
}
shared_ptr<MoneroBlock> nodeToBlockRequest(const boost::property_tree::ptree& node) {
shared_ptr<MoneroBlock> block = make_shared<MoneroBlock>();
shared_ptr<monero_block> nodeToBlockRequest(const boost::property_tree::ptree& node) {
shared_ptr<monero_block> block = make_shared<monero_block>();
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
if (key == string("txs")) {
@@ -238,8 +238,8 @@ shared_ptr<MoneroBlock> nodeToBlockRequest(const boost::property_tree::ptree& no
return block;
}
shared_ptr<MoneroDestination> nodeToDestination(const boost::property_tree::ptree& node) {
shared_ptr<MoneroDestination> destination = make_shared<MoneroDestination>();
shared_ptr<monero_destination> nodeToDestination(const boost::property_tree::ptree& node) {
shared_ptr<monero_destination> destination = make_shared<monero_destination>();
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
if (key == string("address")) destination->address = it->second.data();
@@ -250,19 +250,19 @@ shared_ptr<MoneroDestination> nodeToDestination(const boost::property_tree::ptre
// ------------------------- PUBLIC STATIC UTILITIES --------------------------
void MoneroUtils::jsonToBinary(const std::string &json, std::string &bin) {
void monero_utils::jsonToBinary(const std::string &json, std::string &bin) {
epee::serialization::portable_storage ps;
ps.load_from_json(json);
ps.store_to_binary(bin);
}
void MoneroUtils::binaryToJson(const std::string &bin, std::string &json) {
void monero_utils::binaryToJson(const std::string &bin, std::string &json) {
epee::serialization::portable_storage ps;
ps.load_from_binary(bin);
ps.dump_as_json(json);
}
void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json) {
void monero_utils::binaryBlocksToJson(const std::string &bin, std::string &json) {
// load binary rpc response to struct
cryptonote::COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response resp_struct;
@@ -294,8 +294,8 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
// add tx node to txs node
boost::property_tree::ptree txNode;
MTRACE("PRUNED:\n" << MoneroUtils::get_pruned_tx_json(tx));
txNode.put("", MoneroUtils::get_pruned_tx_json(tx)); // TODO: no pretty print
MTRACE("PRUNED:\n" << monero_utils::get_pruned_tx_json(tx));
txNode.put("", monero_utils::get_pruned_tx_json(tx)); // TODO: no pretty print
txsNode.push_back(std::make_pair("", txNode));
} else {
throw std::runtime_error("failed to parse tx blob at index " + std::to_string(txIdx));
@@ -314,7 +314,7 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
json = ss.str();
}
shared_ptr<MoneroTxRequest> MoneroUtils::deserializeTxRequest(const string& txRequestStr) {
shared_ptr<monero_tx_request> monero_utils::deserializeTxRequest(const string& txRequestStr) {
// deserialize tx request string to property rooted at block
std::istringstream iss = txRequestStr.empty() ? std::istringstream() : std::istringstream(txRequestStr);
@@ -322,16 +322,16 @@ shared_ptr<MoneroTxRequest> MoneroUtils::deserializeTxRequest(const string& txRe
boost::property_tree::read_json(iss, blockNode);
// convert request property tree to block
shared_ptr<MoneroBlock> block = nodeToBlockRequest(blockNode);
shared_ptr<monero_block> block = nodeToBlockRequest(blockNode);
// get tx request
shared_ptr<MoneroTxRequest> txRequest = static_pointer_cast<MoneroTxRequest>(block->txs[0]);
shared_ptr<monero_tx_request> txRequest = static_pointer_cast<monero_tx_request>(block->txs[0]);
// return deserialized request
return txRequest;
}
shared_ptr<MoneroTransferRequest> MoneroUtils::deserializeTransferRequest(const string& transferRequestStr) {
shared_ptr<monero_transfer_request> monero_utils::deserializeTransferRequest(const string& transferRequestStr) {
// deserialize transfer request string to property rooted at block
std::istringstream iss = transferRequestStr.empty() ? std::istringstream() : std::istringstream(transferRequestStr);
@@ -339,16 +339,16 @@ shared_ptr<MoneroTransferRequest> MoneroUtils::deserializeTransferRequest(const
boost::property_tree::read_json(iss, blockNode);
// convert request property tree to block
shared_ptr<MoneroBlock> block = nodeToBlockRequest(blockNode);
shared_ptr<monero_block> block = nodeToBlockRequest(blockNode);
// return mpty request if no txs
if (block->txs.empty()) return make_shared<MoneroTransferRequest>();
if (block->txs.empty()) return make_shared<monero_transfer_request>();
// get tx request
shared_ptr<MoneroTxRequest> txRequest = static_pointer_cast<MoneroTxRequest>(block->txs[0]);
shared_ptr<monero_tx_request> txRequest = static_pointer_cast<monero_tx_request>(block->txs[0]);
// get / create transfer request
shared_ptr<MoneroTransferRequest> transferRequest = txRequest->transferRequest == boost::none ? make_shared<MoneroTransferRequest>() : *txRequest->transferRequest;
shared_ptr<monero_transfer_request> transferRequest = txRequest->transferRequest == boost::none ? make_shared<monero_transfer_request>() : *txRequest->transferRequest;
// transfer request references tx request but not the other way around to avoid circular loop // TODO: could add check within meetsCriterias()
transferRequest->txRequest = txRequest;
@@ -358,7 +358,7 @@ shared_ptr<MoneroTransferRequest> MoneroUtils::deserializeTransferRequest(const
return transferRequest;
}
shared_ptr<MoneroOutputRequest> MoneroUtils::deserializeOutputRequest(const string& outputRequestStr) {
shared_ptr<monero_output_request> monero_utils::deserializeOutputRequest(const string& outputRequestStr) {
// deserialize output request string to property rooted at block
std::istringstream iss = outputRequestStr.empty() ? std::istringstream() : std::istringstream(outputRequestStr);
@@ -366,16 +366,16 @@ shared_ptr<MoneroOutputRequest> MoneroUtils::deserializeOutputRequest(const stri
boost::property_tree::read_json(iss, blockNode);
// convert request property tree to block
shared_ptr<MoneroBlock> block = nodeToBlockRequest(blockNode);
shared_ptr<monero_block> block = nodeToBlockRequest(blockNode);
// empty request if no txs
if (block->txs.empty()) return make_shared<MoneroOutputRequest>();
if (block->txs.empty()) return make_shared<monero_output_request>();
// get tx request
shared_ptr<MoneroTxRequest> txRequest = static_pointer_cast<MoneroTxRequest>(block->txs[0]);
shared_ptr<monero_tx_request> txRequest = static_pointer_cast<monero_tx_request>(block->txs[0]);
// get / create output request
shared_ptr<MoneroOutputRequest> outputRequest = txRequest->outputRequest == boost::none ? make_shared<MoneroOutputRequest>() : *txRequest->outputRequest;
shared_ptr<monero_output_request> outputRequest = txRequest->outputRequest == boost::none ? make_shared<monero_output_request>() : *txRequest->outputRequest;
// output request references tx request but not the other way around to avoid circular loop // TODO: could add check within meetsCriterias()
outputRequest->txRequest = txRequest;
@@ -385,15 +385,15 @@ shared_ptr<MoneroOutputRequest> MoneroUtils::deserializeOutputRequest(const stri
return outputRequest;
}
shared_ptr<MoneroSendRequest> MoneroUtils::deserializeSendRequest(const string& sendRequestStr) {
shared_ptr<monero_send_request> monero_utils::deserializeSendRequest(const string& sendRequestStr) {
// deserialize send request json to property node
std::istringstream iss = sendRequestStr.empty() ? std::istringstream() : std::istringstream(sendRequestStr);
boost::property_tree::ptree node;
boost::property_tree::read_json(iss, node);
// convert request property tree to MoneroSendRequest
shared_ptr<MoneroSendRequest> sendRequest = make_shared<MoneroSendRequest>();
// convert request property tree to monero_send_request
shared_ptr<monero_send_request> sendRequest = make_shared<monero_send_request>();
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
if (key == string("destinations")) {
@@ -422,7 +422,7 @@ shared_ptr<MoneroSendRequest> MoneroUtils::deserializeSendRequest(const string&
return sendRequest;
}
vector<shared_ptr<MoneroKeyImage>> MoneroUtils::deserializeKeyImages(const string& keyImagesJson) {
vector<shared_ptr<monero_key_image>> monero_utils::deserializeKeyImages(const string& keyImagesJson) {
// deserialize json to property node
std::istringstream iss = keyImagesJson.empty() ? std::istringstream() : std::istringstream(keyImagesJson);
@@ -430,7 +430,7 @@ vector<shared_ptr<MoneroKeyImage>> MoneroUtils::deserializeKeyImages(const strin
boost::property_tree::read_json(iss, node);
// convert property tree to key images
vector<shared_ptr<MoneroKeyImage>> keyImages;
vector<shared_ptr<monero_key_image>> keyImages;
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
if (key == string("keyImages")) {
@@ -443,14 +443,14 @@ vector<shared_ptr<MoneroKeyImage>> MoneroUtils::deserializeKeyImages(const strin
return keyImages;
}
string MoneroUtils::serialize(const boost::property_tree::ptree& node) {
string monero_utils::serialize(const boost::property_tree::ptree& node) {
std::stringstream ss;
boost::property_tree::write_json(ss, node, false);
string str = ss.str();
return str.substr(0, str.size() - 1); // strip newline
}
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<string>& strs) {
boost::property_tree::ptree monero_utils::to_property_tree(const vector<string>& strs) {
boost::property_tree::ptree strsNode;
for (const auto& str : strs) {
boost::property_tree::ptree strNode;
@@ -460,7 +460,7 @@ boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<string>& st
return strsNode;
}
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint8_t>& nums) {
boost::property_tree::ptree monero_utils::to_property_tree(const vector<uint8_t>& nums) {
boost::property_tree::ptree numsNode;
for (const auto& num : nums) {
boost::property_tree::ptree numNode;
@@ -471,7 +471,7 @@ boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint8_t>& n
}
// TODO: remove these redundant implementations for different sizes?
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint32_t>& nums) {
boost::property_tree::ptree monero_utils::to_property_tree(const vector<uint32_t>& nums) {
boost::property_tree::ptree numsNode;
for (const auto& num : nums) {
boost::property_tree::ptree numNode;
@@ -481,7 +481,7 @@ boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint32_t>&
return numsNode;
}
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint64_t>& nums) {
boost::property_tree::ptree monero_utils::to_property_tree(const vector<uint64_t>& nums) {
boost::property_tree::ptree numsNode;
for (const auto& num : nums) {
boost::property_tree::ptree numNode;
@@ -491,24 +491,24 @@ boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint64_t>&
return numsNode;
}
shared_ptr<MoneroBlock> MoneroUtils::cnBlockToBlock(const cryptonote::block& cnBlock) {
shared_ptr<monero_block> monero_utils::cnBlockToBlock(const cryptonote::block& cnBlock) {
cryptonote::block temp = cnBlock;
cout << cryptonote::obj_to_json_str(temp) << endl;
shared_ptr<MoneroBlock> block = make_shared<MoneroBlock>();
shared_ptr<monero_block> block = make_shared<monero_block>();
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 = MoneroUtils::cnTxToTx(cnBlock.miner_tx);
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));
}
return block;
}
shared_ptr<MoneroTx> MoneroUtils::cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet) {
shared_ptr<MoneroTx> tx = initAsTxWallet ? make_shared<MoneroTxWallet>() : make_shared<MoneroTx>();
shared_ptr<monero_tx> monero_utils::cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet) {
shared_ptr<monero_tx> tx = initAsTxWallet ? make_shared<monero_tx_wallet>() : make_shared<monero_tx>();
tx->version = cnTx.version;
tx->unlockTime = cnTx.unlock_time;
tx->id = epee::string_tools::pod_to_hex(cnTx.hash);
@@ -519,20 +519,20 @@ shared_ptr<MoneroTx> MoneroUtils::cnTxToTx(const cryptonote::transaction& cnTx,
if (cnVin.which() != 0 && cnVin.which() != 3) throw runtime_error("Unsupported variant type");
if (tx->isMinerTx == boost::none) tx->isMinerTx = 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<MoneroOutput> vin = initAsTxWallet ? make_shared<MoneroOutputWallet>() : make_shared<MoneroOutput>();
shared_ptr<monero_output> vin = initAsTxWallet ? make_shared<monero_output_wallet>() : make_shared<monero_output>();
vin->tx = tx;
tx->vins.push_back(vin);
const txin_to_key& txin = boost::get<txin_to_key>(cnVin);
vin->amount = txin.amount;
vin->ringOutputIndices = txin.key_offsets;
crypto::key_image cnKeyImage = txin.k_image;
vin->keyImage = make_shared<MoneroKeyImage>();
vin->keyImage = make_shared<monero_key_image>();
vin->keyImage.get()->hex = epee::string_tools::pod_to_hex(cnKeyImage);
}
// init vouts
for (const tx_out& cnVout : cnTx.vout) {
shared_ptr<MoneroOutput> vout = initAsTxWallet ? make_shared<MoneroOutputWallet>() : make_shared<MoneroOutput>();
shared_ptr<monero_output> vout = initAsTxWallet ? make_shared<monero_output_wallet>() : make_shared<monero_output>();
vout->tx = tx;
tx->vouts.push_back(vout);
vout->amount = cnVout.amount;
@@ -53,7 +53,7 @@
#ifndef MoneroUtils_h
#define MoneroUtils_h
#include "wallet/MoneroWallet.h"
#include "wallet/monero_wallet.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "serialization/keyvalue_serialization.h" // TODO: consolidate with other binary deps?
#include "storages/portable_storage.h"
@@ -61,7 +61,7 @@
/**
* Collection of utilities for working with Monero's binary portable storage format.
*/
namespace MoneroUtils
namespace monero_utils
{
using namespace std;
using namespace cryptonote;
@@ -72,15 +72,15 @@ namespace MoneroUtils
void binaryBlocksToJson(const std::string &bin, std::string &json);
shared_ptr<MoneroTxRequest> deserializeTxRequest(const string& txRequestStr);
shared_ptr<monero_tx_request> deserializeTxRequest(const string& txRequestStr);
shared_ptr<MoneroTransferRequest> deserializeTransferRequest(const string& transferRequestStr);
shared_ptr<monero_transfer_request> deserializeTransferRequest(const string& transferRequestStr);
shared_ptr<MoneroOutputRequest> deserializeOutputRequest(const string& outputRequestStr);
shared_ptr<monero_output_request> deserializeOutputRequest(const string& outputRequestStr);
shared_ptr<MoneroSendRequest> deserializeSendRequest(const string& sendRequestStr);
shared_ptr<monero_send_request> deserializeSendRequest(const string& sendRequestStr);
vector<shared_ptr<MoneroKeyImage>> deserializeKeyImages(const string& keyImagesJson);
vector<shared_ptr<monero_key_image>> deserializeKeyImages(const string& keyImagesJson);
string serialize(const boost::property_tree::ptree& node);
@@ -90,7 +90,7 @@ namespace MoneroUtils
* @param cnBlock is the Core block to convert
* @return a block in this library's native model
*/
shared_ptr<MoneroBlock> cnBlockToBlock(const cryptonote::block& cnBlock);
shared_ptr<monero_block> cnBlockToBlock(const cryptonote::block& cnBlock);
/**
@@ -98,9 +98,9 @@ namespace MoneroUtils
* native model.
*
* @param cnTx is the Core transaction to convert
* @param initAsTxWallet specifies if a MoneroTx xor MoneroTxWallet should be initialized
* @param initAsTxWallet specifies if a monero_tx xor monero_tx_wallet should be initialized
*/
shared_ptr<MoneroTx> cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet = false);
shared_ptr<monero_tx> cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet = false);
/**
* Modified from core_rpc_server.cpp to return a string.
@@ -118,28 +118,28 @@ namespace MoneroUtils
// ----------------------------- PROPERTY TREE ------------------------------
// TODO: template implementation here, could move to MoneroUtils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
template <class T> boost::property_tree::ptree toPropertyTree(const vector<shared_ptr<T>>& types) {
// TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
template <class T> boost::property_tree::ptree to_property_tree(const vector<shared_ptr<T>>& types) {
boost::property_tree::ptree typeNodes;
for (const auto& type : types) {
typeNodes.push_back(std::make_pair("", type->toPropertyTree()));
typeNodes.push_back(std::make_pair("", type->to_property_tree()));
}
return typeNodes;
}
// TODO: template implementation here, could move to MoneroUtils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
template <class T> boost::property_tree::ptree toPropertyTree(const vector<T>& types) {
// TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
template <class T> boost::property_tree::ptree to_property_tree(const vector<T>& types) {
boost::property_tree::ptree typeNodes;
for (const auto& type : types) {
typeNodes.push_back(std::make_pair("", type.toPropertyTree()));
typeNodes.push_back(std::make_pair("", type.to_property_tree()));
}
return typeNodes;
}
boost::property_tree::ptree toPropertyTree(const vector<string>& strs);
boost::property_tree::ptree toPropertyTree(const vector<uint8_t>& nums);
boost::property_tree::ptree toPropertyTree(const vector<uint32_t>& nums);
boost::property_tree::ptree toPropertyTree(const vector<uint64_t>& nums);
boost::property_tree::ptree to_property_tree(const vector<string>& strs);
boost::property_tree::ptree to_property_tree(const vector<uint8_t>& nums);
boost::property_tree::ptree to_property_tree(const vector<uint32_t>& nums);
boost::property_tree::ptree to_property_tree(const vector<uint64_t>& nums);
// ------------------------- VALUE RECONCILATION- ---------------------------
File diff suppressed because it is too large Load Diff
@@ -52,7 +52,7 @@
#pragma once
#include "MoneroWalletModel.h"
#include "monero_wallet_model.h"
#include "wallet/wallet2.h"
#include <boost/thread/mutex.hpp>
@@ -100,7 +100,7 @@ namespace monero {
/**
* Receives progress notifications as a wallet is synchronized.
*/
class MoneroSyncListener {
class monero_sync_listener {
public:
/**
@@ -112,13 +112,13 @@ namespace monero {
* @param percentDone is the sync progress as a percentage
* @param message is a human-readable description of the current progress
*/
virtual void onSyncProgress(uint64_t height, uint64_t startHeight, uint64_t endHeight, double percentDone, const string& message) {}
virtual void on_sync_progress(uint64_t height, uint64_t startHeight, uint64_t endHeight, double percentDone, const string& message) {}
};
/**
* Receives notifications as a wallet is updated.
*/
class MoneroWalletListener : public MoneroSyncListener {
class MoneroWalletListener : public monero_sync_listener {
public:
/**
@@ -126,21 +126,21 @@ namespace monero {
*
* @param block is the newly processed block
*/
virtual void onNewBlock(uint64_t height) {};
virtual void on_new_block(uint64_t height) {};
/**
* Invoked when the wallet receives an output.
*
* @param output is the incoming output to the wallet
*/
virtual void onOutputReceived(const MoneroOutputWallet& output) {};
virtual void on_output_received(const monero_output_wallet& output) {};
/**
* Invoked when the wallet spends an output.
*
* @param output the outgoing transfer from the wallet
*/
virtual void onOutputSpent(const MoneroOutputWallet& output) {};
virtual void on_output_spent(const monero_output_wallet& output) {};
};
// forward declaration of internal wallet2 listener
@@ -151,7 +151,7 @@ namespace monero {
/**
* Monero wallet interface.
*/
class MoneroWallet {
class monero_wallet {
public:
@@ -170,7 +170,7 @@ namespace monero {
* @param password is the password of the wallet file to open
* @param networkType is the wallet's network type
*/
static MoneroWallet* openWallet(const string& path, const string& password, const MoneroNetworkType networkType);
static monero_wallet* open_wallet(const string& path, const string& password, const MoneroNetworkType networkType);
/**
* Create a new wallet with a randomly generated seed.
@@ -181,8 +181,8 @@ namespace monero {
* @param daemonConnection is connection information to a daemon (default = an unconnected wallet)
* @param language is the wallet and mnemonic's language (default = "English")
*/
static MoneroWallet* createWalletRandom(const string& path, const string& password);
static MoneroWallet* createWalletRandom(const string& path, const string& password, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, const string& language);
static monero_wallet* create_wallet_random(const string& path, const string& password);
static monero_wallet* create_wallet_random(const string& path, const string& password, const MoneroNetworkType networkType, const monero_rpc_connection& daemonConnection, const string& language);
/**
* Create a wallet from an existing mnemonic phrase.
@@ -194,8 +194,8 @@ namespace monero {
* @param daemonConnection is connection information to a daemon (default = an unconnected wallet)
* @param restoreHeight is the block height to restore (i.e. scan the chain) from (default = 0)
*/
static MoneroWallet* createWalletFromMnemonic(const string& path, const string& password, const MoneroNetworkType networkType, const string& mnemonic);
static MoneroWallet* createWalletFromMnemonic(const string& path, const string& password, const MoneroNetworkType networkType, const string& mnemonic, const MoneroRpcConnection& daemonConnection, uint64_t restoreHeight);
static monero_wallet* create_wallet_from_mnemonic(const string& path, const string& password, const MoneroNetworkType networkType, const string& mnemonic);
static monero_wallet* create_wallet_from_mnemonic(const string& path, const string& password, const MoneroNetworkType networkType, const string& mnemonic, const monero_rpc_connection& daemonConnection, uint64_t restoreHeight);
/**
* Create a wallet from an address, view key, and spend key.
@@ -210,14 +210,14 @@ namespace monero {
* @param restoreHeight is the block height to restore (i.e. scan the chain) from (default = 0)
* @param language is the wallet and mnemonic's language (default = "English")
*/
static MoneroWallet* createWalletFromKeys(const string& path, const string& password, const MoneroNetworkType networkType, const string& address, const string& viewKey, const string& spendKey);
static MoneroWallet* createWalletFromKeys(const string& path, const string& password, const MoneroNetworkType networkType, const string& address, const string& viewKey, const string& spendKey, const MoneroRpcConnection& daemonConnection, uint64_t restoreHeight);
static MoneroWallet* createWalletFromKeys(const string& path, const string& password, const MoneroNetworkType networkType, const string& address, const string& viewKey, const string& spendKey, const MoneroRpcConnection& daemonConnection, uint64_t restoreHeight, const string& language);
static monero_wallet* create_wallet_from_keys(const string& path, const string& password, const MoneroNetworkType networkType, const string& address, const string& viewKey, const string& spendKey);
static monero_wallet* create_wallet_from_keys(const string& path, const string& password, const MoneroNetworkType networkType, const string& address, const string& viewKey, const string& spendKey, const monero_rpc_connection& daemonConnection, uint64_t restoreHeight);
static monero_wallet* create_wallet_from_keys(const string& path, const string& password, const MoneroNetworkType networkType, const string& address, const string& viewKey, const string& spendKey, const monero_rpc_connection& daemonConnection, uint64_t restoreHeight, const string& language);
/**
* Deconstruct the wallet.
*/
~MoneroWallet();
~monero_wallet();
/**
* Set the wallet's daemon connection.
@@ -226,133 +226,133 @@ namespace monero {
* @param username is the username to authenticate with the daemon (optional)
* @param password is the password to authenticate with the daemon (optional)
*/
void setDaemonConnection(const string& uri, const string& username = "", const string& password = "");
void set_daemon_connection(const string& uri, const string& username = "", const string& password = "");
/**
* Set the wallet's daemon connection.
*
* @param connection is the connection to set
*/
void setDaemonConnection(const MoneroRpcConnection& connection);
void set_daemon_connection(const monero_rpc_connection& connection);
/**
* Get the wallet's daemon connection.
*
* @return the wallet's daemon connection
*/
shared_ptr<MoneroRpcConnection> getDaemonConnection() const;
shared_ptr<monero_rpc_connection> get_daemon_connection() const;
/**
* Indicates if the wallet is connected a daemon.
*
* @return true if the wallet is connected to a daemon, false otherwise
*/
bool getIsConnected() const;
bool get_is_connected() const;
/**
* Get the height that the wallet's daemon is synced to.
*
* @return the height that the wallet's daemon is synced to
*/
uint64_t getDaemonHeight() const;
uint64_t get_daemon_height() const;
/**
* Get the height of the next block in the chain.
*
* @return the height of the next block in the chain
*/
uint64_t getDaemonTargetHeight() const;
uint64_t get_daemon_target_height() const;
/**
* Indicates if the wallet's daemon is synced with the network.
*
* @return true if the daemon is synced with the network, false otherwise
*/
bool getIsDaemonSynced() const;
bool get_is_daemon_synced() const;
/**
* Indicates if the wallet is synced with the daemon.
*
* @return true if the wallet is synced with the daemon, false otherwise
*/
bool getIsSynced() const;
bool get_is_synced() const;
/**
* Get the path of this wallet's file on disk.
*
* @return the path of this wallet's file on disk
*/
string getPath() const;
string get_path() const;
/**
* Get the wallet's network type (mainnet, testnet, or stagenet).
*
* @return the wallet's network type
*/
MoneroNetworkType getNetworkType() const;
MoneroNetworkType get_network_type() const;
/**
* Get the wallet's seed.
*
* @return the wallet's seed
*/
string getSeed() const;
string get_seed() const;
/**
* Get the wallet's mnemonic phrase derived from the seed.
*
* @param mnemonic is assigned the wallet's mnemonic phrase
*/
string getMnemonic() const;
string get_mnemonic() const;
/**
* Get the language of the wallet's mnemonic phrase.
*
* @return the language of the wallet's mnemonic phrase
*/
string getLanguage() const;
string get_language() const;
/**
* Get a list of available languages for the wallet's mnemonic phrase.
*
* @return the available languages for the wallet's mnemonic phrase
*/
vector<string> getLanguages() const;
vector<string> get_languages() const;
/**
* Get the wallet's public view key.
*
* @return the wallet's public view key
*/
string getPublicViewKey() const;
string get_public_view_key() const;
/**
* Get the wallet's private view key.
*
* @return the wallet's private view key
*/
string getPrivateViewKey() const;
string get_private_view_key() const;
/**
* Get the wallet's public spend key.
*
* @return the wallet's public spend key
*/
string getPublicSpendKey() const;
string get_public_spend_key() const;
/**
* Get the wallet's private spend key.
*
* @return the wallet's private spend key
*/
string getPrivateSpendKey() const;
string get_private_spend_key() const;
/**
* Get the wallet's primary address.
*
* @return the wallet's primary address
*/
string getPrimaryAddress() const;
string get_primary_address() const;
/**
* Get the address of a specific subaddress.
@@ -361,7 +361,7 @@ namespace monero {
* @param subaddressIdx specifies the subaddress index within the account
* @return the receive address of the specified subaddress
*/
string getAddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const;
string get_address(const uint32_t accountIdx, const uint32_t subaddressIdx) const;
/**
* Get the account and subaddress index of the given address.
@@ -370,7 +370,7 @@ namespace monero {
* @return the account and subaddress indices
* @throws exception if address is not a wallet address
*/
MoneroSubaddress getAddressIndex(const string& address) const;
monero_subaddress get_address_index(const string& address) const;
/**
* Get an integrated address from a standard address and a payment id.
@@ -379,7 +379,7 @@ namespace monero {
* @param paymentId is the integrated addresse's payment id (defaults to randomly generating new payment id)
* @return the integrated address
*/
MoneroIntegratedAddress getIntegratedAddress(const string& standardAddress = "", const string& paymentId = "") const;
monero_integrated_address get_integrated_address(const string& standardAddress = "", const string& paymentId = "") const;
/**
* Decode an integrated address to get its standard address and payment id.
@@ -387,21 +387,21 @@ namespace monero {
* @param integratedAddress is an integrated address to decode
* @return the decoded integrated address including standard address and payment id
*/
MoneroIntegratedAddress decodeIntegratedAddress(const string& integratedAddress) const;
monero_integrated_address decode_integrated_address(const string& integratedAddress) const;
/**
* Set the wallet's listener to receive wallet notifications.
*
* @param listener is the listener to receive wallet notifications
*/
void setListener(boost::optional<MoneroWalletListener&> listener);
void set_listener(boost::optional<MoneroWalletListener&> listener);
/**
* Synchronize the wallet with the daemon as a one-time synchronous process.
*
* @return the sync result
*/
MoneroSyncResult sync();
monero_sync_result sync();
/**
* Synchronize the wallet with the daemon as a one-time synchronous process.
@@ -409,7 +409,7 @@ namespace monero {
* @param listener is invoked as sync progress is made
* @return the sync result
*/
MoneroSyncResult sync(MoneroSyncListener& listener);
monero_sync_result sync(monero_sync_listener& listener);
/**
* Synchronize the wallet with the daemon as a one-time synchronous process.
@@ -417,7 +417,7 @@ namespace monero {
* @param startHeight is the start height to sync from (ignored if less than last processed block)
* @return the sync result
*/
MoneroSyncResult sync(uint64_t startHeight);
monero_sync_result sync(uint64_t startHeight);
/**
* Synchronizes the wallet with the blockchain.
@@ -426,17 +426,17 @@ namespace monero {
* @param listener is invoked as sync progress is made
* @return the sync result
*/
MoneroSyncResult sync(uint64_t startHeight, MoneroSyncListener& listener);
monero_sync_result sync(uint64_t startHeight, monero_sync_listener& listener);
/**
* Start an asynchronous thread to continuously synchronize the wallet with the daemon.
*/
void startSyncing();
void start_syncing();
/**
* Stop the asynchronous thread to continuously synchronize the wallet with the daemon.
*/
void stopSyncing();
void stop_syncing();
/**
* Rescan the blockchain from scratch, losing any information which cannot be recovered from
@@ -445,14 +445,14 @@ namespace monero {
* WARNING: This method discards local wallet data like destination addresses, tx secret keys,
* tx notes, etc.
*/
void rescanBlockchain();
void rescan_blockchain();
/**
* Get the height of the last block processed by the wallet (its index + 1).
*
* @return the height of the last block processed by the wallet
*/
uint64_t getHeight() const;
uint64_t get_height() const;
/**
* Get the blockchain's height.
@@ -466,14 +466,14 @@ namespace monero {
*
* @return the height of the first block that the wallet scans
*/
uint64_t getRestoreHeight() const;
uint64_t get_restore_height() const;
/**
* Set the height of the first block that the wallet scans.
*
* @param restoreHeight is the height of the first block that the wallet scans
*/
void setRestoreHeight(uint64_t restoreHeight);
void set_restore_height(uint64_t restoreHeight);
// /**
// * Indicates if importing multisig data is needed for returning a correct balance.
@@ -487,7 +487,7 @@ namespace monero {
*
* @return the wallet's balance
*/
uint64_t getBalance() const;
uint64_t get_balance() const;
/**
* Get an account's balance.
@@ -495,7 +495,7 @@ namespace monero {
* @param accountIdx is the index of the account to get the balance of
* @return the account's balance
*/
uint64_t getBalance(uint32_t accountIdx) const;
uint64_t get_balance(uint32_t accountIdx) const;
/**
* Get a subaddress's balance.
@@ -504,14 +504,14 @@ namespace monero {
* @param subaddressIdx is the index of the subaddress to get the balance of
* @return the subaddress's balance
*/
uint64_t getBalance(uint32_t accountIdx, uint32_t subaddressIdx) const;
uint64_t get_balance(uint32_t accountIdx, uint32_t subaddressIdx) const;
/**
* Get the wallet's unlocked balance.
*
* @return the wallet's unlocked balance
*/
uint64_t getUnlockedBalance() const;
uint64_t get_unlocked_balance() const;
/**
* Get an account's unlocked balance.
@@ -519,7 +519,7 @@ namespace monero {
* @param accountIdx is the index of the account to get the unlocked balance of
* @return the account's unlocked balance
*/
uint64_t getUnlockedBalance(uint32_t accountIdx) const;
uint64_t get_unlocked_balance(uint32_t accountIdx) const;
/**
* Get a subaddress's unlocked balance.
@@ -528,39 +528,39 @@ namespace monero {
* @param subaddressIdx is the index of the subaddress to get the unlocked balance of
* @return the subaddress's balance
*/
uint64_t getUnlockedBalance(uint32_t accountIdx, uint32_t subaddressIdx) const;
uint64_t get_unlocked_balance(uint32_t accountIdx, uint32_t subaddressIdx) const;
/**
* Get all accounts.
*
* @return List<MoneroAccount> are all accounts within the wallet
* @return List<monero_account> are all accounts within the wallet
*/
vector<MoneroAccount> getAccounts() const;
vector<monero_account> get_accounts() const;
/**
* Get all accounts.
*
* @param includeSubaddresses specifies if subaddresses should be included
* @return List<MoneroAccount> are all accounts
* @return List<monero_account> are all accounts
*/
vector<MoneroAccount> getAccounts(bool includeSubaddresses) const;
vector<monero_account> get_accounts(bool includeSubaddresses) const;
/**
* Get accounts with a given tag.
*
* @param tag is the tag for filtering accounts, all accounts if null
* @return List<MoneroAccount> are all accounts for the wallet with the given tag
* @return List<monero_account> are all accounts for the wallet with the given tag
*/
vector<MoneroAccount> getAccounts(const string& tag) const;
vector<monero_account> get_accounts(const string& tag) const;
/**
* Get accounts with a given tag.
*
* @param includeSubaddresses specifies if subaddresses should be included
* @param tag is the tag for filtering accounts, all accounts if null
* @return List<MoneroAccount> are all accounts for the wallet with the given tag
* @return List<monero_account> are all accounts for the wallet with the given tag
*/
vector<MoneroAccount> getAccounts(bool includeSubaddresses, const string& tag) const;
vector<monero_account> get_accounts(bool includeSubaddresses, const string& tag) const;
/**
* Get an account without subaddress information.
@@ -568,7 +568,7 @@ namespace monero {
* @param accountIdx specifies the account to get
* @return the retrieved account
*/
MoneroAccount getAccount(uint32_t accountIdx) const;
monero_account get_account(uint32_t accountIdx) const;
/**
* Get an account.
@@ -577,7 +577,7 @@ namespace monero {
* @param includeSubaddresses specifies if subaddresses should be included
* @return the retrieved account
*/
MoneroAccount getAccount(const uint32_t accountIdx, bool includeSubaddresses) const;
monero_account get_account(const uint32_t accountIdx, bool includeSubaddresses) const;
/**
* Create a new account with a label for the first subaddress.
@@ -585,15 +585,15 @@ namespace monero {
* @param label specifies the label for the account's first subaddress (optional)
* @return the created account
*/
MoneroAccount createAccount(const string& label = "");
monero_account create_account(const string& label = "");
/**
* Get all subaddresses in an account.
*
* @param accountIdx specifies the account to get subaddresses within
* @return List<MoneroSubaddress> are the retrieved subaddresses
* @return List<monero_subaddress> are the retrieved subaddresses
*/
vector<MoneroSubaddress> getSubaddresses(const uint32_t accountIdx) const;
vector<monero_subaddress> get_subaddresses(const uint32_t accountIdx) const;
/**
* Get subaddresses in an account.
@@ -602,7 +602,7 @@ namespace monero {
* @param subaddressIndices are specific subaddresses to get (optional)
* @return the retrieved subaddresses
*/
vector<MoneroSubaddress> getSubaddresses(const uint32_t accountIdx, const vector<uint32_t>& subaddressIndices) const;
vector<monero_subaddress> get_subaddresses(const uint32_t accountIdx, const vector<uint32_t>& subaddressIndices) const;
/**
* Get a subaddress.
@@ -611,7 +611,7 @@ namespace monero {
* @param subaddressIdx specifies index of the subaddress within the account
* @return the retrieved subaddress
*/
MoneroSubaddress getSubaddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const;
monero_subaddress getSubaddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const;
/**
* Create a subaddress within an account.
@@ -620,15 +620,15 @@ namespace monero {
* @param label specifies the the label for the subaddress (defaults to empty string)
* @return the created subaddress
*/
MoneroSubaddress createSubaddress(uint32_t accountIdx, const string& label = "");
monero_subaddress create_subaddress(uint32_t accountIdx, const string& label = "");
// /**
// * Get a wallet transaction by id.
// *
// * @param txId is an id of a transaction to get
// * @return MoneroTxWallet is the identified transactions
// * @return monero_tx_wallet is the identified transactions
// */
// public MoneroTxWallet getTx(string txId);
// public monero_tx_wallet getTx(string txId);
/**
* Get all wallet transactions. Wallet transactions contain one or more
@@ -636,7 +636,7 @@ namespace monero {
*
* @return all wallet transactions
*/
vector<shared_ptr<MoneroTxWallet>> getTxs() const;
vector<shared_ptr<monero_tx_wallet>> get_txs() const;
// /**
// * Get wallet transactions by id.
@@ -644,7 +644,7 @@ namespace monero {
// * @param txIds are ids of transactions to get
// * @return the identified transactions
// */
// public List<MoneroTxWallet> getTxs(Collection<string> txIds);
// public List<monero_tx_wallet> get_txs(Collection<string> txIds);
/**
* Get wallet transactions. Wallet transactions contain one or more
@@ -658,7 +658,7 @@ namespace monero {
* @param request filters query results (optional)
* @return wallet transactions per the request
*/
vector<shared_ptr<MoneroTxWallet>> getTxs(const MoneroTxRequest& request) const;
vector<shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_request& request) const;
// /**
// * Get all incoming and outgoing transfers to and from this wallet. An
@@ -670,7 +670,7 @@ namespace monero {
// *
// * @return all wallet transfers
// */
// public List<MoneroTransfer> getTransfers();
// public List<monero_transfer> get_transfers();
//
// /**
// * Get incoming and outgoing transfers to and from an account. An outgoing
@@ -683,7 +683,7 @@ namespace monero {
// * @param accountIdx is the index of the account to get transfers from
// * @return transfers to/from the account
// */
// public List<MoneroTransfer> getTransfers(int accountIdx);
// public List<monero_transfer> get_transfers(int accountIdx);
//
// /**
// * Get incoming and outgoing transfers to and from a subaddress. An outgoing
@@ -697,7 +697,7 @@ namespace monero {
// * @param subaddressIdx is the index of the subaddress to get transfers from
// * @return transfers to/from the subaddress
// */
// public List<MoneroTransfer> getTransfers(int accountIdx, int subaddressIdx);
// public List<monero_transfer> get_transfers(int accountIdx, int subaddressIdx);
/**
* Get incoming and outgoing transfers to and from this wallet. An outgoing
@@ -707,7 +707,7 @@ namespace monero {
* a subaddress within an account. Transfers belong to transactions which
* are stored on the blockchain.
*
* Query results can be filtered by passing in a MoneroTransferRequest.
* Query results can be filtered by passing in a monero_transfer_request.
* Transfers must meet every criteria defined in the request in order to be
* returned. All filtering is optional and no filtering is applied when not
* defined.
@@ -715,37 +715,37 @@ namespace monero {
* @param request filters query results (optional)
* @return wallet transfers per the request
*/
vector<shared_ptr<MoneroTransfer>> getTransfers(const MoneroTransferRequest& request) const;
vector<shared_ptr<monero_transfer>> get_transfers(const monero_transfer_request& request) const;
// /**
// * Get outputs created from previous transactions that belong to the wallet
// * (i.e. that the wallet can spend one time). Outputs are part of
// * transactions which are stored in blocks on the blockchain.
// *
// * @return List<MoneroOutputWallet> are all wallet outputs
// * @return List<monero_output_wallet> are all wallet outputs
// */
// public List<MoneroOutputWallet> getOutputs();
// public List<monero_output_wallet> get_outputs();
/**
* Get outputs created from previous transactions that belong to the wallet
* (i.e. that the wallet can spend one time). Outputs are part of
* transactions which are stored in blocks on the blockchain.
*
* Results can be configured by passing a MoneroOutputRequest. Outputs must
* Results can be configured by passing a monero_output_request. Outputs must
* meet every criteria defined in the request in order to be returned. All
* filtering is optional and no filtering is applied when not defined.
*
* @param request specifies request options (optional)
* @return List<MoneroOutputWallet> are wallet outputs per the request
* @return List<monero_output_wallet> are wallet outputs per the request
*/
vector<shared_ptr<MoneroOutputWallet>> getOutputs(const MoneroOutputRequest& request) const;
vector<shared_ptr<monero_output_wallet>> get_outputs(const monero_output_request& request) const;
/**
* Export all outputs in hex format.
*
* @return all outputs in hex format, empty string if no outputs
*/
string getOutputsHex() const;
string get_outputs_hex() const;
/**
* Import outputs in hex format.
@@ -753,14 +753,14 @@ namespace monero {
* @param outputsHex are outputs in hex format
* @return the number of outputs imported
*/
int importOutputsHex(const string& outputsHex);
int import_outputs_hex(const string& outputsHex);
/**
* Get all signed key images.
*
* @return the wallet's signed key images
*/
vector<shared_ptr<MoneroKeyImage>> getKeyImages() const;
vector<shared_ptr<monero_key_image>> get_key_images() const;
/**
* Import signed key images and verify their spent status.
@@ -768,14 +768,14 @@ namespace monero {
* @param keyImages are key images to import and verify (requires hex and signature)
* @return results of the import
*/
shared_ptr<MoneroKeyImageImportResult> importKeyImages(const vector<shared_ptr<MoneroKeyImage>>& keyImages);
shared_ptr<monero_key_image_import_result> import_key_images(const vector<shared_ptr<monero_key_image>>& keyImages);
// /**
// * Get new key images from the last imported outputs.
// *
// * @return the key images from the last imported outputs
// */
// public List<MoneroKeyImage> getNewKeyImagesFromLastImport();
// public List<monero_key_image> getNewKeyImagesFromLastImport();
/**
* Create one or more transactions which transfer funds from this wallet to
@@ -784,7 +784,7 @@ namespace monero {
* @param request configures the transaction
* @return the resulting transaction
*/
vector<shared_ptr<MoneroTxWallet>> sendSplit(const MoneroSendRequest& request);
vector<shared_ptr<monero_tx_wallet>> send_split(const monero_send_request& request);
//
// /**
@@ -796,7 +796,7 @@ namespace monero {
// * @param sendAmount is the amount being sent
// * @return the resulting transaction
// */
// public MoneroTxWallet send(int accountIndex, string address, BigInteger sendAmount);
// public monero_tx_wallet send(int accountIndex, string address, BigInteger sendAmount);
//
// /**
// * Create and relay a transaction which transfers funds from this wallet to
@@ -808,7 +808,7 @@ namespace monero {
// * @param priority is the send priority (default normal)
// * @return the resulting transaction
// */
// public MoneroTxWallet send(int accountIndex, string address, BigInteger sendAmount, MoneroSendPriority priority);
// public monero_tx_wallet send(int accountIndex, string address, BigInteger sendAmount, monero_send_priority priority);
//
// /**
// * Create and relay (depending on configuration) one or more transactions
@@ -817,7 +817,7 @@ namespace monero {
// * @param request configures the transactions
// * @return the resulting transactions
// */
// public List<MoneroTxWallet> sendSplit(MoneroSendRequest request);
// public List<monero_tx_wallet> send_split(monero_send_request request);
//
// /**
// * Create and relay one or more transactions which transfer funds from this
@@ -828,7 +828,7 @@ namespace monero {
// * @param sendAmount is the amount being sent
// * @return the resulting transactions
// */
// public List<MoneroTxWallet> sendSplit(int accountIndex, string address, BigInteger sendAmount);
// public List<monero_tx_wallet> send_split(int accountIndex, string address, BigInteger sendAmount);
//
// /**
// * Create and relay one or more transactions which transfer funds from this
@@ -840,7 +840,7 @@ namespace monero {
// * @param priority is the send priority (default normal)
// * @return the resulting transactions
// */
// public List<MoneroTxWallet> sendSplit(int accountIndex, string address, BigInteger sendAmount, MoneroSendPriority priority);
// public List<monero_tx_wallet> send_split(int accountIndex, string address, BigInteger sendAmount, monero_send_priority priority);
/**
* Sweep an output with a given key image.
@@ -848,7 +848,7 @@ namespace monero {
* @param request configures the sweep transaction
* @return the resulting transaction from sweeping an output
*/
shared_ptr<MoneroTxWallet> sweepOutput(const MoneroSendRequest& request) const;
shared_ptr<monero_tx_wallet> sweep_output(const monero_send_request& request) const;
// /**
// * Sweep an output with a given key image.
@@ -857,7 +857,7 @@ namespace monero {
// * @param keyImage is the key image hex of the output to sweep
// * @return the resulting transaction from sweeping an output
// */
// public MoneroTxWallet sweepOutput(string address, string keyImage);
// public monero_tx_wallet sweep_output(string address, string keyImage);
//
// /**
// * Sweep an output with a given key image.
@@ -867,7 +867,7 @@ namespace monero {
// * @param priority is the transaction priority (optional)
// * @return the resulting transaction from sweeping an output
// */
// public MoneroTxWallet sweepOutput(string address, string keyImage, MoneroSendPriority priority);
// public monero_tx_wallet sweep_output(string address, string keyImage, monero_send_priority priority);
//
// /**
// * Sweep a subaddress's unlocked funds to an address.
@@ -877,7 +877,7 @@ namespace monero {
// * @param address is the address to sweep the subaddress's funds to
// * @return the resulting transactions
// */
// public List<MoneroTxWallet> sweepSubaddress(int accountIdx, int subaddressIdx, string address);
// public List<monero_tx_wallet> sweepSubaddress(int accountIdx, int subaddressIdx, string address);
//
// /**
// * Sweep an acount's unlocked funds to an address.
@@ -886,7 +886,7 @@ namespace monero {
// * @param address is the address to sweep the account's funds to
// * @return the resulting transactions
// */
// public List<MoneroTxWallet> sweepAccount(int accountIdx, string address);
// public List<monero_tx_wallet> sweepAccount(int accountIdx, string address);
//
// /**
// * Sweep the wallet's unlocked funds to an address.
@@ -894,7 +894,7 @@ namespace monero {
// * @param address is the address to sweep the wallet's funds to
// * @return the resulting transactions
// */
// public List<MoneroTxWallet> sweepWallet(string address);
// public List<monero_tx_wallet> sweepWallet(string address);
//
// /**
// * Sweep all unlocked funds according to the given request.
@@ -902,7 +902,7 @@ namespace monero {
// * @param request is the sweep configuration
// * @return the resulting transactions
// */
// public List<MoneroTxWallet> sweepAllUnlocked(MoneroSendRequest request);
// public List<monero_tx_wallet> sweepAllUnlocked(monero_send_request request);
//
// /**
// * Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix.
@@ -911,7 +911,7 @@ namespace monero {
// *
// * @return the resulting transactions from sweeping dust
// */
// public List<MoneroTxWallet> sweepDust();
// public List<monero_tx_wallet> sweep_dust();
/**
* Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix.
@@ -919,7 +919,7 @@ namespace monero {
* @param doNotRelay specifies if the resulting transaction should not be relayed (defaults to false i.e. relayed)
* @return the resulting transactions from sweeping dust
*/
vector<shared_ptr<MoneroTxWallet>> sweepDust(bool doNotRelay = false);
vector<shared_ptr<monero_tx_wallet>> sweep_dust(bool doNotRelay = false);
//
// /**
// * Relay a transaction previously created without relaying.
@@ -935,7 +935,7 @@ namespace monero {
* @param txMetadatas are transaction metadata previously created without relaying
* @return the ids of the relayed txs
*/
vector<string> relayTxs(const vector<string>& txMetadatas);
vector<string> relay_txs(const vector<string>& txMetadatas);
/**
* Get a transaction note.
@@ -943,7 +943,7 @@ namespace monero {
* @param txId specifies the transaction to get the note of
* @return the tx note
*/
string getTxNote(const string& txId) const;
string get_tx_note(const string& txId) const;
/**
* Get notes for multiple transactions.
@@ -951,7 +951,7 @@ namespace monero {
* @param txIds identify the transactions to get notes for
* @preturns notes for the transactions
*/
vector<string> getTxNotes(const vector<string>& txIds) const;
vector<string> get_tx_notes(const vector<string>& txIds) const;
/**
* Set a note for a specific transaction.
@@ -959,7 +959,7 @@ namespace monero {
* @param txId specifies the transaction
* @param note specifies the note
*/
void setTxNote(const string& txId, const string& note);
void set_tx_note(const string& txId, const string& note);
/**
* Set notes for multiple transactions.
@@ -967,7 +967,7 @@ namespace monero {
* @param txIds specify the transactions to set notes for
* @param notes are the notes to set for the transactions
*/
void setTxNotes(const vector<string>& txIds, const vector<string>& notes);
void set_tx_notes(const vector<string>& txIds, const vector<string>& notes);
/**
* Sign a message.
@@ -993,7 +993,7 @@ namespace monero {
* @param txId is the transaction's id
* @return is the transaction's secret key
*/
string getTxKey(const string& txId) const;
string get_tx_key(const string& txId) const;
/**
* Check a transaction in the blockchain with its secret key.
@@ -1003,7 +1003,7 @@ namespace monero {
* @param address is the destination public address of the transaction
* @return the result of the check
*/
shared_ptr<MoneroCheckTx> checkTxKey(const string& txId, const string& txKey, const string& address) const;
shared_ptr<monero_check_tx> check_tx_key(const string& txId, const string& txKey, const string& address) const;
// /**
// * Get a transaction signature to prove it.
@@ -1012,7 +1012,7 @@ namespace monero {
// * @param address is the destination public address of the transaction
// * @return the transaction signature
// */
// string getTxProof(const string& txId, const string& address) const;
// string get_tx_proof(const string& txId, const string& address) const;
/**
* Get a transaction signature to prove it.
@@ -1022,7 +1022,7 @@ namespace monero {
* @param message is a message to include with the signature to further authenticate the proof (optional)
* @return the transaction signature
*/
string getTxProof(const string& txId, const string& address, const string& message) const;
string get_tx_proof(const string& txId, const string& address, const string& message) const;
/**
* Prove a transaction by checking its signature.
@@ -1033,7 +1033,7 @@ namespace monero {
* @param signature is the transaction signature to confirm
* @return the result of the check
*/
shared_ptr<MoneroCheckTx> checkTxProof(const string& txId, const string& address, const string& message, const string& signature) const;
shared_ptr<monero_check_tx> check_tx_proof(const string& txId, const string& address, const string& message, const string& signature) const;
// /**
// * Generate a signature to prove a spend. Unlike proving a transaction, it does not require the destination public address.
@@ -1041,7 +1041,7 @@ namespace monero {
// * @param txId specifies the transaction to prove
// * @return the transaction signature
// */
// string getSpendProof(const string& txId) const;
// string get_spend_proof(const string& txId) const;
/**
* Generate a signature to prove a spend. Unlike proving a transaction, it does not require the destination public address.
@@ -1050,7 +1050,7 @@ namespace monero {
* @param message is a message to include with the signature to further authenticate the proof (optional)
* @return the transaction signature
*/
string getSpendProof(const string& txId, const string& message) const;
string get_spend_proof(const string& txId, const string& message) const;
/**
* Prove a spend using a signature. Unlike proving a transaction, it does not require the destination public address.
@@ -1060,7 +1060,7 @@ namespace monero {
* @param signature is the transaction signature to confirm
* @return true if the signature is good, false otherwise
*/
bool checkSpendProof(const string& txId, const string& message, const string& signature) const;
bool check_spend_proof(const string& txId, const string& message, const string& signature) const;
/**
* Generate a signature to prove the entire balance of the wallet.
@@ -1068,7 +1068,7 @@ namespace monero {
* @param message is a message included with the signature to further authenticate the proof (optional)
* @return the reserve proof signature
*/
string getReserveProofWallet(const string& message) const;
string get_reserve_proof_wallet(const string& message) const;
/**
* Generate a signature to prove an available amount in an account.
@@ -1078,7 +1078,7 @@ namespace monero {
* @param message is a message to include with the signature to further authenticate the proof (optional)
* @return the reserve proof signature
*/
string getReserveProofAccount(uint32_t accountIdx, uint64_t amount, const string& message) const;
string get_reserve_proof_account(uint32_t accountIdx, uint64_t amount, const string& message) const;
/**
* Proves a wallet has a disposable reserve using a signature.
@@ -1088,7 +1088,7 @@ namespace monero {
* @param signature is the reserve proof signature to check
* @return the result of checking the signature proof
*/
shared_ptr<MoneroCheckReserve> checkReserveProof(const string& address, const string& message, const string& signature) const;
shared_ptr<monero_check_reserve> check_reserve_proof(const string& address, const string& message, const string& signature) const;
// /**
// * Get all address book entries.
@@ -1167,7 +1167,7 @@ namespace monero {
* @param request specifies configuration for a potential tx
* @return is the payment uri
*/
string createPaymentUri(const MoneroSendRequest& request) const;
string create_payment_uri(const monero_send_request& request) const;
/**
* Parses a payment URI to a send request.
@@ -1175,7 +1175,7 @@ namespace monero {
* @param uri is the payment uri to parse
* @return the send request parsed from the uri
*/
shared_ptr<MoneroSendRequest> parsePaymentUri(const string& uri) const;
shared_ptr<monero_send_request> parse_payment_uri(const string& uri) const;
/**
* Set an arbitrary attribute.
@@ -1183,7 +1183,7 @@ namespace monero {
* @param key is the attribute key
* @param val is the attribute value
*/
void setAttribute(const string& key, const string& val);
void set_attribute(const string& key, const string& val);
/**
* Get an attribute.
@@ -1191,7 +1191,7 @@ namespace monero {
* @param key is the attribute to get the value of
* @return the attribute's value
*/
string getAttribute(const string& key) const;
string get_attribute(const string& key) const;
/**
* Start mining.
@@ -1200,12 +1200,12 @@ namespace monero {
* @param backgroundMining specifies if mining should occur in the background (optional)
* @param ignoreBattery specifies if the battery should be ignored for mining (optional)
*/
void startMining(boost::optional<uint64_t> numThreads, boost::optional<bool> backgroundMining, boost::optional<bool> ignoreBattery);
void start_mining(boost::optional<uint64_t> numThreads, boost::optional<bool> backgroundMining, boost::optional<bool> ignoreBattery);
/**
* Stop mining.
*/
void stopMining();
void stop_mining();
/**
* Save the wallet at its current path.
@@ -1218,7 +1218,7 @@ namespace monero {
* @param path is the new wallet's path
* @param password is the new wallet's password
*/
void moveTo(string path, string password);
void move_to(string path, string password);
/**
* Close the wallet.
@@ -1234,7 +1234,7 @@ namespace monero {
boost::optional<MoneroWalletListener&> listener = boost::none; // wallet's external listener
void initCommon();
vector<MoneroSubaddress> getSubaddressesAux(uint32_t accountIdx, const vector<uint32_t>& subaddressIndices, const vector<tools::wallet2::transfer_details>& transfers) const;
vector<monero_subaddress> getSubaddressesAux(uint32_t accountIdx, const vector<uint32_t>& subaddressIndices, const vector<tools::wallet2::transfer_details>& transfers) const;
// blockchain sync management
mutable std::atomic<bool> isSynced; // whether or not wallet is synced
@@ -1248,7 +1248,7 @@ namespace monero {
boost::mutex syncingMutex; // synchronize auto sync loop
std::atomic<bool> syncingThreadDone; // whether or not the syncing thread is shut down
void syncingThreadFunc(); // function to run thread with syncing loop
MoneroSyncResult lockAndSync(boost::optional<uint64_t> startHeight = boost::none, boost::optional<MoneroSyncListener&> listener = boost::none); // internal function to synchronize request to sync and rescan
MoneroSyncResult syncAux(boost::optional<uint64_t> startHeight = boost::none, boost::optional<MoneroSyncListener&> listener = boost::none); // internal function to immediately block, sync, and report progress
monero_sync_result lockAndSync(boost::optional<uint64_t> startHeight = boost::none, boost::optional<monero_sync_listener&> listener = boost::none); // internal function to synchronize request to sync and rescan
monero_sync_result syncAux(boost::optional<uint64_t> startHeight = boost::none, boost::optional<monero_sync_listener&> listener = boost::none); // internal function to immediately block, sync, and report progress
};
}
@@ -50,9 +50,9 @@
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/
#include "MoneroWallet.h"
#include "monero_wallet.h"
#include "utils/MoneroUtils.h"
#include "utils/monero_utils.h"
#include <stdio.h>
#include <iostream>
@@ -65,8 +65,8 @@ namespace monero {
// ----------------------- UNDECLARED PRIVATE HELPERS -----------------------
void mergeIncomingTransfer(vector<shared_ptr<MoneroIncomingTransfer>>& transfers, const shared_ptr<MoneroIncomingTransfer>& transfer) {
for (const shared_ptr<MoneroIncomingTransfer>& aTransfer : transfers) {
void mergeIncomingTransfer(vector<shared_ptr<monero_incoming_transfer>>& transfers, const shared_ptr<monero_incoming_transfer>& transfer) {
for (const shared_ptr<monero_incoming_transfer>& aTransfer : transfers) {
if (aTransfer->accountIndex.get() == transfer->accountIndex.get() && aTransfer->subaddressIndex.get() == transfer->subaddressIndex.get()) {
aTransfer->merge(aTransfer, transfer);
return;
@@ -77,19 +77,19 @@ namespace monero {
// ---------------------------- MONERO ACCOUNT ------------------------------
boost::property_tree::ptree MoneroAccount::toPropertyTree() const {
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 (balance != boost::none) node.put("balance", *balance);
if (unlockedBalance != boost::none) node.put("unlockedBalance", *unlockedBalance);
if (!subaddresses.empty()) node.add_child("subaddresses", MoneroUtils::toPropertyTree(subaddresses));
if (!subaddresses.empty()) node.add_child("subaddresses", monero_utils::to_property_tree(subaddresses));
return node;
}
// -------------------------- MONERO SUBADDRESS -----------------------------
boost::property_tree::ptree MoneroSubaddress::toPropertyTree() const {
boost::property_tree::ptree monero_subaddress::to_property_tree() const {
boost::property_tree::ptree node;
if (accountIndex != boost::none) node.put("accountIndex", *accountIndex);
if (index != boost::none) node.put("index", *index);
@@ -105,29 +105,29 @@ namespace monero {
// --------------------------- MONERO TX WALLET -----------------------------
shared_ptr<MoneroTxWallet> MoneroTxWallet::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const {
MTRACE("MoneroTxWallet::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt)");
return MoneroTxWallet::copy(static_pointer_cast<MoneroTxWallet>(src), static_pointer_cast<MoneroTxWallet>(tgt));
shared_ptr<monero_tx_wallet> monero_tx_wallet::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const {
MTRACE("monero_tx_wallet::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt)");
return monero_tx_wallet::copy(static_pointer_cast<monero_tx_wallet>(src), static_pointer_cast<monero_tx_wallet>(tgt));
};
shared_ptr<MoneroTxWallet> MoneroTxWallet::copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt) const {
MTRACE("MoneroTxWallet::copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt)");
shared_ptr<monero_tx_wallet> monero_tx_wallet::copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt) const {
MTRACE("monero_tx_wallet::copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
// copy base class
MoneroTx::copy(static_pointer_cast<MoneroTx>(src), static_pointer_cast<MoneroTx>(tgt));
monero_tx::copy(static_pointer_cast<monero_tx>(src), static_pointer_cast<monero_tx>(tgt));
// copy wallet extensions
if (!src->incomingTransfers.empty()) {
tgt->incomingTransfers = vector<shared_ptr<MoneroIncomingTransfer>>();
for (const shared_ptr<MoneroIncomingTransfer>& transfer : src->incomingTransfers) {
shared_ptr<MoneroIncomingTransfer> transferCopy = transfer->copy(transfer, make_shared<MoneroIncomingTransfer>());
tgt->incomingTransfers = vector<shared_ptr<monero_incoming_transfer>>();
for (const shared_ptr<monero_incoming_transfer>& transfer : src->incomingTransfers) {
shared_ptr<monero_incoming_transfer> transferCopy = transfer->copy(transfer, make_shared<monero_incoming_transfer>());
transferCopy->tx = tgt;
tgt->incomingTransfers.push_back(transferCopy);
}
}
if (src->outgoingTransfer != boost::none) {
shared_ptr<MoneroOutgoingTransfer> transferCopy = src->outgoingTransfer.get()->copy(src->outgoingTransfer.get(), make_shared<MoneroOutgoingTransfer>());
shared_ptr<monero_outgoing_transfer> transferCopy = src->outgoingTransfer.get()->copy(src->outgoingTransfer.get(), make_shared<monero_outgoing_transfer>());
transferCopy->tx = tgt;
tgt->outgoingTransfer = transferCopy;
}
@@ -136,39 +136,39 @@ namespace monero {
return tgt;
};
boost::property_tree::ptree MoneroTxWallet::toPropertyTree() const {
boost::property_tree::ptree node = MoneroTx::toPropertyTree();
if (!incomingTransfers.empty()) node.add_child("incomingTransfers", MoneroUtils::toPropertyTree(incomingTransfers));
if (outgoingTransfer != boost::none) node.add_child("outgoingTransfer", (*outgoingTransfer)->toPropertyTree());
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 (note != boost::none) node.put("note", *note);
return node;
}
bool MoneroTxWallet::getIsOutgoing() const {
bool monero_tx_wallet::getIsOutgoing() const {
return outgoingTransfer != boost::none;
}
bool MoneroTxWallet::getIsIncoming() const {
bool monero_tx_wallet::getIsIncoming() const {
return !incomingTransfers.empty();
}
void MoneroTxWallet::merge(const shared_ptr<MoneroTx>& self, const shared_ptr<MoneroTx>& other) {
merge(static_pointer_cast<MoneroTxWallet>(self), static_pointer_cast<MoneroTxWallet>(other));
void monero_tx_wallet::merge(const shared_ptr<monero_tx>& self, const shared_ptr<monero_tx>& other) {
merge(static_pointer_cast<monero_tx_wallet>(self), static_pointer_cast<monero_tx_wallet>(other));
}
void MoneroTxWallet::merge(const shared_ptr<MoneroTxWallet>& self, const shared_ptr<MoneroTxWallet>& other) {
void monero_tx_wallet::merge(const shared_ptr<monero_tx_wallet>& self, const shared_ptr<monero_tx_wallet>& other) {
if (this != self.get()) throw runtime_error("this != self");
if (self == other) return;
// merge base classes
MoneroTx::merge(self, other);
monero_tx::merge(self, other);
// merge wallet extensions
note = MoneroUtils::reconcile(note, other->note);
note = monero_utils::reconcile(note, other->note);
// merge incoming transfers
if (!other->incomingTransfers.empty()) {
for (const shared_ptr<MoneroIncomingTransfer>& transfer : other->incomingTransfers) { // NOTE: not using reference so shared_ptr is not deleted when tx is dereferenced
for (const shared_ptr<monero_incoming_transfer>& transfer : other->incomingTransfers) { // NOTE: not using reference so shared_ptr is not deleted when tx is dereferenced
transfer->tx = self;
mergeIncomingTransfer(self->incomingTransfers, transfer);
}
@@ -184,20 +184,20 @@ namespace monero {
// -------------------------- MONERO TX REQUEST -----------------------------
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const {
return copy(static_pointer_cast<MoneroTxRequest>(src), static_pointer_cast<MoneroTxRequest>(tgt));
shared_ptr<monero_tx_request> monero_tx_request::copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const {
return copy(static_pointer_cast<monero_tx_request>(src), static_pointer_cast<monero_tx_request>(tgt));
};
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt) const {
return copy(static_pointer_cast<MoneroTxRequest>(src), static_pointer_cast<MoneroTxRequest>(tgt));
shared_ptr<monero_tx_request> monero_tx_request::copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt) const {
return copy(static_pointer_cast<monero_tx_request>(src), static_pointer_cast<monero_tx_request>(tgt));
};
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTxRequest>& src, const shared_ptr<MoneroTxRequest>& tgt) const {
MTRACE("MoneroTxRequest::copy(const shared_ptr<MoneroTxRequest>& src, const shared_ptr<MoneroTxRequest>& tgt)");
shared_ptr<monero_tx_request> monero_tx_request::copy(const shared_ptr<monero_tx_request>& src, const shared_ptr<monero_tx_request>& tgt) const {
MTRACE("monero_tx_request::copy(const shared_ptr<monero_tx_request>& src, const shared_ptr<monero_tx_request>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
// copy base class
MoneroTxWallet::copy(static_pointer_cast<MoneroTx>(src), static_pointer_cast<MoneroTx>(tgt));
monero_tx_wallet::copy(static_pointer_cast<monero_tx>(src), static_pointer_cast<monero_tx>(tgt));
// copy request extensions
tgt->isOutgoing = src->isOutgoing;
@@ -209,27 +209,27 @@ namespace monero {
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<MoneroTransferRequest>());
if (src->outputRequest != boost::none) tgt->outputRequest = src->outputRequest.get()->copy(src->outputRequest.get(), make_shared<MoneroOutputRequest>());
if (src->transferRequest != boost::none) tgt->transferRequest = src->transferRequest.get()->copy(src->transferRequest.get(), make_shared<monero_transfer_request>());
if (src->outputRequest != boost::none) tgt->outputRequest = src->outputRequest.get()->copy(src->outputRequest.get(), make_shared<monero_output_request>());
return tgt;
};
boost::property_tree::ptree MoneroTxRequest::toPropertyTree() const {
boost::property_tree::ptree node = MoneroTxWallet::toPropertyTree();
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", MoneroUtils::toPropertyTree(txIds));
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", MoneroUtils::toPropertyTree(paymentIds));
if (!paymentIds.empty()) node.add_child("paymentIds", monero_utils::to_property_tree(paymentIds));
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)->toPropertyTree());
if (transferRequest != boost::none) node.add_child("transferRequest", (*transferRequest)->to_property_tree());
return node;
}
bool MoneroTxRequest::meetsCriteria(MoneroTxWallet* tx) const {
bool monero_tx_request::meetsCriteria(monero_tx_wallet* tx) const {
if (tx == nullptr) return false;
// filter on tx
@@ -246,7 +246,7 @@ namespace monero {
bool matchFound = false;
if (tx->outgoingTransfer != boost::none && (*transferRequest)->meetsCriteria((*tx->outgoingTransfer).get())) matchFound = true;
else if (!tx->incomingTransfers.empty()) {
for (const shared_ptr<MoneroIncomingTransfer>& incomingTransfer : tx->incomingTransfers) {
for (const shared_ptr<monero_incoming_transfer>& incomingTransfer : tx->incomingTransfers) {
if ((*transferRequest)->meetsCriteria(incomingTransfer.get())) {
matchFound = true;
break;
@@ -269,7 +269,7 @@ namespace monero {
if (isOutgoing != boost::none && isOutgoing != tx->getIsOutgoing()) return false;
// filter on remaining fields
boost::optional<uint64_t> txHeight = tx->getHeight();
boost::optional<uint64_t> 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 (height != boost::none && (txHeight == boost::none || *txHeight != *height)) return false;
@@ -282,15 +282,15 @@ namespace monero {
// -------------------------- MONERO DESTINATION ----------------------------
shared_ptr<MoneroDestination> MoneroDestination::copy(const shared_ptr<MoneroDestination>& src, const shared_ptr<MoneroDestination>& tgt) const {
MTRACE("MoneroDestination::copy(const shared_ptr<MoneroDestination>& src, const shared_ptr<MoneroDestination>& tgt)");
shared_ptr<monero_destination> monero_destination::copy(const shared_ptr<monero_destination>& src, const shared_ptr<monero_destination>& tgt) const {
MTRACE("monero_destination::copy(const shared_ptr<monero_destination>& src, const shared_ptr<monero_destination>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
tgt->address = src->address;
tgt->amount = src->amount;
return tgt;
};
boost::property_tree::ptree MoneroDestination::toPropertyTree() const {
boost::property_tree::ptree monero_destination::to_property_tree() const {
boost::property_tree::ptree node;
if (address != boost::none) node.put("address", *address);
if (amount != boost::none) node.put("amount", *amount);
@@ -299,8 +299,8 @@ namespace monero {
// ---------------------------- MONERO TRANSFER -----------------------------
shared_ptr<MoneroTransfer> MoneroTransfer::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const {
MTRACE("MoneroTransfer::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt)");
shared_ptr<monero_transfer> monero_transfer::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const {
MTRACE("monero_transfer::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt)");
tgt->tx = src->tx; // reference parent tx by default
tgt->amount = src->amount;
tgt->accountIndex = src->accountIndex;
@@ -308,7 +308,7 @@ namespace monero {
return tgt;
}
boost::property_tree::ptree MoneroTransfer::toPropertyTree() const {
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);
@@ -316,7 +316,7 @@ namespace monero {
return node;
}
void MoneroTransfer::merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other) {
void monero_transfer::merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other) {
if (this != self.get()) throw runtime_error("this != self");
if (self == other) return;
@@ -327,96 +327,96 @@ namespace monero {
}
// otherwise merge transfer fields
accountIndex = MoneroUtils::reconcile(accountIndex, other->accountIndex, "acountIndex");
accountIndex = monero_utils::reconcile(accountIndex, other->accountIndex, "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
if (amount != boost::none && other->amount != boost::none && *amount != *other->amount && (*amount == 0 || *other->amount == 0)) {
accountIndex = MoneroUtils::reconcile(accountIndex, other->accountIndex, boost::none, boost::none, true, "acountIndex");
numSuggestedConfirmations = MoneroUtils::reconcile(numSuggestedConfirmations, other->numSuggestedConfirmations, boost::none, boost::none, true, "numSuggestedConfirmations");
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");
} else {
amount = MoneroUtils::reconcile(amount, other->amount, "transfer amount");
numSuggestedConfirmations = MoneroUtils::reconcile(numSuggestedConfirmations, other->numSuggestedConfirmations, boost::none, boost::none, false, "numSuggestedConfirmations");
amount = monero_utils::reconcile(amount, other->amount, "transfer amount");
numSuggestedConfirmations = monero_utils::reconcile(numSuggestedConfirmations, other->numSuggestedConfirmations, boost::none, boost::none, false, "numSuggestedConfirmations");
}
}
// ----------------------- MONERO INCOMING TRANSFER -------------------------
shared_ptr<MoneroIncomingTransfer> MoneroIncomingTransfer::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const {
return copy(static_pointer_cast<MoneroIncomingTransfer>(src), static_pointer_cast<MoneroIncomingTransfer>(tgt));
shared_ptr<monero_incoming_transfer> monero_incoming_transfer::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const {
return copy(static_pointer_cast<monero_incoming_transfer>(src), static_pointer_cast<monero_incoming_transfer>(tgt));
}
shared_ptr<MoneroIncomingTransfer> MoneroIncomingTransfer::copy(const shared_ptr<MoneroIncomingTransfer>& src, const shared_ptr<MoneroIncomingTransfer>& tgt) const {
shared_ptr<monero_incoming_transfer> monero_incoming_transfer::copy(const shared_ptr<monero_incoming_transfer>& src, const shared_ptr<monero_incoming_transfer>& tgt) const {
throw runtime_error("MoneroIncomingTransfer::copy(inTransfer) not implemented");
throw runtime_error("monero_incoming_transfer::copy(inTransfer) not implemented");
};
boost::optional<bool> MoneroIncomingTransfer::getIsIncoming() const { return true; }
boost::optional<bool> monero_incoming_transfer::getIsIncoming() const { return true; }
boost::property_tree::ptree MoneroIncomingTransfer::toPropertyTree() const {
boost::property_tree::ptree node = MoneroTransfer::toPropertyTree();
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 (address != boost::none) node.put("address", *address);
return node;
}
void MoneroIncomingTransfer::merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other) {
merge(static_pointer_cast<MoneroIncomingTransfer>(self), static_pointer_cast<MoneroIncomingTransfer>(other));
void monero_incoming_transfer::merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other) {
merge(static_pointer_cast<monero_incoming_transfer>(self), static_pointer_cast<monero_incoming_transfer>(other));
}
void MoneroIncomingTransfer::merge(const shared_ptr<MoneroIncomingTransfer>& self, const shared_ptr<MoneroIncomingTransfer>& other) {
void monero_incoming_transfer::merge(const shared_ptr<monero_incoming_transfer>& self, const shared_ptr<monero_incoming_transfer>& other) {
if (self == other) return;
MoneroTransfer::merge(self, other);
subaddressIndex = MoneroUtils::reconcile(subaddressIndex, other->subaddressIndex, "incoming transfer subaddressIndex");
address = MoneroUtils::reconcile(address, other->address);
monero_transfer::merge(self, other);
subaddressIndex = monero_utils::reconcile(subaddressIndex, other->subaddressIndex, "incoming transfer subaddressIndex");
address = monero_utils::reconcile(address, other->address);
}
// ----------------------- MONERO OUTGOING TRANSFER -------------------------
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const {
return copy(static_pointer_cast<MoneroOutgoingTransfer>(src), static_pointer_cast<MoneroOutgoingTransfer>(tgt));
shared_ptr<monero_outgoing_transfer> monero_outgoing_transfer::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const {
return copy(static_pointer_cast<monero_outgoing_transfer>(src), static_pointer_cast<monero_outgoing_transfer>(tgt));
};
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy(const shared_ptr<MoneroOutgoingTransfer>& src, const shared_ptr<MoneroOutgoingTransfer>& tgt) const {
throw runtime_error("MoneroOutgoingTransfer::copy(outTransfer) not implemented");
shared_ptr<monero_outgoing_transfer> monero_outgoing_transfer::copy(const shared_ptr<monero_outgoing_transfer>& src, const shared_ptr<monero_outgoing_transfer>& tgt) const {
throw runtime_error("monero_outgoing_transfer::copy(outTransfer) not implemented");
};
boost::optional<bool> MoneroOutgoingTransfer::getIsIncoming() const { return false; }
boost::optional<bool> monero_outgoing_transfer::getIsIncoming() const { return false; }
boost::property_tree::ptree MoneroOutgoingTransfer::toPropertyTree() const {
boost::property_tree::ptree node = MoneroTransfer::toPropertyTree();
if (!subaddressIndices.empty()) node.add_child("subaddressIndices", MoneroUtils::toPropertyTree(subaddressIndices));
if (!addresses.empty()) node.add_child("addresses", MoneroUtils::toPropertyTree(addresses));
if (!destinations.empty()) node.add_child("destinations", MoneroUtils::toPropertyTree(destinations));
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 (!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;
}
void MoneroOutgoingTransfer::merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other) {
merge(static_pointer_cast<MoneroOutgoingTransfer>(self), static_pointer_cast<MoneroOutgoingTransfer>(other));
void monero_outgoing_transfer::merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other) {
merge(static_pointer_cast<monero_outgoing_transfer>(self), static_pointer_cast<monero_outgoing_transfer>(other));
}
void MoneroOutgoingTransfer::merge(const shared_ptr<MoneroOutgoingTransfer>& self, const shared_ptr<MoneroOutgoingTransfer>& other) {
void monero_outgoing_transfer::merge(const shared_ptr<monero_outgoing_transfer>& self, const shared_ptr<monero_outgoing_transfer>& other) {
if (self == other) return;
MoneroTransfer::merge(self, other);
subaddressIndices = MoneroUtils::reconcile(subaddressIndices, other->subaddressIndices);
addresses = MoneroUtils::reconcile(addresses, other->addresses);
destinations = MoneroUtils::reconcile(destinations, other->destinations);
monero_transfer::merge(self, other);
subaddressIndices = monero_utils::reconcile(subaddressIndices, other->subaddressIndices);
addresses = monero_utils::reconcile(addresses, other->addresses);
destinations = monero_utils::reconcile(destinations, other->destinations);
}
// ----------------------- MONERO TRANSFER REQUEST --------------------------
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const {
return copy(static_pointer_cast<MoneroTransferRequest>(src), static_pointer_cast<MoneroTransfer>(tgt));
shared_ptr<monero_transfer_request> monero_transfer_request::copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const {
return copy(static_pointer_cast<monero_transfer_request>(src), static_pointer_cast<monero_transfer>(tgt));
};
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy(const shared_ptr<MoneroTransferRequest>& src, const shared_ptr<MoneroTransferRequest>& tgt) const {
MTRACE("MoneroTransferRequest::copy(const shared_ptr<MoneroTransferRequest>& src, const shared_ptr<MoneroTransferRequest>& tgt)");
shared_ptr<monero_transfer_request> monero_transfer_request::copy(const shared_ptr<monero_transfer_request>& src, const shared_ptr<monero_transfer_request>& tgt) const {
MTRACE("monero_transfer_request::copy(const shared_ptr<monero_transfer_request>& src, const shared_ptr<monero_transfer_request>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
// copy base class
MoneroTransfer::copy(static_pointer_cast<MoneroTransfer>(src), static_pointer_cast<MoneroTransfer>(tgt));
monero_transfer::copy(static_pointer_cast<monero_transfer>(src), static_pointer_cast<monero_transfer>(tgt));
// copy extensions
tgt->isIncoming = src->isIncoming;
@@ -425,8 +425,8 @@ namespace monero {
tgt->subaddressIndex = src->subaddressIndex;
if (!src->subaddressIndices.empty()) tgt->subaddressIndices = vector<uint32_t>(src->subaddressIndices);
if (!src->destinations.empty()) {
for (const shared_ptr<MoneroDestination>& destination : src->destinations) {
tgt->destinations.push_back(destination->copy(destination, make_shared<MoneroDestination>()));
for (const shared_ptr<monero_destination>& destination : src->destinations) {
tgt->destinations.push_back(destination->copy(destination, make_shared<monero_destination>()));
}
}
tgt->hasDestinations = src->hasDestinations;
@@ -434,21 +434,21 @@ namespace monero {
return tgt;
};
boost::optional<bool> MoneroTransferRequest::getIsIncoming() const { return isIncoming; }
boost::optional<bool> monero_transfer_request::getIsIncoming() const { return isIncoming; }
boost::property_tree::ptree MoneroTransferRequest::toPropertyTree() const {
boost::property_tree::ptree node = MoneroTransfer::toPropertyTree();
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 (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", MoneroUtils::toPropertyTree(subaddressIndices));
if (!addresses.empty()) node.add_child("addresses", MoneroUtils::toPropertyTree(addresses));
if (!destinations.empty()) node.add_child("destinations", MoneroUtils::toPropertyTree(destinations));
if (!subaddressIndices.empty()) node.add_child("subaddressIndices", monero_utils::to_property_tree(subaddressIndices));
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;
}
bool MoneroTransferRequest::meetsCriteria(MoneroTransfer* transfer) const {
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
@@ -459,7 +459,7 @@ namespace monero {
if (accountIndex != boost::none && *accountIndex != *transfer->accountIndex) return false;
// filter on incoming fields
MoneroIncomingTransfer* inTransfer = dynamic_cast<MoneroIncomingTransfer*>(transfer);
monero_incoming_transfer* inTransfer = dynamic_cast<monero_incoming_transfer*>(transfer);
if (inTransfer != nullptr) {
if (hasDestinations != boost::none) return false;
if (address != boost::none && *address != *inTransfer->address) return false;
@@ -469,7 +469,7 @@ namespace monero {
}
// filter on outgoing fields
MoneroOutgoingTransfer* outTransfer = dynamic_cast<MoneroOutgoingTransfer*>(transfer);
monero_outgoing_transfer* outTransfer = dynamic_cast<monero_outgoing_transfer*>(transfer);
if (outTransfer != nullptr) {
// filter on addresses
@@ -513,7 +513,7 @@ namespace monero {
}
// validate type
if (inTransfer == nullptr && outTransfer == nullptr) throw runtime_error("Transfer must be MoneroIncomingTransfer or MoneroOutgoingTransfer");
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;
@@ -522,17 +522,17 @@ namespace monero {
// ------------------------- MONERO OUTPUT WALLET ---------------------------
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const {
MTRACE("MoneroOutputWallet::copy(output)");
return MoneroOutputWallet::copy(static_pointer_cast<MoneroOutputWallet>(src), static_pointer_cast<MoneroOutputWallet>(tgt));
shared_ptr<monero_output_wallet> monero_output_wallet::copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const {
MTRACE("monero_output_wallet::copy(output)");
return monero_output_wallet::copy(static_pointer_cast<monero_output_wallet>(src), static_pointer_cast<monero_output_wallet>(tgt));
};
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy(const shared_ptr<MoneroOutputWallet>& src, const shared_ptr<MoneroOutputWallet>& tgt) const {
MTRACE("MoneroOutputWallet::copy(outputWallet)");
shared_ptr<monero_output_wallet> monero_output_wallet::copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const {
MTRACE("monero_output_wallet::copy(outputWallet)");
if (this != src.get()) throw runtime_error("this != src");
// copy base class
MoneroOutput::copy(static_pointer_cast<MoneroOutput>(src), static_pointer_cast<MoneroOutput>(tgt));
monero_output::copy(static_pointer_cast<monero_output>(src), static_pointer_cast<monero_output>(tgt));
// copy extensions
tgt->accountIndex = src->accountIndex;
@@ -543,8 +543,8 @@ namespace monero {
return tgt;
};
boost::property_tree::ptree MoneroOutputWallet::toPropertyTree() const {
boost::property_tree::ptree node = MoneroOutput::toPropertyTree();
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);
@@ -553,43 +553,43 @@ namespace monero {
return node;
}
void MoneroOutputWallet::merge(const shared_ptr<MoneroOutput>& self, const shared_ptr<MoneroOutput>& other) {
merge(static_pointer_cast<MoneroOutputWallet>(self), static_pointer_cast<MoneroOutputWallet>(other));
void monero_output_wallet::merge(const shared_ptr<monero_output>& self, const shared_ptr<monero_output>& other) {
merge(static_pointer_cast<monero_output_wallet>(self), static_pointer_cast<monero_output_wallet>(other));
}
void MoneroOutputWallet::merge(const shared_ptr<MoneroOutputWallet>& self, const shared_ptr<MoneroOutputWallet>& other) {
throw runtime_error("MoneroOutputWallet::merge(self, other) not implemented");
void monero_output_wallet::merge(const shared_ptr<monero_output_wallet>& self, const shared_ptr<monero_output_wallet>& other) {
throw runtime_error("monero_output_wallet::merge(self, other) not implemented");
}
// ------------------------ MONERO OUTPUT REQUEST ---------------------------
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const {
return MoneroOutputRequest::copy(static_pointer_cast<MoneroOutputRequest>(src), static_pointer_cast<MoneroOutputRequest>(tgt));
shared_ptr<monero_output_request> monero_output_request::copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const {
return monero_output_request::copy(static_pointer_cast<monero_output_request>(src), static_pointer_cast<monero_output_request>(tgt));
};
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutputWallet>& src, const shared_ptr<MoneroOutputWallet>& tgt) const {
return MoneroOutputRequest::copy(static_pointer_cast<MoneroOutputRequest>(src), static_pointer_cast<MoneroOutputRequest>(tgt));
shared_ptr<monero_output_request> monero_output_request::copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const {
return monero_output_request::copy(static_pointer_cast<monero_output_request>(src), static_pointer_cast<monero_output_request>(tgt));
};
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutputRequest>& src, const shared_ptr<MoneroOutputRequest>& tgt) const {
MTRACE("MoneroOutputRequest::copy(outputRequest)");
shared_ptr<monero_output_request> monero_output_request::copy(const shared_ptr<monero_output_request>& src, const shared_ptr<monero_output_request>& tgt) const {
MTRACE("monero_output_request::copy(outputRequest)");
if (this != src.get()) throw runtime_error("this != src");
// copy base class
MoneroOutputWallet::copy(static_pointer_cast<MoneroOutput>(src), static_pointer_cast<MoneroOutput>(tgt));
monero_output_wallet::copy(static_pointer_cast<monero_output>(src), static_pointer_cast<monero_output>(tgt));
// copy extensions
if (!src->subaddressIndices.empty()) tgt->subaddressIndices = vector<uint32_t>(src->subaddressIndices);
return tgt;
};
boost::property_tree::ptree MoneroOutputRequest::toPropertyTree() const {
boost::property_tree::ptree node = MoneroOutputWallet::toPropertyTree();
if (!subaddressIndices.empty()) node.add_child("subaddressIndices", MoneroUtils::toPropertyTree(subaddressIndices));
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));
return node;
}
bool MoneroOutputRequest::meetsCriteria(MoneroOutputWallet* output) const {
bool monero_output_request::meetsCriteria(monero_output_wallet* output) const {
// filter on output
if (accountIndex != boost::none && *accountIndex != *output->accountIndex) return false;
@@ -609,7 +609,7 @@ namespace monero {
if (!subaddressIndices.empty() && find(subaddressIndices.begin(), subaddressIndices.end(), *output->subaddressIndex) == subaddressIndices.end()) return false;
// filter with tx request
if (txRequest != boost::none && !(*txRequest)->meetsCriteria(static_pointer_cast<MoneroTxWallet>(output->tx).get())) return false;
if (txRequest != boost::none && !(*txRequest)->meetsCriteria(static_pointer_cast<monero_tx_wallet>(output->tx).get())) return false;
// output meets request
return true;
@@ -617,15 +617,15 @@ namespace monero {
// ------------------------- MONERO SEND REQUEST ----------------------------
boost::property_tree::ptree MoneroSendRequest::toPropertyTree() const {
boost::property_tree::ptree monero_send_request::to_property_tree() const {
boost::property_tree::ptree node;
if (!destinations.empty()) node.add_child("destinations", MoneroUtils::toPropertyTree(destinations));
if (!destinations.empty()) node.add_child("destinations", monero_utils::to_property_tree(destinations));
if (paymentId != boost::none) node.put("paymentId", *paymentId);
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", MoneroUtils::toPropertyTree(subaddressIndices));
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);
@@ -639,7 +639,7 @@ namespace monero {
// ---------------------- MONERO INTEGRATED ADDRESS -------------------------
boost::property_tree::ptree MoneroIntegratedAddress::toPropertyTree() const {
boost::property_tree::ptree monero_integrated_address::to_property_tree() const {
boost::property_tree::ptree node;
node.put("standardAddress", standardAddress);
node.put("paymentId", paymentId);
@@ -649,7 +649,7 @@ namespace monero {
// -------------------- MONERO KEY IMAGE IMPORT RESULT ----------------------
boost::property_tree::ptree MoneroKeyImageImportResult::toPropertyTree() const {
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);
@@ -659,7 +659,7 @@ namespace monero {
// ----------------------------- MONERO CHECK -------------------------------
boost::property_tree::ptree MoneroCheck::toPropertyTree() const {
boost::property_tree::ptree monero_check::to_property_tree() const {
boost::property_tree::ptree node;
node.put("isGood", isGood);
return node;
@@ -667,8 +667,8 @@ namespace monero {
// --------------------------- MONERO CHECK TX ------------------------------
boost::property_tree::ptree MoneroCheckTx::toPropertyTree() const {
boost::property_tree::ptree node = MoneroCheck::toPropertyTree();;
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);
@@ -677,8 +677,8 @@ namespace monero {
// ------------------------ MONERO CHECK RESERVE ----------------------------
boost::property_tree::ptree MoneroCheckReserve::toPropertyTree() const {
boost::property_tree::ptree node = MoneroCheck::toPropertyTree();
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);
return node;
@@ -52,7 +52,7 @@
#pragma once
#include "daemon/MoneroDaemonModel.h"
#include "daemon/monero_daemon_model.h"
using namespace std;
using namespace monero;
@@ -65,17 +65,17 @@ namespace monero {
/**
* Models a result of syncing a wallet.
*/
struct MoneroSyncResult {
struct monero_sync_result {
uint64_t numBlocksFetched;
bool receivedMoney;
MoneroSyncResult() {}
MoneroSyncResult(const uint64_t numBlocksFetched, const bool receivedMoney) : numBlocksFetched(numBlocksFetched), receivedMoney(receivedMoney) {}
monero_sync_result() {}
monero_sync_result(const uint64_t numBlocksFetched, const bool receivedMoney) : numBlocksFetched(numBlocksFetched), receivedMoney(receivedMoney) {}
};
/**
* Models a Monero subaddress.
*/
struct MoneroSubaddress : public SerializableStruct {
struct monero_subaddress : public serializable_struct {
boost::optional<uint32_t> accountIndex;
boost::optional<uint32_t> index;
boost::optional<string> address;
@@ -97,20 +97,20 @@ namespace monero {
// KV_SERIALIZE(numBlocksToUnlock)
// END_KV_SERIALIZE_MAP()
boost::property_tree::ptree toPropertyTree() const;
//void merge(const shared_ptr<MoneroSubaddress>& self, const shared_ptr<MoneroSubaddress>& other);
boost::property_tree::ptree to_property_tree() const;
//void merge(const shared_ptr<monero_subaddress>& self, const shared_ptr<monero_subaddress>& other);
};
/**
* Models a Monero account.
*/
struct MoneroAccount : public SerializableStruct {
struct monero_account : public serializable_struct {
boost::optional<uint32_t> index;
boost::optional<string> primaryAddress;
boost::optional<uint64_t> balance;
boost::optional<uint64_t> unlockedBalance;
boost::optional<string> tag;
vector<MoneroSubaddress> subaddresses;
vector<monero_subaddress> subaddresses;
// BEGIN_KV_SERIALIZE_MAP()
// KV_SERIALIZE(index)
// KV_SERIALIZE(primaryAddress)
@@ -121,72 +121,72 @@ namespace monero {
// KV_SERIALIZE(subaddresses)
// END_KV_SERIALIZE_MAP()
boost::property_tree::ptree toPropertyTree() const;
boost::property_tree::ptree to_property_tree() const;
};
// forward declarations
struct MoneroTxWallet;
struct MoneroTxRequest;
struct monero_tx_wallet;
struct monero_tx_request;
/**
* Models an outgoing transfer destination.
*/
struct MoneroDestination {
struct monero_destination {
boost::optional<string> address;
boost::optional<uint64_t> amount;
shared_ptr<MoneroDestination> copy(const shared_ptr<MoneroDestination>& src, const shared_ptr<MoneroDestination>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
shared_ptr<monero_destination> copy(const shared_ptr<monero_destination>& src, const shared_ptr<monero_destination>& tgt) const;
boost::property_tree::ptree to_property_tree() const;
};
/**
* Models a base transfer of funds to or from the wallet.
*/
struct MoneroTransfer : SerializableStruct {
shared_ptr<MoneroTxWallet> tx;
struct monero_transfer : serializable_struct {
shared_ptr<monero_tx_wallet> tx;
boost::optional<uint64_t> amount;
boost::optional<uint32_t> accountIndex;
boost::optional<uint32_t> numSuggestedConfirmations;
virtual boost::optional<bool> getIsIncoming() const = 0; // derived class must implement
shared_ptr<MoneroTransfer> copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const;
shared_ptr<monero_transfer> copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const;
boost::optional<bool> getIsOutgoing() const {
if (getIsIncoming() == boost::none) return boost::none;
return !(*getIsIncoming());
}
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other);
boost::property_tree::ptree to_property_tree() const;
void merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other);
};
/**
* Models an incoming transfer of funds to the wallet.
*/
struct MoneroIncomingTransfer : public MoneroTransfer {
struct monero_incoming_transfer : public monero_transfer {
boost::optional<uint32_t> subaddressIndex;
boost::optional<string> address;
shared_ptr<MoneroIncomingTransfer> copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const;
shared_ptr<MoneroIncomingTransfer> copy(const shared_ptr<MoneroIncomingTransfer>& src, const shared_ptr<MoneroIncomingTransfer>& tgt) const;
shared_ptr<monero_incoming_transfer> copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const;
shared_ptr<monero_incoming_transfer> copy(const shared_ptr<monero_incoming_transfer>& src, const shared_ptr<monero_incoming_transfer>& tgt) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other);
void merge(const shared_ptr<MoneroIncomingTransfer>& self, const shared_ptr<MoneroIncomingTransfer>& other);
boost::property_tree::ptree to_property_tree() const;
void merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other);
void merge(const shared_ptr<monero_incoming_transfer>& self, const shared_ptr<monero_incoming_transfer>& other);
};
/**
* Models an outgoing transfer of funds from the wallet.
*/
struct MoneroOutgoingTransfer : public MoneroTransfer {
struct monero_outgoing_transfer : public monero_transfer {
vector<uint32_t> subaddressIndices;
vector<string> addresses;
vector<shared_ptr<MoneroDestination>> destinations;
vector<shared_ptr<monero_destination>> destinations;
shared_ptr<MoneroOutgoingTransfer> copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const;
shared_ptr<MoneroOutgoingTransfer> copy(const shared_ptr<MoneroOutgoingTransfer>& src, const shared_ptr<MoneroOutgoingTransfer>& tgt) const;
shared_ptr<monero_outgoing_transfer> copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const;
shared_ptr<monero_outgoing_transfer> copy(const shared_ptr<monero_outgoing_transfer>& src, const shared_ptr<monero_outgoing_transfer>& tgt) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other);
void merge(const shared_ptr<MoneroOutgoingTransfer>& self, const shared_ptr<MoneroOutgoingTransfer>& other);
boost::property_tree::ptree to_property_tree() const;
void merge(const shared_ptr<monero_transfer>& self, const shared_ptr<monero_transfer>& other);
void merge(const shared_ptr<monero_outgoing_transfer>& self, const shared_ptr<monero_outgoing_transfer>& other);
};
/**
@@ -194,38 +194,38 @@ namespace monero {
*
* All transfers are returned except those that do not meet the criteria defined in this request.
*/
struct MoneroTransferRequest : public MoneroTransfer {
struct monero_transfer_request : public monero_transfer {
boost::optional<bool> isIncoming;
boost::optional<string> address;
vector<string> addresses;
boost::optional<uint32_t> subaddressIndex;
vector<uint32_t> subaddressIndices;
vector<shared_ptr<MoneroDestination>> destinations;
vector<shared_ptr<monero_destination>> destinations;
boost::optional<bool> hasDestinations;
boost::optional<shared_ptr<MoneroTxRequest>> txRequest;
boost::optional<shared_ptr<monero_tx_request>> txRequest;
shared_ptr<MoneroTransferRequest> copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const;
shared_ptr<MoneroTransferRequest> copy(const shared_ptr<MoneroTransferRequest>& src, const shared_ptr<MoneroTransferRequest>& tgt) const;
shared_ptr<monero_transfer_request> copy(const shared_ptr<monero_transfer>& src, const shared_ptr<monero_transfer>& tgt) const;
shared_ptr<monero_transfer_request> copy(const shared_ptr<monero_transfer_request>& src, const shared_ptr<monero_transfer_request>& tgt) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroTransfer* transfer) const;
boost::property_tree::ptree to_property_tree() const;
bool meetsCriteria(monero_transfer* transfer) const;
};
/**
* Models a Monero output with wallet extensions.
*/
struct MoneroOutputWallet : public MoneroOutput {
struct monero_output_wallet : public monero_output {
boost::optional<uint32_t> accountIndex;
boost::optional<uint32_t> subaddressIndex;
boost::optional<bool> isSpent;
boost::optional<bool> isUnlocked;
boost::optional<bool> isFrozen;
shared_ptr<MoneroOutputWallet> copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const;
shared_ptr<MoneroOutputWallet> copy(const shared_ptr<MoneroOutputWallet>& src, const shared_ptr<MoneroOutputWallet>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroOutput>& self, const shared_ptr<MoneroOutput>& other);
void merge(const shared_ptr<MoneroOutputWallet>& self, const shared_ptr<MoneroOutputWallet>& other);
shared_ptr<monero_output_wallet> copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const;
shared_ptr<monero_output_wallet> copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const;
boost::property_tree::ptree to_property_tree() const;
void merge(const shared_ptr<monero_output>& self, const shared_ptr<monero_output>& other);
void merge(const shared_ptr<monero_output_wallet>& self, const shared_ptr<monero_output_wallet>& other);
};
/**
@@ -234,33 +234,33 @@ namespace monero {
*
* All outputs are returned except those that do not meet the criteria defined in this request.
*/
struct MoneroOutputRequest : public MoneroOutputWallet {
struct monero_output_request : public monero_output_wallet {
vector<uint32_t> subaddressIndices;
boost::optional<shared_ptr<MoneroTxRequest>> txRequest;
boost::optional<shared_ptr<monero_tx_request>> txRequest;
// TODO: necessary to override all super classes?
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutputWallet>& src, const shared_ptr<MoneroOutputWallet>& tgt) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutputRequest>& src, const shared_ptr<MoneroOutputRequest>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroOutputWallet* output) const;
shared_ptr<monero_output_request> copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const;
shared_ptr<monero_output_request> copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const;
shared_ptr<monero_output_request> copy(const shared_ptr<monero_output_request>& src, const shared_ptr<monero_output_request>& tgt) const;
boost::property_tree::ptree to_property_tree() const;
bool meetsCriteria(monero_output_wallet* output) const;
};
/**
* Models a Monero transaction in the context of a wallet.
*/
struct MoneroTxWallet : public MoneroTx {
vector<shared_ptr<MoneroIncomingTransfer>> incomingTransfers;
boost::optional<shared_ptr<MoneroOutgoingTransfer>> outgoingTransfer;
struct monero_tx_wallet : public monero_tx {
vector<shared_ptr<monero_incoming_transfer>> incomingTransfers;
boost::optional<shared_ptr<monero_outgoing_transfer>> outgoingTransfer;
boost::optional<string> note;
shared_ptr<MoneroTxWallet> copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const;
shared_ptr<MoneroTxWallet> copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt) const;
shared_ptr<monero_tx_wallet> copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const;
shared_ptr<monero_tx_wallet> copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt) const;
bool getIsIncoming() const;
bool getIsOutgoing() const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroTx>& self, const shared_ptr<MoneroTx>& other);
void merge(const shared_ptr<MoneroTxWallet>& self, const shared_ptr<MoneroTxWallet>& other);
boost::property_tree::ptree to_property_tree() const;
void merge(const shared_ptr<monero_tx>& self, const shared_ptr<monero_tx>& other);
void merge(const shared_ptr<monero_tx_wallet>& self, const shared_ptr<monero_tx_wallet>& other);
};
/**
@@ -268,7 +268,7 @@ namespace monero {
*
* All transactions are returned except those that do not meet the criteria defined in this request.
*/
struct MoneroTxRequest : public MoneroTxWallet {
struct monero_tx_request : public monero_tx_wallet {
boost::optional<bool> isOutgoing;
boost::optional<bool> isIncoming;
vector<string> txIds;
@@ -278,32 +278,32 @@ namespace monero {
boost::optional<uint64_t> minHeight;
boost::optional<uint64_t> maxHeight;
boost::optional<uint64_t> includeOutputs;
boost::optional<shared_ptr<MoneroTransferRequest>> transferRequest;
boost::optional<shared_ptr<MoneroOutputRequest>> outputRequest;
boost::optional<shared_ptr<monero_transfer_request>> transferRequest;
boost::optional<shared_ptr<monero_output_request>> outputRequest;
// TODO: necessary to override all super classes?
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTxRequest>& src, const shared_ptr<MoneroTxRequest>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroTxWallet* tx) const;
shared_ptr<monero_tx_request> copy(const shared_ptr<monero_tx>& src, const shared_ptr<monero_tx>& tgt) const;
shared_ptr<monero_tx_request> copy(const shared_ptr<monero_tx_wallet>& src, const shared_ptr<monero_tx_wallet>& tgt) const;
shared_ptr<monero_tx_request> copy(const shared_ptr<monero_tx_request>& src, const shared_ptr<monero_tx_request>& tgt) const;
boost::property_tree::ptree to_property_tree() const;
bool meetsCriteria(monero_tx_wallet* tx) const;
};
/**
* Monero integrated address model.
*/
struct MoneroIntegratedAddress : public SerializableStruct {
struct monero_integrated_address : public serializable_struct {
string standardAddress;
string paymentId;
string integratedAddress;
boost::property_tree::ptree toPropertyTree() const;
boost::property_tree::ptree to_property_tree() const;
};
/**
* Enumerates Monero network types.
*/
enum MoneroSendPriority : uint8_t {
enum monero_send_priority : uint8_t {
DEFAULT = 0,
UNIMPORTANT,
NORMAL,
@@ -313,10 +313,10 @@ namespace monero {
/**
* Configures a request to send/sweep funds or create a payment URI.
*/
struct MoneroSendRequest : public SerializableStruct {
vector<shared_ptr<MoneroDestination>> destinations;
struct monero_send_request : public serializable_struct {
vector<shared_ptr<monero_destination>> destinations;
boost::optional<string> paymentId;
boost::optional<MoneroSendPriority> priority;
boost::optional<monero_send_priority> priority;
boost::optional<uint32_t> mixin;
boost::optional<uint32_t> ringSize;
boost::optional<uint64_t> fee;
@@ -331,47 +331,47 @@ namespace monero {
boost::optional<bool> sweepEachSubaddress;
boost::optional<string> keyImage;
boost::property_tree::ptree toPropertyTree() const;
boost::property_tree::ptree to_property_tree() const;
};
/**
* Models results from importing key images.
*/
struct MoneroKeyImageImportResult : public SerializableStruct {
struct monero_key_image_import_result : public serializable_struct {
boost::optional<uint64_t> height;
boost::optional<uint64_t> spentAmount;
boost::optional<uint64_t> unspentAmount;
boost::property_tree::ptree toPropertyTree() const;
boost::property_tree::ptree to_property_tree() const;
};
/**
* Base class for results from checking a transaction or reserve proof.
*/
struct MoneroCheck : public SerializableStruct {
struct monero_check : public serializable_struct {
bool isGood;
boost::property_tree::ptree toPropertyTree() const;
boost::property_tree::ptree to_property_tree() const;
};
/**
* Results from checking a transaction key.
*/
struct MoneroCheckTx : public MoneroCheck {
struct monero_check_tx : public monero_check {
boost::optional<bool> inTxPool;
boost::optional<uint64_t> numConfirmations;
boost::optional<uint64_t> receivedAmount;
boost::property_tree::ptree toPropertyTree() const;
boost::property_tree::ptree to_property_tree() const;
};
/**
* Results from checking a reserve proof.
*/
struct MoneroCheckReserve : public MoneroCheck {
struct monero_check_reserve : public monero_check {
boost::optional<uint64_t> totalAmount;
boost::optional<uint64_t> unconfirmedSpentAmount;
boost::property_tree::ptree toPropertyTree() const;
boost::property_tree::ptree to_property_tree() const;
};
}
+22 -22
View File
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <iostream>
#include "wallet2.h"
#include "wallet/MoneroWallet.h"
#include "wallet/monero_wallet.h"
//#include <boost/stacktrace.hpp>
using namespace std;
@@ -13,14 +13,14 @@ bool walletExists(string path) {
return wallet_file_exists;
}
void openWallet(string path, string password, int networkType) {
cout << "openWallet(" << path << ", " << password << ", " << networkType << ")" << endl;
void open_wallet(string path, string password, int networkType) {
cout << "open_wallet(" << path << ", " << password << ", " << networkType << ")" << endl;
std::unique_ptr<tools::wallet2> wallet;
wallet.reset(new tools::wallet2(cryptonote::network_type::STAGENET, 1, true));
throw runtime_error("Not implemented");
}
void createWalletRandom(string language, int networkType) {
void create_wallet_random(string language, int networkType) {
tools::wallet2* wallet = new tools::wallet2(static_cast<cryptonote::network_type>(networkType), 1, true);
wallet->set_seed_language(language);
crypto::secret_key recovery_val, secret_key;
@@ -57,57 +57,57 @@ int main(int argc, const char* argv[]) {
MINFO("Wallet exists: " << walletExists(path));
// openWallet(path, password, networkType);
// createWalletRandom(language, networkType);
// open_wallet(path, password, networkType);
// create_wallet_random(language, networkType);
// // create wallet
// MoneroWallet* wallet = new MoneroWallet();
// monero_wallet* wallet = new monero_wallet();
//
// // get the mnemonic
// epee::wipeable_string mnemonic;
// wallet->getMnemonic(mnemonic);
// wallet->get_mnemonic(mnemonic);
// cout << "Mnemonic: " << string(mnemonic.data(), mnemonic.size()) << endl;
// load wallet
MoneroWallet* wallet = MoneroWallet::openWallet("../../test_wallets/test_wallet_1", "supersecretpassword123", MoneroNetworkType::STAGENET);
wallet->setDaemonConnection("http://localhost:38081", "", "");
monero_wallet* wallet = monero_wallet::open_wallet("../../test_wallets/test_wallet_1", "supersecretpassword123", MoneroNetworkType::STAGENET);
wallet->set_daemon_connection("http://localhost:38081", "", "");
// fetch txs
vector<shared_ptr<MoneroTxWallet>> txs = wallet->getTxs();
vector<shared_ptr<monero_tx_wallet>> txs = wallet->get_txs();
MINFO("Wallet has " << txs.size() << " txs. Printing some.");
for (int i = 0; i < txs.size() && i < 10; i++) {
MINFO(txs[i]->serialize());
}
// shared_ptr<MoneroTransferRequest> transferRequest = shared_ptr<MoneroTransferRequest>(new MoneroTransferRequest());
// shared_ptr<monero_transfer_request> transferRequest = shared_ptr<monero_transfer_request>(new monero_transfer_request());
// transferRequest->accountIndex = 0;
// shared_ptr<MoneroTxRequest> txRequest = shared_ptr<MoneroTxRequest>(new MoneroTxRequest());
// shared_ptr<monero_tx_request> txRequest = shared_ptr<monero_tx_request>(new monero_tx_request());
// txRequest->isConfirmed = true;
// transferRequest->txRequest = txRequest;
// //txRequest->transferRequest = transferRequest;
// vector<shared_ptr<MoneroTransfer>> transfers = wallet->getTransfers(*transferRequest);
// vector<shared_ptr<monero_transfer>> transfers = wallet->get_transfers(*transferRequest);
// if (transfers.empty()) throw runtime_error("Transfers should not be empty");
// for (const shared_ptr<MoneroTransfer>& transfer : transfers) {
// for (const shared_ptr<monero_transfer>& transfer : transfers) {
// if (*transfer->accountIndex != 0) throw runtime_error("Account should be 0");
// if (!*transfer->tx->isConfirmed) throw runtime_error("Transfer should be confirmed");
// }
// shared_ptr<MoneroTxRequest> txRequest = shared_ptr<MoneroTxRequest>(new MoneroTxRequest());
// shared_ptr<monero_tx_request> txRequest = shared_ptr<monero_tx_request>(new monero_tx_request());
// txRequest->isConfirmed = true;
// vector<shared_ptr<MoneroTxWallet>> txs = wallet->getTxs(*txRequest);
// vector<shared_ptr<monero_tx_wallet>> txs = wallet->get_txs(*txRequest);
// if (txs.empty()) throw runtime_error("Txs should not be empty");
// for (const shared_ptr<MoneroTxWallet>& tx : txs) {
// for (const shared_ptr<monero_tx_wallet>& tx : txs) {
// if (!*tx->isConfirmed) throw runtime_error("Tx should be confirmed");
// }
// // debug simple block merging
// vector<shared_ptr<MoneroTxWallet>> txs = wallet->getTxs();
// vector<shared_ptr<monero_tx_wallet>> txs = wallet->get_txs();
// if (txs.empty()) throw runtime_error("Txs should not be empty");
// shared_ptr<MoneroBlock> block = nullptr;
// for (const shared_ptr<MoneroTxWallet>& tx : txs) {
// if (tx->getHeight().get() != 360559l) throw runtime_error("Anything other than 360559l should be filtered");
// shared_ptr<monero_block> block = nullptr;
// for (const shared_ptr<monero_tx_wallet>& tx : txs) {
// if (tx->get_height().get() != 360559l) throw runtime_error("Anything other than 360559l should be filtered");
// cout << "We have one!!!" << endl;
// if (block == nullptr) block = tx->block.get();
// else {