rename to monero_tx_config, monero_tx_priority

This commit is contained in:
woodser
2020-05-09 23:43:39 -04:00
parent 2c1c86f87d
commit 5fda176a5c
8 changed files with 219 additions and 434 deletions
+8 -8
View File
@@ -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<uint32_t>();
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<uint32_t>();
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<shared_ptr<monero_destination>> destinations; // specify the recipients and their amounts
destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(1, 0), 50000));
destinations.push_back(make_shared<monero_destination>(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<monero_tx_wallet> created_tx = wallet_restored->create_tx(send_request).m_txs[0];
shared_ptr<monero_tx_wallet> 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
```
+26 -220
View File
@@ -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<monero_tx_wallet> get_txs(Collection<string> 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<monero_transfer> 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<monero_transfer> 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<monero_transfer> 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<monero_output_wallet> are all wallet outputs
// */
// public List<monero_output_wallet> get_outputs();
/**
* Get outputs created from previous transactions that belong to the wallet
* (i.e. that the wallet can spend one time). Outputs are part of
@@ -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<monero_key_image> 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<monero_tx_wallet> 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<monero_tx_wallet> 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<monero_tx_set> sweep_unlocked(const monero_send_request& request) {
virtual vector<monero_tx_set> 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<monero_tx_wallet> 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<monero_tx_wallet> 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<monero_tx_wallet> sweepWallet(string address);
//
// /**
// * Sweep all unlocked funds according to the given request.
// *
// * @param request is the sweep configuration
// * @return the resulting transactions
// */
// public List<monero_tx_wallet> sweepAllUnlocked(monero_send_request request);
//
// /**
// * Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix.
// *
// * 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<monero_tx_wallet> 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<Integer> accountIndices);
//
// /**
// * Untag acconts.
// *
// * @param accountIndices are the indices of the accounts to untag
// */
// public void untagAccounts(Collection<Integer> accountIndices);
//
// /**
// * Return all account tags.
// *
// * @return the wallet's account tags
// */
// public List<MoneroAccountTag> 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<monero_send_request> parse_payment_uri(const string& uri) const {
virtual shared_ptr<monero_tx_config> parse_payment_uri(const string& uri) const {
throw runtime_error("parse_payment_uri() not supported");
}
+114 -114
View File
@@ -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<monero_destination>(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<monero_destination>(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<bool> requested_do_not_relay = request.m_do_not_relay;
request.m_do_not_relay = true;
// modify config to not relay
boost::optional<bool> 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<monero_tx_wallet>& 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<monero_destination>(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<monero_destination>(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<tools::wallet_rpc::transfer_destination> tr_destinations;
for (const shared_ptr<monero_destination>& destination : request.m_destinations) {
for (const shared_ptr<monero_destination>& 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<uint32_t> 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<wallet2::pending_tx> 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<string> 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<uint64_t>(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_tx_set> monero_wallet_core::sweep_unlocked(const monero_send_request& request) {
vector<monero_tx_set> 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<uint32_t, vector<uint32_t>> 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<uint32_t> 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<monero_account> accounts = monero_wallet::get_accounts(true);
@@ -2032,8 +2032,8 @@ namespace monero {
vector<monero_tx_set> tx_sets;
for (pair<uint32_t, vector<uint32_t>> 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<wallet_rpc::transfer_destination> 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<cryptonote::tx_destination_entry> dsts;
std::vector<uint8_t> 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<uint32_t> 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<wallet2::pending_tx> 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<string> tx_keys;
@@ -2137,11 +2137,11 @@ namespace monero {
shared_ptr<monero_outgoing_transfer> out_transfer = make_shared<monero_outgoing_transfer>();
tx->m_outgoing_transfer = out_transfer;
out_transfer->m_amount = *tx_amounts_iter;
shared_ptr<monero_destination> destination = make_shared<monero_destination>(request.m_destinations[0]->m_address.get(), out_transfer->m_amount.get());
shared_ptr<monero_destination> destination = make_shared<monero_destination>(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<uint64_t>(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<cryptonote::tx_destination_entry> dsts;
std::vector<uint8_t> extra;
std::list<wallet_rpc::transfer_destination> 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<wallet2::pending_tx> 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<string> 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<uint64_t>(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_send_request> monero_wallet_core::parse_payment_uri(const string& uri) const {
shared_ptr<monero_tx_config> 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<monero_send_request> send_request = make_shared<monero_send_request>();
// initialize config
shared_ptr<monero_tx_config> config = make_shared<monero_tx_config>();
shared_ptr<monero_destination> destination = make_shared<monero_destination>();
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 {
+11 -11
View File
@@ -229,20 +229,20 @@ namespace monero {
int import_outputs_hex(const string& outputs_hex);
vector<shared_ptr<monero_key_image>> get_key_images() const;
shared_ptr<monero_key_image_import_result> import_key_images(const vector<shared_ptr<monero_key_image>>& 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<string> relay_txs(const vector<string>& tx_metadatas);
vector<string> relay_txs(const vector<shared_ptr<monero_tx_wallet>>& 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<monero_tx_set> 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<monero_tx_set> 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<monero_send_request> parse_payment_uri(const string& uri) const;
string create_payment_uri(const monero_tx_config& config) const;
shared_ptr<monero_tx_config> 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<uint64_t> num_threads, boost::optional<bool> background_mining, boost::optional<bool> ignore_battery);
@@ -302,7 +302,7 @@ namespace monero {
void init_common();
vector<monero_subaddress> get_subaddresses_aux(uint32_t account_idx, const vector<uint32_t>& subaddress_indices, const vector<tools::wallet2::transfer_details>& 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<bool> m_is_synced; // whether or not wallet is synced
+44 -44
View File
@@ -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<monero_destination>& 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<monero_destination>& destination : config.m_destinations) {
m_destinations.push_back(destination->copy(destination, make_shared<monero_destination>()));
}
}
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> monero_send_request::deserialize(const string& send_request_json) {
shared_ptr<monero_tx_config> 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<monero_send_request> send_request = make_shared<monero_send_request>();
// convert config property tree to monero_tx_config
shared_ptr<monero_tx_config> config = make_shared<monero_tx_config>();
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<monero_destination> destination = make_shared<monero_destination>();
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<uint32_t>();
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<uint32_t>();
else if (key == string("fee")) send_request->m_fee = it->second.get_value<uint64_t>();
else if (key == string("accountIndex")) send_request->m_account_index = it->second.get_value<uint32_t>();
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<uint32_t>());
else if (key == string("unlockTime")) send_request->m_unlock_time = it->second.get_value<uint64_t>();
else if (key == string("canSplit")) send_request->m_can_split = it->second.get_value<bool>();
else if (key == string("doNotRelay")) send_request->m_do_not_relay = it->second.get_value<bool>();
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<uint64_t>();
else if (key == string("sweepEachSubaddress")) send_request->m_sweep_each_subaddress = it->second.get_value<bool>();
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<uint32_t>();
else if (key == string("fee")) config->m_fee = it->second.get_value<uint64_t>();
else if (key == string("accountIndex")) config->m_account_index = it->second.get_value<uint32_t>();
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<uint32_t>());
else if (key == string("unlockTime")) config->m_unlock_time = it->second.get_value<uint64_t>();
else if (key == string("canSplit")) config->m_can_split = it->second.get_value<bool>();
else if (key == string("doNotRelay")) config->m_do_not_relay = it->second.get_value<bool>();
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<uint64_t>();
else if (key == string("sweepEachSubaddress")) config->m_sweep_each_subaddress = it->second.get_value<bool>();
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 -------------------------
+8 -8
View File
@@ -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<shared_ptr<monero_destination>> m_destinations;
boost::optional<string> m_payment_id;
boost::optional<monero_send_priority> m_priority;
boost::optional<monero_tx_priority> m_priority;
boost::optional<uint32_t> m_ring_size;
boost::optional<uint64_t> m_fee;
boost::optional<uint32_t> m_account_index;
@@ -355,11 +355,11 @@ namespace monero {
boost::optional<bool> m_sweep_each_subaddress;
boost::optional<string> 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<monero_send_request> deserialize(const string& send_request_json);
monero_send_request copy() const;
static shared_ptr<monero_tx_config> deserialize(const string& config_json);
monero_tx_config copy() const;
};
/**
+8 -8
View File
@@ -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<uint32_t>();
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<uint32_t>();
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<shared_ptr<monero_destination>> destinations; // specify the recipients and their amounts
destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(1, 0), 50000));
destinations.push_back(make_shared<monero_destination>(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<monero_tx_wallet> created_tx = wallet_restored->create_tx(send_request).m_txs[0];
shared_ptr<monero_tx_wallet> 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
-21
View File
@@ -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<monero_transfer_request> transfer_request = shared_ptr<monero_transfer_request>(new monero_transfer_request());
// transfer_request->account_index = 0;
// shared_ptr<monero_tx_request> tx_request = shared_ptr<monero_tx_request>(new monero_tx_request());
// tx_request->is_confirmed = true;
// transfer_request->tx_request = tx_request;
// //tx_request->transfer_request = transfer_request;
// vector<shared_ptr<monero_transfer>> transfers = wallet->get_transfers(*transfer_request);
// if (transfers.empty()) throw runtime_error("Transfers should not be empty");
// for (const shared_ptr<monero_transfer>& 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<monero_tx_request> tx_request = shared_ptr<monero_tx_request>(new monero_tx_request());
// tx_request->is_confirmed = true;
// vector<shared_ptr<monero_tx_wallet>> txs = wallet->get_txs(*tx_request);
// if (txs.empty()) throw runtime_error("Txs should not be empty");
// for (const shared_ptr<monero_tx_wallet>& tx : txs) {
// if (!*tx->is_confirmed) throw runtime_error("Tx should be confirmed");
// }
}