move-only: asyncOp_sendmany, target amount calculation moved before find inputs (utxos and notes).

This commit is contained in:
furszy 2020-11-01 11:11:02 -03:00
parent 88eef56581
commit a9f3315872
No known key found for this signature in database
GPG Key ID: 5DD23CCC686AA623
1 changed files with 14 additions and 13 deletions

View File

@ -211,6 +211,20 @@ bool AsyncRPCOperation_sendmany::main_impl() {
bool isPureTaddrOnlyTx = (isfromtaddr_ && z_outputs_.size() == 0);
CAmount minersFee = fee_;
// First calculate the target
CAmount t_outputs_total = 0;
for (SendManyRecipient & t : t_outputs_) {
t_outputs_total += t.amount;
}
CAmount z_outputs_total = 0;
for (SendManyRecipient & t : z_outputs_) {
z_outputs_total += t.amount;
}
CAmount sendAmount = z_outputs_total + t_outputs_total;
CAmount targetAmount = sendAmount + minersFee;
// When spending coinbase utxos, you can only specify a single zaddr as the change must go somewhere
// and if there are multiple zaddrs, we don't know where to send it.
if (isfromtaddr_) {
@ -252,19 +266,6 @@ bool AsyncRPCOperation_sendmany::main_impl() {
z_inputs_total += t.note.value();
}
CAmount t_outputs_total = 0;
for (SendManyRecipient & t : t_outputs_) {
t_outputs_total += t.amount;
}
CAmount z_outputs_total = 0;
for (SendManyRecipient & t : z_outputs_) {
z_outputs_total += t.amount;
}
CAmount sendAmount = z_outputs_total + t_outputs_total;
CAmount targetAmount = sendAmount + minersFee;
assert(!isfromtaddr_ || z_inputs_total == 0);
assert(!isfromzaddr_ || t_inputs_total == 0);