From 3a4a49da782800f5768fa59b0b96b4f690b7b2e1 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 17 Dec 2019 12:23:38 +0300 Subject: [PATCH] simplewallet sweep_below bugfixing --- src/simplewallet/simplewallet.cpp | 9 +++++++-- src/wallet/wallet2.cpp | 5 +++-- src/wallet/wallet2.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 0db65b72..6cde72fc 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1594,13 +1594,18 @@ bool simple_wallet::sweep_below(const std::vector &args) size_t outs_total = 0, outs_swept = 0; uint64_t amount_total = 0, amount_swept = 0; currency::transaction result_tx = AUTO_VAL_INIT(result_tx); - m_wallet->sweep_below(fake_outs_count, addr, amount, payment_id, fee, outs_total, amount_total, outs_swept, &result_tx); + std::string filename = "zano_tx_unsigned"; + m_wallet->sweep_below(fake_outs_count, addr, amount, payment_id, fee, outs_total, amount_total, outs_swept, &result_tx, &filename); if (!get_inputs_money_amount(result_tx, amount_swept)) LOG_ERROR("get_inputs_money_amount failed, tx: " << obj_to_json_str(result_tx)); success_msg_writer(false) << outs_swept << " outputs (" << print_money_brief(amount_swept) << " coins) of " << outs_total << " total (" << print_money_brief(amount_total) << ") below the specified limit of " << print_money_brief(amount) << " were successfully swept"; - success_msg_writer(true) << "tx: " << get_transaction_hash(result_tx) << " size: " << get_object_blobsize(result_tx) << " bytes"; + + if (m_wallet->is_watch_only()) + success_msg_writer(true) << "Transaction prepared for signing and saved into \"" << filename << "\" file, use full wallet to sign transfer and then use \"submit_transfer\" on this wallet to broadcast the transaction to the network"; + else + success_msg_writer(true) << "tx: " << get_transaction_hash(result_tx) << " size: " << get_object_blobsize(result_tx) << " bytes"; } catch (const std::exception& e) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 2a15d019..23401463 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4395,7 +4395,7 @@ void wallet2::transfer(const construct_tx_param& ctp, } //---------------------------------------------------------------------------------------------------- void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public_address& destination_addr, uint64_t threshold_amount, const currency::payment_id_t& payment_id, - uint64_t fee, size_t& outs_total, uint64_t& amount_total, size_t& outs_swept, currency::transaction* p_result_tx /* = nullptr */) + uint64_t fee, size_t& outs_total, uint64_t& amount_total, size_t& outs_swept, currency::transaction* p_result_tx /* = nullptr */, std::string* p_filename_or_unsigned_tx_blob_str /* = nullptr */) { static const size_t estimated_bytes_per_input = 78; const size_t estimated_max_inputs = static_cast(CURRENCY_MAX_TRANSACTION_BLOB_SIZE / (estimated_bytes_per_input * (fake_outs_count + 1.5))); // estimated number of maximum tx inputs under the tx size limit @@ -4624,7 +4624,8 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public if (m_watch_only) { - bool r = store_unsigned_tx_to_file_and_reserve_transfers(ftp, "zano_tx_unsigned"); + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(p_filename_or_unsigned_tx_blob_str != nullptr, "p_filename_or_unsigned_tx_blob_str is null"); + bool r = store_unsigned_tx_to_file_and_reserve_transfers(ftp, *p_filename_or_unsigned_tx_blob_str, p_filename_or_unsigned_tx_blob_str); WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(r, "failed to store unsigned tx"); return; } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 458653e2..e03c8d55 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -623,7 +623,7 @@ namespace tools void submit_transfer_files(const std::string& signed_tx_file, currency::transaction& tx); void sweep_below(size_t fake_outs_count, const currency::account_public_address& destination_addr, uint64_t threshold_amount, const currency::payment_id_t& payment_id, - uint64_t fee, size_t& outs_total, uint64_t& amount_total, size_t& outs_swept, currency::transaction* p_result_tx = nullptr); + uint64_t fee, size_t& outs_total, uint64_t& amount_total, size_t& outs_swept, currency::transaction* p_result_tx = nullptr, std::string* p_filename_or_unsigned_tx_blob_str = nullptr); bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id); uint64_t get_blockchain_current_height() const { return m_blockchain.size(); }