@@ -555,14 +555,20 @@ namespace sdk {
555
555
556
556
// Add all outputs and compute the total amount of satoshi to be sent
557
557
amount required_total{ 0 };
558
+ uint32_t greedy_index = NO_CHANGE_INDEX;
558
559
559
560
if (num_addressees) {
561
+ int addressee_index = 0 ;
560
562
for (auto & addressee : *addressees_p) {
561
563
const auto addressee_asset_id = asset_id_from_json (net_params, addressee);
562
564
if (addressee_asset_id == asset_id) {
563
565
required_total += add_tx_addressee (session, net_params, result, tx, addressee);
564
566
reordered_addressees.push_back (addressee);
567
+ if (addressee.value (" greedy" , false )) {
568
+ greedy_index = addressee_index;
569
+ }
565
570
}
571
+ ++addressee_index;
566
572
}
567
573
}
568
574
@@ -730,6 +736,14 @@ namespace sdk {
730
736
731
737
change = total - required_with_fee;
732
738
739
+ // If a 'greedy' addressee exists send change there
740
+ if (change > 0 && greedy_index != NO_CHANGE_INDEX) {
741
+ set_tx_output_value (net_params, tx, greedy_index, asset_id, change.value ());
742
+ addressees_p->at (greedy_index)[" satoshi" ] = change.value ();
743
+ required_total += change;
744
+ continue ;
745
+ }
746
+
733
747
if ((!have_change_output && change < dust_threshold)
734
748
|| (have_change_output && change >= dust_threshold)) {
735
749
// We don't have a change output, and have only dust left over, or
0 commit comments