aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet_rpc_server.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-04-19 21:20:27 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-04-19 21:20:27 +0100
commitb0850a9beacb3d6d89003ac38d46e859c45124c6 (patch)
tree4c20f3075cf2300b085de14d11a69ce52e3b2671 /src/wallet/wallet_rpc_server.cpp
parentMerge pull request #803 (diff)
downloadmonero-b0850a9beacb3d6d89003ac38d46e859c45124c6.tar.xz
wallet: add a new sweep_all command and RPC command
This sends all outputs in a wallet to a given address, alleviating the difficulty people have had trying to send all monero but being left with some small amount left.
Diffstat (limited to '')
-rw-r--r--src/wallet/wallet_rpc_server.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 6897c3d45..b01ac2f1e 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -382,6 +382,65 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_sweep_all(const wallet_rpc::COMMAND_RPC_SWEEP_ALL::request& req, wallet_rpc::COMMAND_RPC_SWEEP_ALL::response& res, epee::json_rpc::error& er)
+ {
+ std::vector<cryptonote::tx_destination_entry> dsts;
+ std::vector<uint8_t> extra;
+
+ if (m_wallet.restricted())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_DENIED;
+ er.message = "Command unavailable in restricted mode.";
+ return false;
+ }
+
+ // 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 = req.address;
+ if (!validate_transfer(destination, req.payment_id, dsts, extra, er))
+ {
+ return false;
+ }
+
+ try
+ {
+ std::vector<wallet2::pending_tx> ptx_vector = m_wallet.create_transactions_all(dsts[0].addr, req.mixin, req.unlock_time, req.fee, extra, req.trusted_daemon);
+
+ m_wallet.commit_tx(ptx_vector);
+
+ // populate response with tx hashes
+ for (auto & ptx : ptx_vector)
+ {
+ res.tx_hash_list.push_back(boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx.tx)));
+ if (req.get_tx_keys)
+ res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key));
+ }
+
+ return true;
+ }
+ catch (const tools::error::daemon_busy& e)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY;
+ er.message = e.what();
+ return false;
+ }
+ catch (const std::exception& e)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR;
+ er.message = e.what();
+ return false;
+ }
+ catch (...)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR";
+ return false;
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_make_integrated_address(const wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er)
{
try