wallet: handle 0 change properly
With RCT, we allow 0 size outputs, to try and encourage txes with two inputs and two outputs. Consolidation would then have two non zero inputs, one zero output, and one larger output.
This commit is contained in:
parent
e81a2b2cfa
commit
07d353dfc6
|
@ -228,6 +228,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int num_vouts_received = 0;
|
||||||
tx_pub_key = pub_key_field.pub_key;
|
tx_pub_key = pub_key_field.pub_key;
|
||||||
bool r = true;
|
bool r = true;
|
||||||
std::deque<cryptonote::keypair> in_ephemeral(tx.vout.size());
|
std::deque<cryptonote::keypair> in_ephemeral(tx.vout.size());
|
||||||
|
@ -262,6 +263,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
||||||
money_transfered = tools::decodeRct(tx.rct_signatures, rct::sk2rct(in_ephemeral[0].sec), 0, mask[0]);
|
money_transfered = tools::decodeRct(tx.rct_signatures, rct::sk2rct(in_ephemeral[0].sec), 0, mask[0]);
|
||||||
amount[0] = money_transfered;
|
amount[0] = money_transfered;
|
||||||
tx_money_got_in_outs = money_transfered;
|
tx_money_got_in_outs = money_transfered;
|
||||||
|
++num_vouts_received;
|
||||||
|
|
||||||
// process the other outs from that tx
|
// process the other outs from that tx
|
||||||
boost::asio::io_service ioservice;
|
boost::asio::io_service ioservice;
|
||||||
|
@ -301,6 +303,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
||||||
money_transfered[i] = tools::decodeRct(tx.rct_signatures, rct::sk2rct(in_ephemeral[i].sec), i, mask[i]);
|
money_transfered[i] = tools::decodeRct(tx.rct_signatures, rct::sk2rct(in_ephemeral[i].sec), i, mask[i]);
|
||||||
tx_money_got_in_outs += money_transfered[i];
|
tx_money_got_in_outs += money_transfered[i];
|
||||||
amount[i] = money_transfered[i];
|
amount[i] = money_transfered[i];
|
||||||
|
++num_vouts_received;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,6 +348,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
||||||
money_transfered[i] = tools::decodeRct(tx.rct_signatures, rct::sk2rct(in_ephemeral[i].sec), i, mask[i]);
|
money_transfered[i] = tools::decodeRct(tx.rct_signatures, rct::sk2rct(in_ephemeral[i].sec), i, mask[i]);
|
||||||
tx_money_got_in_outs += money_transfered[i];
|
tx_money_got_in_outs += money_transfered[i];
|
||||||
amount[i] = money_transfered[i];
|
amount[i] = money_transfered[i];
|
||||||
|
++num_vouts_received;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,13 +377,14 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
||||||
money_transfered = tools::decodeRct(tx.rct_signatures, rct::sk2rct(in_ephemeral[i].sec), i, mask[i]);
|
money_transfered = tools::decodeRct(tx.rct_signatures, rct::sk2rct(in_ephemeral[i].sec), i, mask[i]);
|
||||||
amount[i] = money_transfered;
|
amount[i] = money_transfered;
|
||||||
tx_money_got_in_outs += money_transfered;
|
tx_money_got_in_outs += money_transfered;
|
||||||
|
++num_vouts_received;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys());
|
THROW_WALLET_EXCEPTION_IF(!r, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys());
|
||||||
|
|
||||||
if(!outs.empty() && tx_money_got_in_outs)
|
if(!outs.empty() && num_vouts_received > 0)
|
||||||
{
|
{
|
||||||
//good news - got money! take care about it
|
//good news - got money! take care about it
|
||||||
//usually we have only one transfer for user in transaction
|
//usually we have only one transfer for user in transaction
|
||||||
|
@ -2969,12 +2974,8 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
|
||||||
}
|
}
|
||||||
|
|
||||||
cryptonote::tx_destination_entry change_dts = AUTO_VAL_INIT(change_dts);
|
cryptonote::tx_destination_entry change_dts = AUTO_VAL_INIT(change_dts);
|
||||||
if (needed_money < found_money)
|
change_dts.addr = m_account.get_keys().m_account_address;
|
||||||
{
|
change_dts.amount = found_money - needed_money; // may be 0, we allow 0 change
|
||||||
change_dts.addr = m_account.get_keys().m_account_address;
|
|
||||||
change_dts.amount = found_money - needed_money;
|
|
||||||
}
|
|
||||||
|
|
||||||
dsts.push_back(change_dts);
|
dsts.push_back(change_dts);
|
||||||
|
|
||||||
crypto::secret_key tx_key;
|
crypto::secret_key tx_key;
|
||||||
|
|
Loading…
Reference in New Issue