change empty_address_count break, don't stop input_selection with dust
@@ -295,9 +295,9 @@ impl<'a> ClientMessageBuilder<'a> {
}
}
None => {
- 'input_selection: loop {
// Reset the empty_address_count for each run of output address searching
let mut empty_address_count: u64 = 0;
+ 'input_selection: loop {
// Get the addresses in the BIP path/index ~ path/index+20
let addresses = self
.client
@@ -326,6 +326,9 @@ impl<'a> ClientMessageBuilder<'a> {
if outputs.is_empty() {
// Accumulate the empty_address_count for each run of output address searching
empty_address_count += 1;
+ } else {
+ // Reset counter if there is an output
+ empty_address_count += 0;
}
for (_offset, output) in outputs.into_iter().enumerate() {
let (output_amount, output_address, check_treshold) =
@@ -336,8 +339,7 @@ impl<'a> ClientMessageBuilder<'a> {
if output.is_spent {
return Err(Error::SpentOutput);
- } else {
- if total_already_spent < total_to_spend {
+ } else if total_already_spent < total_to_spend {
total_already_spent += output_amount;
let address_index_record = ClientMessageBuilder::create_address_index_recorder(
account_index,
@@ -367,8 +369,10 @@ impl<'a> ClientMessageBuilder<'a> {
}
}
}
- }
- if total_already_spent >= total_to_spend {
+ // Break if we have enough funds and don't create dust for the remainder
+ if total_already_spent == total_to_spend
+ || total_already_spent as i64 - total_to_spend as i64 >= DUST_THRESHOLD as i64
+ {
break 'input_selection;
}
// if we just processed an even index, increase the address index
