From 627d9ba2e12f528ed0d00dcdf5e44871fa28eceb Mon Sep 17 00:00:00 2001 From: AwfulCrawler Date: Sun, 10 Apr 2016 17:31:07 +1200 Subject: [PATCH 1/5] confirmation message changes -Always confirm (just my preference) -Confirmation message more verbose, takes into account dust added to fee and dust sent elsewhere (depending on dust policy) --- src/simplewallet/simplewallet.cpp | 37 ++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index d5f9ab22..70516c93 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -920,23 +920,30 @@ bool simple_wallet::transfer(const std::vector &args_) // figure out what tx will be necessary auto ptx_vector = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, DEFAULT_FEE, extra); - // if more than one tx necessary, prompt user to confirm - if (ptx_vector.size() > 1) + uint64_t total_fee = 0; + uint64_t total_dust = 0; + for (size_t n = 0; n < ptx_vector.size(); ++n) { - std::string prompt_str = "Your transaction needs to be split into "; - prompt_str += std::to_string(ptx_vector.size()); - prompt_str += " transactions. This will result in a fee of "; - prompt_str += print_money(ptx_vector.size() * DEFAULT_FEE); - prompt_str += ". Is this okay? (Y/Yes/N/No)"; - std::string accepted = command_line::input_line(prompt_str); - if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes") - { - fail_msg_writer() << "Transaction cancelled."; + total_fee += ptx_vector[n].fee; + total_dust += ptx_vector[n].dust; + } + + uint64_t dust_in_fee = total_fee - ptx_vector.size()*DEFAULT_FEE; + + //AC: Always confirm + std::string prompt_str = "Your transaction needs to be split into " + std::to_string(ptx_vector.size()) + " transactions.\n" + + "This will result in a fee of " + print_money(total_fee); + if (dust_in_fee != 0) prompt_str += " of which " + print_money(dust_in_fee) + " is dust from change"; + if (total_dust != 0) prompt_str += ".\nA total of " + print_money(total_dust) + " dust from change will be sent to dust address"; + prompt_str += ".\nIs this okay? (Y/Yes/N/No)"; + std::string accepted = command_line::input_line(prompt_str); + if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes") + { + fail_msg_writer() << "Transaction cancelled."; - // would like to return false, because no tx made, but everything else returns true - // and I don't know what returning false might adversely affect. *sigh* - return true; - } + // would like to return false, because no tx made, but everything else returns true + // and I don't know what returning false might adversely affect. *sigh* + return true; } // actually commit the transactions From 71600729e7efc741d78376140b3dfe464167f467 Mon Sep 17 00:00:00 2001 From: AwfulCrawler Date: Sun, 10 Apr 2016 17:35:49 +1200 Subject: [PATCH 2/5] fix unconfirmed balance -While transaction is unconfirmed wallet was returning incorrect balance. -Fixed by subtracting the dust added to fee or sent elsewhere from the change amount -Add dust added to fee to the ptx. -ptx.dust is now zero if dust is added to fee or included in change. Only non-zero when sent elsewhere. --- src/wallet/wallet2.cpp | 2 +- src/wallet/wallet2.h | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 92ba2099..e8239dd9 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -813,7 +813,7 @@ void wallet2::commit_tx(pending_tx& ptx) it->m_spent = true; LOG_PRINT_L0("Transaction successfully sent. <" << get_transaction_hash(ptx.tx) << ">" << ENDL - << "Commission: " << print_money(ptx.fee+ptx.dust) << " (dust: " << print_money(ptx.dust) << ")" << ENDL + << "Commission: " << print_money(ptx.fee) << " (dust: " << print_money(ptx.dust) << ")" << ENDL //AC: ptx.fee includes fee-dust. dust now lists dust sent elsewhere. Not fee or change dust. << "Balance: " << print_money(balance()) << ENDL << "Unlocked: " << print_money(unlocked_balance()) << ENDL << "Please, wait for confirmation for your balance to be unlocked."); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 855ec2ef..3689af73 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -472,10 +472,17 @@ namespace tools return true; }); THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx); + + //AC + + bool dust_sent_elsewhere = (dust_policy.addr_for_dust.m_spend_public_key != change_dts.addr.m_spend_public_key + || dust_policy.addr_for_dust.m_view_public_key != change_dts.addr.m_view_public_key); + + if (dust_policy.add_to_fee || dust_sent_elsewhere ) change_dts.amount -= dust; //AC ptx.key_images = key_images; - ptx.fee = fee; - ptx.dust = dust; + ptx.fee = (dust_policy.add_to_fee ? fee + dust : fee); //AC + ptx.dust = ((!dust_policy.add_to_fee && dust_sent_elsewhere) ? dust : 0); //AC: Only record dust amount if it wasn't included in the fee or the change. ptx.tx = tx; ptx.change_dts = change_dts; ptx.selected_transfers = selected_transfers; From c3a6f034150d0c87872a9857f01ba543190fb369 Mon Sep 17 00:00:00 2001 From: AwfulCrawler Date: Sun, 10 Apr 2016 17:44:26 +1200 Subject: [PATCH 3/5] Remove working comment Removing note to self --- src/wallet/wallet2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index e8239dd9..108fde45 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -813,7 +813,7 @@ void wallet2::commit_tx(pending_tx& ptx) it->m_spent = true; LOG_PRINT_L0("Transaction successfully sent. <" << get_transaction_hash(ptx.tx) << ">" << ENDL - << "Commission: " << print_money(ptx.fee) << " (dust: " << print_money(ptx.dust) << ")" << ENDL //AC: ptx.fee includes fee-dust. dust now lists dust sent elsewhere. Not fee or change dust. + << "Commission: " << print_money(ptx.fee) << " (dust: " << print_money(ptx.dust) << ")" << ENDL << "Balance: " << print_money(balance()) << ENDL << "Unlocked: " << print_money(unlocked_balance()) << ENDL << "Please, wait for confirmation for your balance to be unlocked."); From e4ce71aa37b296e9bc3aa7cda24eaa2704e72529 Mon Sep 17 00:00:00 2001 From: AwfulCrawler Date: Sun, 10 Apr 2016 17:45:30 +1200 Subject: [PATCH 4/5] Remove working comments Removing notes to self --- src/wallet/wallet2.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 3689af73..c8a3868a 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -473,16 +473,14 @@ namespace tools }); THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx); - //AC - bool dust_sent_elsewhere = (dust_policy.addr_for_dust.m_spend_public_key != change_dts.addr.m_spend_public_key || dust_policy.addr_for_dust.m_view_public_key != change_dts.addr.m_view_public_key); - if (dust_policy.add_to_fee || dust_sent_elsewhere ) change_dts.amount -= dust; //AC + if (dust_policy.add_to_fee || dust_sent_elsewhere ) change_dts.amount -= dust; ptx.key_images = key_images; - ptx.fee = (dust_policy.add_to_fee ? fee + dust : fee); //AC - ptx.dust = ((!dust_policy.add_to_fee && dust_sent_elsewhere) ? dust : 0); //AC: Only record dust amount if it wasn't included in the fee or the change. + ptx.fee = (dust_policy.add_to_fee ? fee + dust : fee); + ptx.dust = ((!dust_policy.add_to_fee && dust_sent_elsewhere) ? dust : 0); ptx.tx = tx; ptx.change_dts = change_dts; ptx.selected_transfers = selected_transfers; From b57161ce8e040920ee7ef39f08fe2ae5c9c08eb0 Mon Sep 17 00:00:00 2001 From: AwfulCrawler Date: Sun, 10 Apr 2016 17:46:30 +1200 Subject: [PATCH 5/5] Tweak a comment --- src/simplewallet/simplewallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 70516c93..d862594e 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -930,7 +930,7 @@ bool simple_wallet::transfer(const std::vector &args_) uint64_t dust_in_fee = total_fee - ptx_vector.size()*DEFAULT_FEE; - //AC: Always confirm + //Always confirm std::string prompt_str = "Your transaction needs to be split into " + std::to_string(ptx_vector.size()) + " transactions.\n" + "This will result in a fee of " + print_money(total_fee); if (dust_in_fee != 0) prompt_str += " of which " + print_money(dust_in_fee) + " is dust from change";