Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unconfirmed balance, accurately report fees #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,23 +920,30 @@ bool simple_wallet::transfer(const std::vector<std::string> &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;

//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
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
<< "Balance: " << print_money(balance()) << ENDL
<< "Unlocked: " << print_money(unlocked_balance()) << ENDL
<< "Please, wait for confirmation for your balance to be unlocked.");
Expand Down
9 changes: 7 additions & 2 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,15 @@ namespace tools
return true;
});
THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx);

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;

ptx.key_images = key_images;
ptx.fee = fee;
ptx.dust = dust;
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;
Expand Down