aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-11-11 12:35:04 +0200
committerRiccardo Spagni <ric@spagni.net>2016-11-11 12:35:04 +0200
commit0e0bf432a40b20e85538177bbf0d1527a9e96474 (patch)
tree2ea4e06a8222680d3691d2c4249d1ff0ea217c99 /src
parentMerge pull request #1263 (diff)
parentwallet2_api: support for sweeping all (diff)
downloadmonero-0e0bf432a40b20e85538177bbf0d1527a9e96474.tar.xz
Merge pull request #1313
1669621 wallet2_api: support for sweeping all (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/wallet/api/wallet.cpp26
-rw-r--r--src/wallet/api/wallet.h2
-rw-r--r--src/wallet/wallet2_api.h16
3 files changed, 33 insertions, 11 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 6c1c1fea2..d00a8c462 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -540,15 +540,14 @@ int WalletImpl::autoRefreshInterval() const
// - unconfirmed_transfer_details;
// - confirmed_transfer_details)
-PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, const string &payment_id, uint64_t amount, uint32_t mixin_count,
+PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, const string &payment_id, optional<uint64_t> amount, uint32_t mixin_count,
PendingTransaction::Priority priority)
{
clearStatus();
// Pause refresh thread while creating transaction
pauseRefresh();
- vector<cryptonote::tx_destination_entry> dsts;
- cryptonote::tx_destination_entry de;
+ cryptonote::account_public_address addr;
// indicates if dst_addr is integrated address (address + payment_id)
bool has_payment_id;
@@ -561,7 +560,7 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, const
PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);
do {
- if(!cryptonote::get_account_integrated_address_from_str(de.addr, has_payment_id, payment_id_short, m_wallet->testnet(), dst_addr)) {
+ if(!cryptonote::get_account_integrated_address_from_str(addr, has_payment_id, payment_id_short, m_wallet->testnet(), dst_addr)) {
// TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982
m_status = Status_Error;
m_errorString = "Invalid destination address";
@@ -595,14 +594,23 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, const
}
}
- de.amount = amount;
- dsts.push_back(de);
//std::vector<tools::wallet2::pending_tx> ptx_vector;
try {
- transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */,
- static_cast<uint32_t>(priority),
- extra, m_trustedDaemon);
+ if (amount) {
+ vector<cryptonote::tx_destination_entry> dsts;
+ cryptonote::tx_destination_entry de;
+ de.addr = addr;
+ de.amount = *amount;
+ dsts.push_back(de);
+ transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */,
+ static_cast<uint32_t>(priority),
+ extra, m_trustedDaemon);
+ } else {
+ transaction->m_pending_tx = m_wallet->create_transactions_all(addr, fake_outs_count, 0 /* unlock_time */,
+ static_cast<uint32_t>(priority),
+ extra, m_trustedDaemon);
+ }
} catch (const tools::error::daemon_busy&) {
// TODO: make it translatable with "tr"?
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index f40551fac..e447879de 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -89,7 +89,7 @@ public:
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
- uint64_t amount, uint32_t mixin_count,
+ optional<uint64_t> amount, uint32_t mixin_count,
PendingTransaction::Priority priority = PendingTransaction::Priority_Low);
virtual PendingTransaction * createSweepUnmixableTransaction();
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index f0a9ea68b..6fe15d1e3 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -41,6 +41,20 @@ namespace Bitmonero {
namespace Utils {
bool isAddressLocal(const std::string &hostaddr);
}
+
+ template<typename T>
+ class optional {
+ public:
+ optional(): set(false) {}
+ optional(const T &t): t(t), set(true) {}
+ const T &operator*() const { return t; }
+ T &operator*() { return t; }
+ operator bool() const { return set; }
+ private:
+ T t;
+ bool set;
+ };
+
/**
* @brief Transaction-like interface for sending money
*/
@@ -332,7 +346,7 @@ struct Wallet
*/
virtual PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
- uint64_t amount, uint32_t mixin_count,
+ optional<uint64_t> amount, uint32_t mixin_count,
PendingTransaction::Priority = PendingTransaction::Priority_Low) = 0;
/*!