diff --git a/src/daemon/monero_daemon.cpp b/src/daemon/monero_daemon.cpp index ebea4be..55fb478 100644 --- a/src/daemon/monero_daemon.cpp +++ b/src/daemon/monero_daemon.cpp @@ -50,12 +50,11 @@ * Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers */ -#include "MoneroDaemon.h" +#include "monero_daemon.h" /** * Public library intereface. */ namespace monero { - // TODO: MoneroDaemon class implementation } diff --git a/src/daemon/monero_daemon.h b/src/daemon/monero_daemon.h index a9c0486..ec44c9f 100644 --- a/src/daemon/monero_daemon.h +++ b/src/daemon/monero_daemon.h @@ -61,5 +61,4 @@ using namespace std; */ namespace monero { - // TODO: MoneroDaemon class definition } diff --git a/src/daemon/monero_daemon_model.h b/src/daemon/monero_daemon_model.h index 43ca228..996fda9 100644 --- a/src/daemon/monero_daemon_model.h +++ b/src/daemon/monero_daemon_model.h @@ -85,7 +85,7 @@ namespace monero { /** * Enumerates Monero network types. */ - enum MoneroNetworkType : uint8_t { + enum monero_network_type : uint8_t { MAINNET = 0, TESTNET, STAGENET diff --git a/src/utils/monero_utils.cpp b/src/utils/monero_utils.cpp index 883a66d..1f245a7 100644 --- a/src/utils/monero_utils.cpp +++ b/src/utils/monero_utils.cpp @@ -393,33 +393,33 @@ shared_ptr monero_utils::deserialize_send_request(const str boost::property_tree::read_json(iss, node); // convert request property tree to monero_send_request - shared_ptr sendRequest = make_shared(); + shared_ptr send_request = make_shared(); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; if (key == string("destinations")) { boost::property_tree::ptree destinationsNode = it->second; for (boost::property_tree::ptree::const_iterator it2 = destinationsNode.begin(); it2 != destinationsNode.end(); ++it2) { - sendRequest->destinations.push_back(node_to_destination(it2->second)); + send_request->destinations.push_back(node_to_destination(it2->second)); } } - else if (key == string("payment_id")) sendRequest->payment_id = it->second.data(); + else if (key == string("payment_id")) send_request->payment_id = it->second.data(); else if (key == string("priority")) throw runtime_error("deserialize_send_request() payment_id not implemented"); - else if (key == string("mixin")) sendRequest->mixin = it->second.get_value(); - else if (key == string("ringSize")) sendRequest->ringSize = it->second.get_value(); - else if (key == string("fee")) sendRequest->fee = it->second.get_value(); - else if (key == string("account_index")) sendRequest->account_index = it->second.get_value(); - else if (key == string("subaddress_indices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) sendRequest->subaddress_indices.push_back(it2->second.get_value()); - else if (key == string("unlock_time")) sendRequest->unlock_time = it->second.get_value(); - else if (key == string("can_split")) sendRequest->can_split = it->second.get_value(); - else if (key == string("do_not_relay")) sendRequest->do_not_relay = it->second.get_value(); - else if (key == string("note")) sendRequest->note = it->second.data(); - else if (key == string("receipient_name")) sendRequest->receipient_name = it->second.data(); - else if (key == string("below_amount")) sendRequest->below_amount = it->second.get_value(); - else if (key == string("sweep_each_subaddress")) sendRequest->sweep_each_subaddress = it->second.get_value(); - else if (key == string("key_image")) sendRequest->key_image = it->second.data(); + else if (key == string("mixin")) send_request->mixin = it->second.get_value(); + else if (key == string("ring_size")) send_request->ring_size = it->second.get_value(); + else if (key == string("fee")) send_request->fee = it->second.get_value(); + else if (key == string("account_index")) send_request->account_index = it->second.get_value(); + else if (key == string("subaddress_indices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) send_request->subaddress_indices.push_back(it2->second.get_value()); + else if (key == string("unlock_time")) send_request->unlock_time = it->second.get_value(); + else if (key == string("can_split")) send_request->can_split = it->second.get_value(); + else if (key == string("do_not_relay")) send_request->do_not_relay = it->second.get_value(); + else if (key == string("note")) send_request->note = it->second.data(); + else if (key == string("recipient_name")) send_request->recipient_name = it->second.data(); + else if (key == string("below_amount")) send_request->below_amount = it->second.get_value(); + else if (key == string("sweep_each_subaddress")) send_request->sweep_each_subaddress = it->second.get_value(); + else if (key == string("key_image")) send_request->key_image = it->second.data(); } - return sendRequest; + return send_request; } vector> monero_utils::deserialize_key_images(const string& key_images_json) { @@ -430,17 +430,17 @@ vector> monero_utils::deserialize_key_images(const boost::property_tree::read_json(iss, node); // convert property tree to key images - vector> keyImages; + vector> key_images; for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; - if (key == string("keyImages")) { + if (key == string("key_images")) { for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) { - keyImages.push_back(node_to_key_image(it2->second)); + key_images.push_back(node_to_key_image(it2->second)); } } else MWARNING("WARNING MoneroWalletJni::deserialize_key_images() unrecognized key: " << key); } - return keyImages; + return key_images; } string monero_utils::serialize(const boost::property_tree::ptree& node) { @@ -501,8 +501,8 @@ shared_ptr monero_utils::cn_block_to_block(const cryptonote::block block->prev_id = epee::string_tools::pod_to_hex(cn_block.prev_id); block->nonce = cn_block.nonce; block->miner_tx = monero_utils::cn_tx_to_tx(cn_block.miner_tx); - for (const crypto::hash& txHash : cn_block.tx_hashes) { - block->tx_ids.push_back(epee::string_tools::pod_to_hex(txHash)); + for (const crypto::hash& tx_hash : cn_block.tx_hashes) { + block->tx_ids.push_back(epee::string_tools::pod_to_hex(tx_hash)); } return block; } diff --git a/src/wallet/monero_wallet.cpp b/src/wallet/monero_wallet.cpp index be3a120..7b64ab1 100644 --- a/src/wallet/monero_wallet.cpp +++ b/src/wallet/monero_wallet.cpp @@ -82,11 +82,11 @@ namespace monero { // ----------------------- INTERNAL PRIVATE HELPERS ----------------------- - bool boolEquals(bool val, const boost::optional& optVal) { - return optVal == boost::none ? false : val == *optVal; + bool bool_equals(bool val, const boost::optional& opt_val) { + return opt_val == boost::none ? false : val == *opt_val; } - shared_ptr buildTxWithIncomingTransfer(const tools::wallet2& wallet2, uint64_t height, const crypto::hash &payment_id, const tools::wallet2::payment_details &pd) { + shared_ptr builc_tx_with_incoming_transfer(const tools::wallet2& wallet2, uint64_t height, const crypto::hash &payment_id, const tools::wallet2::payment_details &pd) { // construct block shared_ptr block = make_shared(); @@ -114,30 +114,30 @@ namespace monero { tx->is_double_spend_seen = false; // compute num_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 - // TODO: factor out this duplicate code with buildTxWithOutgoingTransfer() + // TODO: factor out this duplicate code with build_tx_with_outgoing_transfer() if (*block->height >= height || (*block->height == 0 && !*tx->in_tx_pool)) tx->num_confirmations = 0; else tx->num_confirmations = height - *block->height; // construct transfer - shared_ptr incomingTransfer = make_shared(); - incomingTransfer->tx = tx; - tx->incoming_transfers.push_back(incomingTransfer); - incomingTransfer->amount = pd.m_amount; - incomingTransfer->account_index = pd.m_subaddr_index.major; - incomingTransfer->subaddress_index = pd.m_subaddr_index.minor; - incomingTransfer->address = wallet2.get_subaddress_as_str(pd.m_subaddr_index); + shared_ptr incoming_transfer = make_shared(); + incoming_transfer->tx = tx; + tx->incoming_transfers.push_back(incoming_transfer); + incoming_transfer->amount = pd.m_amount; + incoming_transfer->account_index = pd.m_subaddr_index.major; + incoming_transfer->subaddress_index = pd.m_subaddr_index.minor; + incoming_transfer->address = wallet2.get_subaddress_as_str(pd.m_subaddr_index); // compute num_suggested_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 `set_confirmations` but it should be encapsulated in wallet2 - // TODO: factor out this duplicate code with buildTxWithOutgoingTransfer() - uint64_t blockReward = wallet2.get_last_block_reward(); - if (blockReward == 0) incomingTransfer->num_suggested_confirmations = 0; - else incomingTransfer->num_suggested_confirmations = (*incomingTransfer->amount + blockReward - 1) / blockReward; + // TODO: factor out this duplicate code with build_tx_with_outgoing_transfer() + uint64_t block_reward = wallet2.get_last_block_reward(); + if (block_reward == 0) incoming_transfer->num_suggested_confirmations = 0; + else incoming_transfer->num_suggested_confirmations = (*incoming_transfer->amount + block_reward - 1) / block_reward; // return pointer to new tx return tx; } - shared_ptr buildTxWithOutgoingTransfer(const tools::wallet2& wallet2, uint64_t height, const crypto::hash &txid, const tools::wallet2::confirmed_transfer_details &pd) { + shared_ptr build_tx_with_outgoing_transfer(const tools::wallet2& wallet2, uint64_t height, const crypto::hash &txid, const tools::wallet2::confirmed_transfer_details &pd) { // construct block shared_ptr block = make_shared(); @@ -201,15 +201,15 @@ namespace monero { } // compute num_suggested_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 - uint64_t blockReward = wallet2.get_last_block_reward(); - if (blockReward == 0) outgoing_transfer->num_suggested_confirmations = 0; - else outgoing_transfer->num_suggested_confirmations = (*outgoing_transfer->amount + blockReward - 1) / blockReward; + uint64_t block_reward = wallet2.get_last_block_reward(); + if (block_reward == 0) outgoing_transfer->num_suggested_confirmations = 0; + else outgoing_transfer->num_suggested_confirmations = (*outgoing_transfer->amount + block_reward - 1) / block_reward; // return pointer to new tx return tx; } - shared_ptr buildTxWithIncomingTransferUnconfirmed(const tools::wallet2& wallet2, const crypto::hash &payment_id, const tools::wallet2::pool_payment_details &ppd) { + shared_ptr build_tx_with_incoming_transfer_unconfirmed(const tools::wallet2& wallet2, const crypto::hash &payment_id, const tools::wallet2::pool_payment_details &ppd) { // construct tx const tools::wallet2::payment_details &pd = ppd.m_pd; @@ -232,24 +232,24 @@ namespace monero { tx->num_confirmations = 0; // construct transfer - shared_ptr incomingTransfer = make_shared(); - incomingTransfer->tx = tx; - tx->incoming_transfers.push_back(incomingTransfer); - incomingTransfer->amount = pd.m_amount; - incomingTransfer->account_index = pd.m_subaddr_index.major; - incomingTransfer->subaddress_index = pd.m_subaddr_index.minor; - incomingTransfer->address = wallet2.get_subaddress_as_str(pd.m_subaddr_index); + shared_ptr incoming_transfer = make_shared(); + incoming_transfer->tx = tx; + tx->incoming_transfers.push_back(incoming_transfer); + incoming_transfer->amount = pd.m_amount; + incoming_transfer->account_index = pd.m_subaddr_index.major; + incoming_transfer->subaddress_index = pd.m_subaddr_index.minor; + incoming_transfer->address = wallet2.get_subaddress_as_str(pd.m_subaddr_index); // compute num_suggested_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 - uint64_t blockReward = wallet2.get_last_block_reward(); - if (blockReward == 0) incomingTransfer->num_suggested_confirmations = 0; - else incomingTransfer->num_suggested_confirmations = (*incomingTransfer->amount + blockReward - 1) / blockReward; + uint64_t block_reward = wallet2.get_last_block_reward(); + if (block_reward == 0) incoming_transfer->num_suggested_confirmations = 0; + else incoming_transfer->num_suggested_confirmations = (*incoming_transfer->amount + block_reward - 1) / block_reward; // return pointer to new tx return tx; } - shared_ptr buildTxWithOutgoingTransferUnconfirmed(const tools::wallet2& wallet2, const crypto::hash &txid, const tools::wallet2::unconfirmed_transfer_details &pd) { + shared_ptr build_tx_with_outgoing_transfer_unconfirmed(const tools::wallet2& wallet2, const crypto::hash &txid, const tools::wallet2::unconfirmed_transfer_details &pd) { // construct tx shared_ptr tx = make_shared(); @@ -302,15 +302,15 @@ namespace monero { } // compute num_suggested_confirmations TODO monero core: this logic is based on wallet_rpc_server.cpp:87 but it should be encapsulated in wallet2 - uint64_t blockReward = wallet2.get_last_block_reward(); - if (blockReward == 0) outgoing_transfer->num_suggested_confirmations = 0; - else outgoing_transfer->num_suggested_confirmations = (*outgoing_transfer->amount + blockReward - 1) / blockReward; + uint64_t block_reward = wallet2.get_last_block_reward(); + if (block_reward == 0) outgoing_transfer->num_suggested_confirmations = 0; + else outgoing_transfer->num_suggested_confirmations = (*outgoing_transfer->amount + block_reward - 1) / block_reward; // return pointer to new tx return tx; } - shared_ptr buildTxWithVout(const tools::wallet2& wallet2, const tools::wallet2::transfer_details& td) { + shared_ptr build_tx_with_vout(const tools::wallet2& wallet2, const tools::wallet2::transfer_details& td) { // construct block shared_ptr block = make_shared(); @@ -351,22 +351,22 @@ namespace monero { /** * Merges a transaction into a unique set of transactions. * - * TODO monero-core: skipIfAbsent only necessary because incoming payments not returned + * TODO monero-core: skip_if_absent only necessary because incoming payments not returned * when sent from/to same account #4500 * * @param tx is the transaction to merge into the existing txs - * @param txMap maps tx ids to txs - * @param blockMap maps block heights to blocks - * @param skipIfAbsent specifies if the tx should not be added if it doesn't already exist + * @param tx_map maps tx ids to txs + * @param block_map maps block heights to blocks + * @param skip_if_absent specifies if the tx should not be added if it doesn't already exist */ - void merge_tx(const shared_ptr& tx, map>& txMap, map>& blockMap, bool skipIfAbsent) { + void merge_tx(const shared_ptr& tx, map>& tx_map, map>& block_map, bool skip_if_absent) { if (tx->id == boost::none) throw runtime_error("Tx id is not initialized"); // if tx doesn't exist, add it (unless skipped) - map>::const_iterator txIter = txMap.find(*tx->id); - if (txIter == txMap.end()) { - if (!skipIfAbsent) { - txMap[*tx->id] = tx; + map>::const_iterator tx_iter = tx_map.find(*tx->id); + if (tx_iter == tx_map.end()) { + if (!skip_if_absent) { + tx_map[*tx->id] = tx; } else { MWARNING("WARNING: tx does not already exist"); } @@ -374,18 +374,18 @@ namespace monero { // otherwise merge with existing tx else { - shared_ptr& aTx = txMap[*tx->id]; - aTx->merge(aTx, tx); + shared_ptr& a_tx = tx_map[*tx->id]; + a_tx->merge(a_tx, tx); } // if confirmed, merge tx's block if (tx->get_height() != boost::none) { - map>::const_iterator blockIter = blockMap.find(tx->get_height().get()); - if (blockIter == blockMap.end()) { - blockMap[tx->get_height().get()] = tx->block.get(); + map>::const_iterator blockIter = block_map.find(tx->get_height().get()); + if (blockIter == block_map.end()) { + block_map[tx->get_height().get()] = tx->block.get(); } else { - shared_ptr& aBlock = blockMap[tx->get_height().get()]; - aBlock->merge(aBlock, tx->block.get()); + shared_ptr& a_block = block_map[tx->get_height().get()]; + a_block->merge(a_block, tx->block.get()); } } } @@ -393,7 +393,7 @@ namespace monero { /** * Returns true iff tx1's height is known to be less than tx2's height for sorting. */ - bool txHeightLessThan(const shared_ptr& tx1, const shared_ptr& tx2) { + bool tx_height_less_than(const shared_ptr& tx1, const shared_ptr& tx2) { if (tx1->block != boost::none && tx2->block != boost::none) return tx1->get_height() < tx2->get_height(); else if (tx1->block == boost::none) return false; else return true; @@ -402,10 +402,10 @@ namespace monero { /** * Returns true iff transfer1 is ordered before transfer2 by ascending account and subaddress indices. */ - bool incomingTransferBefore(const shared_ptr& transfer1, const shared_ptr& transfer2) { + bool incoming_transfer_before(const shared_ptr& transfer1, const shared_ptr& transfer2) { // compare by height - if (txHeightLessThan(transfer1->tx, transfer2->tx)) return true; + if (tx_height_less_than(transfer1->tx, transfer2->tx)) return true; // compare by account and subaddress index if (transfer1->account_index.get() < transfer2->account_index.get()) return true; @@ -416,12 +416,12 @@ namespace monero { /** * Returns true iff wallet vout1 is ordered before vout2 by ascending account and subaddress indices then index. */ - bool voutBefore(const shared_ptr& o1, const shared_ptr& o2) { + bool vout_before(const shared_ptr& o1, const shared_ptr& o2) { shared_ptr ow1 = static_pointer_cast(o1); shared_ptr ow2 = static_pointer_cast(o2); // compare by height - if (txHeightLessThan(ow1->tx, ow2->tx)) return true; + if (tx_height_less_than(ow1->tx, ow2->tx)) return true; // compare by account index, subaddress index, and output if (ow1->account_index.get() < ow2->account_index.get()) return true; @@ -655,7 +655,7 @@ namespace monero { /** * Listens to wallet2 notifications in order to facilitate external wallet notifications. */ - struct Wallet2Listener : public tools::i_wallet2_callback { + struct wallet2_listener : public tools::i_wallet2_callback { public: @@ -665,35 +665,35 @@ namespace monero { * @param wallet provides context to inform external notifications * @param wallet2 provides source notifications which this listener propagates to external listeners */ - Wallet2Listener(monero_wallet& wallet, tools::wallet2& wallet2) : wallet(wallet), wallet2(wallet2) { + wallet2_listener(monero_wallet& wallet, tools::wallet2& wallet2) : wallet(wallet), wallet2(wallet2) { this->listener = boost::none; - this->syncStartHeight = boost::none; - this->syncEndHeight = boost::none; - this->syncListener = boost::none; + this->sync_start_height = boost::none; + this->sync_end_height = boost::none; + this->sync_listener = boost::none; } - ~Wallet2Listener() { - MTRACE("~Wallet2Listener()"); + ~wallet2_listener() { + MTRACE("~wallet2_listener()"); } - void setWalletListener(boost::optional listener) { + void set_wallet_listener(boost::optional listener) { this->listener = listener; - updateListening(); + update_listening(); } - void onSyncStart(uint64_t startHeight, boost::optional syncListener) { - if (syncStartHeight != boost::none || syncEndHeight != boost::none) throw runtime_error("Sync start or end height should not already be allocated, is previous sync in progress?"); - syncStartHeight = startHeight; - syncEndHeight = wallet.getChainHeight(); - this->syncListener = syncListener; - updateListening(); + void on_sync_start(uint64_t start_height, boost::optional sync_listener) { + if (sync_start_height != boost::none || sync_end_height != boost::none) throw runtime_error("Sync start or end height should not already be allocated, is previous sync in progress?"); + sync_start_height = start_height; + sync_end_height = wallet.get_chain_height(); + this->sync_listener = sync_listener; + update_listening(); } - void onSyncEnd() { - syncStartHeight = boost::none; - syncEndHeight = boost::none; - syncListener = boost::none; - updateListening(); + void on_sync_end() { + sync_start_height = boost::none; + sync_end_height = boost::none; + sync_listener = boost::none; + update_listening(); } virtual void on_new_block(uint64_t height, const cryptonote::block& cn_block) { @@ -702,17 +702,17 @@ namespace monero { if (listener != boost::none) listener->on_new_block(height); // notify listeners of sync progress - if (syncStartHeight != boost::none && height >= *syncStartHeight) { - if (height >= *syncEndHeight) syncEndHeight = height + 1; // increase end height if necessary - double percentDone = (double) (height - *syncStartHeight + 1) / (double) (*syncEndHeight - *syncStartHeight); + if (sync_start_height != boost::none && height >= *sync_start_height) { + if (height >= *sync_end_height) sync_end_height = height + 1; // increase end height if necessary + double percent_done = (double) (height - *sync_start_height + 1) / (double) (*sync_end_height - *sync_start_height); string message = string("Synchronizing"); - if (listener != boost::none) listener.get().on_sync_progress(height, *syncStartHeight, *syncEndHeight, percentDone, message); - if (syncListener != boost::none) syncListener.get().on_sync_progress(height, *syncStartHeight, *syncEndHeight, percentDone, message); + if (listener != boost::none) listener.get().on_sync_progress(height, *sync_start_height, *sync_end_height, percent_done, message); + if (sync_listener != boost::none) sync_listener.get().on_sync_progress(height, *sync_start_height, *sync_end_height, percent_done, message); } } virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cn_tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time) { - MTRACE("Wallet2Listener::on_money_received()"); + MTRACE("wallet2_listener::on_money_received()"); if (listener == boost::none) return; // create native library tx @@ -735,7 +735,7 @@ namespace monero { } virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cnTxIn, uint64_t amount, const cryptonote::transaction& cnTxOut, const cryptonote::subaddress_index& subaddr_index) { - MTRACE("Wallet2Listener::on_money_spent()"); + MTRACE("wallet2_listener::on_money_spent()"); if (&cnTxIn != &cnTxOut) throw runtime_error("on_money_spent() in tx is different than out tx"); // create native library tx @@ -771,33 +771,33 @@ namespace monero { private: monero_wallet& wallet; // wallet to provide context for notifications tools::wallet2& wallet2; // internal wallet implementation to listen to - boost::optional listener; // target listener to invoke with notifications - boost::optional syncListener; - boost::optional syncStartHeight; - boost::optional syncEndHeight; + boost::optional listener; // target listener to invoke with notifications + boost::optional sync_listener; + boost::optional sync_start_height; + boost::optional sync_end_height; - void updateListening() { - wallet2.callback(listener == boost::none && syncListener == boost::none ? nullptr : this); + void update_listening() { + wallet2.callback(listener == boost::none && sync_listener == boost::none ? nullptr : this); } }; // ---------------------------- WALLET MANAGEMENT --------------------------- - bool monero_wallet::walletExists(const string& path) { - MTRACE("walletExists(" << path << ")"); - bool keyFileExists; - bool walletFileExists; - tools::wallet2::wallet_exists(path, keyFileExists, walletFileExists); - return walletFileExists; + bool monero_wallet::wallet_exists(const string& path) { + MTRACE("wallet_exists(" << path << ")"); + bool key_file_exists; + bool wallet_file_exists; + tools::wallet2::wallet_exists(path, key_file_exists, wallet_file_exists); + return wallet_file_exists; } - monero_wallet* monero_wallet::open_wallet(const string& path, const string& password, const MoneroNetworkType networkType) { - MTRACE("open_wallet(" << path << ", " << password << ", " << networkType << ")"); + monero_wallet* monero_wallet::open_wallet(const string& path, const string& password, const monero_network_type network_type) { + MTRACE("open_wallet(" << path << ", " << password << ", " << network_type << ")"); monero_wallet* wallet = new monero_wallet(); - wallet->wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); + wallet->wallet2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); wallet->wallet2->load(path, password); wallet->wallet2->init(""); - wallet->initCommon(); + wallet->init_common(); return wallet; } @@ -806,109 +806,109 @@ namespace monero { throw runtime_error("Not implemented"); } - monero_wallet* monero_wallet::create_wallet_random(const string& path, const string& password, const MoneroNetworkType networkType, const monero_rpc_connection& daemonConnection, const string& language) { - MTRACE("create_wallet_random(path, password, networkType, daemonConnection, language)"); + monero_wallet* monero_wallet::create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const string& language) { + MTRACE("create_wallet_random(path, password, network_type, daemon_connection, language)"); monero_wallet* wallet = new monero_wallet(); - wallet->wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); - wallet->set_daemon_connection(daemonConnection); + wallet->wallet2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); + wallet->set_daemon_connection(daemon_connection); wallet->wallet2->set_seed_language(language); crypto::secret_key secret_key; wallet->wallet2->generate(path, password, secret_key, false, false); - wallet->initCommon(); + wallet->init_common(); return wallet; } - monero_wallet* monero_wallet::create_wallet_from_mnemonic(const string& path, const string& password, const MoneroNetworkType networkType, const string& mnemonic) { - MTRACE("create_wallet_from_mnemonic(path, password, networkType, mnemonic)"); + monero_wallet* monero_wallet::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic) { + MTRACE("create_wallet_from_mnemonic(path, password, network_type, mnemonic)"); throw runtime_error("Not implemented"); } - monero_wallet* 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) { - MTRACE("create_wallet_from_mnemonic(path, password, mnemonic, networkType, daemonConnection, restoreHeight)"); + monero_wallet* monero_wallet::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height) { + MTRACE("create_wallet_from_mnemonic(path, password, mnemonic, network_type, daemon_connection, restore_height)"); monero_wallet* wallet = new monero_wallet(); // validate mnemonic and get recovery key and language crypto::secret_key recoveryKey; std::string language; - bool isValid = crypto::ElectrumWords::words_to_bytes(mnemonic, recoveryKey, language); - if (!isValid) throw runtime_error("Invalid mnemonic"); + bool is_valid = crypto::ElectrumWords::words_to_bytes(mnemonic, recoveryKey, language); + if (!is_valid) throw runtime_error("Invalid mnemonic"); if (language == crypto::ElectrumWords::old_language_name) language = Language::English().get_language_name(); // initialize wallet - wallet->wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); - wallet->set_daemon_connection(daemonConnection); + wallet->wallet2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); + wallet->set_daemon_connection(daemon_connection); wallet->wallet2->set_seed_language(language); wallet->wallet2->generate(path, password, recoveryKey, true, false); - wallet->wallet2->set_refresh_from_block_height(restoreHeight); - wallet->initCommon(); + wallet->wallet2->set_refresh_from_block_height(restore_height); + wallet->init_common(); return wallet; } - monero_wallet* monero_wallet::create_wallet_from_keys(const string& path, const string& password, const MoneroNetworkType networkType, const string& address, const string& viewKey, const string& spendKey) { - MTRACE("create_wallet_from_keys(path, password, address, viewKey, spendKey, networkType)"); + monero_wallet* monero_wallet::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key) { + MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type)"); throw runtime_error("Not implemented"); } - monero_wallet* 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) { - MTRACE("create_wallet_from_keys(path, password, address, viewKey, spendKey, networkType, daemonConnection, restoreHeight)"); + monero_wallet* monero_wallet::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height) { + MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height)"); throw runtime_error("Not implemented"); } - monero_wallet* 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) { - MTRACE("create_wallet_from_keys(path, password, address, viewKey, spendKey, networkType, daemonConnection, restoreHeight, language)"); + monero_wallet* monero_wallet::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language) { + MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height, language)"); monero_wallet* wallet = new monero_wallet(); // validate and parse address cryptonote::address_parse_info info; - if (!get_account_address_from_str(info, static_cast(networkType), address)) throw runtime_error("failed to parse address"); + if (!get_account_address_from_str(info, static_cast(network_type), address)) throw runtime_error("failed to parse address"); // validate and parse optional private spend key - crypto::secret_key spendKeySK; - bool hasSpendKey = false; - if (!spendKey.empty()) { - cryptonote::blobdata spendKeyData; - if (!epee::string_tools::parse_hexstr_to_binbuff(spendKey, spendKeyData) || spendKeyData.size() != sizeof(crypto::secret_key)) { + crypto::secret_key spend_key_sk; + bool has_spend_key = false; + if (!spend_key.empty()) { + cryptonote::blobdata spend_key_data; + if (!epee::string_tools::parse_hexstr_to_binbuff(spend_key, spend_key_data) || spend_key_data.size() != sizeof(crypto::secret_key)) { throw runtime_error("failed to parse secret spend key"); } - hasSpendKey = true; - spendKeySK = *reinterpret_cast(spendKeyData.data()); + has_spend_key = true; + spend_key_sk = *reinterpret_cast(spend_key_data.data()); } // validate and parse private view key - bool hasViewKey = true; - crypto::secret_key viewKeySK; - if (!viewKey.empty()) { - if (hasSpendKey) hasViewKey = false; + bool has_view_key = true; + crypto::secret_key view_key_sk; + if (!view_key.empty()) { + if (has_spend_key) has_view_key = false; else throw runtime_error("Neither view key nor spend key supplied, cancelled"); } - if (hasViewKey) { - cryptonote::blobdata viewKeyData; - if (!epee::string_tools::parse_hexstr_to_binbuff(viewKey, viewKeyData) || viewKeyData.size() != sizeof(crypto::secret_key)) { + if (has_view_key) { + cryptonote::blobdata view_key_data; + if (!epee::string_tools::parse_hexstr_to_binbuff(view_key, view_key_data) || view_key_data.size() != sizeof(crypto::secret_key)) { throw runtime_error("failed to parse secret view key"); } - viewKeySK = *reinterpret_cast(viewKeyData.data()); + view_key_sk = *reinterpret_cast(view_key_data.data()); } // check the spend and view keys match the given address crypto::public_key pkey; - if (hasSpendKey) { - if (!crypto::secret_key_to_public_key(spendKeySK, pkey)) throw runtime_error("failed to verify secret spend key"); + if (has_spend_key) { + if (!crypto::secret_key_to_public_key(spend_key_sk, pkey)) throw runtime_error("failed to verify secret spend key"); if (info.address.m_spend_public_key != pkey) throw runtime_error("spend key does not match address"); } - if (hasViewKey) { - if (!crypto::secret_key_to_public_key(viewKeySK, pkey)) throw runtime_error("failed to verify secret view key"); + if (has_view_key) { + if (!crypto::secret_key_to_public_key(view_key_sk, pkey)) throw runtime_error("failed to verify secret view key"); if (info.address.m_view_public_key != pkey) throw runtime_error("view key does not match address"); } // initialize wallet - wallet->wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); - if (hasSpendKey && hasViewKey) wallet->wallet2->generate(path, password, info.address, spendKeySK, viewKeySK); - if (!hasSpendKey && hasViewKey) wallet->wallet2->generate(path, password, info.address, viewKeySK); - if (hasSpendKey && !hasViewKey) wallet->wallet2->generate(path, password, spendKeySK, true, false); - wallet->set_daemon_connection(daemonConnection); - wallet->wallet2->set_refresh_from_block_height(restoreHeight); + wallet->wallet2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); + if (has_spend_key && has_view_key) wallet->wallet2->generate(path, password, info.address, spend_key_sk, view_key_sk); + if (!has_spend_key && has_view_key) wallet->wallet2->generate(path, password, info.address, view_key_sk); + if (has_spend_key && !has_view_key) wallet->wallet2->generate(path, password, spend_key_sk, true, false); + wallet->set_daemon_connection(daemon_connection); + wallet->wallet2->set_refresh_from_block_height(restore_height); wallet->wallet2->set_seed_language(language); - wallet->initCommon(); + wallet->init_common(); return wallet; } @@ -922,16 +922,16 @@ namespace monero { void monero_wallet::set_daemon_connection(const string& uri, const string& username, const string& password) { MTRACE("set_daemon_connection(" << uri << ", " << username << ", " << password << ")"); - // prepare uri, login, and isTrusted for wallet2 + // prepare uri, login, and is_trusted for wallet2 boost::optional login{}; login.emplace(username, password); - bool isTrusted = false; - try { isTrusted = tools::is_local_address(uri); } // wallet is trusted iff local + bool is_trusted = false; + try { is_trusted = tools::is_local_address(uri); } // wallet is trusted iff local catch (const exception &e) { } // init wallet2 and set daemon connection if (!wallet2->init(uri, login)) throw runtime_error("Failed to initialize wallet with daemon connection"); - get_is_connected(); // update isConnected cache // TODO: better naming? + get_is_connected(); // update is_connected cache // TODO: better naming? } void monero_wallet::set_daemon_connection(const monero_rpc_connection& connection) { @@ -955,14 +955,14 @@ namespace monero { // TODO: could return Wallet::ConnectionStatus_Disconnected, Wallet::ConnectionStatus_WrongVersion, Wallet::ConnectionStatus_Connected like wallet.cpp::connected() bool monero_wallet::get_is_connected() const { uint32_t version = 0; - isConnected = wallet2->check_connection(&version, NULL, DEFAULT_CONNECTION_TIMEOUT_MILLIS); // TODO: should this be updated elsewhere? - if (!isConnected) return false; - if (!wallet2->light_wallet() && (version >> 16) != CORE_RPC_VERSION_MAJOR) isConnected = false; - return isConnected; + is_connected = wallet2->check_connection(&version, NULL, DEFAULT_CONNECTION_TIMEOUT_MILLIS); // TODO: should this be updated elsewhere? + if (!is_connected) return false; + if (!wallet2->light_wallet() && (version >> 16) != CORE_RPC_VERSION_MAJOR) is_connected = false; // wrong network type + return is_connected; } uint64_t monero_wallet::get_daemon_height() const { - if (!isConnected) throw runtime_error("wallet is not connected to daemon"); + if (!is_connected) throw runtime_error("wallet is not connected to daemon"); std::string err; uint64_t result = wallet2->get_daemon_blockchain_height(err); if (!err.empty()) throw runtime_error(err); @@ -970,7 +970,7 @@ namespace monero { } uint64_t monero_wallet::get_daemon_target_height() const { - if (!isConnected) throw runtime_error("wallet is not connected to daemon"); + if (!is_connected) throw runtime_error("wallet is not connected to daemon"); std::string err; uint64_t result = wallet2->get_daemon_blockchain_target_height(err); if (!err.empty()) throw runtime_error(err); @@ -979,21 +979,21 @@ namespace monero { } bool monero_wallet::get_is_daemon_synced() const { - if (!isConnected) throw runtime_error("wallet is not connected to daemon"); + if (!is_connected) throw runtime_error("wallet is not connected to daemon"); uint64_t daemonHeight = get_daemon_height(); return daemonHeight >= get_daemon_target_height() && daemonHeight > 1; } bool monero_wallet::get_is_synced() const { - return isSynced; + return is_synced; } string monero_wallet::get_path() const { return wallet2->path(); } - MoneroNetworkType monero_wallet::get_network_type() const { - return static_cast(wallet2->nettype()); + monero_network_type monero_wallet::get_network_type() const { + return static_cast(wallet2->nettype()); } string monero_wallet::get_language() const { @@ -1008,8 +1008,8 @@ namespace monero { // get primary address (default impl?) - string monero_wallet::get_address(uint32_t accountIdx, uint32_t subaddressIdx) const { - return wallet2->get_subaddress_as_str({accountIdx, subaddressIdx}); + string monero_wallet::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { + return wallet2->get_subaddress_as_str({account_idx, subaddress_idx}); } monero_subaddress monero_wallet::get_address_index(const string& address) const { @@ -1027,9 +1027,9 @@ namespace monero { // return indices in subaddress monero_subaddress subaddress; - cryptonote::subaddress_index cnIndex = *index; - subaddress.account_index = cnIndex.major; - subaddress.index = cnIndex.minor; + cryptonote::subaddress_index cn_index = *index; + subaddress.account_index = cn_index.major; + subaddress.index = cn_index.minor; return subaddress; } @@ -1039,16 +1039,16 @@ namespace monero { // TODO monero-core: this logic is based on wallet_rpc_server::on_make_integrated_address() and should be moved to wallet so this is unecessary for api users // randomly generate payment id if not given, else validate - crypto::hash8 paymentIdH8; + crypto::hash8 paymen_id_h8; if (payment_id.empty()) { - paymentIdH8 = crypto::rand(); + paymen_id_h8 = crypto::rand(); } else { - if (!tools::wallet2::parse_short_payment_id(payment_id, paymentIdH8)) throw runtime_error("Invalid payment ID: " + payment_id); + if (!tools::wallet2::parse_short_payment_id(payment_id, paymen_id_h8)) throw runtime_error("Invalid payment ID: " + payment_id); } // use primary address if standard address not given, else validate if (standard_address.empty()) { - return decode_integrated_address(wallet2->get_integrated_address_as_str(paymentIdH8)); + return decode_integrated_address(wallet2->get_integrated_address_as_str(paymen_id_h8)); } else { // validate standard address @@ -1059,7 +1059,7 @@ namespace monero { if (payment_id.empty()) throw runtime_error("Payment ID shouldn't be left unspecified"); // create integrated address from given standard address - return decode_integrated_address(cryptonote::get_account_integrated_address_as_str(wallet2->nettype(), info.address, paymentIdH8)); + return decode_integrated_address(cryptonote::get_account_integrated_address_as_str(wallet2->nettype(), info.address, paymen_id_h8)); } } @@ -1105,42 +1105,42 @@ namespace monero { return epee::string_tools::pod_to_hex(wallet2->get_account().get_keys().m_spend_secret_key); } - void monero_wallet::set_listener(const boost::optional listener) { + void monero_wallet::set_listener(const boost::optional listener) { MTRACE("set_listener()"); - wallet2Listener->setWalletListener(listener); + wallet2_listener->set_wallet_listener(listener); } monero_sync_result monero_wallet::sync() { MTRACE("sync()"); - if (!isConnected) throw runtime_error("No connection to daemon"); - return lockAndSync(); + if (!is_connected) throw runtime_error("No connection to daemon"); + return lock_and_sync(); } monero_sync_result monero_wallet::sync(monero_sync_listener& listener) { MTRACE("sync(listener)"); - if (!isConnected) throw runtime_error("No connection to daemon"); - return lockAndSync(boost::none, listener); + if (!is_connected) throw runtime_error("No connection to daemon"); + return lock_and_sync(boost::none, listener); } - monero_sync_result monero_wallet::sync(uint64_t startHeight) { - MTRACE("sync(" << startHeight << ")"); - if (!isConnected) throw runtime_error("No connection to daemon"); - return lockAndSync(startHeight); + monero_sync_result monero_wallet::sync(uint64_t start_height) { + MTRACE("sync(" << start_height << ")"); + if (!is_connected) throw runtime_error("No connection to daemon"); + return lock_and_sync(start_height); } - monero_sync_result monero_wallet::sync(uint64_t startHeight, monero_sync_listener& listener) { - MTRACE("sync(" << startHeight << ", listener)"); - if (!isConnected) throw runtime_error("No connection to daemon"); - return lockAndSync(startHeight, listener); + monero_sync_result monero_wallet::sync(uint64_t start_height, monero_sync_listener& listener) { + MTRACE("sync(" << start_height << ", listener)"); + if (!is_connected) throw runtime_error("No connection to daemon"); + return lock_and_sync(start_height, listener); } /** * Start automatic syncing as its own thread. */ void monero_wallet::start_syncing() { - if (!syncingEnabled) { - syncingEnabled = true; - syncCV.notify_one(); + if (!syncing_enabled) { + syncing_enabled = true; + sync_cv.notify_one(); } } @@ -1148,17 +1148,17 @@ namespace monero { * Stop automatic syncing as its own thread. */ void monero_wallet::stop_syncing() { - if (!syncingThreadDone) { - syncingEnabled = false; + if (!syncing_thread_done) { + syncing_enabled = false; } } // TODO: support arguments bool hard, bool refresh = true, bool keep_key_images = false void monero_wallet::rescan_blockchain() { MTRACE("rescan_blockchain()"); - if (!isConnected) throw runtime_error("No connection to daemon"); - rescanOnSync = true; - lockAndSync(); + if (!is_connected) throw runtime_error("No connection to daemon"); + rescan_on_sync = true; + lock_and_sync(); } // isMultisigImportNeeded @@ -1167,33 +1167,33 @@ namespace monero { return wallet2->get_blockchain_current_height(); } - uint64_t monero_wallet::getChainHeight() const { + uint64_t monero_wallet::get_chain_height() const { string err; - if (!isConnected) throw runtime_error("No connection to daemon"); - uint64_t chainHeight = wallet2->get_daemon_blockchain_height(err); + if (!is_connected) throw runtime_error("No connection to daemon"); + uint64_t chain_height = wallet2->get_daemon_blockchain_height(err); if (!err.empty()) throw runtime_error(err); - return chainHeight; + return chain_height; } uint64_t monero_wallet::get_restore_height() const { return wallet2->get_refresh_from_block_height(); } - void monero_wallet::set_restore_height(uint64_t restoreHeight) { - wallet2->set_refresh_from_block_height(restoreHeight); + void monero_wallet::set_restore_height(uint64_t restore_height) { + wallet2->set_refresh_from_block_height(restore_height); } uint64_t monero_wallet::get_balance() const { return wallet2->balance_all(); } - uint64_t monero_wallet::get_balance(uint32_t accountIdx) const { - return wallet2->balance(accountIdx); + uint64_t monero_wallet::get_balance(uint32_t account_idx) const { + return wallet2->balance(account_idx); } - uint64_t monero_wallet::get_balance(uint32_t accountIdx, uint32_t subaddressIdx) const { - map balancePerSubaddress = wallet2->balance_per_subaddress(accountIdx); - auto iter = balancePerSubaddress.find(subaddressIdx); + uint64_t monero_wallet::get_balance(uint32_t account_idx, uint32_t subaddress_idx) const { + map balancePerSubaddress = wallet2->balance_per_subaddress(account_idx); + auto iter = balancePerSubaddress.find(subaddress_idx); return iter == balancePerSubaddress.end() ? 0 : iter->second; } @@ -1201,13 +1201,13 @@ namespace monero { return wallet2->unlocked_balance_all(); } - uint64_t monero_wallet::get_unlocked_balance(uint32_t accountIdx) const { - return wallet2->unlocked_balance(accountIdx); + uint64_t monero_wallet::get_unlocked_balance(uint32_t account_idx) const { + return wallet2->unlocked_balance(account_idx); } - uint64_t monero_wallet::get_unlocked_balance(uint32_t accountIdx, uint32_t subaddressIdx) const { - map> unlockedBalancePerSubaddress = wallet2->unlocked_balance_per_subaddress(accountIdx); - auto iter = unlockedBalancePerSubaddress.find(subaddressIdx); + uint64_t monero_wallet::get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const { + map> unlockedBalancePerSubaddress = wallet2->unlocked_balance_per_subaddress(account_idx); + auto iter = unlockedBalancePerSubaddress.find(subaddress_idx); return iter == unlockedBalancePerSubaddress.end() ? 0 : iter->second.first; } @@ -1216,8 +1216,8 @@ namespace monero { return get_accounts(false, string("")); } - vector monero_wallet::get_accounts(bool includeSubaddresses) const { - MTRACE("get_accounts(" << includeSubaddresses << ")"); + vector monero_wallet::get_accounts(bool include_subaddresses) const { + MTRACE("get_accounts(" << include_subaddresses << ")"); throw runtime_error("Not implemented"); } @@ -1226,46 +1226,46 @@ namespace monero { throw runtime_error("Not implemented"); } - vector monero_wallet::get_accounts(bool includeSubaddresses, const string& tag) const { - MTRACE("get_accounts(" << includeSubaddresses << ", " << tag << ")"); + vector monero_wallet::get_accounts(bool include_subaddresses, const string& tag) const { + MTRACE("get_accounts(" << include_subaddresses << ", " << tag << ")"); // need transfers to inform if subaddresses used vector transfers; - if (includeSubaddresses) wallet2->get_transfers(transfers); + if (include_subaddresses) wallet2->get_transfers(transfers); // build accounts vector accounts; - for (uint32_t accountIdx = 0; accountIdx < wallet2->get_num_subaddress_accounts(); accountIdx++) { + for (uint32_t account_idx = 0; account_idx < wallet2->get_num_subaddress_accounts(); account_idx++) { monero_account account; - account.index = accountIdx; - account.primary_address = get_address(accountIdx, 0); - account.balance = wallet2->balance(accountIdx); - account.unlocked_balance = wallet2->unlocked_balance(accountIdx); - if (includeSubaddresses) account.subaddresses = getSubaddressesAux(accountIdx, vector(), transfers); + account.index = account_idx; + account.primary_address = get_address(account_idx, 0); + account.balance = wallet2->balance(account_idx); + account.unlocked_balance = wallet2->unlocked_balance(account_idx); + if (include_subaddresses) account.subaddresses = get_subaddresses_aux(account_idx, vector(), transfers); accounts.push_back(account); } return accounts; } - monero_account monero_wallet::get_account(const uint32_t accountIdx) const { - return get_account(accountIdx, false); + monero_account monero_wallet::get_account(const uint32_t account_idx) const { + return get_account(account_idx, false); } - monero_account monero_wallet::get_account(uint32_t accountIdx, bool includeSubaddresses) const { - MTRACE("get_account(" << accountIdx << ", " << includeSubaddresses << ")"); + monero_account monero_wallet::get_account(uint32_t account_idx, bool include_subaddresses) const { + MTRACE("get_account(" << account_idx << ", " << include_subaddresses << ")"); // need transfers to inform if subaddresses used vector transfers; - if (includeSubaddresses) wallet2->get_transfers(transfers); + if (include_subaddresses) wallet2->get_transfers(transfers); // build and return account monero_account account; - account.index = accountIdx; - account.primary_address = get_address(accountIdx, 0); - account.balance = wallet2->balance(accountIdx); - account.unlocked_balance = wallet2->unlocked_balance(accountIdx); - if (includeSubaddresses) account.subaddresses = getSubaddressesAux(accountIdx, vector(), transfers); + account.index = account_idx; + account.primary_address = get_address(account_idx, 0); + account.balance = wallet2->balance(account_idx); + account.unlocked_balance = wallet2->unlocked_balance(account_idx); + if (include_subaddresses) account.subaddresses = get_subaddresses_aux(account_idx, vector(), transfers); return account; } @@ -1284,36 +1284,36 @@ namespace monero { return account; } - vector monero_wallet::get_subaddresses(const uint32_t accountIdx) const { - return get_subaddresses(accountIdx, vector()); + vector monero_wallet::get_subaddresses(const uint32_t account_idx) const { + return get_subaddresses(account_idx, vector()); } - vector monero_wallet::get_subaddresses(const uint32_t accountIdx, const vector& subaddress_indices) const { - MTRACE("get_subaddresses(" << accountIdx << ", ...)"); + vector monero_wallet::get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const { + MTRACE("get_subaddresses(" << account_idx << ", ...)"); MTRACE("Subaddress indices size: " << subaddress_indices.size()); vector transfers; wallet2->get_transfers(transfers); - return getSubaddressesAux(accountIdx, subaddress_indices, transfers); + return get_subaddresses_aux(account_idx, subaddress_indices, transfers); } - monero_subaddress monero_wallet::getSubaddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const { + monero_subaddress monero_wallet::getSubaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const { throw runtime_error("Not implemented"); } // get_subaddresses - monero_subaddress monero_wallet::create_subaddress(const uint32_t accountIdx, const string& label) { - MTRACE("create_subaddress(" << accountIdx << ", " << label << ")"); + monero_subaddress monero_wallet::create_subaddress(const uint32_t account_idx, const string& label) { + MTRACE("create_subaddress(" << account_idx << ", " << label << ")"); // create subaddress - wallet2->add_subaddress(accountIdx, label); + wallet2->add_subaddress(account_idx, label); // initialize and return result monero_subaddress subaddress; - subaddress.account_index = accountIdx; - subaddress.index = wallet2->get_num_subaddresses(accountIdx) - 1; - subaddress.address = wallet2->get_subaddress_as_str({accountIdx, subaddress.index.get()}); + subaddress.account_index = account_idx; + subaddress.index = wallet2->get_num_subaddresses(account_idx) - 1; + subaddress.address = wallet2->get_subaddress_as_str({account_idx, subaddress.index.get()}); subaddress.label = label; subaddress.balance = 0; subaddress.unlocked_balance = 0; @@ -1335,7 +1335,7 @@ namespace monero { shared_ptr requestSp = make_shared(request); // convert to shared pointer for copy shared_ptr req = requestSp->copy(requestSp, make_shared()); if (req->transfer_request == boost::none) req->transfer_request = make_shared(); - shared_ptr transferReq = req->transfer_request.get(); + shared_ptr transfer_req = req->transfer_request.get(); // print req if (req->block != boost::none) MTRACE("Tx req's rooted at [block]: " << req->block.get()->serialize()); @@ -1345,9 +1345,9 @@ namespace monero { req->transfer_request = boost::none; // fetch all transfers that meet tx request - monero_transfer_request tempTransferReq; - tempTransferReq.tx_request = make_shared(*req); - vector> transfers = get_transfers(tempTransferReq); + monero_transfer_request temp_transfer_req; + temp_transfer_req.tx_request = make_shared(*req); + vector> transfers = get_transfers(temp_transfer_req); // collect unique txs from transfers while retaining order vector> txs = vector>(); @@ -1360,58 +1360,58 @@ namespace monero { } // cache types into maps for merging and lookup - map> txMap; - map> blockMap; + map> tx_map; + map> block_map; for (const shared_ptr& tx : txs) { - merge_tx(tx, txMap, blockMap, false); + merge_tx(tx, tx_map, block_map, false); } // fetch and merge outputs if requested - monero_output_request tempOutputReq; - tempOutputReq.tx_request = make_shared(*req); + monero_output_request temp_output_req; + temp_output_req.tx_request = make_shared(*req); if (req->include_outputs != boost::none && *req->include_outputs) { // fetch outputs - vector> outputs = get_outputs(tempOutputReq); + vector> outputs = get_outputs(temp_output_req); // merge output txs one time while retaining order unordered_set> outputTxs; for (const shared_ptr& output : outputs) { shared_ptr tx = static_pointer_cast(output->tx); if (outputTxs.find(tx) == outputTxs.end()) { - merge_tx(tx, txMap, blockMap, true); + merge_tx(tx, tx_map, block_map, true); outputTxs.insert(tx); } } } // filter txs that don't meet transfer req // TODO: port this updated version to js - req->transfer_request = transferReq; - vector> txsRequested; - vector>::iterator txIter = txs.begin(); - while (txIter != txs.end()) { - shared_ptr tx = *txIter; - if (req->meetsCriteria(tx.get())) { - txsRequested.push_back(tx); - txIter++; + req->transfer_request = transfer_req; + vector> txs_requested; + vector>::iterator tx_iter = txs.begin(); + while (tx_iter != txs.end()) { + shared_ptr tx = *tx_iter; + if (req->meets_criteria(tx.get())) { + txs_requested.push_back(tx); + tx_iter++; } else { - txIter = txs.erase(txIter); - if (tx->block != boost::none) 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 txIter? + tx_iter = txs.erase(tx_iter); + if (tx->block != boost::none) 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 tx_iter? } } - txs = txsRequested; + txs = txs_requested; // verify all specified tx ids found if (!req->tx_ids.empty()) { - for (const string& txId : req->tx_ids) { + for (const string& tx_id : req->tx_ids) { bool found = false; for (const shared_ptr& tx : txs) { - if (txId == *tx->id) { + if (tx_id == *tx->id) { found = true; break; } } - if (!found) throw runtime_error("Tx not found in wallet: " + txId); + if (!found) throw runtime_error("Tx not found in wallet: " + tx_id); } } @@ -1423,12 +1423,12 @@ namespace monero { // otherwise order txs if tx ids given then return if (!req->tx_ids.empty()) { - vector> orderedTxs; - for (const string& txId : req->tx_ids) { - map>::const_iterator txIter = txMap.find(txId); - orderedTxs.push_back(txIter->second); + vector> ordered_txs; + for (const string& tx_id : req->tx_ids) { + map>::const_iterator tx_iter = tx_map.find(tx_id); + ordered_txs.push_back(tx_iter->second); } - txs = orderedTxs; + txs = ordered_txs; } return txs; } @@ -1446,23 +1446,23 @@ namespace monero { shared_ptr req; if (request.tx_request == boost::none) req = request.copy(make_shared(request), make_shared()); else { - shared_ptr txReq = request.tx_request.get()->copy(request.tx_request.get(), make_shared()); + shared_ptr tx_req = request.tx_request.get()->copy(request.tx_request.get(), make_shared()); if (request.tx_request.get()->transfer_request != boost::none && request.tx_request.get()->transfer_request.get().get() == &request) { - req = txReq->transfer_request.get(); + req = tx_req->transfer_request.get(); } else { if (request.tx_request.get()->transfer_request != boost::none) throw new runtime_error("Transfer request's tx request must be a circular reference or null"); shared_ptr requestSp = make_shared(request); // convert request to shared pointer for copy req = requestSp->copy(requestSp, make_shared()); - req->tx_request = txReq; + req->tx_request = tx_req; } } if (req->tx_request == boost::none) req->tx_request = make_shared(); - shared_ptr txReq = req->tx_request.get(); - txReq->transfer_request = boost::none; // break circular link for meetsCriteria() + shared_ptr tx_req = req->tx_request.get(); + tx_req->transfer_request = boost::none; // break circular link for meets_criteria() // build parameters for wallet2->get_payments() - uint64_t min_height = txReq->min_height == boost::none ? 0 : *txReq->min_height; - uint64_t max_height = txReq->max_height == boost::none ? CRYPTONOTE_MAX_BLOCK_NUMBER : min((uint64_t) CRYPTONOTE_MAX_BLOCK_NUMBER, *txReq->max_height); + uint64_t min_height = tx_req->min_height == boost::none ? 0 : *tx_req->min_height; + uint64_t max_height = tx_req->max_height == boost::none ? CRYPTONOTE_MAX_BLOCK_NUMBER : min((uint64_t) CRYPTONOTE_MAX_BLOCK_NUMBER, *tx_req->max_height); if (min_height > 0) min_height--; // TODO monero core: wallet2::get_payments() min_height is exclusive, so manually offset to match intended range (issues 5751, #5598) boost::optional account_index = boost::none; if (req->account_index != boost::none) account_index = *req->account_index; @@ -1472,85 +1472,85 @@ namespace monero { } // translate from monero_tx_request to in, out, pending, pool, failed terminology used by monero-wallet-rpc - bool canBeConfirmed = !boolEquals(false, txReq->is_confirmed) && !boolEquals(true, txReq->in_tx_pool) && !boolEquals(true, txReq->is_failed) && !boolEquals(false, txReq->is_relayed); - bool canBeInTxPool = !boolEquals(true, txReq->is_confirmed) && !boolEquals(false, txReq->in_tx_pool) && !boolEquals(true, txReq->is_failed) && !boolEquals(false, txReq->is_relayed) && txReq->get_height() == boost::none && txReq->min_height == boost::none; - bool canBeIncoming = !boolEquals(false, req->is_incoming) && !boolEquals(true, req->getIsOutgoing()) && !boolEquals(true, req->has_destinations); - bool canBeOutgoing = !boolEquals(false, req->getIsOutgoing()) && !boolEquals(true, req->is_incoming); - bool isIn = canBeIncoming && canBeConfirmed; - bool isOut = canBeOutgoing && canBeConfirmed; - bool isPending = canBeOutgoing && canBeInTxPool; - bool isPool = canBeIncoming && canBeInTxPool; - bool is_failed = !boolEquals(false, txReq->is_failed) && !boolEquals(true, txReq->is_confirmed) && !boolEquals(true, txReq->in_tx_pool); + bool can_be_confirmed = !bool_equals(false, tx_req->is_confirmed) && !bool_equals(true, tx_req->in_tx_pool) && !bool_equals(true, tx_req->is_failed) && !bool_equals(false, tx_req->is_relayed); + bool can_be_in_tx_pool = !bool_equals(true, tx_req->is_confirmed) && !bool_equals(false, tx_req->in_tx_pool) && !bool_equals(true, tx_req->is_failed) && !bool_equals(false, tx_req->is_relayed) && tx_req->get_height() == boost::none && tx_req->min_height == boost::none; + bool can_be_incoming = !bool_equals(false, req->is_incoming) && !bool_equals(true, req->getIsOutgoing()) && !bool_equals(true, req->has_destinations); + bool can_be_outgoing = !bool_equals(false, req->getIsOutgoing()) && !bool_equals(true, req->is_incoming); + bool is_in = can_be_incoming && can_be_confirmed; + bool is_out = can_be_outgoing && can_be_confirmed; + bool is_pending = can_be_outgoing && can_be_in_tx_pool; + bool is_pool = can_be_incoming && can_be_in_tx_pool; + bool is_failed = !bool_equals(false, tx_req->is_failed) && !bool_equals(true, tx_req->is_confirmed) && !bool_equals(true, tx_req->in_tx_pool); // cache unique txs and blocks uint64_t height = get_height(); - map> txMap; - map> blockMap; + map> tx_map; + map> block_map; // get confirmed incoming transfers - if (isIn) { + if (is_in) { std::list> payments; wallet2->get_payments(payments, min_height, max_height, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { - shared_ptr tx = buildTxWithIncomingTransfer(*wallet2, height, i->first, i->second); - merge_tx(tx, txMap, blockMap, false); + shared_ptr tx = builc_tx_with_incoming_transfer(*wallet2, height, i->first, i->second); + merge_tx(tx, tx_map, block_map, false); } } // get confirmed outgoing transfers - if (isOut) { + if (is_out) { std::list> payments; wallet2->get_payments_out(payments, min_height, max_height, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { - shared_ptr tx = buildTxWithOutgoingTransfer(*wallet2, height, i->first, i->second); - merge_tx(tx, txMap, blockMap, false); + shared_ptr tx = build_tx_with_outgoing_transfer(*wallet2, height, i->first, i->second); + merge_tx(tx, tx_map, block_map, false); } } // get unconfirmed or failed outgoing transfers - if (isPending || is_failed) { + if (is_pending || is_failed) { std::list> upayments; wallet2->get_unconfirmed_payments_out(upayments, account_index, subaddress_indices); for (std::list>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) { - shared_ptr tx = buildTxWithOutgoingTransferUnconfirmed(*wallet2, i->first, i->second); - if (txReq->is_failed != boost::none && txReq->is_failed.get() != tx->is_failed.get()) continue; // skip merging if tx unrequested - merge_tx(tx, txMap, blockMap, false); + shared_ptr tx = build_tx_with_outgoing_transfer_unconfirmed(*wallet2, i->first, i->second); + if (tx_req->is_failed != boost::none && tx_req->is_failed.get() != tx->is_failed.get()) continue; // skip merging if tx unrequested + merge_tx(tx, tx_map, block_map, false); } } // get unconfirmed incoming transfers - if (isPool) { + if (is_pool) { wallet2->update_pool_state(); // TODO monero-core: this should be encapsulated in wallet when unconfirmed transfers requested std::list> payments; wallet2->get_unconfirmed_payments(payments, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { - shared_ptr tx = buildTxWithIncomingTransferUnconfirmed(*wallet2, i->first, i->second); - merge_tx(tx, txMap, blockMap, false); + shared_ptr tx = build_tx_with_incoming_transfer_unconfirmed(*wallet2, i->first, i->second); + merge_tx(tx, tx_map, block_map, false); } } // sort txs by block height vector> txs ; - for (map>::const_iterator txIter = txMap.begin(); txIter != txMap.end(); txIter++) { - txs.push_back(txIter->second); + for (map>::const_iterator tx_iter = tx_map.begin(); tx_iter != tx_map.end(); tx_iter++) { + txs.push_back(tx_iter->second); } - sort(txs.begin(), txs.end(), txHeightLessThan); + sort(txs.begin(), txs.end(), tx_height_less_than); // filter and return transfers vector> transfers; for (const shared_ptr& tx : txs) { // sort transfers - sort(tx->incoming_transfers.begin(), tx->incoming_transfers.end(), incomingTransferBefore); + sort(tx->incoming_transfers.begin(), tx->incoming_transfers.end(), incoming_transfer_before); // collect outgoing transfer, erase if filtered TODO: js does not erase unrequested data, port to js - if (tx->outgoing_transfer != boost::none && req->meetsCriteria(tx->outgoing_transfer.get().get())) transfers.push_back(tx->outgoing_transfer.get()); + if (tx->outgoing_transfer != boost::none && req->meets_criteria(tx->outgoing_transfer.get().get())) transfers.push_back(tx->outgoing_transfer.get()); else tx->outgoing_transfer = boost::none; // collect incoming transfers, erase if unrequested vector>::iterator iter = tx->incoming_transfers.begin(); while (iter != tx->incoming_transfers.end()) { - if (req->meetsCriteria((*iter).get())) { + if (req->meets_criteria((*iter).get())) { transfers.push_back(*iter); iter++; } else { @@ -1582,53 +1582,53 @@ namespace monero { shared_ptr req; if (request.tx_request == boost::none) req = request.copy(make_shared(request), make_shared()); else { - shared_ptr txReq = request.tx_request.get()->copy(request.tx_request.get(), make_shared()); + shared_ptr tx_req = request.tx_request.get()->copy(request.tx_request.get(), make_shared()); if (request.tx_request.get()->output_request != boost::none && request.tx_request.get()->output_request.get().get() == &request) { - req = txReq->output_request.get(); + req = tx_req->output_request.get(); } else { if (request.tx_request.get()->output_request != boost::none) throw new runtime_error("Output request's tx request must be a circular reference or null"); shared_ptr requestSp = make_shared(request); // convert request to shared pointer for copy req = requestSp->copy(requestSp, make_shared()); - req->tx_request = txReq; + req->tx_request = tx_req; } } if (req->tx_request == boost::none) req->tx_request = make_shared(); - shared_ptr txReq = req->tx_request.get(); - txReq->output_request = boost::none; // break circular link for meetsCriteria() + shared_ptr tx_req = req->tx_request.get(); + tx_req->output_request = boost::none; // break circular link for meets_criteria() // get output data from wallet2 - tools::wallet2::transfer_container outputsW2; - wallet2->get_transfers(outputsW2); + tools::wallet2::transfer_container outputs_w2; + wallet2->get_transfers(outputs_w2); // cache unique txs and blocks - map> txMap; - map> blockMap; - for (const auto& outputW2 : outputsW2) { + map> tx_map; + map> block_map; + for (const auto& output_w2 : outputs_w2) { // TODO: skip tx building if w2 output filtered by indices, etc - shared_ptr tx = buildTxWithVout(*wallet2, outputW2); - merge_tx(tx, txMap, blockMap, false); + shared_ptr tx = build_tx_with_vout(*wallet2, output_w2); + merge_tx(tx, tx_map, block_map, false); } // sort txs by block height vector> txs ; - for (map>::const_iterator txIter = txMap.begin(); txIter != txMap.end(); txIter++) { - txs.push_back(txIter->second); + for (map>::const_iterator tx_iter = tx_map.begin(); tx_iter != tx_map.end(); tx_iter++) { + txs.push_back(tx_iter->second); } - sort(txs.begin(), txs.end(), txHeightLessThan); + sort(txs.begin(), txs.end(), tx_height_less_than); // filter and return outputs vector> vouts; for (const shared_ptr& tx : txs) { // sort outputs - sort(tx->vouts.begin(), tx->vouts.end(), voutBefore); + sort(tx->vouts.begin(), tx->vouts.end(), vout_before); // collect requested outputs, remove unrequested outputs vector>::iterator voutIter = tx->vouts.begin(); while (voutIter != tx->vouts.end()) { - shared_ptr voutWallet = static_pointer_cast(*voutIter); - if (req->meetsCriteria(voutWallet.get())) { - vouts.push_back(voutWallet); + shared_ptr vout_wallet = static_pointer_cast(*voutIter); + if (req->meets_criteria(vout_wallet.get())) { + vouts.push_back(vout_wallet); voutIter++; } else { voutIter = tx->vouts.erase(voutIter); // remove unrequested vouts @@ -1645,11 +1645,11 @@ namespace monero { return epee::string_tools::buff_to_hex_nodelimer(wallet2->export_outputs_to_str(true)); } - int monero_wallet::import_outputs_hex(const string& outputsHex) { + int monero_wallet::import_outputs_hex(const string& outputs_hex) { // validate and parse hex data cryptonote::blobdata blob; - if (!epee::string_tools::parse_hexstr_to_binbuff(outputsHex, blob)) { + if (!epee::string_tools::parse_hexstr_to_binbuff(outputs_hex, blob)) { throw runtime_error("Failed to parse hex."); } @@ -1661,28 +1661,28 @@ namespace monero { MTRACE("monero_wallet::get_key_images()"); // build key images from wallet2 types - vector> keyImages; + vector> key_images; std::pair>> ski = wallet2->export_key_images(true); for (size_t n = 0; n < ski.second.size(); ++n) { shared_ptr key_image = make_shared(); - keyImages.push_back(key_image); + key_images.push_back(key_image); key_image->hex = epee::string_tools::pod_to_hex(ski.second[n].first); key_image->signature = epee::string_tools::pod_to_hex(ski.second[n].second); } - return keyImages; + return key_images; } - shared_ptr monero_wallet::import_key_images(const vector>& keyImages) { + shared_ptr monero_wallet::import_key_images(const vector>& key_images) { MTRACE("monero_wallet::import_key_images()"); // validate and prepare key images for wallet2 std::vector> ski; - ski.resize(keyImages.size()); + ski.resize(key_images.size()); for (size_t n = 0; n < ski.size(); ++n) { - if (!epee::string_tools::hex_to_pod(keyImages[n]->hex.get(), ski[n].first)) { + if (!epee::string_tools::hex_to_pod(key_images[n]->hex.get(), ski[n].first)) { throw runtime_error("failed to parse key image"); } - if (!epee::string_tools::hex_to_pod(keyImages[n]->signature.get(), ski[n].second)) { + if (!epee::string_tools::hex_to_pod(key_images[n]->signature.get(), ski[n].second)) { throw runtime_error("failed to parse signature"); } } @@ -1709,29 +1709,29 @@ namespace monero { // prepare parameters for wallet rpc's validate_transfer() string payment_id = request.payment_id == boost::none ? string("") : request.payment_id.get(); - list trDestinations; + list tr_destinations; for (const shared_ptr& destination : request.destinations) { - tools::wallet_rpc::transfer_destination trDestination; - trDestination.amount = destination->amount.get(); - trDestination.address = destination->address.get(); - trDestinations.push_back(trDestination); + tools::wallet_rpc::transfer_destination tr_destination; + tr_destination.amount = destination->amount.get(); + tr_destination.address = destination->address.get(); + tr_destinations.push_back(tr_destination); } // validate the requested txs and populate dsts & extra std::vector dsts; std::vector extra; - if (!validate_transfer(wallet2.get(), trDestinations, payment_id, dsts, extra, true, err)) { + if (!validate_transfer(wallet2.get(), tr_destinations, payment_id, dsts, extra, true, err)) { throw runtime_error("Need to handle send_split() validate_transfer error"); // TODO } // prepare parameters for wallet2's create_transactions_2() - uint64_t mixin = wallet2->adjust_mixin(request.ringSize == boost::none ? 0 : request.ringSize.get() - 1); + uint64_t mixin = wallet2->adjust_mixin(request.ring_size == boost::none ? 0 : request.ring_size.get() - 1); uint32_t priority = wallet2->adjust_priority(request.priority == boost::none ? 0 : request.priority.get()); uint64_t unlock_time = request.unlock_time == boost::none ? 0 : request.unlock_time.get(); if (request.account_index == boost::none) throw runtime_error("Must specify the account index to send from"); uint32_t account_index = request.account_index.get(); std::set subaddress_indices; - for (const uint32_t& subaddressIdx : request.subaddress_indices) subaddress_indices.insert(subaddressIdx); + for (const uint32_t& subaddress_idx : request.subaddress_indices) subaddress_indices.insert(subaddress_idx); // prepare transactions vector ptx_vector = wallet2->create_transactions_2(dsts, mixin, unlock_time, priority, extra, account_index, subaddress_indices); @@ -1743,45 +1743,45 @@ namespace monero { } // config for fill_response() - bool getTxKeys = true; - bool getTxHex = true; - bool getTxMetadata = true; + bool get_tx_keys = true; + bool get_tx_hex = true; + bool get_tx_metadata = true; bool do_not_relay = request.do_not_relay == boost::none ? false : request.do_not_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() - list txKeys; - list txAmounts; - list txFees; - string multisigTxSet; - string unsignedTxSet; + list tx_keys; + list tx_amounts; + list tx_fees; + string multisig_tx_set; + string unsigned_tx_set; list tx_ids; - list txBlobs; - list txMetadatas; - if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, do_not_relay, tx_ids, getTxHex, txBlobs, getTxMetadata, txMetadatas, err)) { + list tx_blobs; + list tx_metadatas; + if (!fill_response(wallet2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, multisig_tx_set, unsigned_tx_set, do_not_relay, tx_ids, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) { throw runtime_error("need to handle error filling response!"); // TODO } // build sent txs from results // TODO: break this into separate utility function vector> txs; - auto txIdsIter = tx_ids.begin(); - auto txKeysIter = txKeys.begin(); - auto txAmountsIter = txAmounts.begin(); - auto txFeesIter = txFees.begin(); - auto txBlobsIter = txBlobs.begin(); - auto txMetadatasIter = txMetadatas.begin(); - while (txIdsIter != tx_ids.end()) { + auto tx_ids_iter = tx_ids.begin(); + auto tx_keys_iter = tx_keys.begin(); + auto tx_amounts_iter = tx_amounts.begin(); + auto tx_fees_iter = tx_fees.begin(); + auto tx_blobs_iter = tx_blobs.begin(); + auto tx_metadatas_iter = tx_metadatas.begin(); + while (tx_ids_iter != tx_ids.end()) { // init tx with outgoing transfer from filled values shared_ptr tx = make_shared(); txs.push_back(tx); - tx->id = *txIdsIter; - tx->key = *txKeysIter; - tx->fee = *txFeesIter; - tx->full_hex = *txBlobsIter; - tx->metadata = *txMetadatasIter; - shared_ptr outTransfer = make_shared(); - tx->outgoing_transfer = outTransfer; - outTransfer->amount = *txAmountsIter; + tx->id = *tx_ids_iter; + tx->key = *tx_keys_iter; + tx->fee = *tx_fees_iter; + tx->full_hex = *tx_blobs_iter; + tx->metadata = *tx_metadatas_iter; + shared_ptr out_transfer = make_shared(); + tx->outgoing_transfer = out_transfer; + out_transfer->amount = *tx_amounts_iter; // init other known fields tx->payment_id = request.payment_id; @@ -1796,17 +1796,17 @@ namespace monero { tx->mixin = request.mixin; tx->unlock_time = request.unlock_time == boost::none ? 0 : request.unlock_time.get(); if (tx->is_relayed.get()) tx->last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 - outTransfer->account_index = request.account_index; - if (request.subaddress_indices.size() == 1) outTransfer->subaddress_indices.push_back(request.subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here - outTransfer->destinations = request.destinations; + out_transfer->account_index = request.account_index; + if (request.subaddress_indices.size() == 1) out_transfer->subaddress_indices.push_back(request.subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here + out_transfer->destinations = request.destinations; // iterate to next element - txKeysIter++; - txAmountsIter++; - txFeesIter++; - txIdsIter++; - txBlobsIter++; - txMetadatasIter++; + tx_keys_iter++; + tx_amounts_iter++; + tx_fees_iter++; + tx_ids_iter++; + tx_blobs_iter++; + tx_metadatas_iter++; } return txs; } @@ -1840,7 +1840,7 @@ namespace monero { } // create transaction - uint64_t mixin = wallet2->adjust_mixin(request.ringSize == boost::none ? 0 : request.ringSize.get() - 1); + uint64_t mixin = wallet2->adjust_mixin(request.ring_size == boost::none ? 0 : request.ring_size.get() - 1); uint32_t priority = wallet2->adjust_priority(request.priority == boost::none ? 0 : request.priority.get()); uint64_t unlock_time = request.unlock_time == boost::none ? 0 : request.unlock_time.get(); std::vector ptx_vector = wallet2->create_transactions_single(ki, dsts[0].addr, dsts[0].is_subaddress, 1, mixin, unlock_time, priority, extra); @@ -1852,45 +1852,45 @@ namespace monero { if (ptx.selected_transfers.size() > 1) throw runtime_error("The transaction uses multiple inputs, which is not supposed to happen"); // config for fill_response() - bool getTxKeys = true; - bool getTxHex = true; - bool getTxMetadata = true; + bool get_tx_keys = true; + bool get_tx_hex = true; + bool get_tx_metadata = true; bool do_not_relay = request.do_not_relay == boost::none ? false : request.do_not_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() - list txKeys; - list txAmounts; - list txFees; - string multisigTxSet; - string unsignedTxSet; + list tx_keys; + list tx_amounts; + list tx_fees; + string multisig_tx_set; + string unsigned_tx_set; list tx_ids; - list txBlobs; - list txMetadatas; - if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, do_not_relay, tx_ids, getTxHex, txBlobs, getTxMetadata, txMetadatas, er)) { + list tx_blobs; + list tx_metadatas; + if (!fill_response(wallet2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, multisig_tx_set, unsigned_tx_set, do_not_relay, tx_ids, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, er)) { throw runtime_error("need to handle error filling response!"); // TODO: return err message } // build sent txs from results // TODO: use common utility with send_split() to avoid code duplication vector> txs; - auto txIdsIter = tx_ids.begin(); - auto txKeysIter = txKeys.begin(); - auto txAmountsIter = txAmounts.begin(); - auto txFeesIter = txFees.begin(); - auto txBlobsIter = txBlobs.begin(); - auto txMetadatasIter = txMetadatas.begin(); - while (txIdsIter != tx_ids.end()) { + auto tx_ids_iter = tx_ids.begin(); + auto tx_keys_iter = tx_keys.begin(); + auto tx_amounts_iter = tx_amounts.begin(); + auto tx_fees_iter = tx_fees.begin(); + auto tx_blobs_iter = tx_blobs.begin(); + auto tx_metadatas_iter = tx_metadatas.begin(); + while (tx_ids_iter != tx_ids.end()) { // init tx with outgoing transfer from filled values shared_ptr tx = make_shared(); txs.push_back(tx); - tx->id = *txIdsIter; - tx->key = *txKeysIter; - tx->fee = *txFeesIter; - tx->full_hex = *txBlobsIter; - tx->metadata = *txMetadatasIter; - shared_ptr outTransfer = make_shared(); - tx->outgoing_transfer = outTransfer; - outTransfer->amount = *txAmountsIter; + tx->id = *tx_ids_iter; + tx->key = *tx_keys_iter; + tx->fee = *tx_fees_iter; + tx->full_hex = *tx_blobs_iter; + tx->metadata = *tx_metadatas_iter; + shared_ptr out_transfer = make_shared(); + tx->outgoing_transfer = out_transfer; + out_transfer->amount = *tx_amounts_iter; // init other known fields tx->payment_id = request.payment_id; @@ -1905,18 +1905,18 @@ namespace monero { tx->mixin = request.mixin; tx->unlock_time = request.unlock_time == boost::none ? 0 : request.unlock_time.get(); if (tx->is_relayed.get()) tx->last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 - outTransfer->account_index = request.account_index; - if (request.subaddress_indices.size() == 1) outTransfer->subaddress_indices.push_back(request.subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here - outTransfer->destinations = request.destinations; - outTransfer->destinations[0]->amount = *txAmountsIter; + out_transfer->account_index = request.account_index; + if (request.subaddress_indices.size() == 1) out_transfer->subaddress_indices.push_back(request.subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here + out_transfer->destinations = request.destinations; + out_transfer->destinations[0]->amount = *tx_amounts_iter; // iterate to next element - txKeysIter++; - txAmountsIter++; - txFeesIter++; - txIdsIter++; - txBlobsIter++; - txMetadatasIter++; + tx_keys_iter++; + tx_amounts_iter++; + tx_fees_iter++; + tx_ids_iter++; + tx_blobs_iter++; + tx_metadatas_iter++; } // return tx @@ -1931,45 +1931,45 @@ namespace monero { std::vector ptx_vector = wallet2->create_unmixable_sweep_transactions(); // config for fill_response - bool getTxKeys = true; - bool getTxHex = true; - bool getTxMetadata = true; + bool get_tx_keys = true; + bool get_tx_hex = true; + bool get_tx_metadata = true; // commit txs (if relaying) and get response using wallet rpc's fill_response() - list txKeys; - list txAmounts; - list txFees; - string multisigTxSet; - string unsignedTxSet; + list tx_keys; + list tx_amounts; + list tx_fees; + string multisig_tx_set; + string unsigned_tx_set; list tx_ids; - list txBlobs; - list txMetadatas; + list tx_blobs; + list tx_metadatas; epee::json_rpc::error er; - if (!fill_response(wallet2.get(), ptx_vector, getTxKeys, txKeys, txAmounts, txFees, multisigTxSet, unsignedTxSet, do_not_relay, tx_ids, getTxHex, txBlobs, getTxMetadata, txMetadatas, er)) { + if (!fill_response(wallet2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, multisig_tx_set, unsigned_tx_set, do_not_relay, tx_ids, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, er)) { throw runtime_error("need to handle error filling response!"); // TODO: return err message } // build sent txs from results // TODO: use common utility with send_split() to avoid code duplication vector> txs; - auto txIdsIter = tx_ids.begin(); - auto txKeysIter = txKeys.begin(); - auto txAmountsIter = txAmounts.begin(); - auto txFeesIter = txFees.begin(); - auto txBlobsIter = txBlobs.begin(); - auto txMetadatasIter = txMetadatas.begin(); - while (txIdsIter != tx_ids.end()) { + auto tx_ids_iter = tx_ids.begin(); + auto tx_keys_iter = tx_keys.begin(); + auto tx_amounts_iter = tx_amounts.begin(); + auto tx_fees_iter = tx_fees.begin(); + auto tx_blobs_iter = tx_blobs.begin(); + auto tx_metadatas_iter = tx_metadatas.begin(); + while (tx_ids_iter != tx_ids.end()) { // init tx with outgoing transfer from filled values shared_ptr tx = make_shared(); txs.push_back(tx); - tx->id = *txIdsIter; - tx->key = *txKeysIter; - tx->fee = *txFeesIter; - tx->full_hex = *txBlobsIter; - tx->metadata = *txMetadatasIter; - shared_ptr outTransfer = make_shared(); - tx->outgoing_transfer = outTransfer; - outTransfer->amount = *txAmountsIter; + tx->id = *tx_ids_iter; + tx->key = *tx_keys_iter; + tx->fee = *tx_fees_iter; + tx->full_hex = *tx_blobs_iter; + tx->metadata = *tx_metadatas_iter; + shared_ptr out_transfer = make_shared(); + tx->outgoing_transfer = out_transfer; + out_transfer->amount = *tx_amounts_iter; // init other known fields tx->is_confirmed = false; @@ -1983,26 +1983,26 @@ namespace monero { //tx->mixin = request.mixin; // TODO: how to get? tx->unlock_time = 0; if (tx->is_relayed.get()) tx->last_relayed_timestamp = static_cast(time(NULL)); // set last relayed timestamp to current time iff relayed // TODO monero core: this should be encapsulated in wallet2 - outTransfer->destinations[0]->amount = *txAmountsIter; + out_transfer->destinations[0]->amount = *tx_amounts_iter; // iterate to next element - txKeysIter++; - txAmountsIter++; - txFeesIter++; - txIdsIter++; - txBlobsIter++; - txMetadatasIter++; + tx_keys_iter++; + tx_amounts_iter++; + tx_fees_iter++; + tx_ids_iter++; + tx_blobs_iter++; + tx_metadatas_iter++; } return txs; } - vector monero_wallet::relay_txs(const vector& txMetadatas) { + vector monero_wallet::relay_txs(const vector& tx_metadatas) { MTRACE("relay_txs()"); // relay each metadata as a tx vector tx_ids; - for (const auto& txMetadata : txMetadatas) { + for (const auto& txMetadata : tx_metadatas) { // parse tx metadata hex cryptonote::blobdata blob; @@ -2035,38 +2035,38 @@ namespace monero { return tx_ids; } - string monero_wallet::get_tx_note(const string& txId) const { + string monero_wallet::get_tx_note(const string& tx_id) const { MTRACE("monero_wallet::get_tx_note()"); - cryptonote::blobdata txBlob; - if (!epee::string_tools::parse_hexstr_to_binbuff(txId, txBlob) || txBlob.size() != sizeof(crypto::hash)) { + cryptonote::blobdata tx_blob; + if (!epee::string_tools::parse_hexstr_to_binbuff(tx_id, tx_blob) || tx_blob.size() != sizeof(crypto::hash)) { throw runtime_error("TX ID has invalid format"); } - crypto::hash txHash = *reinterpret_cast(txBlob.data()); - return wallet2->get_tx_note(txHash); + crypto::hash tx_hash = *reinterpret_cast(tx_blob.data()); + return wallet2->get_tx_note(tx_hash); } vector monero_wallet::get_tx_notes(const vector& tx_ids) const { MTRACE("monero_wallet::get_tx_notes()"); - vector txNotes; - for (const auto& txId : tx_ids) txNotes.push_back(get_tx_note(txId)); - return txNotes; + vector notes; + for (const auto& tx_id : tx_ids) notes.push_back(get_tx_note(tx_id)); + return notes; } - void monero_wallet::set_tx_note(const string& txId, const string& note) { + void monero_wallet::set_tx_note(const string& tx_id, const string& note) { MTRACE("monero_wallet::set_tx_note()"); - cryptonote::blobdata txBlob; - if (!epee::string_tools::parse_hexstr_to_binbuff(txId, txBlob) || txBlob.size() != sizeof(crypto::hash)) { + cryptonote::blobdata tx_blob; + if (!epee::string_tools::parse_hexstr_to_binbuff(tx_id, tx_blob) || tx_blob.size() != sizeof(crypto::hash)) { throw runtime_error("TX ID has invalid format"); } - crypto::hash txHash = *reinterpret_cast(txBlob.data()); - wallet2->set_tx_note(txHash, note); + crypto::hash tx_hash = *reinterpret_cast(tx_blob.data()); + wallet2->set_tx_note(tx_hash, note); } - void monero_wallet::set_tx_notes(const vector& tx_ids, const vector& txNotes) { + void monero_wallet::set_tx_notes(const vector& tx_ids, const vector& notes) { MTRACE("monero_wallet::set_tx_notes()"); - if (tx_ids.size() != txNotes.size()) throw runtime_error("Different amount of txids and notes"); + if (tx_ids.size() != notes.size()) throw runtime_error("Different amount of txids and notes"); for (int i = 0; i < tx_ids.size(); i++) { - set_tx_note(tx_ids[i], txNotes[i]); + set_tx_note(tx_ids[i], notes[i]); } } @@ -2099,37 +2099,37 @@ namespace monero { return wallet2->verify(msg, info.address, signature); } - string monero_wallet::get_tx_key(const string& txId) const { + string monero_wallet::get_tx_key(const string& tx_id) const { MTRACE("monero_wallet::get_tx_key()"); // validate and parse tx id hash - crypto::hash txHash; - if (!epee::string_tools::hex_to_pod(txId, txHash)) { + crypto::hash tx_hash; + if (!epee::string_tools::hex_to_pod(tx_id, tx_hash)) { throw runtime_error("TX ID has invalid format"); } // get tx key and additional keys crypto::secret_key txKey; - std::vector additionalTxKeys; - if (!wallet2->get_tx_key(txHash, txKey, additionalTxKeys)) { + std::vector additional_tx_keys; + if (!wallet2->get_tx_key(tx_hash, txKey, additional_tx_keys)) { throw runtime_error("No tx secret key is stored for this tx"); } // build and return tx key with additional keys epee::wipeable_string s; s += epee::to_hex::wipeable_string(txKey); - for (size_t i = 0; i < additionalTxKeys.size(); ++i) { - s += epee::to_hex::wipeable_string(additionalTxKeys[i]); + for (size_t i = 0; i < additional_tx_keys.size(); ++i) { + s += epee::to_hex::wipeable_string(additional_tx_keys[i]); } return std::string(s.data(), s.size()); } - shared_ptr monero_wallet::check_tx_key(const string& txId, const string& txKey, const string& address) const { + shared_ptr monero_wallet::check_tx_key(const string& tx_id, const string& txKey, const string& address) const { MTRACE("monero_wallet::check_tx_key()"); // validate and parse tx id - crypto::hash txHash; - if (!epee::string_tools::hex_to_pod(txId, txHash)) { + crypto::hash tx_hash; + if (!epee::string_tools::hex_to_pod(tx_id, tx_hash)) { throw runtime_error("TX ID has invalid format"); } @@ -2146,10 +2146,10 @@ namespace monero { // get additional keys size_t offset = 64; - std::vector additionalTxKeys; + std::vector additional_tx_keys; while (offset < tx_key_str.size()) { - additionalTxKeys.resize(additionalTxKeys.size() + 1); - if (!epee::wipeable_string(data + offset, 64).hex_to_pod(unwrap(unwrap(additionalTxKeys.back())))) { + additional_tx_keys.resize(additional_tx_keys.size() + 1); + if (!epee::wipeable_string(data + offset, 64).hex_to_pod(unwrap(unwrap(additional_tx_keys.back())))) { throw runtime_error("Tx key has invalid format"); } offset += 64; @@ -2165,7 +2165,7 @@ namespace monero { uint64_t received_amount; bool in_tx_pool; uint64_t num_confirmations; - wallet2->check_tx_key(txHash, tx_key, additionalTxKeys, info.address, received_amount, in_tx_pool, num_confirmations); + wallet2->check_tx_key(tx_hash, tx_key, additional_tx_keys, info.address, received_amount, in_tx_pool, num_confirmations); shared_ptr checkTx = make_shared(); checkTx->is_good = true; // check is good if we get this far checkTx->received_amount = received_amount; @@ -2174,11 +2174,11 @@ namespace monero { return checkTx; } - string monero_wallet::get_tx_proof(const string& txId, const string& address, const string& message) const { + string monero_wallet::get_tx_proof(const string& tx_id, const string& address, const string& message) const { // validate and parse tx id hash - crypto::hash txHash; - if (!epee::string_tools::hex_to_pod(txId, txHash)) { + crypto::hash tx_hash; + if (!epee::string_tools::hex_to_pod(tx_id, tx_hash)) { throw runtime_error("TX ID has invalid format"); } @@ -2189,15 +2189,15 @@ namespace monero { } // get tx proof - return wallet2->get_tx_proof(txHash, info.address, info.is_subaddress, message); + return wallet2->get_tx_proof(tx_hash, info.address, info.is_subaddress, message); } - shared_ptr monero_wallet::check_tx_proof(const string& txId, const string& address, const string& message, const string& signature) const { + shared_ptr monero_wallet::check_tx_proof(const string& tx_id, const string& address, const string& message, const string& signature) const { MTRACE("monero_wallet::check_tx_proof()"); // validate and parse tx id - crypto::hash txHash; - if (!epee::string_tools::hex_to_pod(txId, txHash)) { + crypto::hash tx_hash; + if (!epee::string_tools::hex_to_pod(tx_id, tx_hash)) { throw runtime_error("TX ID has invalid format"); } @@ -2212,7 +2212,7 @@ namespace monero { uint64_t received_amount; bool in_tx_pool; uint64_t num_confirmations; - checkTx->is_good = wallet2->check_tx_proof(txHash, info.address, info.is_subaddress, message, signature, received_amount, in_tx_pool, num_confirmations); + checkTx->is_good = wallet2->check_tx_proof(tx_hash, info.address, info.is_subaddress, message, signature, received_amount, in_tx_pool, num_confirmations); if (checkTx->is_good) { checkTx->received_amount = received_amount; checkTx->in_tx_pool = in_tx_pool; @@ -2221,30 +2221,30 @@ namespace monero { return checkTx; } - string monero_wallet::get_spend_proof(const string& txId, const string& message) const { + string monero_wallet::get_spend_proof(const string& tx_id, const string& message) const { MTRACE("monero_wallet::get_spend_proof()"); // validate and parse tx id - crypto::hash txHash; - if (!epee::string_tools::hex_to_pod(txId, txHash)) { + crypto::hash tx_hash; + if (!epee::string_tools::hex_to_pod(tx_id, tx_hash)) { throw runtime_error("TX ID has invalid format"); } // return spend proof signature - return wallet2->get_spend_proof(txHash, message); + return wallet2->get_spend_proof(tx_hash, message); } - bool monero_wallet::check_spend_proof(const string& txId, const string& message, const string& signature) const { + bool monero_wallet::check_spend_proof(const string& tx_id, const string& message, const string& signature) const { MTRACE("monero_wallet::check_spend_proof()"); // validate and parse tx id - crypto::hash txHash; - if (!epee::string_tools::hex_to_pod(txId, txHash)) { + crypto::hash tx_hash; + if (!epee::string_tools::hex_to_pod(tx_id, tx_hash)) { throw runtime_error("TX ID has invalid format"); } // check spend proof - return wallet2->check_spend_proof(txHash, message, signature); + return wallet2->check_spend_proof(tx_hash, message, signature); } string monero_wallet::get_reserve_proof_wallet(const string& message) const { @@ -2253,11 +2253,11 @@ namespace monero { return wallet2->get_reserve_proof(account_minreserve, message); } - string monero_wallet::get_reserve_proof_account(uint32_t accountIdx, uint64_t amount, const string& message) const { + string monero_wallet::get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const { MTRACE("monero_wallet::get_reserve_proof_account()"); boost::optional> 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); + if (account_idx >= wallet2->get_num_subaddress_accounts()) throw runtime_error("Account index is out of bound"); + account_minreserve = std::make_pair(account_idx, amount); return wallet2->get_reserve_proof(account_minreserve, message); } @@ -2294,11 +2294,11 @@ namespace monero { string payment_id = request.payment_id == boost::none ? "" : request.payment_id.get(); uint64_t amount = request.destinations.at(0)->amount.get(); string note = request.note == boost::none ? "" : request.note.get(); - string receipient_name = request.receipient_name == boost::none ? "" : request.receipient_name.get(); + string recipient_name = request.recipient_name == boost::none ? "" : request.recipient_name.get(); // make uri using wallet2 std::string error; - string uri = wallet2->make_uri(address, payment_id, amount, note, receipient_name, error); + string uri = wallet2->make_uri(address, payment_id, amount, note, recipient_name, error); if (uri.empty()) throw runtime_error("Cannot make URI from supplied parameters: " + error); return uri; } @@ -2311,24 +2311,24 @@ namespace monero { string payment_id; uint64_t amount = 0; string note; - string receipient_name; - vector unknownParameters; + string recipient_name; + vector unknown_parameters; string error; - if (!wallet2->parse_uri(uri, address, payment_id, amount, note, receipient_name, unknownParameters, error)) { + if (!wallet2->parse_uri(uri, address, payment_id, amount, note, recipient_name, unknown_parameters, error)) { throw runtime_error("Error parsing URI: " + error); } // initialize send request - shared_ptr sendRequest = make_shared(); + shared_ptr send_request = make_shared(); shared_ptr destination = make_shared(); - sendRequest->destinations.push_back(destination); + send_request->destinations.push_back(destination); if (!address.empty()) destination->address = address; destination->amount = amount; - if (!payment_id.empty()) sendRequest->payment_id = payment_id; - if (!note.empty()) sendRequest->note = note; - if (!receipient_name.empty()) sendRequest->receipient_name = receipient_name; - if (!unknownParameters.empty()) MWARNING("WARNING in monero_wallet::parse_payment_uri: URI contains unknown parameters which are discarded"); // TODO: return unknown parameters? - return sendRequest; + if (!payment_id.empty()) send_request->payment_id = payment_id; + if (!note.empty()) send_request->note = note; + if (!recipient_name.empty()) send_request->recipient_name = recipient_name; + if (!unknown_parameters.empty()) MWARNING("WARNING in monero_wallet::parse_payment_uri: URI contains unknown parameters which are discarded"); // TODO: return unknown parameters? + return send_request; } void monero_wallet::set_attribute(const string& key, const string& val) { @@ -2339,29 +2339,29 @@ namespace monero { return wallet2->get_attribute(key); } - void monero_wallet::start_mining(boost::optional numThreads, boost::optional backgroundMining, boost::optional ignoreBattery) { + void monero_wallet::start_mining(boost::optional num_threads, boost::optional background_mining, boost::optional ignore_battery) { MTRACE("start_mining()"); // only mine on trusted daemon if (!wallet2->is_trusted_daemon()) throw runtime_error("This command requires a trusted daemon."); // set defaults - if (numThreads == boost::none || numThreads.get() == 0) numThreads = 1; // TODO: how to autodetect optimal number of threads which daemon supports? - if (backgroundMining == boost::none) backgroundMining = false; - if (ignoreBattery == boost::none) ignoreBattery = false; + if (num_threads == boost::none || num_threads.get() == 0) num_threads = 1; // TODO: how to autodetect optimal number of threads which daemon supports? + if (background_mining == boost::none) background_mining = false; + if (ignore_battery == boost::none) ignore_battery = false; // validate num threads size_t max_mining_threads_count = (std::max)(tools::get_max_concurrency(), static_cast(2)); - if (numThreads.get() < 1 || max_mining_threads_count < numThreads.get()) { + if (num_threads.get() < 1 || max_mining_threads_count < num_threads.get()) { throw runtime_error("The specified number of threads is inappropriate."); } // start mining on daemon cryptonote::COMMAND_RPC_START_MINING::request daemon_req = AUTO_VAL_INIT(daemon_req); daemon_req.miner_address = wallet2->get_account().get_public_address_str(wallet2->nettype()); - daemon_req.threads_count = numThreads.get(); - daemon_req.do_background_mining = backgroundMining.get(); - daemon_req.ignore_battery = ignoreBattery.get(); + daemon_req.threads_count = num_threads.get(); + daemon_req.do_background_mining = background_mining.get(); + daemon_req.ignore_battery = ignore_battery.get(); cryptonote::COMMAND_RPC_START_MINING::response daemon_res; bool r = wallet2->invoke_http_json("/start_mining", daemon_req, daemon_res); if (!r || daemon_res.status != CORE_RPC_STATUS_OK) { @@ -2391,119 +2391,119 @@ namespace monero { void monero_wallet::close() { MTRACE("close()"); - syncingEnabled = false; - syncingThreadDone = true; - syncCV.notify_one(); - syncingThread.join(); + syncing_enabled = false; + syncing_thread_done = true; + sync_cv.notify_one(); + syncing_thread.join(); wallet2->stop(); wallet2->deinit(); } // ------------------------------- PRIVATE HELPERS ---------------------------- - void monero_wallet::initCommon() { - MTRACE("monero_wallet.cpp initCommon()"); - wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); - if (get_daemon_connection() == nullptr) isConnected = false; - isSynced = false; - rescanOnSync = false; - syncingEnabled = false; - syncingThreadDone = false; - syncingInterval = DEFAULT_SYNC_INTERVAL_MILLIS; + void monero_wallet::init_common() { + MTRACE("monero_wallet.cpp init_common()"); + wallet2_listener = unique_ptr(new wallet2_listener(*this, *wallet2)); + if (get_daemon_connection() == nullptr) is_connected = false; + is_synced = false; + rescan_on_sync = false; + syncing_enabled = false; + syncing_thread_done = false; + syncing_interval = DEFAULT_SYNC_INTERVAL_MILLIS; // start auto sync loop - syncingThread = boost::thread([this]() { - this->syncingThreadFunc(); + syncing_thread = boost::thread([this]() { + this->sync_thread_func(); }); } - void monero_wallet::syncingThreadFunc() { - MTRACE("syncingThreadFunc()"); + void monero_wallet::sync_thread_func() { + MTRACE("sync_thread_func()"); while (true) { - boost::mutex::scoped_lock lock(syncingMutex); - if (syncingThreadDone) break; - if (syncingEnabled) { - boost::posix_time::milliseconds wait_for_ms(syncingInterval.load()); - syncCV.timed_wait(lock, wait_for_ms); + boost::mutex::scoped_lock lock(syncing_mutex); + if (syncing_thread_done) break; + if (syncing_enabled) { + boost::posix_time::milliseconds wait_for_ms(syncing_interval.load()); + sync_cv.timed_wait(lock, wait_for_ms); } else { - syncCV.wait(lock); + sync_cv.wait(lock); } - if (syncingEnabled) { - lockAndSync(); + if (syncing_enabled) { + lock_and_sync(); } } } - monero_sync_result monero_wallet::lockAndSync(boost::optional startHeight, boost::optional listener) { - bool rescan = rescanOnSync.exchange(false); - boost::lock_guard guarg(syncMutex); // synchronize sync() and syncAsync() + monero_sync_result monero_wallet::lock_and_sync(boost::optional start_height, boost::optional listener) { + bool rescan = rescan_on_sync.exchange(false); + boost::lock_guard guarg(sync_mutex); // synchronize sync() and syncAsync() monero_sync_result result; result.num_blocks_fetched = 0; result.received_money = false; do { // skip if daemon is not connected or synced - if (isConnected && get_is_daemon_synced()) { + if (is_connected && get_is_daemon_synced()) { // rescan blockchain if requested if (rescan) wallet2->rescan_blockchain(false); // sync wallet - result = syncAux(startHeight, listener); + result = sync_aux(start_height, listener); // find and save rings wallet2->find_and_save_rings(false); } - } while (!rescan && (rescan = rescanOnSync.exchange(false))); // repeat if not rescanned and rescan was requested + } while (!rescan && (rescan = rescan_on_sync.exchange(false))); // repeat if not rescanned and rescan was requested return result; } - monero_sync_result monero_wallet::syncAux(boost::optional startHeight, boost::optional listener) { - MTRACE("syncAux()"); + monero_sync_result monero_wallet::sync_aux(boost::optional start_height, boost::optional listener) { + MTRACE("sync_aux()"); // determine sync start height - uint64_t syncStartHeight = startHeight == boost::none ? max(get_height(), get_restore_height()) : *startHeight; - if (syncStartHeight < get_restore_height()) set_restore_height(syncStartHeight); // TODO monero core: start height processed > requested start height unless restore height manually set + uint64_t sync_start_height = start_height == boost::none ? max(get_height(), get_restore_height()) : *start_height; + if (sync_start_height < get_restore_height()) set_restore_height(sync_start_height); // TODO monero core: start height processed > requested start height unless restore height manually set // sync wallet and return result - wallet2Listener->onSyncStart(syncStartHeight, listener); + wallet2_listener->on_sync_start(sync_start_height, listener); monero_sync_result result; - wallet2->refresh(wallet2->is_trusted_daemon(), syncStartHeight, result.num_blocks_fetched, result.received_money, true); - if (!isSynced) isSynced = true; - wallet2Listener->onSyncEnd(); + wallet2->refresh(wallet2->is_trusted_daemon(), sync_start_height, result.num_blocks_fetched, result.received_money, true); + if (!is_synced) is_synced = true; + wallet2_listener->on_sync_end(); return result; } // private helper to initialize subaddresses using transfer details - vector monero_wallet::getSubaddressesAux(const uint32_t accountIdx, const vector& subaddress_indices, const vector& transfers) const { + vector monero_wallet::get_subaddresses_aux(const uint32_t account_idx, const vector& subaddress_indices, const vector& transfers) const { vector subaddresses; // get balances per subaddress as maps - map balancePerSubaddress = wallet2->balance_per_subaddress(accountIdx); - map> unlockedBalancePerSubaddress = wallet2->unlocked_balance_per_subaddress(accountIdx); + map balancePerSubaddress = wallet2->balance_per_subaddress(account_idx); + map> unlockedBalancePerSubaddress = wallet2->unlocked_balance_per_subaddress(account_idx); // get all indices if no indices given - vector subaddressIndicesReq; + vector subaddress_indices_req; if (subaddress_indices.empty()) { - for (uint32_t subaddressIdx = 0; subaddressIdx < wallet2->get_num_subaddresses(accountIdx); subaddressIdx++) { - subaddressIndicesReq.push_back(subaddressIdx); + for (uint32_t subaddress_idx = 0; subaddress_idx < wallet2->get_num_subaddresses(account_idx); subaddress_idx++) { + subaddress_indices_req.push_back(subaddress_idx); } } else { - subaddressIndicesReq = subaddress_indices; + subaddress_indices_req = subaddress_indices; } // initialize subaddresses at indices - for (uint32_t subaddressIndicesIdx = 0; subaddressIndicesIdx < subaddressIndicesReq.size(); subaddressIndicesIdx++) { + for (uint32_t subaddressIndicesIdx = 0; subaddressIndicesIdx < subaddress_indices_req.size(); subaddressIndicesIdx++) { monero_subaddress subaddress; - subaddress.account_index = accountIdx; - uint32_t subaddressIdx = subaddressIndicesReq.at(subaddressIndicesIdx); - subaddress.index = subaddressIdx; - subaddress.address = get_address(accountIdx, subaddressIdx); - subaddress.label = wallet2->get_subaddress_label({accountIdx, subaddressIdx}); - auto iter1 = balancePerSubaddress.find(subaddressIdx); + subaddress.account_index = account_idx; + uint32_t subaddress_idx = subaddress_indices_req.at(subaddressIndicesIdx); + subaddress.index = subaddress_idx; + subaddress.address = get_address(account_idx, subaddress_idx); + subaddress.label = wallet2->get_subaddress_label({account_idx, subaddress_idx}); + auto iter1 = balancePerSubaddress.find(subaddress_idx); subaddress.balance = iter1 == balancePerSubaddress.end() ? 0 : iter1->second; - auto iter2 = unlockedBalancePerSubaddress.find(subaddressIdx); + auto iter2 = unlockedBalancePerSubaddress.find(subaddress_idx); subaddress.unlocked_balance = iter2 == unlockedBalancePerSubaddress.end() ? 0 : iter2->second.first; - cryptonote::subaddress_index index = {accountIdx, subaddressIdx}; + cryptonote::subaddress_index index = {account_idx, subaddress_idx}; subaddress.num_unspent_outputs = count_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return !td.m_spent && td.m_subaddr_index == index; }); subaddress.is_used = find_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return td.m_subaddr_index == index; }) != transfers.end(); subaddress.num_blocks_to_unlock = iter1 == balancePerSubaddress.end() ? 0 : iter2->second.second; diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index d602931..24e7543 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -70,33 +70,6 @@ namespace monero { // --------------------------------- LISTENERS ------------------------------ - // TODO: this is here for reference to complete the wallet listener - // class i_wallet2_callback - // { - // public: - // // Full wallet callbacks - // virtual void on_new_block(uint64_t height, const cryptonote::block& block) {} - // 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) {} - // virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {} - // 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) {} - // virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {} - // virtual boost::optional on_get_password(const char *reason) { return boost::none; } - // // Light wallet callbacks - // virtual void on_lw_new_block(uint64_t height) {} - // virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {} - // virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {} - // virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount) {} - // // Device callbacks - // virtual void on_device_button_request(uint64_t code) {} - // virtual void on_device_button_pressed() {} - // virtual boost::optional on_device_pin_request() { return boost::none; } - // virtual boost::optional on_device_passphrase_request(bool on_device) { return boost::none; } - // virtual void on_device_progress(const hw::device_progress& event) {}; - // // Common callbacks - // virtual void on_pool_tx_removed(const crypto::hash &txid) {} - // virtual ~i_wallet2_callback() {} - // }; - /** * Receives progress notifications as a wallet is synchronized. */ @@ -107,18 +80,18 @@ namespace monero { * Invoked when sync progress is made. * * @param height is the height of the synced block - * @param startHeight is the starting height of the sync request - * @param endHeight is the ending height of the sync request - * @param percentDone is the sync progress as a percentage + * @param start_height is the starting height of the sync request + * @param end_height is the ending height of the sync request + * @param percent_done is the sync progress as a percentage * @param message is a human-readable description of the current progress */ - virtual void on_sync_progress(uint64_t height, uint64_t startHeight, uint64_t endHeight, double percentDone, const string& message) {} + virtual void on_sync_progress(uint64_t height, uint64_t start_height, uint64_t end_height, double percent_done, const string& message) {} }; /** * Receives notifications as a wallet is updated. */ - class MoneroWalletListener : public monero_sync_listener { + class monero_wallet_listener : public monero_sync_listener { public: /** @@ -144,7 +117,7 @@ namespace monero { }; // forward declaration of internal wallet2 listener - struct Wallet2Listener; + struct wallet2_listener; // ---------------------------- WALLET INTERFACE ---------------------------- @@ -161,58 +134,58 @@ namespace monero { * @param path is the path to check for a wallet * @return true if a wallet exists at the given path, false otherwise */ - static bool walletExists(const string& path); + static bool wallet_exists(const string& path); /** * Open an existing wallet. * * @param path is the path to the wallet file to open * @param password is the password of the wallet file to open - * @param networkType is the wallet's network type + * @param network_type is the wallet's network type */ - static monero_wallet* open_wallet(const string& path, const string& password, const MoneroNetworkType networkType); + static monero_wallet* open_wallet(const string& path, const string& password, const monero_network_type network_type); /** * Create a new wallet with a randomly generated seed. * * @param path is the path to create the wallet * @param password is the password encrypt the wallet - * @param networkType is the wallet's network type (default = MoneroNetworkType.MAINNET) - * @param daemonConnection is connection information to a daemon (default = an unconnected wallet) + * @param network_type is the wallet's network type (default = monero_network_type.MAINNET) + * @param daemon_connection is connection information to a daemon (default = an unconnected wallet) * @param language is the wallet and mnemonic's language (default = "English") */ 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); + static monero_wallet* create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const string& language); /** * Create a wallet from an existing mnemonic phrase. * * @param path is the path to create the wallet * @param password is the password encrypt the wallet - * @param networkType is the wallet's network type + * @param network_type is the wallet's network type * @param mnemonic is the mnemonic of the wallet to construct - * @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) + * @param daemon_connection is connection information to a daemon (default = an unconnected wallet) + * @param restore_height is the block height to restore (i.e. scan the chain) from (default = 0) */ - 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); + static monero_wallet* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic); + static monero_wallet* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height); /** * Create a wallet from an address, view key, and spend key. * * @param path is the path to create the wallet * @param password is the password encrypt the wallet - * @param networkType is the wallet's network type + * @param network_type is the wallet's network type * @param address is the address of the wallet to construct - * @param viewKey is the view key of the wallet to construct - * @param spendKey is the spend key of the wallet to construct - * @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) + * @param view_key is the view key of the wallet to construct + * @param spend_key is the spend key of the wallet to construct + * @param daemon_connection is connection information to a daemon (default = an unconnected wallet) + * @param restore_height 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 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); + static monero_wallet* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key); + static monero_wallet* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height); + static monero_wallet* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language); /** * Deconstruct the wallet. @@ -289,7 +262,7 @@ namespace monero { * * @return the wallet's network type */ - MoneroNetworkType get_network_type() const; + monero_network_type get_network_type() const; /** * Get the wallet's seed. @@ -357,11 +330,11 @@ namespace monero { /** * Get the address of a specific subaddress. * - * @param accountIdx specifies the account index of the address's subaddress - * @param subaddressIdx specifies the subaddress index within the account + * @param account_idx specifies the account index of the address's subaddress + * @param subaddress_idx specifies the subaddress index within the account * @return the receive address of the specified subaddress */ - string get_address(const uint32_t accountIdx, const uint32_t subaddressIdx) const; + string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const; /** * Get the account and subaddress index of the given address. @@ -394,7 +367,7 @@ namespace monero { * * @param listener is the listener to receive wallet notifications */ - void set_listener(boost::optional listener); + void set_listener(boost::optional listener); /** * Synchronize the wallet with the daemon as a one-time synchronous process. @@ -414,19 +387,19 @@ namespace monero { /** * Synchronize the wallet with the daemon as a one-time synchronous process. * - * @param startHeight is the start height to sync from (ignored if less than last processed block) + * @param start_height is the start height to sync from (ignored if less than last processed block) * @return the sync result */ - monero_sync_result sync(uint64_t startHeight); + monero_sync_result sync(uint64_t start_height); /** * Synchronizes the wallet with the blockchain. * - * @param startHeight is the start height to sync from (ignored if less than last processed block) + * @param start_height is the start height to sync from (ignored if less than last processed block) * @param listener is invoked as sync progress is made * @return the sync result */ - monero_sync_result sync(uint64_t startHeight, monero_sync_listener& listener); + monero_sync_result sync(uint64_t start_height, monero_sync_listener& listener); /** * Start an asynchronous thread to continuously synchronize the wallet with the daemon. @@ -459,7 +432,7 @@ namespace monero { * * @return the blockchain's height */ - uint64_t getChainHeight() const; + uint64_t get_chain_height() const; /** * Get the height of the first block that the wallet scans. @@ -471,9 +444,9 @@ namespace monero { /** * Set the height of the first block that the wallet scans. * - * @param restoreHeight is the height of the first block that the wallet scans + * @param restore_height is the height of the first block that the wallet scans */ - void set_restore_height(uint64_t restoreHeight); + void set_restore_height(uint64_t restore_height); // /** // * Indicates if importing multisig data is needed for returning a correct balance. @@ -492,19 +465,19 @@ namespace monero { /** * Get an account's balance. * - * @param accountIdx is the index of the account to get the balance of + * @param account_idx is the index of the account to get the balance of * @return the account's balance */ - uint64_t get_balance(uint32_t accountIdx) const; + uint64_t get_balance(uint32_t account_idx) const; /** * Get a subaddress's balance. * - * @param accountIdx is the index of the subaddress's account to get the balance of - * @param subaddressIdx is the index of the subaddress to get the balance of + * @param account_idx is the index of the subaddress's account to get the balance of + * @param subaddress_idx is the index of the subaddress to get the balance of * @return the subaddress's balance */ - uint64_t get_balance(uint32_t accountIdx, uint32_t subaddressIdx) const; + uint64_t get_balance(uint32_t account_idx, uint32_t subaddress_idx) const; /** * Get the wallet's unlocked balance. @@ -516,19 +489,19 @@ namespace monero { /** * Get an account's unlocked balance. * - * @param accountIdx is the index of the account to get the unlocked balance of + * @param account_idx is the index of the account to get the unlocked balance of * @return the account's unlocked balance */ - uint64_t get_unlocked_balance(uint32_t accountIdx) const; + uint64_t get_unlocked_balance(uint32_t account_idx) const; /** * Get a subaddress's unlocked balance. * - * @param accountIdx is the index of the subaddress's account to get the unlocked balance of - * @param subaddressIdx is the index of the subaddress to get the unlocked balance of + * @param account_idx is the index of the subaddress's account to get the unlocked balance of + * @param subaddress_idx is the index of the subaddress to get the unlocked balance of * @return the subaddress's balance */ - uint64_t get_unlocked_balance(uint32_t accountIdx, uint32_t subaddressIdx) const; + uint64_t get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const; /** * Get all accounts. @@ -540,10 +513,10 @@ namespace monero { /** * Get all accounts. * - * @param includeSubaddresses specifies if subaddresses should be included + * @param include_subaddresses specifies if subaddresses should be included * @return List are all accounts */ - vector get_accounts(bool includeSubaddresses) const; + vector get_accounts(bool include_subaddresses) const; /** * Get accounts with a given tag. @@ -556,28 +529,28 @@ namespace monero { /** * Get accounts with a given tag. * - * @param includeSubaddresses specifies if subaddresses should be included + * @param include_subaddresses specifies if subaddresses should be included * @param tag is the tag for filtering accounts, all accounts if null * @return List are all accounts for the wallet with the given tag */ - vector get_accounts(bool includeSubaddresses, const string& tag) const; + vector get_accounts(bool include_subaddresses, const string& tag) const; /** * Get an account without subaddress information. * - * @param accountIdx specifies the account to get + * @param account_idx specifies the account to get * @return the retrieved account */ - monero_account get_account(uint32_t accountIdx) const; + monero_account get_account(uint32_t account_idx) const; /** * Get an account. * - * @param accountIdx specifies the account to get - * @param includeSubaddresses specifies if subaddresses should be included + * @param account_idx specifies the account to get + * @param include_subaddresses specifies if subaddresses should be included * @return the retrieved account */ - monero_account get_account(const uint32_t accountIdx, bool includeSubaddresses) const; + monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const; /** * Create a new account with a label for the first subaddress. @@ -590,45 +563,45 @@ namespace monero { /** * Get all subaddresses in an account. * - * @param accountIdx specifies the account to get subaddresses within + * @param account_idx specifies the account to get subaddresses within * @return List are the retrieved subaddresses */ - vector get_subaddresses(const uint32_t accountIdx) const; + vector get_subaddresses(const uint32_t account_idx) const; /** * Get subaddresses in an account. * - * @param accountIdx specifies the account to get subaddresses within + * @param account_idx specifies the account to get subaddresses within * @param subaddress_indices are specific subaddresses to get (optional) * @return the retrieved subaddresses */ - vector get_subaddresses(const uint32_t accountIdx, const vector& subaddress_indices) const; + vector get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const; /** * Get a subaddress. * - * @param accountIdx specifies the index of the subaddress's account - * @param subaddressIdx specifies index of the subaddress within the account + * @param account_idx specifies the index of the subaddress's account + * @param subaddress_idx specifies index of the subaddress within the account * @return the retrieved subaddress */ - monero_subaddress getSubaddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const; + monero_subaddress getSubaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const; /** * Create a subaddress within an account. * - * @param accountIdx specifies the index of the account to create the subaddress within + * @param account_idx specifies the index of the account to create the subaddress within * @param label specifies the the label for the subaddress (defaults to empty string) * @return the created subaddress */ - monero_subaddress create_subaddress(uint32_t accountIdx, const string& label = ""); + monero_subaddress create_subaddress(uint32_t account_idx, const string& label = ""); // /** // * Get a wallet transaction by id. // * -// * @param txId is an id of a transaction to get +// * @param tx_id is an id of a transaction to get // * @return monero_tx_wallet is the identified transactions // */ -// public monero_tx_wallet getTx(string txId); +// public monero_tx_wallet getTx(string tx_id); /** * Get all wallet transactions. Wallet transactions contain one or more @@ -680,10 +653,10 @@ namespace monero { // * a subaddress within an account. Transfers belong to transactions which // * are stored on the blockchain. // * -// * @param accountIdx is the index of the account to get transfers from +// * @param account_idx is the index of the account to get transfers from // * @return transfers to/from the account // */ -// public List get_transfers(int accountIdx); +// public List get_transfers(int account_idx); // // /** // * Get incoming and outgoing transfers to and from a subaddress. An outgoing @@ -693,11 +666,11 @@ namespace monero { // * a subaddress within an account. Transfers belong to transactions which // * are stored on the blockchain. // * -// * @param accountIdx is the index of the account to get transfers from -// * @param subaddressIdx is the index of the subaddress to get transfers from +// * @param account_idx is the index of the account to get transfers from +// * @param subaddress_idx is the index of the subaddress to get transfers from // * @return transfers to/from the subaddress // */ -// public List get_transfers(int accountIdx, int subaddressIdx); +// public List get_transfers(int account_idx, int subaddress_idx); /** * Get incoming and outgoing transfers to and from this wallet. An outgoing @@ -750,10 +723,10 @@ namespace monero { /** * Import outputs in hex format. * - * @param outputsHex are outputs in hex format + * @param outputs_hex are outputs in hex format * @return the number of outputs imported */ - int import_outputs_hex(const string& outputsHex); + int import_outputs_hex(const string& outputs_hex); /** * Get all signed key images. @@ -765,10 +738,10 @@ namespace monero { /** * Import signed key images and verify their spent status. * - * @param keyImages are key images to import and verify (requires hex and signature) + * @param key_images are key images to import and verify (requires hex and signature) * @return results of the import */ - shared_ptr import_key_images(const vector>& keyImages); + shared_ptr import_key_images(const vector>& key_images); // /** // * Get new key images from the last imported outputs. @@ -872,21 +845,21 @@ namespace monero { // /** // * Sweep a subaddress's unlocked funds to an address. // * -// * @param accountIdx is the index of the account -// * @param subaddressIdx is the index of the subaddress +// * @param account_idx is the index of the account +// * @param subaddress_idx is the index of the subaddress // * @param address is the address to sweep the subaddress's funds to // * @return the resulting transactions // */ -// public List sweepSubaddress(int accountIdx, int subaddressIdx, string address); +// public List sweepSubaddress(int account_idx, int subaddress_idx, string address); // // /** // * Sweep an acount's unlocked funds to an address. // * -// * @param accountIdx is the index of the account +// * @param account_idx is the index of the account // * @param address is the address to sweep the account's funds to // * @return the resulting transactions // */ -// public List sweepAccount(int accountIdx, string address); +// public List sweepAccount(int account_idx, string address); // // /** // * Sweep the wallet's unlocked funds to an address. @@ -932,18 +905,18 @@ namespace monero { /** * Relay transactions previously created without relaying. * - * @param txMetadatas are transaction metadata previously created without relaying + * @param tx_metadatas are transaction metadata previously created without relaying * @return the ids of the relayed txs */ - vector relay_txs(const vector& txMetadatas); + vector relay_txs(const vector& tx_metadatas); /** * Get a transaction note. * - * @param txId specifies the transaction to get the note of + * @param tx_id specifies the transaction to get the note of * @return the tx note */ - string get_tx_note(const string& txId) const; + string get_tx_note(const string& tx_id) const; /** * Get notes for multiple transactions. @@ -956,10 +929,10 @@ namespace monero { /** * Set a note for a specific transaction. * - * @param txId specifies the transaction + * @param tx_id specifies the transaction * @param note specifies the note */ - void set_tx_note(const string& txId, const string& note); + void set_tx_note(const string& tx_id, const string& note); /** * Set notes for multiple transactions. @@ -990,77 +963,77 @@ namespace monero { /** * Get a transaction's secret key from its id. * - * @param txId is the transaction's id + * @param tx_id is the transaction's id * @return is the transaction's secret key */ - string get_tx_key(const string& txId) const; + string get_tx_key(const string& tx_id) const; /** * Check a transaction in the blockchain with its secret key. * - * @param txId specifies the transaction to check + * @param tx_id specifies the transaction to check * @param txKey is the transaction's secret key * @param address is the destination public address of the transaction * @return the result of the check */ - shared_ptr check_tx_key(const string& txId, const string& txKey, const string& address) const; + shared_ptr check_tx_key(const string& tx_id, const string& txKey, const string& address) const; // /** // * Get a transaction signature to prove it. // * -// * @param txId specifies the transaction to prove +// * @param tx_id specifies the transaction to prove // * @param address is the destination public address of the transaction // * @return the transaction signature // */ -// string get_tx_proof(const string& txId, const string& address) const; +// string get_tx_proof(const string& tx_id, const string& address) const; /** * Get a transaction signature to prove it. * - * @param txId specifies the transaction to prove + * @param tx_id specifies the transaction to prove * @param address is the destination public address of the transaction * @param message is a message to include with the signature to further authenticate the proof (optional) * @return the transaction signature */ - string get_tx_proof(const string& txId, const string& address, const string& message) const; + string get_tx_proof(const string& tx_id, const string& address, const string& message) const; /** * Prove a transaction by checking its signature. * - * @param txId specifies the transaction to prove + * @param tx_id specifies the transaction to prove * @param address is the destination public address of the transaction * @param message is a message included with the signature to further authenticate the proof (optional) * @param signature is the transaction signature to confirm * @return the result of the check */ - shared_ptr check_tx_proof(const string& txId, const string& address, const string& message, const string& signature) const; + shared_ptr check_tx_proof(const string& tx_id, 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. // * -// * @param txId specifies the transaction to prove +// * @param tx_id specifies the transaction to prove // * @return the transaction signature // */ -// string get_spend_proof(const string& txId) const; +// string get_spend_proof(const string& tx_id) const; /** * Generate a signature to prove a spend. Unlike proving a transaction, it does not require the destination public address. * - * @param txId specifies the transaction to prove + * @param tx_id specifies the transaction to prove * @param message is a message to include with the signature to further authenticate the proof (optional) * @return the transaction signature */ - string get_spend_proof(const string& txId, const string& message) const; + string get_spend_proof(const string& tx_id, const string& message) const; /** * Prove a spend using a signature. Unlike proving a transaction, it does not require the destination public address. * - * @param txId specifies the transaction to prove + * @param tx_id specifies the transaction to prove * @param message is a message included with the signature to further authenticate the proof (optional) * @param signature is the transaction signature to confirm * @return true if the signature is good, false otherwise */ - bool check_spend_proof(const string& txId, const string& message, const string& signature) const; + bool check_spend_proof(const string& tx_id, const string& message, const string& signature) const; /** * Generate a signature to prove the entire balance of the wallet. @@ -1073,12 +1046,12 @@ namespace monero { /** * Generate a signature to prove an available amount in an account. * - * @param accountIdx specifies the account to prove ownership of the amount + * @param account_idx specifies the account to prove ownership of the amount * @param amount is the minimum amount to prove as available in the account * @param message is a message to include with the signature to further authenticate the proof (optional) * @return the reserve proof signature */ - string get_reserve_proof_account(uint32_t accountIdx, uint64_t amount, const string& message) const; + string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const; /** * Proves a wallet has a disposable reserve using a signature. @@ -1196,11 +1169,11 @@ namespace monero { /** * Start mining. * - * @param numThreads is the number of threads created for mining (optional) - * @param backgroundMining specifies if mining should occur in the background (optional) - * @param ignoreBattery specifies if the battery should be ignored for mining (optional) + * @param num_threads is the number of threads created for mining (optional) + * @param background_mining specifies if mining should occur in the background (optional) + * @param ignore_battery specifies if the battery should be ignored for mining (optional) */ - void start_mining(boost::optional numThreads, boost::optional backgroundMining, boost::optional ignoreBattery); + void start_mining(boost::optional num_threads, boost::optional background_mining, boost::optional ignore_battery); /** * Stop mining. @@ -1228,27 +1201,27 @@ namespace monero { // --------------------------------- PRIVATE -------------------------------- private: - friend struct Wallet2Listener; - unique_ptr wallet2; // internal wallet implementation - unique_ptr wallet2Listener; // listener for internal wallet implementation - boost::optional listener = boost::none; // wallet's external listener + friend struct wallet2_listener; + unique_ptr wallet2; // internal wallet implementation + unique_ptr wallet2_listener; // listener for internal wallet implementation + boost::optional listener = boost::none; // wallet's external listener - void initCommon(); - vector getSubaddressesAux(uint32_t accountIdx, const vector& subaddress_indices, const vector& transfers) const; + void init_common(); + vector get_subaddresses_aux(uint32_t account_idx, const vector& subaddress_indices, const vector& transfers) const; // blockchain sync management - mutable std::atomic isSynced; // whether or not wallet is synced - mutable std::atomic isConnected; // cache connection status to avoid unecessary RPC calls - boost::condition_variable syncCV; // to awaken sync threads - boost::mutex syncMutex; // synchronize sync() and syncAsync() requests - std::atomic rescanOnSync; // whether or not to rescan on sync - std::atomic syncingEnabled; // whether or not auto sync is enabled - std::atomic syncingInterval; // auto sync loop interval in milliseconds - boost::thread syncingThread; // thread for auto sync loop - boost::mutex syncingMutex; // synchronize auto sync loop - std::atomic syncingThreadDone; // whether or not the syncing thread is shut down - void syncingThreadFunc(); // function to run thread with syncing loop - monero_sync_result lockAndSync(boost::optional startHeight = boost::none, boost::optional listener = boost::none); // internal function to synchronize request to sync and rescan - monero_sync_result syncAux(boost::optional startHeight = boost::none, boost::optional listener = boost::none); // internal function to immediately block, sync, and report progress + mutable std::atomic is_synced; // whether or not wallet is synced + mutable std::atomic is_connected; // cache connection status to avoid unecessary RPC calls + boost::condition_variable sync_cv; // to awaken sync threads + boost::mutex sync_mutex; // synchronize sync() and syncAsync() requests + std::atomic rescan_on_sync; // whether or not to rescan on sync + std::atomic syncing_enabled; // whether or not auto sync is enabled + std::atomic syncing_interval; // auto sync loop interval in milliseconds + boost::thread syncing_thread; // thread for auto sync loop + boost::mutex syncing_mutex; // synchronize auto sync loop + std::atomic syncing_thread_done; // whether or not the syncing thread is shut down + void sync_thread_func(); // function to run thread with syncing loop + monero_sync_result lock_and_sync(boost::optional start_height = boost::none, boost::optional listener = boost::none); // internal function to synchronize request to sync and rescan + monero_sync_result sync_aux(boost::optional start_height = boost::none, boost::optional listener = boost::none); // internal function to immediately block, sync, and report progress }; } diff --git a/src/wallet/monero_wallet_model.cpp b/src/wallet/monero_wallet_model.cpp index 29924d2..14f9592 100644 --- a/src/wallet/monero_wallet_model.cpp +++ b/src/wallet/monero_wallet_model.cpp @@ -229,7 +229,7 @@ namespace monero { return node; } - bool monero_tx_request::meetsCriteria(monero_tx_wallet* tx) const { + bool monero_tx_request::meets_criteria(monero_tx_wallet* tx) const { if (tx == nullptr) return false; // filter on tx @@ -244,10 +244,10 @@ namespace monero { // at least one transfer must meet transfer request if defined if (transfer_request != boost::none) { bool matchFound = false; - if (tx->outgoing_transfer != boost::none && (*transfer_request)->meetsCriteria((*tx->outgoing_transfer).get())) matchFound = true; + if (tx->outgoing_transfer != boost::none && (*transfer_request)->meets_criteria((*tx->outgoing_transfer).get())) matchFound = true; else if (!tx->incoming_transfers.empty()) { for (const shared_ptr& incomingTransfer : tx->incoming_transfers) { - if ((*transfer_request)->meetsCriteria(incomingTransfer.get())) { + if ((*transfer_request)->meets_criteria(incomingTransfer.get())) { matchFound = true; break; } @@ -380,7 +380,7 @@ namespace monero { }; shared_ptr monero_outgoing_transfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { - throw runtime_error("monero_outgoing_transfer::copy(outTransfer) not implemented"); + throw runtime_error("monero_outgoing_transfer::copy(out_transfer) not implemented"); }; boost::optional monero_outgoing_transfer::getIsIncoming() const { return false; } @@ -448,7 +448,7 @@ namespace monero { return node; } - bool monero_transfer_request::meetsCriteria(monero_transfer* transfer) const { + bool monero_transfer_request::meets_criteria(monero_transfer* transfer) const { if (transfer == nullptr) throw runtime_error("transfer is null"); if (tx_request != boost::none && (*tx_request)->transfer_request != boost::none) throw runtime_error("Transfer request's tx request cannot have a circular transfer request"); // TODO: could auto detect and handle this. port to java/js @@ -469,15 +469,15 @@ namespace monero { } // filter on outgoing fields - monero_outgoing_transfer* outTransfer = dynamic_cast(transfer); - if (outTransfer != nullptr) { + monero_outgoing_transfer* out_transfer = dynamic_cast(transfer); + if (out_transfer != nullptr) { // filter on addresses - if (address != boost::none && (outTransfer->addresses.empty() || find(outTransfer->addresses.begin(), outTransfer->addresses.end(), *address) == outTransfer->addresses.end())) return false; // TODO: will filter all transfers if they don't contain addresses + if (address != boost::none && (out_transfer->addresses.empty() || find(out_transfer->addresses.begin(), out_transfer->addresses.end(), *address) == out_transfer->addresses.end())) return false; // TODO: will filter all transfers if they don't contain addresses if (!addresses.empty()) { bool intersects = false; for (const string& addressReq : addresses) { - for (const string& address : outTransfer->addresses) { + for (const string& address : out_transfer->addresses) { if (addressReq == address) { intersects = true; break; @@ -488,11 +488,11 @@ namespace monero { } // filter on subaddress indices - if (subaddress_index != boost::none && (outTransfer->subaddress_indices.empty() || find(outTransfer->subaddress_indices.begin(), outTransfer->subaddress_indices.end(), *subaddress_index) == outTransfer->subaddress_indices.end())) return false; // TODO: will filter all transfers if they don't contain subaddress indices + if (subaddress_index != boost::none && (out_transfer->subaddress_indices.empty() || find(out_transfer->subaddress_indices.begin(), out_transfer->subaddress_indices.end(), *subaddress_index) == out_transfer->subaddress_indices.end())) return false; // TODO: will filter all transfers if they don't contain subaddress indices if (!subaddress_indices.empty()) { bool intersects = false; for (const uint32_t& subaddressIndexReq : subaddress_indices) { - for (const uint32_t& subaddress_index : outTransfer->subaddress_indices) { + for (const uint32_t& subaddress_index : out_transfer->subaddress_indices) { if (subaddressIndexReq == subaddress_index) { intersects = true; break; @@ -504,8 +504,8 @@ namespace monero { // filter on having destinations if (has_destinations != boost::none) { - if (*has_destinations && outTransfer->destinations.empty()) return false; - if (!*has_destinations && !outTransfer->destinations.empty()) return false; + if (*has_destinations && out_transfer->destinations.empty()) return false; + if (!*has_destinations && !out_transfer->destinations.empty()) return false; } // filter on destinations TODO: start with test for this @@ -513,10 +513,10 @@ namespace monero { } // validate type - if (inTransfer == nullptr && outTransfer == nullptr) throw runtime_error("Transfer must be monero_incoming_transfer or monero_outgoing_transfer"); + if (inTransfer == nullptr && out_transfer == nullptr) throw runtime_error("Transfer must be monero_incoming_transfer or monero_outgoing_transfer"); // filter with tx request - if (tx_request != boost::none && !(*tx_request)->meetsCriteria(transfer->tx.get())) return false; + if (tx_request != boost::none && !(*tx_request)->meets_criteria(transfer->tx.get())) return false; return true; } @@ -589,7 +589,7 @@ namespace monero { return node; } - bool monero_output_request::meetsCriteria(monero_output_wallet* output) const { + bool monero_output_request::meets_criteria(monero_output_wallet* output) const { // filter on output if (account_index != boost::none && *account_index != *output->account_index) return false; @@ -609,7 +609,7 @@ namespace monero { if (!subaddress_indices.empty() && find(subaddress_indices.begin(), subaddress_indices.end(), *output->subaddress_index) == subaddress_indices.end()) return false; // filter with tx request - if (tx_request != boost::none && !(*tx_request)->meetsCriteria(static_pointer_cast(output->tx).get())) return false; + if (tx_request != boost::none && !(*tx_request)->meets_criteria(static_pointer_cast(output->tx).get())) return false; // output meets request return true; @@ -623,14 +623,14 @@ namespace monero { if (payment_id != boost::none) node.put("payment_id", *payment_id); if (priority != boost::none) node.put("priority", *priority); if (mixin != boost::none) node.put("mixin", *mixin); - if (ringSize != boost::none) node.put("ringSize", *ringSize); + if (ring_size != boost::none) node.put("ring_size", *ring_size); if (account_index != boost::none) node.put("account_index", *account_index); if (!subaddress_indices.empty()) node.add_child("subaddress_indices", monero_utils::to_property_tree(subaddress_indices)); if (unlock_time != boost::none) node.put("unlock_time", *unlock_time); if (can_split != boost::none) node.put("can_split", *can_split); if (do_not_relay != boost::none) node.put("do_not_relay", *do_not_relay); if (note != boost::none) node.put("note", *note); - if (receipient_name != boost::none) node.put("receipient_name", *receipient_name); + if (recipient_name != boost::none) node.put("recipient_name", *recipient_name); if (below_amount != boost::none) node.put("below_amount", *below_amount); if (sweep_each_subaddress != boost::none) node.put("sweep_each_subaddress", *sweep_each_subaddress); if (key_image != boost::none) node.put("key_image", *key_image); diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index 2c43ad2..3eb0a5a 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -208,7 +208,7 @@ namespace monero { shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::optional getIsIncoming() const; boost::property_tree::ptree to_property_tree() const; - bool meetsCriteria(monero_transfer* transfer) const; + bool meets_criteria(monero_transfer* transfer) const; }; /** @@ -243,7 +243,7 @@ namespace monero { shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree to_property_tree() const; - bool meetsCriteria(monero_output_wallet* output) const; + bool meets_criteria(monero_output_wallet* output) const; }; /** @@ -286,7 +286,7 @@ namespace monero { shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree to_property_tree() const; - bool meetsCriteria(monero_tx_wallet* tx) const; + bool meets_criteria(monero_tx_wallet* tx) const; }; /** @@ -318,7 +318,7 @@ namespace monero { boost::optional payment_id; boost::optional priority; boost::optional mixin; - boost::optional ringSize; + boost::optional ring_size; boost::optional fee; boost::optional account_index; vector subaddress_indices; @@ -326,7 +326,7 @@ namespace monero { boost::optional can_split; boost::optional do_not_relay; boost::optional note; - boost::optional receipient_name; + boost::optional recipient_name; boost::optional below_amount; boost::optional sweep_each_subaddress; boost::optional key_image; diff --git a/test/scratchpad.cpp b/test/scratchpad.cpp index 007e612..5342c2b 100644 --- a/test/scratchpad.cpp +++ b/test/scratchpad.cpp @@ -5,7 +5,7 @@ //#include using namespace std; -bool walletExists(string path) { +bool wallet_exists(string path) { //std::cout << boost::stacktrace::stacktrace(); bool keys_file_exists; bool wallet_file_exists; @@ -13,15 +13,15 @@ bool walletExists(string path) { return wallet_file_exists; } -void open_wallet(string path, string password, int networkType) { - cout << "open_wallet(" << path << ", " << password << ", " << networkType << ")" << endl; +void open_wallet(string path, string password, int network_type) { + cout << "open_wallet(" << path << ", " << password << ", " << network_type << ")" << endl; std::unique_ptr wallet; wallet.reset(new tools::wallet2(cryptonote::network_type::STAGENET, 1, true)); throw runtime_error("Not implemented"); } -void create_wallet_random(string language, int networkType) { - tools::wallet2* wallet = new tools::wallet2(static_cast(networkType), 1, true); +void create_wallet_random(string language, int network_type) { + tools::wallet2* wallet = new tools::wallet2(static_cast(network_type), 1, true); wallet->set_seed_language(language); crypto::secret_key recovery_val, secret_key; wallet->generate(string(""), string(""), secret_key, false, false); @@ -53,12 +53,12 @@ int main(int argc, const char* argv[]) { string path = "test_wallet_1"; string password = "supersecretpassword123"; string language = "English"; - int networkType = 2; + int network_type = 2; - MINFO("Wallet exists: " << walletExists(path)); + MINFO("Wallet exists: " << wallet_exists(path)); -// open_wallet(path, password, networkType); -// create_wallet_random(language, networkType); +// open_wallet(path, password, network_type); +// create_wallet_random(language, network_type); // // create wallet // monero_wallet* wallet = new monero_wallet(); @@ -70,7 +70,7 @@ int main(int argc, const char* argv[]) { // load wallet - monero_wallet* wallet = monero_wallet::open_wallet("../../test_wallets/test_wallet_1", "supersecretpassword123", MoneroNetworkType::STAGENET); + monero_wallet* wallet = monero_wallet::open_wallet("../../test_wallets/test_wallet_1", "supersecretpassword123", monero_network_type::STAGENET); wallet->set_daemon_connection("http://localhost:38081", "", ""); // fetch txs