From 493a3beb17dc9c436855f7483a1376f1de49d9c5 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 9 Aug 2019 14:04:32 -0400 Subject: [PATCH] monero_destination(address, amount) constructor; sample_code compiling; some convenience send methods impl --- src/wallet/monero_wallet.cpp | 28 ++++++++++++++++++++++------ src/wallet/monero_wallet.h | 28 +++++++++++++++++++++++----- src/wallet/monero_wallet_model.h | 2 ++ test/sample_code.cpp | 4 ++-- todo.txt | 1 + 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/wallet/monero_wallet.cpp b/src/wallet/monero_wallet.cpp index 781e399..b509c6c 100644 --- a/src/wallet/monero_wallet.cpp +++ b/src/wallet/monero_wallet.cpp @@ -1694,24 +1694,36 @@ namespace monero { return result; } + shared_ptr monero_wallet::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)[0]; + } + shared_ptr monero_wallet::create_tx(uint32_t account_index, string address, uint64_t amount) { - throw new runtime_error("create_tx not implemented"); + return create_tx(account_index, address, amount, monero_send_priority::NORMAL); } shared_ptr monero_wallet::create_tx(int account_index, string address, uint64_t amount, monero_send_priority priority) { - throw new runtime_error("create_tx not implemented"); + 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); } - shared_ptr monero_wallet::create_tx(const monero_send_request& request) { - throw new runtime_error("create_tx not implemented"); + vector> monero_wallet::create_txs(const monero_send_request& request) { + throw new runtime_error("not implemented"); } string monero_wallet::relay_tx(const string& tx_metadata) { - throw new runtime_error("relay_tx not implemented"); + vector tx_metadatas; + tx_metadatas.push_back(tx_metadata); + return relay_txs(tx_metadatas)[0]; } string monero_wallet::relay_tx(const monero_tx_wallet& tx) { - throw new runtime_error("relay_tx not implemented"); + return relay_tx(tx.m_metadata.get()); } vector monero_wallet::relay_txs(const vector& tx_metadatas) { @@ -1756,6 +1768,10 @@ namespace monero { throw new runtime_error("relay_txs not implemented"); } + shared_ptr monero_wallet::send(monero_send_request& request) { + throw new runtime_error("send not implemented"); + } + shared_ptr monero_wallet::send(uint32_t account_index, string address, uint64_t amount) { throw new runtime_error("send not implemented"); } diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 1da1110..d55a6ba 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -745,6 +745,15 @@ namespace monero { // */ // public List getNewKeyImagesFromLastImport(); + /** + * Create a transaction to transfer funds from this wallet according to the + * given request. The transaction may be relayed later. + * + * @param request configures the transaction to create + * @return the created transaction + */ + shared_ptr create_tx(monero_send_request& request); + /** * Create a transaction to transfers funds from this wallet to a destination address. * The transaction may be relayed later. @@ -769,13 +778,13 @@ namespace monero { shared_ptr create_tx(int account_index, string address, uint64_t amount, monero_send_priority priority); /** - * Create a transaction to transfer funds from this wallet according to the - * given request. The transaction may be relayed later. + * Create one or more transactions to transfer funds from this wallet + * according to the given request. The transactions may later be relayed. * - * @param request configures the transaction to create - * @return the created transaction + * @param request configures the transactions to create + * @return the created transactions */ - shared_ptr create_tx(const monero_send_request& request); + vector> create_txs(const monero_send_request& request); /** * Relay a transaction previously created without relaying. @@ -809,6 +818,15 @@ namespace monero { */ vector relay_txs(const vector& txs); + /** + * Create and relay a transaction to transfer funds from this wallet + * according to the given request. + * + * @param request configures the transaction + * @return the resulting transaction + */ + shared_ptr send(monero_send_request& request); + /** * Create and relay a transaction to transfers funds from this wallet to * a destination address. diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index ea9218f..541df9b 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -135,6 +135,8 @@ namespace monero { boost::optional m_address; boost::optional m_amount; + monero_destination() {} + monero_destination(const string& address, uint64_t amount) : m_address(address), m_amount(amount) {} shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree to_property_tree() const; }; diff --git a/test/sample_code.cpp b/test/sample_code.cpp index bd92e00..dfad21c 100644 --- a/test/sample_code.cpp +++ b/test/sample_code.cpp @@ -95,8 +95,8 @@ int main(int argc, const char* argv[]) { 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 vector> destinations; // specify the recipients and their amounts -// destinations.push_back(make_shared(wallet_random->get_address(1, 0), 50000)); // TODO: destination constructor -// destinations.push_back(make_shared(wallet_random->get_address(2, 0), 50000)); + 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; // create the transaction, confirm with the user, and relay to the network diff --git a/todo.txt b/todo.txt index 8c4be6d..77a113e 100644 --- a/todo.txt +++ b/todo.txt @@ -5,6 +5,7 @@ sample code including readme monero_wallet_listener should be a class? MEDIUM PRIORITY +create_tx and send_tx request arg should be const; need to copy should not need wallet.h / wallet.cpp as dependency, why are GUI deps needed? make model fields private and use accessors / mutators? remove jstring2string, be consistent with other string inits