From 5fda176a5c6d9a8e7fe825f6548ee80ad2b41ddf Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 9 May 2020 23:43:39 -0400 Subject: [PATCH] rename to monero_tx_config, monero_tx_priority --- README.md | 16 +- src/wallet/monero_wallet.h | 246 +++-------------------------- src/wallet/monero_wallet_core.cpp | 228 +++++++++++++------------- src/wallet/monero_wallet_core.h | 22 +-- src/wallet/monero_wallet_model.cpp | 88 +++++------ src/wallet/monero_wallet_model.h | 16 +- test/sample_code.cpp | 16 +- test/scratchpad.cpp | 21 --- 8 files changed, 219 insertions(+), 434 deletions(-) diff --git a/README.md b/README.md index d987f10..f3b70af 100644 --- a/README.md +++ b/README.md @@ -121,19 +121,19 @@ uint64_t next_height = wallet_random->wait_for_next_block(); wallet_restored->stop_mining(); // create a request to send funds to multiple destinations in the random wallet -monero_send_request send_request = monero_send_request(); -send_request.m_account_index = 1; // withdraw funds from this account -send_request.m_subaddress_indices = vector(); -send_request.m_subaddress_indices.push_back(0); -send_request.m_subaddress_indices.push_back(1); // withdraw funds from these subaddresses within the account -send_request.m_priority = monero_send_priority::UNIMPORTANT; // no rush +monero_tx_config config = monero_tx_config(); +config.m_account_index = 1; // withdraw funds from this account +config.m_subaddress_indices = vector(); +config.m_subaddress_indices.push_back(0); +config.m_subaddress_indices.push_back(1); // withdraw funds from these subaddresses within the account +config.m_priority = monero_tx_priority::UNIMPORTANT; // no rush vector> destinations; // specify the recipients and their amounts destinations.push_back(make_shared(wallet_random->get_address(1, 0), 50000)); destinations.push_back(make_shared(wallet_random->get_address(2, 0), 50000)); -send_request.m_destinations = destinations; +config.m_destinations = destinations; // create the transaction, confirm with the user, and relay to the network -shared_ptr created_tx = wallet_restored->create_tx(send_request).m_txs[0]; +shared_ptr created_tx = wallet_restored->create_tx(config).m_txs[0]; uint64_t fee = created_tx->m_fee.get(); // "Are you sure you want to send ...?" wallet_restored->relay_tx(*created_tx); // submit the transaction to the Monero network which will notify the recipient wallet ``` diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index e02e6cc..1a459a9 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -476,13 +476,6 @@ namespace monero { throw runtime_error("rescan_blockchain() not supported"); } -// /** -// * Indicates if importing multisig data is needed for returning a correct balance. -// * -// * @return true if importing multisig data is needed for returning a correct balance, false otherwise -// */ -// public boolean isMultisigImportNeeded(); - /** * Get the wallet's balance. * @@ -657,14 +650,6 @@ namespace monero { throw runtime_error("create_subaddress() not supported"); } -// /** -// * Get a wallet transaction by hash. -// * -// * @param tx_hash is a hash of a transaction to get -// * @return monero_tx_wallet is the identified transactions -// */ -// public monero_tx_wallet getTx(string tx_hash); - /** * Get all wallet transactions. Wallet transactions contain one or more * transfers that are either incoming or outgoing to the wallet. @@ -675,14 +660,6 @@ namespace monero { throw runtime_error("get_txs() not supported"); } -// /** -// * Get wallet transactions by hash. -// * -// * @param tx_hashes are hashes of transactions to get -// * @return the identified transactions -// */ -// public List get_txs(Collection tx_hashes); - /** * Get wallet transactions. Wallet transactions contain one or more * transfers that are either incoming or outgoing to the wallet. @@ -700,10 +677,10 @@ namespace monero { } /** - * Same as get_txs(request) but collects missing tx hashes instead of throwing an error. + * Same as get_txs(query) but collects missing tx hashes instead of throwing an error. * This method is separated because WebAssembly does not support exception handling. * - * @param request filters query results (optional) + * @param query filters results (optional) * @param missing_tx_hashes are populated with requested tx hashes that are not part of the wallet * @return wallet transactions per the request */ @@ -711,45 +688,6 @@ namespace monero { throw runtime_error("get_txs(query, missing_tx_hashes) not supported"); } -// /** -// * Get all incoming and outgoing transfers to and from this wallet. An -// * outgoing transfer represents a total amount sent from one or more -// * subaddresses within an account to individual destination addresses, each -// * with their own amount. An incoming transfer represents a total amount -// * received into a subaddress within an account. Transfers belong to -// * transactions which are stored on the blockchain. -// * -// * @return all wallet transfers -// */ -// public List get_transfers(); -// -// /** -// * Get incoming and outgoing transfers to and from an account. An outgoing -// * transfer represents a total amount sent from one or more subaddresses -// * within an account to individual destination addresses, each with their -// * own amount. An incoming transfer represents a total amount received into -// * a subaddress within an account. Transfers belong to transactions which -// * are stored on the blockchain. -// * -// * @param account_idx is the index of the account to get transfers from -// * @return transfers to/from the account -// */ -// public List get_transfers(int account_idx); -// -// /** -// * Get incoming and outgoing transfers to and from a subaddress. An outgoing -// * transfer represents a total amount sent from one or more subaddresses -// * within an account to individual destination addresses, each with their -// * own amount. An incoming transfer represents a total amount received into -// * a subaddress within an account. Transfers belong to transactions which -// * are stored on the blockchain. -// * -// * @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 account_idx, int subaddress_idx); - /** * Get incoming and outgoing transfers to and from this wallet. An outgoing * transfer represents a total amount sent from one or more subaddresses @@ -770,15 +708,6 @@ namespace monero { throw runtime_error("get_transfers() not supported"); } -// /** -// * Get outputs created from previous transactions that belong to the wallet -// * (i.e. that the wallet can spend one time). Outputs are part of -// * transactions which are stored in blocks on the blockchain. -// * -// * @return List are all wallet outputs -// */ -// public List get_outputs(); - /** * Get outputs created from previous transactions that belong to the wallet * (i.e. that the wallet can spend one time). Outputs are part of @@ -833,21 +762,14 @@ namespace monero { throw runtime_error("import_key_images() not supported"); } -// /** -// * Get new key images from the last imported outputs. -// * -// * @return the key images from the last imported outputs -// */ -// public List getNewKeyImagesFromLastImport(); - /** * Create a transaction to transfer funds from this wallet according to the - * given request. The transaction may be relayed later. + * given config. The transaction may be relayed later. * - * @param request configures the transaction to create + * @param config configures the transaction to create * @return a tx set for the requested transaction if possible */ - virtual monero_tx_set create_tx(monero_send_request& request) { + virtual monero_tx_set create_tx(monero_tx_config& config) { throw runtime_error("create_tx() not supported"); } @@ -874,18 +796,18 @@ namespace monero { * @param priority is the send priority (default normal) * @return a tx set for the requested transaction if possible */ - virtual monero_tx_set create_tx(int account_index, string address, uint64_t amount, monero_send_priority priority) { + virtual monero_tx_set create_tx(int account_index, string address, uint64_t amount, monero_tx_priority priority) { throw runtime_error("create_tx() not supported"); } /** * Create one or more transactions to transfer funds from this wallet - * according to the given request. The transactions may later be relayed. + * according to the given config. The transactions may later be relayed. * - * @param request configures the transactions to create + * @param config configures the transactions to create * @return a tx set for the requested transactions if possible */ - virtual monero_tx_set create_txs(monero_send_request& request) { + virtual monero_tx_set create_txs(monero_tx_config& config) { throw runtime_error("create_txs() not supported"); } @@ -931,12 +853,12 @@ namespace monero { /** * Create and relay a transaction to transfer funds from this wallet - * according to the given request. + * according to the given config. * - * @param request configures the transaction + * @param config configures the transaction * @return a tx set with the requested transaction if possible */ - virtual monero_tx_set send_tx(const monero_send_request& request) { + virtual monero_tx_set send_tx(const monero_tx_config& config) { throw runtime_error("send_tx() not supported"); } @@ -963,7 +885,7 @@ namespace monero { * @param priority is the send priority (default normal) * @return a tx set with the requested transaction if possible */ - virtual monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount, monero_send_priority priority) { + virtual monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount, monero_tx_priority priority) { throw runtime_error("send_tx() not supported"); } @@ -971,119 +893,33 @@ namespace monero { * Create one or more transactions which transfer funds from this wallet to * one or more destinations depending on the given configuration. * - * @param request configures the transaction + * @param config configures the transaction * @return a tx set with the requested transactions if possible */ - virtual monero_tx_set send_txs(const monero_send_request& request) { + virtual monero_tx_set send_txs(const monero_tx_config& config) { throw runtime_error("send_txs() not supported"); } - // /** - // * Create and relay one or more transactions which transfer funds from this - // * wallet to one or more destination. - // * - // * @param account_index is the index of the account to draw funds from - // * @param address is the destination address to send funds to - // * @param sendAmount is the amount being sent - // * @return the resulting transactions - // */ - // public List send_txs(int account_index, string address, BigInteger sendAmount); - // - // /** - // * Create and relay one or more transactions which transfer funds from this - // * wallet to one or more destination. - // * - // * @param account_index is the index of the account to draw funds from - // * @param address is the destination address to send funds to - // * @param sendAmount is the amount being sent - // * @param priority is the send priority (default normal) - // * @return the resulting transactions - // */ - // public List send_txs(int account_index, string address, BigInteger sendAmount, monero_send_priority priority); - /** - * Sweep unlocked funds according to the given request. + * Sweep unlocked funds according to the given config. * - * @param request is the sweep configuration + * @param config is the sweep configuration * @return the tx sets with the requested transactions */ - virtual vector sweep_unlocked(const monero_send_request& request) { + virtual vector sweep_unlocked(const monero_tx_config& config) { throw runtime_error("sweep_unlocked() not supported"); } /** * Sweep an output with a given key image. * - * @param request configures the sweep transaction + * @param config configures the sweep transaction * @return a tx set with the requested transaction if possible */ - virtual monero_tx_set sweep_output(const monero_send_request& request) { + virtual monero_tx_set sweep_output(const monero_tx_config& config) { throw runtime_error("sweep_output() not supported"); } -// /** -// * Sweep an output with a given key image. -// * -// * @param address is the destination address to send to -// * @param key_image is the key image hex of the output to sweep -// * @return the resulting transaction from sweeping an output -// */ -// public monero_tx_wallet sweep_output(string address, string key_image); -// -// /** -// * Sweep an output with a given key image. -// * -// * @param address is the destination address to send to -// * @param key_image is the key image hex of the output to sweep -// * @param priority is the transaction priority (optional) -// * @return the resulting transaction from sweeping an output -// */ -// public monero_tx_wallet sweep_output(string address, string key_image, monero_send_priority priority); -// -// /** -// * Sweep a subaddress's unlocked funds to an address. -// * -// * @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 account_idx, int subaddress_idx, string address); -// -// /** -// * Sweep an acount's unlocked funds to an address. -// * -// * @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 account_idx, string address); -// -// /** -// * Sweep the wallet's unlocked funds to an address. -// * -// * @param address is the address to sweep the wallet's funds to -// * @return the resulting transactions -// */ -// public List sweepWallet(string address); -// -// /** -// * Sweep all unlocked funds according to the given request. -// * -// * @param request is the sweep configuration -// * @return the resulting transactions -// */ -// public List sweepAllUnlocked(monero_send_request request); -// -// /** -// * Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix. -// * -// * NOTE: Dust only exists pre RCT, so this method will return "no dust to sweep" on new wallets. -// * -// * @return the resulting transactions from sweeping dust -// */ -// public List sweep_dust(); - /** * Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix. * @@ -1333,53 +1169,23 @@ namespace monero { throw runtime_error("delete_address_book_entry() not supported"); } -// /** -// * Tag accounts. -// * -// * @param tag is the tag to apply to the specified accounts -// * @param accountIndices are the indices of the accounts to tag -// */ -// public void tagAccounts(string tag, Collection accountIndices); -// -// /** -// * Untag acconts. -// * -// * @param accountIndices are the indices of the accounts to untag -// */ -// public void untagAccounts(Collection accountIndices); -// -// /** -// * Return all account tags. -// * -// * @return the wallet's account tags -// */ -// public List getAccountTags(); -// -// /** -// * Sets a human-readable description for a tag. -// * -// * @param tag is the tag to set a description for -// * @param label is the label to set for the tag -// */ -// public void setAccountTagLabel(string tag, string label); - /** - * Creates a payment URI from a send configuration. + * Creates a payment URI from a tx configuration. * - * @param request specifies configuration for a potential tx + * @param config specifies configuration for a potential tx * @return is the payment uri */ - virtual string create_payment_uri(const monero_send_request& request) const { + virtual string create_payment_uri(const monero_tx_config& config) const { throw runtime_error("create_payment_uri() not supported"); } /** - * Parses a payment URI to a send request. + * Parses a payment URI to a tx configuration. * * @param uri is the payment uri to parse - * @return the send request parsed from the uri + * @return the tx configuration parsed from the uri */ - virtual shared_ptr parse_payment_uri(const string& uri) const { + virtual shared_ptr parse_payment_uri(const string& uri) const { throw runtime_error("parse_payment_uri() not supported"); } diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index bcbf95c..4627203 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -1769,35 +1769,35 @@ namespace monero { return result; } - monero_tx_set monero_wallet_core::create_tx(monero_send_request& request) { - if (request.m_can_split != boost::none && request.m_can_split.get()) throw runtime_error("Cannot request split transactions with create_tx() which prevents splitting; use create_txs() instead"); - request.m_can_split = false; - return create_txs(request); + monero_tx_set monero_wallet_core::create_tx(monero_tx_config& config) { + if (config.m_can_split != boost::none && config.m_can_split.get()) throw runtime_error("Cannot request split transactions with create_tx() which prevents splitting; use create_txs() instead"); + config.m_can_split = false; + return create_txs(config); } monero_tx_set monero_wallet_core::create_tx(uint32_t account_index, string address, uint64_t amount) { - return create_tx(account_index, address, amount, monero_send_priority::NORMAL); + return create_tx(account_index, address, amount, monero_tx_priority::NORMAL); } - monero_tx_set monero_wallet_core::create_tx(int account_index, string address, uint64_t amount, monero_send_priority priority) { - monero_send_request req; - req.m_account_index = account_index; - req.m_destinations.push_back(make_shared(address, amount)); - req.m_priority = priority; - return create_tx(req); + monero_tx_set monero_wallet_core::create_tx(int account_index, string address, uint64_t amount, monero_tx_priority priority) { + monero_tx_config config; + config.m_account_index = account_index; + config.m_destinations.push_back(make_shared(address, amount)); + config.m_priority = priority; + return create_tx(config); } - monero_tx_set monero_wallet_core::create_txs(monero_send_request& request) { + monero_tx_set monero_wallet_core::create_txs(monero_tx_config& config) { - // modify request to not relay - boost::optional requested_do_not_relay = request.m_do_not_relay; - request.m_do_not_relay = true; + // modify config to not relay + boost::optional requested_do_not_relay = config.m_do_not_relay; + config.m_do_not_relay = true; // invoke common method which doesn't relay - monero_tx_set tx_set = send_txs(request); + monero_tx_set tx_set = send_txs(config); - // restore doNotRelay of request and txs - request.m_do_not_relay = requested_do_not_relay; + // restore doNotRelay of config and txs + config.m_do_not_relay = requested_do_not_relay; for (const shared_ptr& tx : tx_set.m_txs) tx->m_do_not_relay = requested_do_not_relay; // return results @@ -1858,36 +1858,36 @@ namespace monero { return relay_txs(tx_hexes); } - monero_tx_set monero_wallet_core::send_tx(const monero_send_request& request) { - if (request.m_can_split != boost::none && request.m_can_split.get()) throw runtime_error("Cannot request split transactions with send_tx() which prevents splitting; use sendSplit() instead"); - monero_send_request copy = request.copy(); + monero_tx_set monero_wallet_core::send_tx(const monero_tx_config& config) { + if (config.m_can_split != boost::none && config.m_can_split.get()) throw runtime_error("Cannot request split transactions with send_tx() which prevents splitting; use sendSplit() instead"); + monero_tx_config copy = config.copy(); copy.m_can_split = false; return send_txs(copy); } monero_tx_set monero_wallet_core::send_tx(uint32_t account_index, string address, uint64_t amount) { - return send_tx(account_index, address, amount, monero_send_priority::NORMAL); + return send_tx(account_index, address, amount, monero_tx_priority::NORMAL); } - monero_tx_set monero_wallet_core::send_tx(uint32_t account_index, string address, uint64_t amount, monero_send_priority priority) { - monero_send_request req; - req.m_account_index = account_index; - req.m_destinations.push_back(make_shared(address, amount)); - req.m_priority = priority; - return send_tx(req); + monero_tx_set monero_wallet_core::send_tx(uint32_t account_index, string address, uint64_t amount, monero_tx_priority priority) { + monero_tx_config config; + config.m_account_index = account_index; + config.m_destinations.push_back(make_shared(address, amount)); + config.m_priority = priority; + return send_tx(config); } - monero_tx_set monero_wallet_core::send_txs(const monero_send_request& request) { - MTRACE("monero_wallet_core::send_txs(request)"); - //MTRACE("monero_send_request: " << request.serialize()); + monero_tx_set monero_wallet_core::send_txs(const monero_tx_config& config) { + MTRACE("monero_wallet_core::send_txs(config)"); + //MTRACE("monero_tx_config: " << config.serialize()); - // validate request - if (request.m_account_index == boost::none) throw runtime_error("Must specify account index to send from"); + // validate config + if (config.m_account_index == boost::none) throw runtime_error("Must specify account index to send from"); // prepare parameters for wallet rpc's validate_transfer() - string payment_id = request.m_payment_id == boost::none ? string("") : request.m_payment_id.get(); + string payment_id = config.m_payment_id == boost::none ? string("") : config.m_payment_id.get(); list tr_destinations; - for (const shared_ptr& destination : request.m_destinations) { + for (const shared_ptr& destination : config.m_destinations) { tools::wallet_rpc::transfer_destination tr_destination; tr_destination.amount = destination->m_amount.get(); tr_destination.address = destination->m_address.get(); @@ -1904,18 +1904,18 @@ namespace monero { // prepare parameters for wallet2's create_transactions_2() uint64_t mixin = m_w2->adjust_mixin(0); // get mixin for call to 'create_transactions_2' - uint32_t priority = m_w2->adjust_priority(request.m_priority == boost::none ? 0 : request.m_priority.get()); - uint64_t unlock_time = request.m_unlock_time == boost::none ? 0 : request.m_unlock_time.get(); - uint32_t account_index = request.m_account_index.get(); + uint32_t priority = m_w2->adjust_priority(config.m_priority == boost::none ? 0 : config.m_priority.get()); + uint64_t unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); + uint32_t account_index = config.m_account_index.get(); std::set subaddress_indices; - for (const uint32_t& subaddress_idx : request.m_subaddress_indices) subaddress_indices.insert(subaddress_idx); + for (const uint32_t& subaddress_idx : config.m_subaddress_indices) subaddress_indices.insert(subaddress_idx); // prepare transactions vector ptx_vector = m_w2->create_transactions_2(dsts, mixin, unlock_time, priority, extra, account_index, subaddress_indices); if (ptx_vector.empty()) throw runtime_error("No transaction created"); // check if request cannot be fulfilled due to splitting - if (request.m_can_split != boost::none && request.m_can_split.get() == false && ptx_vector.size() != 1) { + if (config.m_can_split != boost::none && config.m_can_split.get() == false && ptx_vector.size() != 1) { throw runtime_error("Transaction would be too large. Try send_txs()"); } @@ -1923,7 +1923,7 @@ namespace monero { bool get_tx_keys = true; bool get_tx_hex = true; bool get_tx_metadata = true; - bool m_do_not_relay = request.m_do_not_relay == boost::none ? false : request.m_do_not_relay.get(); + bool m_do_not_relay = config.m_do_not_relay == boost::none ? false : config.m_do_not_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() list tx_keys; @@ -1962,22 +1962,22 @@ namespace monero { // init other known fields tx->m_is_outgoing = true; - tx->m_payment_id = request.m_payment_id; + tx->m_payment_id = config.m_payment_id; tx->m_is_confirmed = false; tx->m_is_miner_tx = false; tx->m_is_failed = false; // TODO: test and handle if true - tx->m_do_not_relay = request.m_do_not_relay != boost::none && request.m_do_not_relay.get() == true; + tx->m_do_not_relay = config.m_do_not_relay != boost::none && config.m_do_not_relay.get() == true; tx->m_is_relayed = tx->m_do_not_relay.get() != true; tx->m_in_tx_pool = !tx->m_do_not_relay.get(); if (!tx->m_is_failed.get() && tx->m_is_relayed.get()) tx->m_is_double_spend_seen = false; // TODO: test and handle if true tx->m_num_confirmations = 0; tx->m_ring_size = monero_utils::RING_SIZE; - tx->m_unlock_time = request.m_unlock_time == boost::none ? 0 : request.m_unlock_time.get(); + tx->m_unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); tx->m_is_locked = true; if (tx->m_is_relayed.get()) tx->m_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 - out_transfer->m_account_index = request.m_account_index; - if (request.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(request.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here - out_transfer->m_destinations = request.m_destinations; + out_transfer->m_account_index = config.m_account_index; + if (config.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(config.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here + out_transfer->m_destinations = config.m_destinations; // iterate to next element tx_keys_iter++; @@ -1996,24 +1996,24 @@ namespace monero { return tx_set; } - vector monero_wallet_core::sweep_unlocked(const monero_send_request& request) { + vector monero_wallet_core::sweep_unlocked(const monero_tx_config& config) { - // validate request - if (request.m_destinations.size() != 1) throw runtime_error("Must specify exactly one destination to sweep to"); - if (request.m_destinations[0]->m_address == boost::none) throw runtime_error("Must specify destination address to sweep to"); - if (request.m_account_index == boost::none && request.m_subaddress_indices.size() != 0) throw runtime_error("Must specify account index if subaddress indices are specified"); + // validate config + if (config.m_destinations.size() != 1) throw runtime_error("Must specify exactly one destination to sweep to"); + if (config.m_destinations[0]->m_address == boost::none) throw runtime_error("Must specify destination address to sweep to"); + if (config.m_account_index == boost::none && config.m_subaddress_indices.size() != 0) throw runtime_error("Must specify account index if subaddress indices are specified"); // determine account and subaddress indices to sweep; default to all with unlocked balance if not specified std::map> indices; - if (request.m_account_index != boost::none) { - if (request.m_subaddress_indices.size() != 0) { - indices[request.m_account_index.get()] = request.m_subaddress_indices; + if (config.m_account_index != boost::none) { + if (config.m_subaddress_indices.size() != 0) { + indices[config.m_account_index.get()] = config.m_subaddress_indices; } else { vector subaddress_indices; - for (const monero_subaddress& subaddress : monero_wallet::get_subaddresses(request.m_account_index.get())) { + for (const monero_subaddress& subaddress : monero_wallet::get_subaddresses(config.m_account_index.get())) { if (subaddress.m_unlocked_balance.get() > 0) subaddress_indices.push_back(subaddress.m_index.get()); } - indices[request.m_account_index.get()] = subaddress_indices; + indices[config.m_account_index.get()] = subaddress_indices; } } else { vector accounts = monero_wallet::get_accounts(true); @@ -2032,8 +2032,8 @@ namespace monero { vector tx_sets; for (pair> subaddress_indices_pair : indices) { - // copy and modify the original request - monero_send_request copy = request.copy(); + // copy and modify the original config + monero_tx_config copy = config.copy(); copy.m_account_index = subaddress_indices_pair.first; copy.m_sweep_each_subaddress = false; @@ -2058,21 +2058,21 @@ namespace monero { return tx_sets; } - monero_tx_set monero_wallet_core::sweep_account(const monero_send_request& request) { + monero_tx_set monero_wallet_core::sweep_account(const monero_tx_config& config) { - // validate request - if (request.m_account_index == boost::none) throw runtime_error("Must specify account index to sweep from"); - if (request.m_destinations.size() != 1 || request.m_destinations[0]->m_address == boost::none || request.m_destinations[0]->m_address.get().empty()) throw runtime_error("Must provide exactly one destination address to sweep output to"); - if (request.m_destinations[0]->m_amount != boost::none) throw runtime_error("Cannot specify destination amount to sweep"); - if (request.m_key_image != boost::none) throw runtime_error("Cannot define key image in sweep_account(); use sweep_output() to sweep an output by its key image"); - if (request.m_sweep_each_subaddress != boost::none && request.m_sweep_each_subaddress.get() == true) throw runtime_error("Cannot sweep each subaddress individually with sweep_account"); + // validate config + if (config.m_account_index == boost::none) throw runtime_error("Must specify account index to sweep from"); + if (config.m_destinations.size() != 1 || config.m_destinations[0]->m_address == boost::none || config.m_destinations[0]->m_address.get().empty()) throw runtime_error("Must provide exactly one destination address to sweep output to"); + if (config.m_destinations[0]->m_amount != boost::none) throw runtime_error("Cannot specify destination amount to sweep"); + if (config.m_key_image != boost::none) throw runtime_error("Cannot define key image in sweep_account(); use sweep_output() to sweep an output by its key image"); + if (config.m_sweep_each_subaddress != boost::none && config.m_sweep_each_subaddress.get() == true) throw runtime_error("Cannot sweep each subaddress individually with sweep_account"); // validate the transfer requested and populate dsts & extra std::list destination; destination.push_back(wallet_rpc::transfer_destination()); destination.back().amount = 0; - destination.back().address = request.m_destinations[0]->m_address.get(); - string payment_id = request.m_payment_id == boost::none ? string("") : request.m_payment_id.get(); + destination.back().address = config.m_destinations[0]->m_address.get(); + string payment_id = config.m_payment_id == boost::none ? string("") : config.m_payment_id.get(); std::vector dsts; std::vector extra; epee::json_rpc::error err; @@ -2084,13 +2084,13 @@ namespace monero { uint64_t num_outputs = 1; // prepare parameters for wallet2's create_transactions_all() - uint64_t below_amount = request.m_below_amount == boost::none ? 0 : request.m_below_amount.get(); + uint64_t below_amount = config.m_below_amount == boost::none ? 0 : config.m_below_amount.get(); uint64_t mixin = m_w2->adjust_mixin(0); - uint32_t priority = m_w2->adjust_priority(request.m_priority == boost::none ? 0 : request.m_priority.get()); - uint64_t unlock_time = request.m_unlock_time == boost::none ? 0 : request.m_unlock_time.get(); - uint32_t account_index = request.m_account_index.get(); + uint32_t priority = m_w2->adjust_priority(config.m_priority == boost::none ? 0 : config.m_priority.get()); + uint64_t unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); + uint32_t account_index = config.m_account_index.get(); std::set subaddress_indices; - for (const uint32_t& subaddress_idx : request.m_subaddress_indices) subaddress_indices.insert(subaddress_idx); + for (const uint32_t& subaddress_idx : config.m_subaddress_indices) subaddress_indices.insert(subaddress_idx); // prepare transactions std::vector ptx_vector = m_w2->create_transactions_all(below_amount, dsts[0].addr, dsts[0].is_subaddress, num_outputs, mixin, unlock_time, priority, extra, account_index, subaddress_indices); @@ -2099,7 +2099,7 @@ namespace monero { bool get_tx_keys = true; bool get_tx_hex = true; bool get_tx_metadata = true; - bool do_not_relay = request.m_do_not_relay != boost::none && request.m_do_not_relay.get(); + bool do_not_relay = config.m_do_not_relay != boost::none && config.m_do_not_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() list tx_keys; @@ -2137,11 +2137,11 @@ namespace monero { shared_ptr out_transfer = make_shared(); tx->m_outgoing_transfer = out_transfer; out_transfer->m_amount = *tx_amounts_iter; - shared_ptr destination = make_shared(request.m_destinations[0]->m_address.get(), out_transfer->m_amount.get()); + shared_ptr destination = make_shared(config.m_destinations[0]->m_address.get(), out_transfer->m_amount.get()); out_transfer->m_destinations.push_back(destination); // init other known fields - tx->m_payment_id = request.m_payment_id; + tx->m_payment_id = config.m_payment_id; tx->m_is_confirmed = false; tx->m_is_miner_tx = false; tx->m_is_failed = false; // TODO: test and handle if true @@ -2151,10 +2151,10 @@ namespace monero { if (!tx->m_is_failed.get() && tx->m_is_relayed.get()) tx->m_is_double_spend_seen = false; // TODO: test and handle if true tx->m_num_confirmations = 0; tx->m_ring_size = monero_utils::RING_SIZE; - tx->m_unlock_time = request.m_unlock_time == boost::none ? 0 : request.m_unlock_time.get(); + tx->m_unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); if (tx->m_is_relayed.get()) tx->m_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 - out_transfer->m_account_index = request.m_account_index; - if (request.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(request.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here + out_transfer->m_account_index = config.m_account_index; + if (config.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(config.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here // iterate to next element tx_keys_iter++; @@ -2173,22 +2173,22 @@ namespace monero { return tx_set; } - monero_tx_set monero_wallet_core::sweep_output(const monero_send_request& request) { + monero_tx_set monero_wallet_core::sweep_output(const monero_tx_config& config) { MTRACE("sweep_output()"); - //MTRACE("monero_send_request: " << request.serialize()); + //MTRACE("monero_tx_config: " << config.serialize()); - // validate input request - if (request.m_key_image == boost::none || request.m_key_image.get().empty()) throw runtime_error("Must provide key image of output to sweep"); - if (request.m_destinations.size() != 1 || request.m_destinations[0]->m_address == boost::none || request.m_destinations[0]->m_address.get().empty()) throw runtime_error("Must provide exactly one destination address to sweep output to"); + // validate input config + if (config.m_key_image == boost::none || config.m_key_image.get().empty()) throw runtime_error("Must provide key image of output to sweep"); + if (config.m_destinations.size() != 1 || config.m_destinations[0]->m_address == boost::none || config.m_destinations[0]->m_address.get().empty()) throw runtime_error("Must provide exactly one destination address to sweep output to"); // validate the transfer queried and populate dsts & extra - string m_payment_id = request.m_payment_id == boost::none ? string("") : request.m_payment_id.get(); + string m_payment_id = config.m_payment_id == boost::none ? string("") : config.m_payment_id.get(); std::vector dsts; std::vector extra; std::list destination; destination.push_back(wallet_rpc::transfer_destination()); destination.back().amount = 0; - destination.back().address = request.m_destinations[0]->m_address.get(); + destination.back().address = config.m_destinations[0]->m_address.get(); epee::json_rpc::error err; if (!validate_transfer(m_w2.get(), destination, m_payment_id, dsts, extra, true, err)) { //throw runtime_error(er); // TODO @@ -2197,14 +2197,14 @@ namespace monero { // validate key image crypto::key_image ki; - if (!epee::string_tools::hex_to_pod(request.m_key_image.get(), ki)) { + if (!epee::string_tools::hex_to_pod(config.m_key_image.get(), ki)) { throw runtime_error("failed to parse key image"); } // create transaction uint64_t mixin = m_w2->adjust_mixin(0); - uint32_t priority = m_w2->adjust_priority(request.m_priority == boost::none ? 0 : request.m_priority.get()); - uint64_t unlock_time = request.m_unlock_time == boost::none ? 0 : request.m_unlock_time.get(); + uint32_t priority = m_w2->adjust_priority(config.m_priority == boost::none ? 0 : config.m_priority.get()); + uint64_t unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); std::vector ptx_vector = m_w2->create_transactions_single(ki, dsts[0].addr, dsts[0].is_subaddress, 1, mixin, unlock_time, priority, extra); // validate created transaction @@ -2217,7 +2217,7 @@ namespace monero { bool get_tx_keys = true; bool get_tx_hex = true; bool get_tx_metadata = true; - bool m_do_not_relay = request.m_do_not_relay == boost::none ? false : request.m_do_not_relay.get(); + bool m_do_not_relay = config.m_do_not_relay == boost::none ? false : config.m_do_not_relay.get(); // commit txs (if relaying) and get response using wallet rpc's fill_response() list tx_keys; @@ -2256,22 +2256,22 @@ namespace monero { out_transfer->m_amount = *tx_amounts_iter; // init other known fields - tx->m_payment_id = request.m_payment_id; + tx->m_payment_id = config.m_payment_id; tx->m_is_confirmed = false; tx->m_is_miner_tx = false; tx->m_is_failed = false; // TODO: test and handle if true - tx->m_do_not_relay = request.m_do_not_relay != boost::none && request.m_do_not_relay.get() == true; + tx->m_do_not_relay = config.m_do_not_relay != boost::none && config.m_do_not_relay.get() == true; tx->m_is_relayed = tx->m_do_not_relay.get() != true; tx->m_in_tx_pool = !tx->m_do_not_relay.get(); if (!tx->m_is_failed.get() && tx->m_is_relayed.get()) tx->m_is_double_spend_seen = false; // TODO: test and handle if true tx->m_num_confirmations = 0; tx->m_ring_size = monero_utils::RING_SIZE; - tx->m_unlock_time = request.m_unlock_time == boost::none ? 0 : request.m_unlock_time.get(); + tx->m_unlock_time = config.m_unlock_time == boost::none ? 0 : config.m_unlock_time.get(); tx->m_is_locked = true; if (tx->m_is_relayed.get()) tx->m_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 - out_transfer->m_account_index = request.m_account_index; - if (request.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(request.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here - out_transfer->m_destinations = request.m_destinations; + out_transfer->m_account_index = config.m_account_index; + if (config.m_subaddress_indices.size() == 1) out_transfer->m_subaddress_indices.push_back(config.m_subaddress_indices[0]); // subaddress index is known iff 1 requested // TODO: get all known subaddress indices here + out_transfer->m_destinations = config.m_destinations; out_transfer->m_destinations[0]->m_amount = *tx_amounts_iter; // iterate to next element @@ -2910,20 +2910,20 @@ namespace monero { if (!m_w2->delete_address_book_row(index)) throw runtime_error("Failed to delete address book entry"); } - string monero_wallet_core::create_payment_uri(const monero_send_request& request) const { + string monero_wallet_core::create_payment_uri(const monero_tx_config& config) const { MTRACE("create_payment_uri()"); - // validate request - if (request.m_destinations.size() != 1) throw runtime_error("Cannot make URI from supplied parameters: must provide exactly one destination to send funds"); - if (request.m_destinations.at(0)->m_address == boost::none) throw runtime_error("Cannot make URI from supplied parameters: must provide destination address"); - if (request.m_destinations.at(0)->m_amount == boost::none) throw runtime_error("Cannot make URI from supplied parameters: must provide destination amount"); + // validate config + if (config.m_destinations.size() != 1) throw runtime_error("Cannot make URI from supplied parameters: must provide exactly one destination to send funds"); + if (config.m_destinations.at(0)->m_address == boost::none) throw runtime_error("Cannot make URI from supplied parameters: must provide destination address"); + if (config.m_destinations.at(0)->m_amount == boost::none) throw runtime_error("Cannot make URI from supplied parameters: must provide destination amount"); // prepare wallet2 params - string address = request.m_destinations.at(0)->m_address.get(); - string payment_id = request.m_payment_id == boost::none ? "" : request.m_payment_id.get(); - uint64_t amount = request.m_destinations.at(0)->m_amount.get(); - string note = request.m_note == boost::none ? "" : request.m_note.get(); - string m_recipient_name = request.m_recipient_name == boost::none ? "" : request.m_recipient_name.get(); + string address = config.m_destinations.at(0)->m_address.get(); + string payment_id = config.m_payment_id == boost::none ? "" : config.m_payment_id.get(); + uint64_t amount = config.m_destinations.at(0)->m_amount.get(); + string note = config.m_note == boost::none ? "" : config.m_note.get(); + string m_recipient_name = config.m_recipient_name == boost::none ? "" : config.m_recipient_name.get(); // make uri using wallet2 std::string error; @@ -2932,7 +2932,7 @@ namespace monero { return uri; } - shared_ptr monero_wallet_core::parse_payment_uri(const string& uri) const { + shared_ptr monero_wallet_core::parse_payment_uri(const string& uri) const { MTRACE("parse_payment_uri(" << uri << ")"); // decode uri to parameters @@ -2947,17 +2947,17 @@ namespace monero { throw runtime_error("Error parsing URI: " + error); } - // initialize send request - shared_ptr send_request = make_shared(); + // initialize config + shared_ptr config = make_shared(); shared_ptr destination = make_shared(); - send_request->m_destinations.push_back(destination); + config->m_destinations.push_back(destination); if (!address.empty()) destination->m_address = address; destination->m_amount = amount; - if (!payment_id.empty()) send_request->m_payment_id = payment_id; - if (!note.empty()) send_request->m_note = note; - if (!m_recipient_name.empty()) send_request->m_recipient_name = m_recipient_name; + if (!payment_id.empty()) config->m_payment_id = payment_id; + if (!note.empty()) config->m_note = note; + if (!m_recipient_name.empty()) config->m_recipient_name = m_recipient_name; if (!unknown_parameters.empty()) MWARNING("WARNING in monero_wallet_core::parse_payment_uri: URI contains unknown parameters which are discarded"); // TODO: return unknown parameters? - return send_request; + return config; } bool monero_wallet_core::get_attribute(const string& key, string& value) const { diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index 8c304eb..3fc6c36 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -229,20 +229,20 @@ namespace monero { int import_outputs_hex(const string& outputs_hex); vector> get_key_images() const; shared_ptr import_key_images(const vector>& key_images); - monero_tx_set create_tx(monero_send_request& request); + monero_tx_set create_tx(monero_tx_config& config); monero_tx_set create_tx(uint32_t account_index, string address, uint64_t amount); - monero_tx_set create_tx(int account_index, string address, uint64_t amount, monero_send_priority priority); - monero_tx_set create_txs(monero_send_request& request); + monero_tx_set create_tx(int account_index, string address, uint64_t amount, monero_tx_priority priority); + monero_tx_set create_txs(monero_tx_config& config); string relay_tx(const string& tx_metadata); string relay_tx(const monero_tx_wallet& tx); vector relay_txs(const vector& tx_metadatas); vector relay_txs(const vector>& txs); - monero_tx_set send_tx(const monero_send_request& request); + monero_tx_set send_tx(const monero_tx_config& config); monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount); - monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount, monero_send_priority priority); - monero_tx_set send_txs(const monero_send_request& request); - vector sweep_unlocked(const monero_send_request& request); - monero_tx_set sweep_output(const monero_send_request& request); + monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount, monero_tx_priority priority); + monero_tx_set send_txs(const monero_tx_config& config); + vector sweep_unlocked(const monero_tx_config& config); + monero_tx_set sweep_output(const monero_tx_config& config); monero_tx_set sweep_dust(bool do_not_relay = false); monero_tx_set parse_tx_set(const monero_tx_set& tx_set); string sign_txs(const string& unsigned_tx_hex); @@ -266,8 +266,8 @@ namespace monero { uint64_t add_address_book_entry(const string& address, const string& description); void edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description); void delete_address_book_entry(uint64_t index); - string create_payment_uri(const monero_send_request& request) const; - shared_ptr parse_payment_uri(const string& uri) const; + string create_payment_uri(const monero_tx_config& config) const; + shared_ptr parse_payment_uri(const string& uri) const; bool get_attribute(const string& key, string& value) const; void set_attribute(const string& key, const string& val); void start_mining(boost::optional num_threads, boost::optional background_mining, boost::optional ignore_battery); @@ -302,7 +302,7 @@ namespace monero { void init_common(); vector get_subaddresses_aux(uint32_t account_idx, const vector& subaddress_indices, const vector& transfers) const; - monero_tx_set sweep_account(const monero_send_request& request); // sweeps unlocked funds within an account; private helper to sweep_unlocked() + monero_tx_set sweep_account(const monero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked() // blockchain sync management mutable std::atomic m_is_synced; // whether or not wallet is synced diff --git a/src/wallet/monero_wallet_model.cpp b/src/wallet/monero_wallet_model.cpp index fa0d2ab..2558e0b 100644 --- a/src/wallet/monero_wallet_model.cpp +++ b/src/wallet/monero_wallet_model.cpp @@ -1041,29 +1041,29 @@ namespace monero { // ------------------------- MONERO SEND REQUEST ---------------------------- - monero_send_request::monero_send_request(const monero_send_request& request) { - if (request.m_destinations.size() > 0) { - for (const shared_ptr& destination : request.m_destinations) { + monero_tx_config::monero_tx_config(const monero_tx_config& config) { + if (config.m_destinations.size() > 0) { + for (const shared_ptr& destination : config.m_destinations) { m_destinations.push_back(destination->copy(destination, make_shared())); } } - m_payment_id = request.m_payment_id; - m_priority = request.m_priority; - m_ring_size = request.m_ring_size; - m_fee = request.m_fee; - m_account_index = request.m_account_index; - m_subaddress_indices = request.m_subaddress_indices; - m_unlock_time = request.m_unlock_time; - m_can_split = request.m_can_split; - m_do_not_relay = request.m_do_not_relay; - m_note = request.m_note; - m_recipient_name = request.m_recipient_name; - m_below_amount = request.m_below_amount; - m_sweep_each_subaddress = request.m_sweep_each_subaddress; - m_key_image = request.m_key_image; + m_payment_id = config.m_payment_id; + m_priority = config.m_priority; + m_ring_size = config.m_ring_size; + m_fee = config.m_fee; + m_account_index = config.m_account_index; + m_subaddress_indices = config.m_subaddress_indices; + m_unlock_time = config.m_unlock_time; + m_can_split = config.m_can_split; + m_do_not_relay = config.m_do_not_relay; + m_note = config.m_note; + m_recipient_name = config.m_recipient_name; + m_below_amount = config.m_below_amount; + m_sweep_each_subaddress = config.m_sweep_each_subaddress; + m_key_image = config.m_key_image; } - rapidjson::Value monero_send_request::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { + rapidjson::Value monero_tx_config::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { // create root rapidjson::Value root(rapidjson::kObjectType); @@ -1096,15 +1096,15 @@ namespace monero { return root; } - shared_ptr monero_send_request::deserialize(const string& send_request_json) { + shared_ptr monero_tx_config::deserialize(const string& config_json) { - // deserialize send request json to property node - std::istringstream iss = send_request_json.empty() ? std::istringstream() : std::istringstream(send_request_json); + // deserialize config json to property node + std::istringstream iss = config_json.empty() ? std::istringstream() : std::istringstream(config_json); boost::property_tree::ptree node; boost::property_tree::read_json(iss, node); - // convert request property tree to monero_send_request - shared_ptr send_request = make_shared(); + // convert config property tree to monero_tx_config + shared_ptr config = make_shared(); for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { string key = it->first; if (key == string("destinations")) { @@ -1112,37 +1112,37 @@ namespace monero { for (boost::property_tree::ptree::const_iterator it2 = destinationsNode.begin(); it2 != destinationsNode.end(); ++it2) { shared_ptr destination = make_shared(); monero_destination::from_property_tree(it2->second, destination); - send_request->m_destinations.push_back(destination); + config->m_destinations.push_back(destination); } } - else if (key == string("paymentId")) send_request->m_payment_id = it->second.data(); + else if (key == string("paymentId")) config->m_payment_id = it->second.data(); else if (key == string("priority")) { uint32_t priority_num = it->second.get_value(); - if (priority_num == 0) send_request->m_priority = monero_send_priority::DEFAULT; - else if (priority_num == 1) send_request->m_priority = monero_send_priority::UNIMPORTANT; - else if (priority_num == 2) send_request->m_priority = monero_send_priority::NORMAL; - else if (priority_num == 3) send_request->m_priority = monero_send_priority::ELEVATED; + if (priority_num == 0) config->m_priority = monero_tx_priority::DEFAULT; + else if (priority_num == 1) config->m_priority = monero_tx_priority::UNIMPORTANT; + else if (priority_num == 2) config->m_priority = monero_tx_priority::NORMAL; + else if (priority_num == 3) config->m_priority = monero_tx_priority::ELEVATED; else throw new runtime_error("Invalid priority number: " + std::to_string(priority_num)); } - else if (key == string("ringSize")) send_request->m_ring_size = it->second.get_value(); - else if (key == string("fee")) send_request->m_fee = it->second.get_value(); - else if (key == string("accountIndex")) send_request->m_account_index = it->second.get_value(); - else if (key == string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) send_request->m_subaddress_indices.push_back(it2->second.get_value()); - else if (key == string("unlockTime")) send_request->m_unlock_time = it->second.get_value(); - else if (key == string("canSplit")) send_request->m_can_split = it->second.get_value(); - else if (key == string("doNotRelay")) send_request->m_do_not_relay = it->second.get_value(); - else if (key == string("note")) send_request->m_note = it->second.data(); - else if (key == string("recipientName")) send_request->m_recipient_name = it->second.data(); - else if (key == string("belowAmount")) send_request->m_below_amount = it->second.get_value(); - else if (key == string("sweepEachSubaddress")) send_request->m_sweep_each_subaddress = it->second.get_value(); - else if (key == string("keyImage")) send_request->m_key_image = it->second.data(); + else if (key == string("ringSize")) config->m_ring_size = it->second.get_value(); + else if (key == string("fee")) config->m_fee = it->second.get_value(); + else if (key == string("accountIndex")) config->m_account_index = it->second.get_value(); + else if (key == string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) config->m_subaddress_indices.push_back(it2->second.get_value()); + else if (key == string("unlockTime")) config->m_unlock_time = it->second.get_value(); + else if (key == string("canSplit")) config->m_can_split = it->second.get_value(); + else if (key == string("doNotRelay")) config->m_do_not_relay = it->second.get_value(); + else if (key == string("note")) config->m_note = it->second.data(); + else if (key == string("recipientName")) config->m_recipient_name = it->second.data(); + else if (key == string("belowAmount")) config->m_below_amount = it->second.get_value(); + else if (key == string("sweepEachSubaddress")) config->m_sweep_each_subaddress = it->second.get_value(); + else if (key == string("keyImage")) config->m_key_image = it->second.data(); } - return send_request; + return config; } - monero_send_request monero_send_request::copy() const { - return monero_send_request(*this); + monero_tx_config monero_tx_config::copy() const { + return monero_tx_config(*this); } // ---------------------- MONERO INTEGRATED ADDRESS ------------------------- diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index 9c0d405..92cb758 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -328,7 +328,7 @@ namespace monero { /** * Enumerates Monero network types. */ - enum monero_send_priority : uint8_t { + enum monero_tx_priority : uint8_t { DEFAULT = 0, UNIMPORTANT, NORMAL, @@ -336,12 +336,12 @@ namespace monero { }; /** - * Configures a request to send/sweep funds or create a payment URI. + * Configures a transaction to send, sweep, or create a payment URI. */ - struct monero_send_request : public serializable_struct { + struct monero_tx_config : public serializable_struct { vector> m_destinations; boost::optional m_payment_id; - boost::optional m_priority; + boost::optional m_priority; boost::optional m_ring_size; boost::optional m_fee; boost::optional m_account_index; @@ -355,11 +355,11 @@ namespace monero { boost::optional m_sweep_each_subaddress; boost::optional m_key_image; - monero_send_request() {} - monero_send_request(const monero_send_request& request); + monero_tx_config() {} + monero_tx_config(const monero_tx_config& config); rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; - static shared_ptr deserialize(const string& send_request_json); - monero_send_request copy() const; + static shared_ptr deserialize(const string& config_json); + monero_tx_config copy() const; }; /** diff --git a/test/sample_code.cpp b/test/sample_code.cpp index 519219f..879c120 100644 --- a/test/sample_code.cpp +++ b/test/sample_code.cpp @@ -116,19 +116,19 @@ int main(int argc, const char* argv[]) { wallet_restored->stop_mining(); // create a request to send funds to multiple destinations in the random wallet - monero_send_request send_request = monero_send_request(); - send_request.m_account_index = 1; // withdraw funds from this account - send_request.m_subaddress_indices = vector(); - send_request.m_subaddress_indices.push_back(0); - send_request.m_subaddress_indices.push_back(1); // withdraw funds from these subaddresses within the account - send_request.m_priority = monero_send_priority::UNIMPORTANT; // no rush + monero_tx_config config = monero_tx_config(); + config.m_account_index = 1; // withdraw funds from this account + config.m_subaddress_indices = vector(); + config.m_subaddress_indices.push_back(0); + config.m_subaddress_indices.push_back(1); // withdraw funds from these subaddresses within the account + config.m_priority = monero_tx_priority::UNIMPORTANT; // no rush vector> destinations; // specify the recipients and their amounts destinations.push_back(make_shared(wallet_random->get_address(1, 0), 50000)); destinations.push_back(make_shared(wallet_random->get_address(2, 0), 50000)); - send_request.m_destinations = destinations; + config.m_destinations = destinations; // create the transaction, confirm with the user, and relay to the network - shared_ptr created_tx = wallet_restored->create_tx(send_request).m_txs[0]; + shared_ptr created_tx = wallet_restored->create_tx(config).m_txs[0]; uint64_t fee = created_tx->m_fee.get(); // "Are you sure you want to send ...?" wallet_restored->relay_tx(*created_tx); // submit the transaction to the Monero network which will notify the recipient wallet diff --git a/test/scratchpad.cpp b/test/scratchpad.cpp index 28e3a0e..8ca1159 100644 --- a/test/scratchpad.cpp +++ b/test/scratchpad.cpp @@ -38,25 +38,4 @@ int main(int argc, const char* argv[]) { for (int i = 0; i < txs.size() && i < 10; i++) { MINFO(txs[i]->serialize()); } - -// shared_ptr transfer_request = shared_ptr(new monero_transfer_request()); -// transfer_request->account_index = 0; -// shared_ptr tx_request = shared_ptr(new monero_tx_request()); -// tx_request->is_confirmed = true; -// transfer_request->tx_request = tx_request; -// //tx_request->transfer_request = transfer_request; -// vector> transfers = wallet->get_transfers(*transfer_request); -// if (transfers.empty()) throw runtime_error("Transfers should not be empty"); -// for (const shared_ptr& transfer : transfers) { -// if (*transfer->account_index != 0) throw runtime_error("Account should be 0"); -// if (!*transfer->tx->is_confirmed) throw runtime_error("Transfer should be confirmed"); -// } - -// shared_ptr tx_request = shared_ptr(new monero_tx_request()); -// tx_request->is_confirmed = true; -// vector> txs = wallet->get_txs(*tx_request); -// if (txs.empty()) throw runtime_error("Txs should not be empty"); -// for (const shared_ptr& tx : txs) { -// if (!*tx->is_confirmed) throw runtime_error("Tx should be confirmed"); -// } }