convert couts to logging

This commit is contained in:
woodser
2019-07-26 15:22:23 -04:00
parent 06c6f4ac27
commit c328b1cb98
5 changed files with 81 additions and 208 deletions
-6
View File
@@ -86,7 +86,6 @@ namespace monero {
// ------------------------- MONERO BLOCK HEADER ----------------------------
boost::property_tree::ptree MoneroBlockHeader::toPropertyTree() const {
//cout << "MoneroBlockHeader::toPropertyTree(block)" << endl;
boost::property_tree::ptree node;
if (id != boost::none) node.put("id", *id);
if (height != boost::none) node.put("height", *height);
@@ -135,7 +134,6 @@ namespace monero {
// ----------------------------- MONERO BLOCK -------------------------------
boost::property_tree::ptree MoneroBlock::toPropertyTree() const {
//cout << "MoneroBlock::toPropertyTree(block)" << endl;
boost::property_tree::ptree node = MoneroBlockHeader::toPropertyTree();
if (hex != boost::none) node.put("hex", *hex);
if (coinbaseTx != boost::none) node.add_child("coinbaseTx", (*coinbaseTx)->toPropertyTree());
@@ -178,7 +176,6 @@ namespace monero {
// ------------------------------- MONERO TX --------------------------------
boost::property_tree::ptree MoneroTx::toPropertyTree() const {
//cout << "MoneroTx::txToPropertyTree(tx)" << endl;
boost::property_tree::ptree node;
if (id != boost::none) node.put("id", *id);
if (version != boost::none) node.put("version", *version);
@@ -357,7 +354,6 @@ namespace monero {
// --------------------------- MONERO KEY IMAGE -----------------------------
boost::property_tree::ptree MoneroKeyImage::toPropertyTree() const {
//cout << "MoneroKeyImage::toPropertyTree(tx)" << endl;
boost::property_tree::ptree node;
if (hex != boost::none) node.put("hex", *hex);
if (signature != boost::none) node.put("signature", *signature);
@@ -365,14 +361,12 @@ namespace monero {
}
void MoneroKeyImage::merge(const shared_ptr<MoneroKeyImage>& self, const shared_ptr<MoneroKeyImage>& other) {
cout << "MoneroKeyImage::merge()" << endl;
throw runtime_error("Not implemented");
}
// ------------------------------ MONERO OUTPUT -----------------------------
boost::property_tree::ptree MoneroOutput::toPropertyTree() const {
//cout << "MoneroOutput::toPropertyTree(tx)" << endl;
boost::property_tree::ptree node;
if (keyImage != boost::none) node.add_child("keyImage", (*keyImage)->toPropertyTree());
if (amount != boost::none) node.put("amount", *amount);
+3 -45
View File
@@ -74,7 +74,6 @@ void nodeToTransfer(const boost::property_tree::ptree& node, shared_ptr<MoneroTr
// initialize transfer from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Transfer node key: " << key << endl;
if (key == string("accountIndex")) transfer->accountIndex = it->second.get_value<uint32_t>();
}
}
@@ -86,7 +85,6 @@ shared_ptr<MoneroTransferRequest> nodeToTransferRequest(const boost::property_tr
// initialize request from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Transfer request node key: " << key << endl;
if (key == string("isIncoming")) transferRequest->isIncoming = stringToBool(it->second.data());
else if (key == string("address")) transferRequest->address = it->second.data();
else if (key == string("addresses")) throw runtime_error("addresses not implemented");
@@ -110,7 +108,6 @@ shared_ptr<MoneroKeyImage> nodeToKeyImage(const boost::property_tree::ptree& nod
shared_ptr<MoneroKeyImage> keyImage = shared_ptr<MoneroKeyImage>(new MoneroKeyImage());
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
//cout << "Key image node key: " << key << endl;
if (key == string("hex")) keyImage->hex = it->second.data();
else if (key == string("signature")) keyImage->signature = it->second.data();
}
@@ -119,18 +116,10 @@ shared_ptr<MoneroKeyImage> nodeToKeyImage(const boost::property_tree::ptree& nod
}
void nodeToOutput(const boost::property_tree::ptree& node, shared_ptr<MoneroOutput> output) {
cout << "nodeToOutput()" << endl;
// // print for debug
// std::stringstream ss;
// boost::property_tree::write_json(ss, node, false);
// string receivedNode = ss.str();
// cout << "Received node: " << receivedNode << endl;
// initialize output from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Output node key: " << key << endl;
if (key == string("keyImage")) output->keyImage = nodeToKeyImage(it->second);
else if (key == string("amount")) output->amount = it->second.get_value<uint64_t>();
else if (key == string("index")) output->index = it->second.get_value<uint32_t>();
@@ -143,7 +132,6 @@ void nodeToOutputWallet(const boost::property_tree::ptree& node, shared_ptr<Mone
nodeToOutput(node, outputWallet);
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Output wallet node key: " << key << endl;
if (key == string("accountIndex")) outputWallet->accountIndex = it->second.get_value<uint32_t>();
else if (key == string("subaddressIndex")) outputWallet->subaddressIndex = it->second.get_value<uint32_t>();
else if (key == string("isSpent")) outputWallet->isSpent = stringToBool(it->second.data());
@@ -159,7 +147,6 @@ shared_ptr<MoneroOutputRequest> nodeToOutputRequest(const boost::property_tree::
// initialize request from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Output request node key: " << key << endl;
if (key == string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) outputRequest->subaddressIndices.push_back(it2->second.get_value<uint32_t>());
else if (key == string("txRequest")) {} // ignored
}
@@ -168,18 +155,10 @@ shared_ptr<MoneroOutputRequest> nodeToOutputRequest(const boost::property_tree::
}
void nodeToTx(const boost::property_tree::ptree& node, shared_ptr<MoneroTx> tx) {
cout << "nodeToTx()" << endl;
// // print for debug
// std::stringstream ss;
// boost::property_tree::write_json(ss, node, false);
// string receivedNode = ss.str();
// cout << "Received node: " << receivedNode << endl;
// initialize tx from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Tx node key: " << key << endl;
if (key == string("id")) tx->id = it->second.data();
else if (key == string("version")) throw runtime_error("version deserializationn not implemented");
else if (key == string("isCoinbase")) tx->isCoinbase = stringToBool(it->second.data());
@@ -220,12 +199,12 @@ 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) {
nodeToTx(node, txWallet);
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Tx wallet node key: " << key << endl;
//if (key == string("id")) tx->id = it->second.data();
}
}
@@ -237,7 +216,6 @@ shared_ptr<MoneroTxRequest> nodeToTxRequest(const boost::property_tree::ptree& n
// initialize request from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Tx request node key: " << key << endl;
if (key == string("isOutgoing")) txRequest->isOutgoing = stringToBool(it->second.data());
else if (key == string("isIncoming")) txRequest->isIncoming = stringToBool(it->second.data());
else if (key == string("txIds")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) txRequest->txIds.push_back(it2->second.data());
@@ -255,11 +233,9 @@ shared_ptr<MoneroTxRequest> nodeToTxRequest(const boost::property_tree::ptree& n
}
shared_ptr<MoneroBlock> nodeToBlockRequest(const boost::property_tree::ptree& node) {
cout << "nodeToBlockRequest()" << endl;
shared_ptr<MoneroBlock> block = shared_ptr<MoneroBlock>(new MoneroBlock());
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Block node key: " << key << endl;
if (key == string("height")) block->height = (uint64_t) 7; // TODO
else if (key == string("txs")) {
boost::property_tree::ptree txsNode = it->second;
@@ -272,11 +248,9 @@ shared_ptr<MoneroBlock> nodeToBlockRequest(const boost::property_tree::ptree& no
}
shared_ptr<MoneroDestination> nodeToDestination(const boost::property_tree::ptree& node) {
cout << "nodeToDestination()" << endl;
shared_ptr<MoneroDestination> destination = shared_ptr<MoneroDestination>(new MoneroDestination());
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Destination node key: " << key << endl;
if (key == string("address")) destination->address = it->second.data();
else if (key == string("amount")) destination->amount = it->second.get_value<uint64_t>();
}
@@ -329,7 +303,7 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
// add tx node to txs node
boost::property_tree::ptree txNode;
//std::cout << "PRUNED:\n" << MoneroUtils::get_pruned_tx_json(tx) << "\n";
MTRACE("PRUNED:\n" << MoneroUtils::get_pruned_tx_json(tx));
txNode.put("", MoneroUtils::get_pruned_tx_json(tx)); // TODO: no pretty print
txsNode.push_back(std::make_pair("", txNode));
} else {
@@ -350,7 +324,6 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
}
shared_ptr<MoneroTxRequest> MoneroUtils::deserializeTxRequest(const string& txRequestStr) {
cout << "deserializeTxRequest(): " << txRequestStr << endl;
// deserialize tx request string to property rooted at block
std::istringstream iss = txRequestStr.empty() ? std::istringstream() : std::istringstream(txRequestStr);
@@ -363,14 +336,11 @@ shared_ptr<MoneroTxRequest> MoneroUtils::deserializeTxRequest(const string& txRe
// get tx request
shared_ptr<MoneroTxRequest> txRequest = static_pointer_cast<MoneroTxRequest>(block->txs[0]);
cout << "Returning deserialized tx request" << endl;
// return deserialized request
return txRequest;
}
shared_ptr<MoneroTransferRequest> MoneroUtils::deserializeTransferRequest(const string& transferRequestStr) {
cout << "deserializeTransferRequest(): " << transferRequestStr << endl;
// deserialize transfer request string to property rooted at block
std::istringstream iss = transferRequestStr.empty() ? std::istringstream() : std::istringstream(transferRequestStr);
@@ -393,14 +363,11 @@ shared_ptr<MoneroTransferRequest> MoneroUtils::deserializeTransferRequest(const
transferRequest->txRequest = txRequest;
txRequest->transferRequest = boost::none;
cout << "Returning deserialized transfer request" << endl;
// return deserialized request
return transferRequest;
}
shared_ptr<MoneroOutputRequest> MoneroUtils::deserializeOutputRequest(const string& outputRequestStr) {
cout << "deserializeOutputRequest(): " << outputRequestStr << endl;
// deserialize output request string to property rooted at block
std::istringstream iss = outputRequestStr.empty() ? std::istringstream() : std::istringstream(outputRequestStr);
@@ -423,15 +390,11 @@ shared_ptr<MoneroOutputRequest> MoneroUtils::deserializeOutputRequest(const stri
outputRequest->txRequest = txRequest;
txRequest->outputRequest = boost::none;
//cout << block->serialize() << endl;
cout << "Returning deserialized output request" << endl;
// return deserialized request
return outputRequest;
}
shared_ptr<MoneroSendRequest> MoneroUtils::deserializeSendRequest(const string& sendRequestStr) {
cout << "deserializeSendRequest(): " << sendRequestStr << endl;
// deserialize send request json to property node
std::istringstream iss = sendRequestStr.empty() ? std::istringstream() : std::istringstream(sendRequestStr);
@@ -442,7 +405,6 @@ shared_ptr<MoneroSendRequest> MoneroUtils::deserializeSendRequest(const string&
shared_ptr<MoneroSendRequest> sendRequest = shared_ptr<MoneroSendRequest>(new MoneroSendRequest());
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
cout << "Send request node key: " << key << endl;
if (key == string("destinations")) {
boost::property_tree::ptree destinationsNode = it->second;
for (boost::property_tree::ptree::const_iterator it2 = destinationsNode.begin(); it2 != destinationsNode.end(); ++it2) {
@@ -466,7 +428,6 @@ shared_ptr<MoneroSendRequest> MoneroUtils::deserializeSendRequest(const string&
else if (key == string("keyImage")) sendRequest->keyImage = it->second.data();
}
cout << "Returning deserialized send request" << endl;
return sendRequest;
}
@@ -481,13 +442,12 @@ vector<shared_ptr<MoneroKeyImage>> MoneroUtils::deserializeKeyImages(const strin
vector<shared_ptr<MoneroKeyImage>> keyImages;
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
string key = it->first;
//cout << "deserializeKeyImage() key: " << key << endl;
if (key == string("keyImages")) {
for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
keyImages.push_back(nodeToKeyImage(it2->second));
}
}
else cout << "WARNING MoneroWalletJni::deserializeKeyImages() unrecognized key: " << key << endl;
else MWARNING("WARNING MoneroWalletJni::deserializeKeyImages() unrecognized key: " << key);
}
return keyImages;
}
@@ -500,7 +460,6 @@ string MoneroUtils::serialize(const boost::property_tree::ptree& node) {
}
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<string> strs) {
//cout << "toPropertyTree(strs)" << endl;
boost::property_tree::ptree strsNode;
for (const auto& str : strs) {
boost::property_tree::ptree strNode;
@@ -511,7 +470,6 @@ boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<string> str
}
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint32_t> nums) {
//cout << "toPropertyTree(nums)" << endl;
boost::property_tree::ptree numsNode;
for (const auto& num : nums) {
boost::property_tree::ptree numNode;
+76 -104
View File
@@ -87,7 +87,6 @@ namespace monero {
}
shared_ptr<MoneroTxWallet> buildTxWithIncomingTransfer(const tools::wallet2& wallet2, uint64_t height, const crypto::hash &payment_id, const tools::wallet2::payment_details &pd) {
//cout << "buildTxWithIncomingTransfer()" << endl;
// construct block
shared_ptr<MoneroBlock> block = shared_ptr<MoneroBlock>(new MoneroBlock());
@@ -139,7 +138,6 @@ namespace monero {
}
shared_ptr<MoneroTxWallet> buildTxWithOutgoingTransfer(const tools::wallet2& wallet2, uint64_t height, const crypto::hash &txid, const tools::wallet2::confirmed_transfer_details &pd) {
//cout << "buildTxWithOutgoingTransfer()" << endl;
// construct block
shared_ptr<MoneroBlock> block = shared_ptr<MoneroBlock>(new MoneroBlock());
@@ -212,7 +210,6 @@ namespace monero {
}
shared_ptr<MoneroTxWallet> buildTxWithIncomingTransferUnconfirmed(const tools::wallet2& wallet2, const crypto::hash &payment_id, const tools::wallet2::pool_payment_details &ppd) {
//cout << "buildTxWithIncomingTransferUnconfirmed()" << endl;
// construct tx
const tools::wallet2::payment_details &pd = ppd.m_pd;
@@ -253,7 +250,6 @@ namespace monero {
}
shared_ptr<MoneroTxWallet> buildTxWithOutgoingTransferUnconfirmed(const tools::wallet2& wallet2, const crypto::hash &txid, const tools::wallet2::unconfirmed_transfer_details &pd) {
//cout << "buildTxWithOutgoingTransferUnconfirmed()" << endl;
// construct tx
shared_ptr<MoneroTxWallet> tx = shared_ptr<MoneroTxWallet>(new MoneroTxWallet());
@@ -372,7 +368,7 @@ namespace monero {
if (!skipIfAbsent) {
txMap[*tx->id] = tx;
} else {
cout << "WARNING: tx does not already exist" << endl; // TODO: proper logging
MWARNING("WARNING: tx does not already exist");
}
}
@@ -653,7 +649,7 @@ namespace monero {
}
~Wallet2Listener() {
cout << "~Wallet2Listener()" << endl;
MTRACE("~Wallet2Listener()");
}
void setWalletListener(boost::optional<MoneroWalletListener&> listener) {
@@ -696,12 +692,12 @@ namespace monero {
}
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time) {
//cout << "Wallet2Listener::on_money_received()" << endl;
//MTRACE("Wallet2Listener::on_money_received()");
//throw runtime_error("Not implemented");
}
virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index) {
// cout << "Wallet2Listener::on_money_spent()" << endl;
// MTRACE("Wallet2Listener::on_money_spent()")
// // TODO;
// std::string tx_hash = epee::string_tools::pod_to_hex(txid);
// LOG_PRINT_L3(__FUNCTION__ << ": money spent. height: " << height
@@ -747,12 +743,12 @@ namespace monero {
}
MoneroWallet::MoneroWallet(const string& path, const string& password) {
cout << "MoneroWallet()" << endl;
MTRACE("MoneroWallet()");
throw runtime_error("Not implemented");
}
MoneroWallet::MoneroWallet(const string& path, const string&password, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, const string& language) {
cout << "MoneroWallet(3)" << endl;
MTRACE("MoneroWallet(3)");
wallet2 = unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<network_type>(networkType), 1, true));
setDaemonConnection(daemonConnection);
wallet2->set_seed_language(language);
@@ -780,7 +776,7 @@ namespace monero {
}
MoneroWallet::MoneroWallet(const string& path, const string& password, const string& address, const string& viewKey, const string& spendKey, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, uint64_t restoreHeight, const string& language) {
cout << "MoneroWallet(7)" << endl;
MTRACE("MoneroWallet(7)");
// validate and parse address
cryptonote::address_parse_info info;
@@ -836,12 +832,12 @@ namespace monero {
}
MoneroWallet::~MoneroWallet() {
cout << "~MoneroWallet()" << endl;
MTRACE("~MoneroWallet()");
close();
}
void MoneroWallet::setDaemonConnection(const string& uri, const string& username, const string& password) {
cout << "setDaemonConnection(" << uri << ", " << username << ", " << password << ")" << endl;
MTRACE("setDaemonConnection(" << uri << ", " << username << ", " << password << ")");
// prepare uri, login, and isTrusted for wallet2
boost::optional<epee::net_utils::http::login> login{};
@@ -860,7 +856,7 @@ namespace monero {
}
shared_ptr<MoneroRpcConnection> MoneroWallet::getDaemonConnection() const {
cout << "MoneroWallet::getDaemonConnection()" << endl;
MTRACE("MoneroWallet::getDaemonConnection()");
if (wallet2->get_daemon_address().empty()) return nullptr;
shared_ptr<MoneroRpcConnection> connection = shared_ptr<MoneroRpcConnection>(new MoneroRpcConnection());
if (!wallet2->get_daemon_address().empty()) connection->uri = wallet2->get_daemon_address();
@@ -934,7 +930,7 @@ namespace monero {
}
MoneroSubaddress MoneroWallet::getAddressIndex(const string& address) const {
cout << "getAddressIndex(" << address << ")" << endl;
MTRACE("getAddressIndex(" << address << ")");
// validate address
cryptonote::address_parse_info info;
@@ -955,7 +951,7 @@ namespace monero {
}
MoneroIntegratedAddress MoneroWallet::getIntegratedAddress(const string& standardAddress, const string& paymentId) const {
cout << "getIntegratedAddress(" << standardAddress << ", " << paymentId << ")" << endl;
MTRACE("getIntegratedAddress(" << standardAddress << ", " << paymentId << ")");
// TODO monero-core: this logic is based on wallet_rpc_server::on_make_integrated_address() and should be moved to wallet so this is unecessary for api users
@@ -985,7 +981,7 @@ namespace monero {
}
MoneroIntegratedAddress MoneroWallet::decodeIntegratedAddress(const string& integratedAddress) const {
cout << "decodeIntegratedAddress(" << integratedAddress << ")" << endl;
MTRACE("decodeIntegratedAddress(" << integratedAddress << ")");
// validate integrated address
cryptonote::address_parse_info info;
@@ -1007,47 +1003,47 @@ namespace monero {
}
string MoneroWallet::getPublicViewKey() const {
cout << "getPrivateViewKey()" << endl;
MTRACE("getPrivateViewKey()");
return epee::string_tools::pod_to_hex(wallet2->get_account().get_keys().m_account_address.m_view_public_key);
}
string MoneroWallet::getPrivateViewKey() const {
cout << "getPrivateViewKey()" << endl;
MTRACE("getPrivateViewKey()");
return epee::string_tools::pod_to_hex(wallet2->get_account().get_keys().m_view_secret_key);
}
string MoneroWallet::getPublicSpendKey() const {
cout << "getPrivateSpendKey()" << endl;
MTRACE("getPrivateSpendKey()");
return epee::string_tools::pod_to_hex(wallet2->get_account().get_keys().m_account_address.m_spend_public_key);
}
string MoneroWallet::getPrivateSpendKey() const {
cout << "getPrivateSpendKey()" << endl;
MTRACE("getPrivateSpendKey()");
return epee::string_tools::pod_to_hex(wallet2->get_account().get_keys().m_spend_secret_key);
}
void MoneroWallet::setListener(boost::optional<MoneroWalletListener&> listener) {
cout << "setListener()" << endl;
MTRACE("setListener()");
wallet2Listener->setWalletListener(listener);
}
MoneroSyncResult MoneroWallet::sync() {
cout << "sync()" << endl;
MTRACE("sync()");
return lockAndSync();
}
MoneroSyncResult MoneroWallet::sync(MoneroSyncListener& listener) {
cout << "sync(listener)" << endl;
MTRACE("sync(listener)");
return lockAndSync(boost::none, listener);
}
MoneroSyncResult MoneroWallet::sync(uint64_t startHeight) {
cout << "sync(startHeight)" << endl;
MTRACE("sync(" << startHeight << ")");
return lockAndSync(startHeight);
}
MoneroSyncResult MoneroWallet::sync(uint64_t startHeight, MoneroSyncListener& listener) {
cout << "sync(startHeight, listener)" << endl;
MTRACE("sync(" << startHeight << ", listener)");
return lockAndSync(startHeight, listener);
}
@@ -1072,7 +1068,7 @@ namespace monero {
// TODO: support arguments bool hard, bool refresh = true, bool keep_key_images = false
void MoneroWallet::rescanBlockchain() {
cout << "rescanBlockchain()" << endl;
MTRACE("rescanBlockchain()");
rescanOnSync = true;
lockAndSync();
}
@@ -1128,22 +1124,22 @@ namespace monero {
}
vector<MoneroAccount> MoneroWallet::getAccounts() const {
cout << "getAccounts()" << endl;
MTRACE("getAccounts()");
return getAccounts(false, string(""));
}
vector<MoneroAccount> MoneroWallet::getAccounts(const bool includeSubaddresses) const {
cout << "getAccounts(" << includeSubaddresses << ")" << endl;
MTRACE("getAccounts(" << includeSubaddresses << ")");
throw runtime_error("Not implemented");
}
vector<MoneroAccount> MoneroWallet::getAccounts(const string& tag) const {
cout << "getAccounts(" << tag << ")" << endl;
MTRACE("getAccounts(" << tag << ")");
throw runtime_error("Not implemented");
}
vector<MoneroAccount> MoneroWallet::getAccounts(const bool includeSubaddresses, const string& tag) const {
cout << "getAccounts(" << includeSubaddresses << ", " << tag << ")" << endl;
MTRACE("getAccounts(" << includeSubaddresses << ", " << tag << ")");
// need transfers to inform if subaddresses used
vector<tools::wallet2::transfer_details> transfers;
@@ -1169,7 +1165,7 @@ namespace monero {
}
MoneroAccount MoneroWallet::getAccount(uint32_t accountIdx, const bool includeSubaddresses) const {
cout << "getAccount(" << accountIdx << ", " << includeSubaddresses << ")" << endl;
MTRACE("getAccount(" << accountIdx << ", " << includeSubaddresses << ")");
// need transfers to inform if subaddresses used
vector<tools::wallet2::transfer_details> transfers;
@@ -1186,7 +1182,7 @@ namespace monero {
}
MoneroAccount MoneroWallet::createAccount(const string& label) {
cout << "createAccount(" << label << ")" << endl;
MTRACE("createAccount(" << label << ")");
// create account
wallet2->add_subaddress_account(label);
@@ -1207,10 +1203,8 @@ namespace monero {
}
vector<MoneroSubaddress> MoneroWallet::getSubaddresses(const uint32_t accountIdx, const vector<uint32_t> subaddressIndices) const {
cout << "getSubaddresses(" << accountIdx << ", ...)" << endl;
cout << "Subaddress indices size: " << subaddressIndices.size();
if (subaddressIndices.size() > 0) cout << ", First element: " << subaddressIndices.at(0) << endl;
else cout << endl;
MTRACE("getSubaddresses(" << accountIdx << ", ...)");
MTRACE("Subaddress indices size: " << subaddressIndices.size());
vector<tools::wallet2::transfer_details> transfers;
wallet2->get_transfers(transfers);
@@ -1224,7 +1218,7 @@ namespace monero {
// getSubaddresses
MoneroSubaddress MoneroWallet::createSubaddress(const uint32_t accountIdx, const string& label) {
cout << "createSubaddress(" << accountIdx << ", " << label << ")" << endl;
MTRACE("createSubaddress(" << accountIdx << ", " << label << ")");
// create subaddress
wallet2->add_subaddress(accountIdx, label);
@@ -1249,11 +1243,11 @@ namespace monero {
}
vector<shared_ptr<MoneroTxWallet>> MoneroWallet::getTxs(MoneroTxRequest& request) const {
cout << "getTxs(request)" << endl;
MTRACE("getTxs(request)");
// print request
cout << "Tx request: " << request.serialize() << endl;
if (request.block != boost::none) cout << "Tx request's rooted at [block]: " << request.block.get()->serialize() << endl;
if (request.block != boost::none) MTRACE("Tx request's rooted at [block]: " << request.block.get()->serialize());
else MTRACE("Tx request: " << request.serialize());
// normalize request
// TODO: this modifies original request so given req cannot be constant, make given request constant
@@ -1353,25 +1347,19 @@ namespace monero {
}
vector<shared_ptr<MoneroTransfer>> MoneroWallet::getTransfers(const MoneroTransferRequest& request) const {
cout << "MoneroWallet::getTransfers(request)" << endl;
MTRACE("MoneroWallet::getTransfers(request)");
//cout << "1" << endl;
// print request
cout << "Transfer request: " << request.serialize() << endl;
// LOG request
MTRACE("Transfer request: " << request.serialize());
if (request.txRequest != boost::none) {
if ((*request.txRequest)->block == boost::none) cout << "Transfer request's tx request rooted at [tx]:" << (*request.txRequest)->serialize() << endl;
else cout << "Transfer request's tx request rooted at [block]: " << (*(*request.txRequest)->block)->serialize() << endl;
if ((*request.txRequest)->block == boost::none) MTRACE("Transfer request's tx request rooted at [tx]:" << (*request.txRequest)->serialize());
else MTRACE("Transfer request's tx request rooted at [block]: " << (*(*request.txRequest)->block)->serialize());
}
// normalize request
// TODO: this will modify original request, construct copy? add test
MoneroTxRequest txReq = *(request.txRequest != boost::none ? *request.txRequest : shared_ptr<MoneroTxRequest>(new MoneroTxRequest()));
// print request
//cout << "Tx request: " << txReq.serialize() << endl;
//cout << "2" << endl;
// build parameters for wallet2->get_payments()
uint64_t minHeight = txReq.minHeight == boost::none ? 0 : *txReq.minHeight;
uint64_t maxHeight = txReq.maxHeight == boost::none ? CRYPTONOTE_MAX_BLOCK_NUMBER : min((uint64_t) CRYPTONOTE_MAX_BLOCK_NUMBER, *txReq.maxHeight);
@@ -1383,8 +1371,6 @@ namespace monero {
subaddressIndices.insert(request.subaddressIndices[i]);
}
//cout << "3" << endl;
// translate from MoneroTxRequest to in, out, pending, pool, failed terminology used by monero-wallet-rpc
bool canBeConfirmed = !boolEquals(false, txReq.isConfirmed) && !boolEquals(true, txReq.inTxPool) && !boolEquals(true, txReq.isFailed) && !boolEquals(false, txReq.isRelayed);
bool canBeInTxPool = !boolEquals(true, txReq.isConfirmed) && !boolEquals(false, txReq.inTxPool) && !boolEquals(true, txReq.isFailed) && !boolEquals(false, txReq.isRelayed) && txReq.getHeight() == boost::none && txReq.minHeight == boost::none;
@@ -1396,8 +1382,6 @@ namespace monero {
bool isPool = canBeIncoming && canBeInTxPool;
bool isFailed = !boolEquals(false, txReq.isFailed) && !boolEquals(true, txReq.isConfirmed) && !boolEquals(true, txReq.inTxPool);
//cout << "4" << endl;
// cache unique txs and blocks
uint64_t height = getHeight();
map<string, shared_ptr<MoneroTxWallet>> txMap;
@@ -1413,8 +1397,6 @@ namespace monero {
}
}
//cout << "5" << endl;
// get confirmed outgoing transfers
if (isOut) {
std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> payments;
@@ -1425,8 +1407,6 @@ namespace monero {
}
}
//cout << "6" << endl;
// get unconfirmed or failed outgoing transfers
if (isPending || isFailed) {
std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>> upayments;
@@ -1438,8 +1418,6 @@ namespace monero {
}
}
//cout << "7" << endl;
// get unconfirmed incoming transfers
if (isPool) {
wallet2->update_pool_state(); // TODO monero-core: this should be encapsulated in wallet when unconfirmed transfers requested
@@ -1451,8 +1429,6 @@ namespace monero {
}
}
//cout << "8" << endl;
// sort txs by block height
vector<shared_ptr<MoneroTxWallet>> txs ;
for (map<string, shared_ptr<MoneroTxWallet>>::const_iterator txIter = txMap.begin(); txIter != txMap.end(); txIter++) {
@@ -1487,20 +1463,19 @@ namespace monero {
tx->block.get()->txs.erase(std::remove(tx->block.get()->txs.begin(), tx->block.get()->txs.end(), tx), tx->block.get()->txs.end()); // TODO, no way to use const_iterator?
}
}
//cout << "9" << endl;
cout << "MoneroWallet.cpp getTransfers() returning " << transfers.size() << " transfers" << endl;
MTRACE("MoneroWallet.cpp getTransfers() returning " << transfers.size() << " transfers");
return transfers;
}
vector<shared_ptr<MoneroOutputWallet>> MoneroWallet::getOutputs(const MoneroOutputRequest& request) const {
cout << "MoneroWallet::getOutputs(request)" << endl;
MTRACE("MoneroWallet::getOutputs(request)");
// print request
cout << "Output request: " << request.serialize() << endl;
MTRACE("Output request: " << request.serialize());
if (request.txRequest != boost::none) {
if ((*request.txRequest)->block == boost::none) cout << "Output request's tx request rooted at [tx]:" << (*request.txRequest)->serialize() << endl;
else cout << "Output request's tx request rooted at [block]: " << (*(*request.txRequest)->block)->serialize() << endl;
if ((*request.txRequest)->block == boost::none) MTRACE("Output request's tx request rooted at [tx]:" << (*request.txRequest)->serialize());
else MTRACE("Output request's tx request rooted at [block]: " << (*(*request.txRequest)->block)->serialize());
}
// normalize request
@@ -1558,7 +1533,7 @@ namespace monero {
}
vector<shared_ptr<MoneroKeyImage>> MoneroWallet::getKeyImages() const {
cout << "MoneroWallet::getKeyImages()" << endl;
MTRACE("MoneroWallet::getKeyImages()");
// build key images from wallet2 types
vector<shared_ptr<MoneroKeyImage>> keyImages;
@@ -1573,7 +1548,7 @@ namespace monero {
}
shared_ptr<MoneroKeyImageImportResult> MoneroWallet::importKeyImages(const vector<shared_ptr<MoneroKeyImage>>& keyImages) {
cout << "MoneroWallet::importKeyImages()" << endl;
MTRACE("MoneroWallet::importKeyImages()");
// validate and prepare key images for wallet2
std::vector<std::pair<crypto::key_image, crypto::signature>> ski;
@@ -1600,8 +1575,8 @@ namespace monero {
}
vector<shared_ptr<MoneroTxWallet>> MoneroWallet::sendSplit(const MoneroSendRequest& request) {
cout << "MoneroWallet::sendSplit(request)" << endl;
cout << "MoneroSendRequest: " << request.serialize() << endl;
MTRACE("MoneroWallet::sendSplit(request)");
MTRACE("MoneroSendRequest: " << request.serialize());
wallet_rpc::COMMAND_RPC_TRANSFER::request req;
wallet_rpc::COMMAND_RPC_TRANSFER::response res;
@@ -1635,7 +1610,6 @@ namespace monero {
// prepare transactions
vector<wallet2::pending_tx> ptx_vector = wallet2->create_transactions_2(dsts, mixin, unlockTime, priority, extra, accountIndex, subaddressIndices);
cout << "CREATED " << ptx_vector.size() << " PENDING TXS" << endl;
if (ptx_vector.empty()) throw runtime_error("No transaction created");
// check if request cannot be fulfilled due to splitting
@@ -1648,7 +1622,6 @@ namespace monero {
bool getTxHex = true;
bool getTxMetadata = true;
bool doNotRelay = request.doNotRelay == boost::none ? false : request.doNotRelay.get();
cout << "doNotRelay: " << doNotRelay << endl;
// commit txs (if relaying) and get response using wallet rpc's fill_response()
list<string> txKeys;
@@ -1714,8 +1687,8 @@ namespace monero {
}
shared_ptr<MoneroTxWallet> MoneroWallet::sweepOutput(const MoneroSendRequest& request) const {
cout << "sweepOutput()" << endl;
cout << "MoneroSendRequest: " << request.serialize() << endl;
MTRACE("sweepOutput()");
MTRACE("MoneroSendRequest: " << request.serialize());
// validate input request
if (request.keyImage == boost::none || request.keyImage.get().empty()) throw runtime_error("Must provide key image of output to sweep");
@@ -1758,7 +1731,6 @@ namespace monero {
bool getTxHex = true;
bool getTxMetadata = true;
bool doNotRelay = request.doNotRelay == boost::none ? false : request.doNotRelay.get();
cout << "doNotRelay: " << doNotRelay << endl;
// commit txs (if relaying) and get response using wallet rpc's fill_response()
list<string> txKeys;
@@ -1828,7 +1800,7 @@ namespace monero {
}
vector<shared_ptr<MoneroTxWallet>> MoneroWallet::sweepDust(bool doNotRelay) {
cout << "MoneroWallet::sweepDust()" << endl;
MTRACE("MoneroWallet::sweepDust()");
// create transaction to fill
std::vector<wallet2::pending_tx> ptx_vector = wallet2->create_unmixable_sweep_transactions();
@@ -1901,7 +1873,7 @@ namespace monero {
}
vector<string> MoneroWallet::relayTxs(const vector<string>& txMetadatas) {
cout << "relayTxs()" << endl;
MTRACE("relayTxs()");
// relay each metadata as a tx
vector<string> txIds;
@@ -1939,7 +1911,7 @@ namespace monero {
}
string MoneroWallet::getTxNote(const string& txId) const {
cout << "MoneroWallet::getTxNote" << endl;
MTRACE("MoneroWallet::getTxNote()");
cryptonote::blobdata txBlob;
if (!epee::string_tools::parse_hexstr_to_binbuff(txId, txBlob) || txBlob.size() != sizeof(crypto::hash)) {
throw runtime_error("TX ID has invalid format");
@@ -1949,14 +1921,14 @@ namespace monero {
}
vector<string> MoneroWallet::getTxNotes(const vector<string>& txIds) const {
cout << "MoneroWallet::getTxNotes()" << endl;
MTRACE("MoneroWallet::getTxNotes()");
vector<string> txNotes;
for (const auto& txId : txIds) txNotes.push_back(getTxNote(txId));
return txNotes;
}
void MoneroWallet::setTxNote(const string& txId, const string& note) {
cout << "MoneroWallet::setTxNote" << endl;
MTRACE("MoneroWallet::setTxNote()");
cryptonote::blobdata txBlob;
if (!epee::string_tools::parse_hexstr_to_binbuff(txId, txBlob) || txBlob.size() != sizeof(crypto::hash)) {
throw runtime_error("TX ID has invalid format");
@@ -1966,7 +1938,7 @@ namespace monero {
}
void MoneroWallet::setTxNotes(const vector<string>& txIds, const vector<string>& txNotes) {
cout << "MoneroWallet::setTxNotes()" << endl;
MTRACE("MoneroWallet::setTxNotes()");
if (txIds.size() != txNotes.size()) throw runtime_error("Different amount of txids and notes");
for (int i = 0; i < txIds.size(); i++) {
setTxNote(txIds[i], txNotes[i]);
@@ -2003,7 +1975,7 @@ namespace monero {
}
string MoneroWallet::getTxKey(const string& txId) const {
cout << "MoneroWallet::getTxKey()" << endl;
MTRACE("MoneroWallet::getTxKey()");
// validate and parse tx id hash
crypto::hash txHash;
@@ -2028,7 +2000,7 @@ namespace monero {
}
shared_ptr<MoneroCheckTx> MoneroWallet::checkTxKey(const string& txId, const string& txKey, const string& address) const {
cout << "MoneroWallet::checkTxKey()" << endl;
MTRACE("MoneroWallet::checkTxKey()");
// validate and parse tx id
crypto::hash txHash;
@@ -2096,7 +2068,7 @@ namespace monero {
}
shared_ptr<MoneroCheckTx> MoneroWallet::checkTxProof(const string& txId, const string& address, const string& message, const string& signature) const {
cout << "MoneroWallet::checkTxProof()" << endl;
MTRACE("MoneroWallet::checkTxProof()");
// validate and parse tx id
crypto::hash txHash;
@@ -2125,7 +2097,7 @@ namespace monero {
}
string MoneroWallet::getSpendProof(const string& txId, const string& message) const {
cout << "MoneroWallet::getSpendProof()" << endl;
MTRACE("MoneroWallet::getSpendProof()");
// validate and parse tx id
crypto::hash txHash;
@@ -2138,7 +2110,7 @@ namespace monero {
}
bool MoneroWallet::checkSpendProof(const string& txId, const string& message, const string& signature) const {
cout << "MoneroWallet::checkSpendProof()" << endl;
MTRACE("MoneroWallet::checkSpendProof()");
// validate and parse tx id
crypto::hash txHash;
@@ -2151,13 +2123,13 @@ namespace monero {
}
string MoneroWallet::getReserveProofWallet(const string& message) const {
cout << "MoneroWallet::getReserveProofWallet()" << endl;
MTRACE("MoneroWallet::getReserveProofWallet()");
boost::optional<std::pair<uint32_t, uint64_t>> account_minreserve;
return wallet2->get_reserve_proof(account_minreserve, message);
}
string MoneroWallet::getReserveProofAccount(uint32_t accountIdx, uint64_t amount, const string& message) const {
cout << "MoneroWallet::getReserveProofAccount()" << endl;
MTRACE("MoneroWallet::getReserveProofAccount()");
boost::optional<std::pair<uint32_t, uint64_t>> account_minreserve;
if (accountIdx >= wallet2->get_num_subaddress_accounts()) throw runtime_error("Account index is out of bound");
account_minreserve = std::make_pair(accountIdx, amount);
@@ -2165,7 +2137,7 @@ namespace monero {
}
shared_ptr<MoneroCheckReserve> MoneroWallet::checkReserveProof(const string& address, const string& message, const string& signature) const {
cout << "MoneroWallet::checkReserveProof()" << endl;
MTRACE("MoneroWallet::checkReserveProof()");
// validate and parse input
cryptonote::address_parse_info info;
@@ -2185,7 +2157,7 @@ namespace monero {
}
string MoneroWallet::createPaymentUri(const MoneroSendRequest& request) const {
cout << "createPaymentUri()" << endl;
MTRACE("createPaymentUri()");
// validate request
if (request.destinations.size() != 1) throw runtime_error("Cannot make URI from supplied parameters: must provide exactly one destination to send funds");
@@ -2207,7 +2179,7 @@ namespace monero {
}
shared_ptr<MoneroSendRequest> MoneroWallet::parsePaymentUri(const string& uri) const {
cout << "parsePaymentUri(" << uri << ")" << endl;
MTRACE("parsePaymentUri(" << uri << ")");
// decode uri to parameters
string address;
@@ -2230,7 +2202,7 @@ namespace monero {
if (!paymentId.empty()) sendRequest->paymentId = paymentId;
if (!note.empty()) sendRequest->note = note;
if (!recipientName.empty()) sendRequest->recipientName = recipientName;
if (!unknownParameters.empty()) cout << "WARNING in MoneroWallet::parsePaymentUri: URI contains unknown parameters which are discarded" << endl; // TODO: return unknown parameters?
if (!unknownParameters.empty()) MWARNING("WARNING in MoneroWallet::parsePaymentUri: URI contains unknown parameters which are discarded"); // TODO: return unknown parameters?
return sendRequest;
}
@@ -2243,7 +2215,7 @@ namespace monero {
}
void MoneroWallet::startMining(boost::optional<uint64_t> numThreads, boost::optional<bool> backgroundMining, boost::optional<bool> ignoreBattery) {
cout << "startMining" << endl;
MTRACE("startMining()");
// only mine on trusted daemon
if (!wallet2->is_trusted_daemon()) throw runtime_error("This command requires a trusted daemon.");
@@ -2273,7 +2245,7 @@ namespace monero {
}
void MoneroWallet::stopMining() {
cout << "stopMining()" << endl;
MTRACE("stopMining()");
cryptonote::COMMAND_RPC_STOP_MINING::request daemon_req;
cryptonote::COMMAND_RPC_STOP_MINING::response daemon_res;
bool r = wallet2->invoke_http_json("/stop_mining", daemon_req, daemon_res);
@@ -2283,17 +2255,17 @@ namespace monero {
}
void MoneroWallet::save() {
cout << "save()" << endl;
MTRACE("save()");
wallet2->store();
}
void MoneroWallet::moveTo(string path, string password) {
cout << "moveTo(" << path << ", " << password << ")" << endl;
MTRACE("moveTo(" << path << ", " << password << ")");
wallet2->store_to(path, password);
}
void MoneroWallet::close() {
cout << "close()" << endl;
MTRACE("close()");
syncingEnabled = false;
syncingThreadDone = true;
syncCV.notify_one();
@@ -2305,7 +2277,7 @@ namespace monero {
// ------------------------------- PRIVATE HELPERS ----------------------------
void MoneroWallet::initCommon() {
cout << "MoneroWallet.cpp initCommon()" << endl;
MTRACE("MoneroWallet.cpp initCommon()");
wallet2Listener = unique_ptr<Wallet2Listener>(new Wallet2Listener(*this, *wallet2));
if (getDaemonConnection() == nullptr) isConnected = false;
isSynced = false;
@@ -2321,7 +2293,7 @@ namespace monero {
}
void MoneroWallet::syncingThreadFunc() {
cout << "syncingThreadFunc()" << endl;
MTRACE("syncingThreadFunc()");
while (true) {
boost::mutex::scoped_lock lock(syncingMutex);
if (syncingThreadDone) break;
@@ -2361,7 +2333,7 @@ namespace monero {
}
MoneroSyncResult MoneroWallet::syncAux(boost::optional<uint64_t> startHeight, boost::optional<MoneroSyncListener&> listener) {
cout << "syncAux()" << endl;
MTRACE("syncAux()");
// determine sync start height
uint64_t syncStartHeight = startHeight == boost::none ? max(getHeight(), getRestoreHeight()) : *startHeight;
+1 -53
View File
@@ -81,7 +81,6 @@ namespace monero {
// TODO: ensure return object is not being unecessarily copied
boost::property_tree::ptree MoneroAccount::toPropertyTree() const {
//cout << "MoneroAccount::toPropertyTree(node)" << endl;
boost::property_tree::ptree node;
if (index != boost::none) node.put("index", *index);
if (primaryAddress != boost::none) node.put("primaryAddress", *primaryAddress);
@@ -94,7 +93,6 @@ namespace monero {
// -------------------------- MONERO SUBADDRESS -----------------------------
boost::property_tree::ptree MoneroSubaddress::toPropertyTree() const {
//cout << "MoneroSubaddress::toPropertyTree(node)" << endl;
boost::property_tree::ptree node;
if (accountIndex != boost::none) node.put("accountIndex", *accountIndex);
if (index != boost::none) node.put("index", *index);
@@ -159,7 +157,6 @@ namespace monero {
// -------------------------- MONERO TX REQUEST -----------------------------
boost::property_tree::ptree MoneroTxRequest::toPropertyTree() const {
// cout << "MoneroTxRequest::toPropertyTree(node)" << endl;
boost::property_tree::ptree node = MoneroTxWallet::toPropertyTree();
if (isOutgoing != boost::none) node.put("isOutgoing", *isOutgoing);
if (isIncoming != boost::none) node.put("isIncoming", *isIncoming);
@@ -177,10 +174,6 @@ namespace monero {
bool MoneroTxRequest::meetsCriteria(MoneroTxWallet* tx) const {
if (tx == nullptr) return false;
//cout << "MoneroTxRequest::meetsCriteria()" << endl;
//cout << "Testing tx: " << tx->serialize() << endl;
//cout << "1" << endl;
// filter on tx
if (id != boost::none && id != tx->id) return false;
if (paymentId != boost::none && paymentId != tx->paymentId) return false;
@@ -190,8 +183,6 @@ namespace monero {
if (isFailed != boost::none && isFailed != tx->isFailed) return false;
if (isCoinbase != boost::none && isCoinbase != tx->isCoinbase) return false;
//cout << "2" << endl;
// at least one transfer must meet transfer request if defined
if (transferRequest != boost::none) {
bool matchFound = false;
@@ -207,26 +198,18 @@ namespace monero {
if (!matchFound) return false;
}
//cout << "3" << endl;
// filter on having a payment id
if (hasPaymentId != boost::none) {
if (*hasPaymentId && tx->paymentId == boost::none) return false;
if (!*hasPaymentId && tx->paymentId != boost::none) return false;
}
//cout << "4" << endl;
// filter on incoming
if (isIncoming != boost::none && isIncoming != tx->getIsIncoming()) return false;
//cout << "5" << endl;
// filter on outgoing
if (isOutgoing != boost::none && isOutgoing != tx->getIsOutgoing()) return false;
//cout << "6" << endl;
// filter on remaining fields
boost::optional<uint64_t> txHeight = tx->getHeight();
if (!txIds.empty() && find(txIds.begin(), txIds.end(), *tx->id) == txIds.end()) return false;
@@ -235,31 +218,13 @@ namespace monero {
if (minHeight != boost::none && (txHeight == boost::none || *txHeight < *minHeight)) return false;
if (maxHeight != boost::none && (txHeight == boost::none || *txHeight > *maxHeight)) return false;
//cout << "7" << endl;
// transaction meets request criteria
return true;
}
//boost::property_tree::ptree MoneroUtils::txRequestToPropertyTree(const MoneroTxRequest& tx) {
// cout << "txWalletToPropertyTree(tx)" << endl;
// boost::property_tree::ptree txNode = txWalletToPropertyTree(tx);
// if (tx.isOutgoing != boost::none) txNode.put("isOutgoing", *tx.isOutgoing);
// if (tx.isIncoming != boost::none) txNode.put("isIncoming", *tx.isIncoming);
// if (!tx.txIds.empty()) throw runtime_error("not implemented");
// if (tx.hasPaymentId != boost::none) txNode.put("hasPaymentId", *tx.hasPaymentId);
// if (!tx.paymentIds.empty()) throw runtime_error("not implemented");
// if (tx.minHeight != boost::none) txNode.put("minHeight", *tx.minHeight);
// if (tx.maxHeight != boost::none) txNode.put("maxHeight", *tx.maxHeight);
// if (tx.includeOutputs != boost::none) txNode.put("includeOutputs", *tx.includeOutputs);
// if (tx.transferRequest != boost::none) throw runtime_error("not implemented");
// return txNode;
//}
// -------------------------- MONERO DESTINATION ----------------------------
boost::property_tree::ptree MoneroDestination::toPropertyTree() const {
//cout << "MoneroDestination::toPropertyTree(node)" << endl;
boost::property_tree::ptree node;
if (address != boost::none) node.put("address", *address);
if (amount != boost::none) node.put("amount", *amount);
@@ -269,7 +234,6 @@ namespace monero {
// ---------------------------- MONERO TRANSFER -----------------------------
boost::property_tree::ptree MoneroTransfer::toPropertyTree() const {
//cout << "MoneroTransfer::toPropertyTree(node)" << endl;
boost::property_tree::ptree node;
if (amount != boost::none) node.put("amount", *amount);
if (accountIndex != boost::none) node.put("accountIndex", *accountIndex);
@@ -278,7 +242,6 @@ namespace monero {
}
void MoneroTransfer::merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other) {
//cout << "MoneroTransfer::merge" << endl;
if (this != self.get()) throw runtime_error("this != self");
if (self == other) return;
@@ -295,7 +258,7 @@ namespace monero {
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");
cout << "WARNING: failed tx in pool causes non-originating wallets to return duplicate incoming transfers but with one amount/numSuggestedConfirmations of 0" << endl;
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");
@@ -307,7 +270,6 @@ namespace monero {
boost::optional<bool> MoneroIncomingTransfer::getIsIncoming() const { return true; }
boost::property_tree::ptree MoneroIncomingTransfer::toPropertyTree() const {
//cout << "MoneroIncomingTransfer::toPropertyTree(node)" << endl;
boost::property_tree::ptree node = MoneroTransfer::toPropertyTree();
if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex);
if (address != boost::none) node.put("address", *address);
@@ -319,7 +281,6 @@ namespace monero {
}
void MoneroIncomingTransfer::merge(const shared_ptr<MoneroIncomingTransfer>& self, const shared_ptr<MoneroIncomingTransfer>& other) {
//cout << "MoneroIncomingTransfer::merge" << endl;
if (self == other) return;
MoneroTransfer::merge(self, other);
subaddressIndex = MoneroUtils::reconcile(subaddressIndex, other->subaddressIndex, "incoming transfer subaddressIndex");
@@ -331,7 +292,6 @@ namespace monero {
boost::optional<bool> MoneroOutgoingTransfer::getIsIncoming() const { return false; }
boost::property_tree::ptree MoneroOutgoingTransfer::toPropertyTree() const {
//cout << "MoneroOutgoingTransfer::toPropertyTree(node)" << endl;
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));
@@ -344,7 +304,6 @@ namespace monero {
}
void MoneroOutgoingTransfer::merge(const shared_ptr<MoneroOutgoingTransfer>& self, const shared_ptr<MoneroOutgoingTransfer>& other) {
//cout << "MoneroOutgoingTransfer::merge" << endl;
if (self == other) return;
MoneroTransfer::merge(self, other);
subaddressIndices = MoneroUtils::reconcile(subaddressIndices, other->subaddressIndices);
@@ -357,7 +316,6 @@ namespace monero {
boost::optional<bool> MoneroTransferRequest::getIsIncoming() const { return isIncoming; }
boost::property_tree::ptree MoneroTransferRequest::toPropertyTree() const {
//cout << "MoneroTransferRequest::toPropertyTree(node)" << endl;
boost::property_tree::ptree node = MoneroTransfer::toPropertyTree();
if (getIsIncoming() != boost::none) node.put("isIncoming", *getIsIncoming());
if (address != boost::none) node.put("address", *address);
@@ -370,20 +328,15 @@ namespace monero {
}
bool MoneroTransferRequest::meetsCriteria(MoneroTransfer* transfer) const {
//cout << "MoneroTransferRequest::meetsCriteria()" << endl;
if (transfer == nullptr) throw runtime_error("transfer is null"); // TODO: port to java/js
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 handl this. port to java/js
//cout << "1" << endl;
// filter on common fields
if (getIsIncoming() != boost::none && *getIsIncoming() != *transfer->getIsIncoming()) return false;
if (getIsOutgoing() != boost::none && getIsOutgoing() != transfer->getIsOutgoing()) return false;
if (amount != boost::none && *amount != *transfer->amount) return false;
if (accountIndex != boost::none && *accountIndex != *transfer->accountIndex) return false;
//cout << "2" << endl;
// filter on incoming fields
MoneroIncomingTransfer* inTransfer = dynamic_cast<MoneroIncomingTransfer*>(transfer);
if (inTransfer != nullptr) {
@@ -394,8 +347,6 @@ namespace monero {
if (!subaddressIndices.empty() && find(subaddressIndices.begin(), subaddressIndices.end(), *inTransfer->subaddressIndex) == subaddressIndices.end()) return false;
}
//cout << "3" << endl;
// filter on outgoing fields
MoneroOutgoingTransfer* outTransfer = dynamic_cast<MoneroOutgoingTransfer*>(transfer);
if (outTransfer != nullptr) {
@@ -440,8 +391,6 @@ namespace monero {
// if (this.getDestionations() != null && this.getDestionations() != transfer.getDestionations()) return false;
}
//cout << "4" << endl;
// validate type
if (inTransfer == nullptr && outTransfer == nullptr) throw runtime_error("Transfer must be MoneroIncomingTransfer or MoneroOutgoingTransfer");
@@ -453,7 +402,6 @@ namespace monero {
// ------------------------- MONERO OUTPUT WALLET ---------------------------
boost::property_tree::ptree MoneroOutputWallet::toPropertyTree() const {
//cout << "MoneroTransfer::toPropertyTree(node)" << endl;
boost::property_tree::ptree node = MoneroOutput::toPropertyTree();
if (accountIndex != boost::none) node.put("accountIndex", *accountIndex);
if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex);
+1
View File
@@ -1,4 +1,5 @@
HIGH PRIORITY
nodeToTransferRequest(), etc need a final else catch-all
sign/submit tx
change shared_ptr<Foo>(new Foo()) to make_shared
cpp library readme with sample code